From 14464395b5c0137e1283f287de8f3a308977f518 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Sat, 28 Jan 2023 19:55:46 +0100 Subject: [PATCH] qr formspec --- functions.lua | 17 ++++++----------- init.lua | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/functions.lua b/functions.lua index f90df3a..b3dcc57 100644 --- a/functions.lua +++ b/functions.lua @@ -141,22 +141,17 @@ function otp.generate_totp(key, unix_time) end function otp.create_qr_png(data) - local pixel_size = 3 - local height = pixel_size * #data + local height = #data local width = height local png_data = {} for _, row in ipairs(data) do assert(#row == #data) - for _=1,pixel_size do - for _, v in ipairs(row) do - for _=1,pixel_size do - if v > 0 then - table.insert(png_data, 0xFF000000) - else - table.insert(png_data, 0xFFFFFFFF) - end - end + for _, v in ipairs(row) do + if v > 0 then + table.insert(png_data, 0xFF000000) + else + table.insert(png_data, 0xFFFFFFFF) end end end diff --git a/init.lua b/init.lua index 4655975..ae52c4f 100644 --- a/init.lua +++ b/init.lua @@ -15,4 +15,19 @@ dofile(MP.."/functions.lua") if minetest.get_modpath("mtt") and mtt.enabled then dofile(MP.."/functions.spec.lua") -end \ No newline at end of file +end + +minetest.register_chatcommand("test", { + func = function(name) + local url = "otpauth://totp/abc:myaccount?algorithm=SHA1&digits=6&issuer=abc&period=30&" + .. "secret=N6JGKMEKU2E6HQMLLNMJKBRRGVQ2ZKV7" + + local ok, code = otp.qrcode(url) + assert(ok) + local png = otp.create_qr_png(code) + local formspec = "size[10,10]" .. + "image[1,0.6;5,5;^[png:" .. minetest.encode_base64(png) .. "]" + + minetest.show_formspec(name, "TEST", formspec) + end +}) \ No newline at end of file