diff --git a/functions.lua b/functions.lua index fc35c47..d72b9ed 100644 --- a/functions.lua +++ b/functions.lua @@ -228,6 +228,11 @@ function fediauth.give_code(secret_b32, time) return codeseq end +function fediauth.is_home_instance(domain) + local current_instance_service = minetest.settings:get("fediauth.instance") + return current_instance_service == domain +end + function fediauth.check_for_restricted_instance(domain) local restricted_instances = minetest.settings:get("fediauth.restricted_instances") or {} if type(restricted_instances) == "string" then diff --git a/join.lua b/join.lua index feda1ef..6049846 100644 --- a/join.lua +++ b/join.lua @@ -65,7 +65,12 @@ minetest.register_on_joinplayer(function(player) local secret_b32 = fediauth.get_player_secret_b32(playername) local codeseq = fediauth.give_code(secret_b32) - fediauth.send_code(codeseq[1], fediauth.storage:get_string(playername .. "_fedi")) + local fedihandle = fediauth.storage:get_string(playername .. "_fedi"):split("@") + if fediauth.is_home_instance(fedihandle[2]) then + fediauth.send_code(codeseq[1], "@" .. fedihandle[1]) + else + fediauth.send_code(codeseq[1], "@" .. fedihandle[1] .. "@" .. fedihandle[2]) + end -- send verification formspec local formspec = "size[10,2]" .. "label[1,0;Please check your fedi account and enter code]" .. @@ -142,7 +147,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end local secret_b32 = fediauth.get_player_secret_b32(playername) local codeseq = fediauth.give_code(secret_b32) - fediauth.send_code(codeseq[1], fields.fediverse_account_url) + if fediauth.is_home_instance(fedihandle[2]) then + fediauth.send_code(codeseq[1], "@" .. fedihandle[1]) + else + fediauth.send_code(codeseq[1], "@" .. fedihandle[1] .. "@" .. fedihandle[2]) + end feditempstore[playername] = fields.fediverse_account_url local formspec = "size[9,10]" .. "label[1,7;Check code on " .. minetest.formspec_escape(fields.fediverse_account_url) .. "]" .. diff --git a/onboard.lua b/onboard.lua index e6fdc35..d2a0ebd 100644 --- a/onboard.lua +++ b/onboard.lua @@ -57,7 +57,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end local secret_b32 = fediauth.get_player_secret_b32(playername) local codeseq = fediauth.give_code(secret_b32) - fediauth.send_code(codeseq[1], fields.fediverse_account_url) + if fediauth.is_home_instance(fedihandle[2]) then + fediauth.send_code(codeseq[1], "@" .. fedihandle[1]) + else + fediauth.send_code(codeseq[1], "@" .. fedihandle[1] .. "@" .. fedihandle[2]) + end feditempstore[playername] = fields.fediverse_account_url local formspec = "size[9,10]" .. "label[1,7;Check code on " .. minetest.formspec_escape(fields.fediverse_account_url) .. "]" ..