-- Descended from a name_restrictions mod originally by ShadowNinja -- License: WTFPL ---------------------------- -- Restriction exemptions -- ---------------------------- -- For legitimate player names that are caught by the filters. local exemptions = {} local temp = minetest.setting_get("name_exemptions") temp = temp and temp:split() or {} for _, allowed_name in pairs(temp) do exemptions[allowed_name] = true end temp = nil -- Exempt server owner exemptions[minetest.setting_get("name")] = true exemptions["singleplayer"] = true -- Exempt others exemptions["betterthanyou710"] = true exemptions["CaptainAmerica"] = true --------------------- -- Simple matching -- --------------------- local msg_not_allowed = "This name is not allowed" local disallowed = { [ "[Ff][Uu][Cc][Kk]" ] = msg_not_allowed , [ "[Cc][Uu][Nn][Tt]" ] = msg_not_allowed , [ "[Ss][Hh][Ii][Tt]" ] = msg_not_allowed , [ "[Pp][Oo][Oo][Pp]" ] = msg_not_allowed , [ "hot.*girl" ] = msg_not_allowed , [ "[^a-zA-Z0-9_%-]" ] = "Name contains characters not allowed" , [ "^-" ] = "Dash is not allowed at start of name" , [ "^[xX][xX]" ] = "Fewer X's please" , [ "[xX][xX]$" ] = "Fewer X's please" , [ "^guest[0-9]*" ] = "Guest accounts are not allowed" , [ "adm[1il]n" ] = "Misleading nickname" , [ "[0o]wn[e3]r" ] = "Misleading nickname" , [ "^[0-9]+$" ] = "All-number names are not allowed" , [ "^..............." ] = "Name is too long" , [ "%d%d%d%d%d" ] = "Name has too many numbers" , [ "[a-z]%d%d%d%d" ] = "Please remove some digits" , [ "^[Ss]adie%d%d" ] = "Please explain all the Sadies" , [ "[A-Z][a-z][A-Z][a-z][A-Z][a-z]" ] = "Name is too complicated" , } -- =================================================================== minetest.register_on_prejoinplayer(function(name, ip) if exemptions[name] then return end -- Check for names prohibited by "disallowed" patterns local lname = name:lower() for re, reason in pairs(disallowed) do if lname:find(re) then return reason end end end) ----------------- -- Name length -- ----------------- local min_name_len = tonumber(minetest.setting_get("name_restrictions.minimum_name_length")) or 4 local max_name_len = tonumber(minetest.setting_get("name_restrictions.maximum_name_length")) or 17 minetest.register_on_prejoinplayer (function (name, ip) if exemptions[name] then return end if #name < min_name_len then return "Your player name is too short" .. " (" .. #name .. " characters, must be " .. min_name_len .. " characters at least)." .. " Please try a longer name." end if #name > max_name_len then return "Your player name is too long" .. " (" .. #name .. " characters, must be " .. max_name_len .. " characters at most)." .. " Please try a shorter name." end end) ---------------------- -- Pronounceability -- ---------------------- -- Original implementation (in Python) by sfan5 -- local function pronounceable (pronounceability, text) local pronounceable = 0 local nonpronounceable = 0 local cn = 0 local lastc = "" for c in text:lower():gmatch(".") do if c:find("[aeiou0-9_-]") then if not c:find("[0-9]") then if cn > 2 then nonpronounceable = nonpronounceable + 1 else pronounceable = pronounceable + 1 end end cn = 0 else if cn == 1 and lastc == c and lastc ~= 's' then nonpronounceable = nonpronounceable + 1 cn = 0 end if cn > 2 then nonpronounceable = nonpronounceable + 1 cn = 0 end if lastc:find("[aeiou]") then pronounceable = pronounceable + 1 cn = 0 end if not (c == "r" and lastc:find("[aipfom]")) and not (lastc == "c" and c == "h") then cn = cn + 1 end end lastc = c end if cn > 0 then nonpronounceable = nonpronounceable + 1 end return pronounceable * pronounceability >= nonpronounceable end -- Pronounceability factor: -- nil = Checking disabled. -- 0 = Everything's unpronounceable. -- 0.5 = Strict checking. -- 1 = Normal checking. -- 2 = Relaxed checking. local pronounceability = tonumber(minetest.setting_get("name_restrictions.pronounceability")) if pronounceability then minetest.register_on_prejoinplayer(function(name, ip) if exemptions[name] then return end if not pronounceable(pronounceability, name) then return "Your player name does not seem to be pronounceable." .." Please choose a more pronounceable name." end end) end