-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
75 lines (70 loc) · 2.57 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
-- No guests mod.
-- By VanessaE, sfan5, and kaeza.
local disallowed = {
["guest"] = "Guest accounts are disallowed on this server. "..
"Please choose a proper username and try again.",
["[4a]dm[1il]n"] = "That is a clearly false, misleading, or otherwise disallowed username. "..
"Please choose a unique username and try again.",
["^[0-9]+$"] = "All-numeric usernames are disallowed on this server. "..
"Please choose a proper username and try again.",
["[0-9].-[0-9].-[0-9].-[0-9].-[0-9]"] = "Too many numbers in your username. "..
"Please try again with less than five digits in your username.",
["^[A-Za-z]+[0-9][0-9][0-9]+$"] = "Please choice your own username. Usernames with letters then 3 or more digits are not allowed"
}
-- Original implementation (in Python) by sfan5
local function judge(msg)
local numspeakable = 0
local numnotspeakable = 0
local cn = 0
local lastc = '____'
for c in msg:gmatch(".") do
c = c:lower()
if c:find("[aeiou0-9_-]") then
if cn > 2 and not c:find("[0-9]") then
numnotspeakable = numnotspeakable + 1
elseif not c:find("[0-9]") then
numspeakable = numspeakable + 1
end
cn = 0
else
if (cn == 1) and (lastc == c) and (lastc ~= 's') then
numnotspeakable = numnotspeakable + 1
cn = 0
end
if cn > 2 then
numnotspeakable = numnotspeakable + 1
cn = 0
end
if lastc:find("[aeiou]") then
numspeakable = numspeakable + 1
cn = 0
end
if not ((lastc:find("[aipfom]") and c == "r") or (lastc == "c" and c == "h")) then
cn = cn + 1
end
end
lastc = c
end
if cn > 0 then
numnotspeakable = numnotspeakable + 1
end
return (numspeakable >= numnotspeakable)
end
minetest.register_on_prejoinplayer(function(name, ip)
if not minetest.player_exists(name) then
local lname = name:lower()
for re, reason in pairs(disallowed) do
if lname:find(re) then
return reason
end
end
if #name < 2 then
return "Too short of a username. "..
"Please pick a name with at least two letters and try again."
end
if not judge(name) and #name > 5 then
return "Your username just plain looks like gibberish. "..
"Please pick something readable and try again."
end
end
end)