Compare commits

2 Commits

Author SHA1 Message Date
87ed4ade88 Allow players that already exist
This prevents players from getting locked out due to a name policy
change or bug.
2017-06-21 18:17:41 -04:00
1e6d9e01b7 Strip whitespace-like characters from names before checking them for similarity
Previously, these characters whern't considered when checking for
conflicts, but they weren't removed -- meaning that a player named
"foo_" would prevent a player named "foo" from logging in, but not
the other way around.
2017-06-21 18:02:21 -04:00

View File

@ -18,6 +18,22 @@ exemptions[minetest.setting_get("name")] = true
exemptions["singleplayer"] = true exemptions["singleplayer"] = true
local function player_exempted(name)
-- Allow specifically exempted players
if exemptions[name] then
return true
end
-- Allow players that already exist
local auth = minetest.get_auth_handler()
if auth.get_auth(name) then
return true
end
return false
end
--------------------- ---------------------
-- Simple matching -- -- Simple matching --
--------------------- ---------------------
@ -35,7 +51,7 @@ local disallowed = {
} }
minetest.register_on_prejoinplayer(function(name, ip) minetest.register_on_prejoinplayer(function(name, ip)
if exemptions[name] then return end if player_exempted(name) then return end
-- Check for disallowed names -- Check for disallowed names
local lname = name:lower() local lname = name:lower()
@ -52,7 +68,7 @@ end)
------------------------ ------------------------
minetest.register_on_prejoinplayer(function(name, ip) minetest.register_on_prejoinplayer(function(name, ip)
if exemptions[name] then return end if player_exempted(name) then return end
-- Check for used names -- Check for used names
local lname = name:lower() local lname = name:lower()
@ -129,10 +145,16 @@ all_chars = all_chars .. "]"
minetest.register_on_prejoinplayer(function(name, ip) minetest.register_on_prejoinplayer(function(name, ip)
if exemptions[name] then return end if player_exempted(name) then return end
-- String off dashes and underscores from the start and end of the name.
local stripped_name = name:match("^[_-]*(.-)[_-]*$")
if not stripped_name or stripped_name == "" then
return "Your name is composed solely of whitespace-like characters."
end
-- Generate a regular expression to match all similar names -- Generate a regular expression to match all similar names
local re = name:gsub(all_chars, char_map) local re = stripped_name:gsub(all_chars, char_map)
re = "^[_-]*" .. re .. "[_-]*$" re = "^[_-]*" .. re .. "[_-]*$"
for authName, _ in pairs(minetest.auth_table) do for authName, _ in pairs(minetest.auth_table) do
@ -151,7 +173,7 @@ end)
local min_name_len = tonumber(minetest.setting_get("name_restrictions.minimum_name_length")) or 3 local min_name_len = tonumber(minetest.setting_get("name_restrictions.minimum_name_length")) or 3
minetest.register_on_prejoinplayer(function(name, ip) minetest.register_on_prejoinplayer(function(name, ip)
if exemptions[name] then return end if player_exempted(name) then return end
if #name < min_name_len then if #name < min_name_len then
return "Your player name is too short, please try a longer name." return "Your player name is too short, please try a longer name."
@ -214,7 +236,7 @@ end
local pronounceability = tonumber(minetest.setting_get("name_restrictions.pronounceability")) local pronounceability = tonumber(minetest.setting_get("name_restrictions.pronounceability"))
if pronounceability then if pronounceability then
minetest.register_on_prejoinplayer(function(name, ip) minetest.register_on_prejoinplayer(function(name, ip)
if exemptions[name] then return end if player_exempted(name) then return end
if not pronounceable(pronounceability, name) then if not pronounceable(pronounceability, name) then
return "Your player name does not seem to be pronounceable." return "Your player name does not seem to be pronounceable."