-- Authentication handler
--
-function core.string_to_privs(str, delim)
- assert(type(str) == "string")
- delim = delim or ','
- privs = {}
- for _, priv in pairs(string.split(str, delim)) do
- privs[priv:trim()] = true
- end
- return privs
-end
-
-function core.privs_to_string(privs, delim)
- assert(type(privs) == "table")
- delim = delim or ','
- list = {}
- for priv, bool in pairs(privs) do
- if bool then
- table.insert(list, priv)
- end
- end
- return table.concat(list, delim)
-end
-
-assert(core.string_to_privs("a,b").b == true)
-assert(core.privs_to_string({a=true,b=true}) == "a,b")
-
core.auth_file_path = core.get_worldpath().."/auth.txt"
core.auth_table = {}
end
end
-- For the admin, give everything
- elseif name == core.setting_get("name") then
+ elseif name == core.settings:get("name") then
for priv, def in pairs(core.registered_privileges) do
privileges[priv] = true
end
core.log('info', "Built-in authentication handler adding player '"..name.."'")
core.auth_table[name] = {
password = password,
- privileges = core.string_to_privs(core.setting_get("default_privs")),
+ privileges = core.string_to_privs(core.settings:get("default_privs")),
last_login = os.time(),
}
save_auth_file()
if not core.auth_table[name] then
core.builtin_auth_handler.create_auth(name,
core.get_password_hash(name,
- core.setting_get("default_password")))
+ core.settings:get("default_password")))
end
core.auth_table[name].privileges = privileges
core.notify_authentication_modified(name)
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()
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)