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.
This commit is contained in:
ShadowNinja 2017-06-21 18:02:21 -04:00
parent 75b96c7cf9
commit 1e6d9e01b7

View File

@ -131,8 +131,14 @@ all_chars = all_chars .. "]"
minetest.register_on_prejoinplayer(function(name, ip)
if exemptions[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
local re = name:gsub(all_chars, char_map)
local re = stripped_name:gsub(all_chars, char_map)
re = "^[_-]*" .. re .. "[_-]*$"
for authName, _ in pairs(minetest.auth_table) do