From 1e6d9e01b78980f7cb372038b6e328b3ca9f17ad Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Wed, 21 Jun 2017 18:02:21 -0400 Subject: [PATCH] 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. --- init.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 94abfd2..13adc79 100644 --- a/init.lua +++ b/init.lua @@ -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