]> git.lizzy.rs Git - minetest.git/blobdiff - builtin/game/auth.lua
Fix /grant & /revoke not working with custom auth handler (#4974)
[minetest.git] / builtin / game / auth.lua
index baeb0159c99227f307b53722bd1ebc11d66461e5..46fe3d342778c50e15dac1d681ac7929a543a45d 100644 (file)
@@ -7,7 +7,7 @@
 function core.string_to_privs(str, delim)
        assert(type(str) == "string")
        delim = delim or ','
-       privs = {}
+       local privs = {}
        for _, priv in pairs(string.split(str, delim)) do
                privs[priv:trim()] = true
        end
@@ -17,10 +17,10 @@ end
 function core.privs_to_string(privs, delim)
        assert(type(privs) == "table")
        delim = delim or ','
-       list = {}
+       local list = {}
        for priv, bool in pairs(privs) do
                if bool then
-                       table.insert(list, priv)
+                       list[#list + 1] = priv
                end
        end
        return table.concat(list, delim)
@@ -171,6 +171,7 @@ function core.register_authentication_handler(handler)
        end
        core.registered_auth_handler = handler
        core.registered_auth_handler_modname = core.get_current_modname()
+       handler.mod_origin = core.registered_auth_handler_modname
 end
 
 function core.get_auth_handler()
@@ -198,3 +199,19 @@ core.register_on_joinplayer(function(player)
        record_login(player:get_player_name())
 end)
 
+core.register_on_prejoinplayer(function(name, ip)
+       local auth = core.auth_table
+       if auth[name] ~= nil then
+               return
+       end
+
+       local name_lower = name:lower()
+       for k in pairs(auth) do
+               if k:lower() == name_lower then
+                       return string.format("\nCannot create new player called '%s'. "..
+                                       "Another account called '%s' is already registered. "..
+                                       "Please check the spelling if it's your account "..
+                                       "or use a different nickname.", name, k)
+               end
+       end
+end)