/
cmds.lua
337 lines (318 loc) · 8.9 KB
/
cmds.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
need("fmt")
need("users")
need("auth")
need("usdeids")
f.cmds = {}
function f.cmds.onsay(id, txt)
local sym = txt:sub(1, 1)
if sym == "!" or sym == "@" then
local space = txt:find(" ") or (#txt + 1)
local cmd = txt:sub(1, space - 1)
local wat = f.cmds.lut[cmd:lower()]
if not wat then
f_msg2(id, "sys", "Command does not exist.")
return 1
end
if f.auth.tab[id][1] < f.cmds[wat].min_lvl then
f_msg2(id, "sys", "Insufficient privilege.")
return 1
end
local ret = f.cmds[wat]:run(id, cmd, txt:sub(space + 1))
if ret == 0 then --silent
elseif ret == 1 then --player used @cmd. rest is hidden
f_msg("sys", player(id, "name").." used ", "red", cmd)
elseif ret == 2 then --player used @cmd params.
f_msg("sys", player(id, "name").." used ", "red", txt)
end
return 1
end
end
addhook("say", "f.cmds.onsay")
local function hook(hook, base, func, ...) --watisthisidonteven
f.cmds[base]["_"..func] = function(...) return f.cmds[base][func](f.cmds[base], ...) end
addhook(hook, "f.cmds."..base.."._"..func, ...)
end
f.cmds.lut = {
["!broadcast"] = "_broadcast",
["!bc"] = "_broadcast",
["!resetscore"] = "_resetscore",
["!rs"] = "_resetscore",
["@say"] = "_say",
["@lock"] = "_team",
["@swap"] = "_team",
["@specall"] = "_team",
["@makespec"] = "_team",
["@maket"] = "_team",
["@makect"] = "_team",
["@p"] = "_parse",
["@parse"] = "_parse",
["@whois"] = "_whois",
["@rl"] = "_rl",
["@useradd"] = "_users",
["@userdel"] = "_users",
["@userlist"] = "_users"
}
for line in io.lines(f_dir.."default_cmds") do
if not f.cmds.lut["@"..line] then
f.cmds.lut["@"..line] = "_generic"
end
end
f.cmds._generic = {
min_lvl = 3,
run = function(self, id, cmd, txt)
print("@COMMAND: NAME="..player(id, "name")..
" IP="..player(id, "ip")..":"..player(id, "port")..
" USGN="..player(id, "usgn")..
" CMD="..cmd..(txt and " "..txt or ""))
parse(cmd:sub(2).." "..txt)
return 1
end
}
f.cmds._broadcast = {
times = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
onleave = function(self, id) self.times[id] = 0 end,
min_lvl = 0,
run = function(self, id, cmd, txt)
local dt = self.times[id] - os.time()
if dt <= 0 then
f_msg(f.colors.team[player(id, "team")], player(id, "name"), "green", " (BROADCAST): ", "std", txt)
self.times[id] = os.time() + 7
else
f_msg2(id, "sys", dt.." seconds until next broadcast.")
end
return 0
end
}
hook("leave", "_broadcast", "onleave")
f.cmds._resetscore = {
min_lvl = 0,
run = function(self, id, cmd, txt)
if player(id, "deaths") ~= 0 or player(id, "score") ~= 0 then
parse("setscore "..id.." 0")
parse("setdeaths "..id.." 0")
return 1
else
f_msg2(id, "sys", "Score already 0/0.")
return 0
end
end
}
f.cmds._say = {
min_lvl = 1,
run = function(self, id, cmd, txt)
f_msg(f.auth.tab[id][3], player(id, "name")..": ", "white", txt)
return 0
end
}
f.cmds._parse = {
min_lvl = 4,
run = function(self, id, cmd, txt)
print("@PARSE: NAME="..player(id, "name")..
" IP="..player(id, "ip")..":"..player(id, "port")..
" USGN="..player(id, "usgn")..
" CMD="..cmd..(txt and " "..txt or ""))
for c in string.gmatch(txt, "[^;]+") do
f_msg("sys", player(id, "name").." used ", "red", cmd.." "..c:gsub("%s.*", ""))
parse(c)
end
return 2
end
}
f.cmds._team = {
team_names = {[0] = "Spectators", "Terrorists", "Counter-Terrorists"},
invert_name_tab = {["none"] = -1, ["spec"] = 0, ["t"] = 1, ["ct"] = 2, ["all"] = 3},
lock_state = -1,
swap = function(self)
local temp = self.lock_state
if temp == 1 or temp == 2 then
temp = 3 - temp
end
self.lock_state = -1
for _, id in pairs(player(0, "table")) do
local t = player(id, "team")
if t == 1 then
parse("makect "..id)
elseif t >= 2 then
parse("maket "..id)
end
end
self.lock_state = temp
end,
specall = function(self)
local temp = self.lock_state
self.lock_state = -1
for _, id in pairs(player(0, "table")) do
parse("makespec "..id)
end
self.lock_state = temp
end,
onmenu = function(self, id, title, btn)
if title ~= "Team Control Menu" then return end
if btn == 1 then
self.lock_state = -1
f_msg("sys", player(id, "name").." unlocked all teams")
elseif btn == 2 then
self.lock_state = 3
f_msg("sys", player(id, "name").." locked all teams")
elseif btn == 4 or btn == 5 or btn == 6 then
local l = btn - 4
self.lock_state = l
f_msg("sys", player(id, "name").." locked "..self.team_names[l].. " team")
elseif btn == 8 then
self:swap()
f_msg("sys", player(id, "name").." swapped teams")
elseif btn == 9 then
self:specall()
f_msg("sys", player(id, "name").." used makespec all")
else
return
end
end,
onteam = function(self, id, team)
if self.lock_state == -1 then
return
end
local pteam = player(id, "team")
if pteam == 3 then pteam = 2 end
if pteam == team then return end
if self.lock_state == 3 then
f_msg2(id, "sys", "All teams are locked.")
return 1
elseif self.lock_state == pteam then
f_msg2(id, "sys", "Your team is locked.")
return 1
elseif self.lock_state == team then
f_msg2(id, "sys", "The "..self.team_names[team].." team is locked.")
return 1
end
end,
min_lvl = 2,
run = function(self, id, cmd, txt)
cmd = cmd:lower()
if cmd == "@swap" then
self:swap()
return 1
elseif cmd == "@specall" then
self:specall()
return 1
elseif cmd:sub(1,5) == "@make" then
local temp = self.lock_state
self.lock_state = -1
parse(cmd:sub(2).." "..txt)
self.lock_state = temp
return 1
end
txt=txt:lower()
if txt == "" then
menu(id, "Team Control Menu,Lock none,Lock all,,Lock Spectators,Lock Terrorists,Lock Counter-Terrorists,,Swap teams,Makespec all")
else
local s = self.invert_name_tab[txt]
if not s then
f_msg2(id, "sys", "Usage: ", "white", "@lock **", "sys",
" where ** is all, none, spec, t, or ct or just use",
"white", "@lock", "sys", " to open a menu.")
return 0
end
self.lock_state = s
end
return 2
end
}
hook("team", "_team", "onteam")
hook("menu", "_team", "onmenu")
f.cmds._whois = {
min_lvl = 2,
run = function(self, id, cmd, txt)
local pid = tonumber(txt)
if not pid then return 0 end
if not player(pid, "exists") then
f_msg2(id, "sys", "Player with id "..pid.." does not exist.")
return 0
end
f_msg2(id, "sys", "name: "..player(pid, "name"))
f_msg2(id, "sys", "ip: "..player(pid, "ip"))
local u = player(pid, "usgn")
if u then
f_msg2(id, "sys", "usgn id: "..u)
f_msg2(id, "sys", "usgn name: "..(f.usdeids[u] or "not in list"))
else
f_msg2(id, "sys", "no usgn id")
end
return 1
end
}
f.cmds._rl = {
--reloads server by changing to current map
min_lvl = 3,
run = function(self, id, cmd, txt)
f_msg(id, "sys", "Reloading server...")
parse("map "..game("sv_map"))
return 1
end
}
f.cmds._users = {
min_lvl = 4,
run = function(self, id, cmd, txt)
if cmd == "@userlist" then
f_msg2(id, "sys", "format:")
f_msg2(id, "red", "usgn, level, name, color")
f_msg2(id, "sys", "currently in server:")
local o = {}
for i = 1,32 do
if #f.auth.tab[i] > 1 then
local u = player(i,"usgn")
o[u] = true
f_msg2(id, "green", player(i, "name")..": "..u..", "..f.auth.tab[i][1]..", "..f.auth.tab[i][2]..", "..f.auth.tab[i][3])
end
end
f_msg2(id, "sys", "not in server:")
for k, v in pairs(f.users.tab) do
if not o[k] then
f_msg2(id, "red", k..", "..v[1]..", "..v[2]..", "..v[3])
end
end
return 0
end
local u = tonumber(txt:find(",") and txt:sub(1, txt:find(",") - 1) or txt)
if not u or u == 0 then
f_msg2(id, "sys", "Usage:")
f_msg2(id, "sys", "@userlist")
f_msg2(id, "sys", "@useradd <usgn>,<level>,<name>,<color>")
f_msg2(id, "sys", "@userdel <usgn>")
f_msg2(id, "sys", "note: @useradd can also modify an existing user")
return 0
end
local exists = false
if f.users.tab[u] then exists = true end
if cmd == "@useradd" then
if exists then
f_msg2(id, "sys", "user with usgn "..u.." already exists and will be modified.")
end
local ret = f.users.add(txt, ",")
if ret == 0 then
f_msg2(id, "sys", "user with usgn "..u.." added successfully")
elseif ret == 1 then
f_msg2(id, "sys", "wrong format. Usage: @useradd <usgn #>,<level>,<name>,<color>")
f_msg2(id, "sys", "<level> goes from 0 to 4 (like user, vip, mod, admin, superadmin)")
return 0
elseif ret == 2 then
f_msg2(id, "sys", "invalid usgn")
return 0
elseif ret == 3 then
f_msg2(id, "sys", "color not found. user with usgn "..u.." added successfully with default color of red")
end
elseif cmd == "@userdel" then
if not exists then
f_msg2(id, "sys", "user with usgn "..u.." does not exist.")
f_msg2(id, "sys", "use @userlist if you want to modify the user.")
return 0
end
f.users.tab[u] = nil
end
for i = 1, 32 do
if player(i, "usgn") == u then f.auth.onjoin(u) end
end
f.users.write()
return 1
end
}