-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathglobalcombined.lua
490 lines (424 loc) · 15.7 KB
/
globalcombined.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
-- Global config set bugfix/exploit Lua v{{ version }}
modname = "globalcombined"
version = "{{ version }}"
function et_InitGame(levelTime,randomSeed,restart)
et.RegisterModname(""..modname.." "..version.." "..et.FindSelf())
config = et.trap_Cvar_Get( "b_config" )
gameformat = tonumber( et.trap_Cvar_Get( "b_gameformat" ) )
maxclients = tonumber( et.trap_Cvar_Get( "sv_maxclients" ) )
serverpassword = tonumber( et.trap_Cvar_Get( "g_password" ) )
sniperaxis = 0
sniperallies = 0
if gameformat == nil then
et.trap_Cvar_Set( "b_gameformat", "0" )
end
et.trap_Cvar_Set("pauselock", "0")
end
-- client command checks, formerly wsfix
-- prevent ws overrun exploit, crlf abuse
function et_ClientCommand(cno,cmd)
local cmd = string.lower(cmd)
local arg1 = string.lower(et.trap_Argv(1))
local byte = string.byte(arg1,1)
if string.find(arg1, "^7ref") or string.find(arg1, "^7rcon") then
et.trap_SendServerCommand( cno, "print \"Ckeck your typing: '"..arg1.."'\n\"" )
return 1
end
if cmd == "team" or cmd == "nextteam" then --exploit fix team command
if string.len(arg1) > 1 then
et.trap_SendServerCommand( cno , "print \"Invalid team join command.\n\"" )
return 1
end
if arg1 ~= "" and byte ~= 98 and byte ~= 114 and byte ~= 115 then
et.trap_SendServerCommand( cno , "print \"Invalid team join command.\n\"" )
return 1
end
end
if cmd == "pause" and tonumber(et.trap_Cvar_Get("pauselock")) == 1 then
et.trap_SendServerCommand( cno , "print \"Pause forbidden during this stage of the map.\n\"" )
return 1
end
if cmd == "forcetapout" then --forcetapout bugfix
if et.gentity_get(cno, "r.contents") == 0 then --contents 0 =nobody
return 1 --prevent it
end
end
if cmd == "b_gameformat" then
et.trap_SendServerCommand( cno,"print \"^wb_gameformat is: "..gameformat.." default: 0\n\"")
return 1
end
if gameformat ~= "6" then -- gameformat check
if cmd == "class" then
if et.trap_Argv(1) == "c" then
if et.trap_Argv(2) == "3" then
for j = 0, (maxclients - 1) do
if getTeam(j) == 2 and getWeapon(j) == 41 then
sniperallies = sniperallies +1
end
end
if getWeapon(cno) == 41 then
sniperallies = sniperallies -1
end
if sniperallies > 0 then
sniperallies = 0
setPlayerWeapon(cno , 10) -- Set Weapon to Sten
return 1
end
for j = 0, (maxclients - 1) do
if getTeam(j) == 1 and getWeapon(j) == 32 then
sniperaxis = sniperaxis +1
end
end
if getWeapon(cno) == 32 then
sniperaxis = sniperaxis -1
end
if sniperaxis > 0 then
sniperaxis = 0
setPlayerWeapon(cno , 10) -- Set Weapon to Sten
return 1
end
end
end
end
if cmd == "team" then
if et.trap_Argv(1) == "b" then
if et.trap_Argv(2) == "4" then
if et.trap_Argv(3) == "25" then
for j = 0, (maxclients - 1) do
if getTeam(j) == 2 and getWeapon(j) == 25 then
sniperallies = sniperallies +1
end
end
if getWeapon(cno) == 25 then
sniperallies = sniperallies -1
end
if sniperallies > 0 then
sniperallies = 0
setPlayerWeapon(cno , 10) -- Set Weapon to Sten
return 1
end
end
end
end
end
if cmd == "team" then
if et.trap_Argv(1) == "r" then
if et.trap_Argv(2) == "4" then
if et.trap_Argv(3) == "32" then
for j = 0, (maxclients - 1) do
if getTeam(j) == 1 and getWeapon(j) == 32 then
sniperaxis = sniperaxis +1
end
end
if getWeapon(cno) == 32 then
sniperaxis = sniperaxis -1
end
if sniperaxis > 0 then
sniperaxis = 0
setPlayerWeapon(cno , 10) -- Set Weapon to Sten
return 1
end
end
end
end
end
end -- gameformat check end
if cmd == "ws" then
local n = tonumber(et.trap_Argv(1))
if not n then
et.G_LogPrint(string.format("wsfix: client %d bad ws not a number [%s]\n",cno,tostring(et.trap_Argv(1))))
return 1
end
if n < 0 or n > 21 then
et.G_LogPrint(string.format("wsfix: client %d bad ws %d\n",cno,n))
return 1
end
return 0
end
if cmd == "callvote" or cmd == "ref" or cmd == "sa" or cmd == "semiadmin" then
local args=et.ConcatArgs(1)
if string.find(args,"[\r\n]") then
et.G_LogPrint(string.format("combinedfixes: client %d bad %s [%s]\n",cno,cmd,args))
return 1;
end
return 0
end
return 0
end --end ClientCommand
-- prevent various exploits by invalid userinfo
badnames = {
'^ShutdownGame',
'^ClientBegin',
'^ClientDisconnect',
'^ExitLevel',
'^Timelimit',
'^EndRound',
'^etpro IAC',
'^Vote',
'^etpro privmsg',
-- "say" is relatively likely to have false positives
-- but can potentially be used to exploit things that use etadmin_mod style !commands
-- '^say',
'^Callvote',
'^broadcast',
'^badinfo',
}
-- returns nil if ok, or reason
function check_userinfo( cno )
if et.gentity_get(cno,"ps.ping") == 0 then return end
local userinfo = et.trap_GetUserinfo(cno)
-- bad things can happen if it's full
if string.len(userinfo) > 980 then
return "oversized"
end
-- newlines can confuse various log parsers, and should never be there
-- note this DOES NOT protect your log parsers, as the userinfo may
-- already have been sent to the log
if string.find(userinfo,"\n") then
return "new line"
end
-- the game never seems to make userinfos without a leading backslash,
-- or with a trailing backslash, so reject those from the start
if (string.sub(userinfo,1,1) ~= "\\" ) then
return "missing leading slash"
end
-- shouldn't really be possible, since the engine stuffs ip\ip:port on the end
if (string.sub(userinfo,-1,1) == "\\" ) then
return "trailing slash"
end
-- now that we know it is properly formed, count the slashes
local n = 0
for _ in string.gfind(userinfo,"\\") do
n = n + 1
end
if math.mod(n,2) == 1 then
return "unbalanced"
end
local m
local t = {}
-- right number of slashes, check for dupe keys
for m in string.gfind(userinfo,"\\([^\\]*)\\") do
if string.len(m) == 0 then
return "empty key"
end
m = string.lower(m)
if t[m] then
return "duplicate key"
end
t[m] = true
end
-- they might hose the userinfo in some way that prevents the ip from being
-- obtained. If so -> dump
local ip = et.Info_ValueForKey( userinfo, "ip" )
if ip == "" then
return "missing ip"
end
-- printf("checkuserinfo: ip [%s]\n", ip)
-- make sure whatever is there is roughly valid while we are at it
-- "localhost" may be present on a listen server. This module is not intended for listen servers.
-- string.match 5.1.x
-- string.find 5.0.x
if string.find(ip,"^%d+%.%d+%.%d+%.%d+:%d+$") == nil then
return "malformed ip"
end
-- check for this to prevent exploitation of guidcheck
-- note the proper solution would be for chats to always have a prefix in the console.
-- Why the fuck does the server console need both
-- say: [NW]reyalP: blah
-- [NW]reyalP: blah
local name = et.Info_ValueForKey( userinfo, "name" )
if name == "" then
return "missing name"
end
for _, badnamepat in ipairs(badnames) do
local mstart,mend,cno = string.find(name,badnamepat)
if mstart then
return "name abuse"
end
end
-- return nil
end
-- 3.2.6 and earlier doesn't actually call et_ClientUserinfoChanged
-- every time the userinfo changes,
-- so we use et_RunFrame to check every so often
-- comment this out or adjust to taste
infocheck_lasttime=0
infocheck_client=0
-- check a client every 5 sec
infocheck_freq=5000
function et_RunFrame( leveltime )
if ( infocheck_lasttime + infocheck_freq > leveltime ) then
return
end
infocheck_lasttime = leveltime
if et.gentity_get(infocheck_client, "pers.connected") ~= 0 then
if et.gentity_get(infocheck_client,"ps.ping") ~= 0 then
if ( et.gentity_get( infocheck_client, "inuse" ) ) then
local reason = check_userinfo( infocheck_client )
if ( reason ) then
et.G_LogPrint(string.format("userinfocheck frame: client %d bad userinfo %s\n",infocheck_client,reason))
et.trap_SetUserinfo( infocheck_client, "name\\badinfo" )
et.trap_DropClient( infocheck_client, "bad userinfo", 0 )
end
end
end
end
infocheck_client = infocheck_client + 1
if ( infocheck_client >= tonumber(et.trap_Cvar_Get("sv_maxclients")) ) then
infocheck_client = 0
end
end
function et_ClientUserinfoChanged( cno )
local reason = check_userinfo( cno )
local guid = string.upper(et.Info_ValueForKey(et.trap_GetUserinfo(cno), "cl_guid"))
if ( reason ) then
et.G_LogPrint(string.format("userinfocheck infochanged: client %d bad userinfo %s\n",cno,reason))
et.trap_SetUserinfo( cno, "name\\badinfo" )
et.trap_DropClient( cno, "bad userinfo", 0 )
end
end
-- prevent etpro guid borkage
-- default to kick with no temp ban for now
DEF_GUIDCHECK_BANTIME = 0
function bad_guid(cno,reason)
local bantime = tonumber(et.trap_Cvar_Get( "guidcheck_bantime" ))
if not bantime or bantime < 0 then
bantime = DEF_GUIDCHECK_BANTIME
end
et.G_LogPrint(string.format("guidcheck: client %d bad GUID %s\n",cno,reason))
-- we don't send them the reason. They can figure it out for themselves.
et.trap_DropClient(cno,"You are banned from this server",0)
end
function check_guid_line(text)
--find a GUID line
local guid,netname
local mstart,mend,cno = string.find(text,"^etpro IAC: (%d+) GUID %[")
if not mstart then
return
end
text=string.sub(text,mend+1)
--GUID] [NETNAME]\n
mstart,mend,guid = string.find(text,"^([^%]]*)%] %[")
if not mstart then
bad_guid(cno,"couldn't parse guid")
return
end
--NETNAME]\n
text=string.sub(text,mend+1)
netname = et.gentity_get(cno,"pers.netname")
mstart,mend = string.find(text,netname,1,true)
if not mstart or mstart ~= 1 then
bad_guid(cno,"couldn't parse name")
return
end
text=string.sub(text,mend+1)
if text ~= "]\n" then
bad_guid(cno,"trailing garbage")
return
end
-- {N} is too complicated!
mstart,mend = string.find(guid,"^%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x$")
if not mstart then
bad_guid(cno,"malformed")
return
end
end
-- limit fakeplayers DOS
-- set ip_max_clients cvar as desired. If not set, defaults to the value below.
DEF_IP_MAX_CLIENTS = 3
et.G_Printf = function(...)
et.G_Print(string.format(unpack(arg)))
end
function IPForClient(cno)
local userinfo = et.trap_GetUserinfo( cno )
if userinfo == "" then
return ""
end
local ip = et.Info_ValueForKey( userinfo, "ip" )
-- find IP and strip port
local ipstart, ipend, ipmatch = string.find(ip,"(%d+%.%d+%.%d+%.%d+)")
-- don't error out if we don't match an ip
if not ipstart then
return ""
end
-- et.G_Printf("IPForClient(%d) = [%s]\n",cno,ipmatch)
return ipmatch
end
function et_ClientConnect( cno, firstTime, isBot )
-- userinfocheck stuff. Do this before IP limit
-- printf("connect %d\n",cno)
if et.gentity_get(cno,"ps.ping") ~= 0 then --allow omnibots
local reason = check_userinfo( cno )
if ( reason ) then
et.G_LogPrint(string.format("userinfocheck connect: client %d bad userinfo %s\n",cno,reason))
return "bad userinfo"
end
-- note IP validity should be enforced by userinfocheck stuff
local ip = IPForClient( cno )
local count = 1 -- we count as the first one
local max = tonumber(et.trap_Cvar_Get( "ip_max_clients" ))
if not max or max <= 0 then
max = DEF_IP_MAX_CLIENTS
end
-- validate userinfo to filter out the people blindly using luigi's code
local userinfo = et.trap_GetUserinfo( cno )
-- et.G_Printf("userinfo: [%s]\n",userinfo)
if et.Info_ValueForKey( userinfo, "rate" ) == "" then
et.G_Printf(""..modname..": invalid userinfo from %s\n",ip)
return "invalid connection"
end
for i = 0, et.trap_Cvar_Get("sv_maxclients") - 1 do
-- pers.connected is set correctly for fake players
-- can't rely on userinfo being empty
if i ~= cno and et.gentity_get(i,"pers.connected") > 0 and ip == IPForClient(i) then
count = count + 1
if count > max then
et.G_Printf(""..modname..": too many connections from %s\n",ip)
-- TODO should we drop / ban all connections from this IP ?
return string.format("only %d connections per IP are allowed on this server",max)
end
end
end
end
end
-- NoAutoDeclare()
function et_ClientSpawn(cno,revived)
if revived == 0 and et.gentity_get(cno, "sess.playerType") == 2 then
et.gentity_set(cno,"ps.ammo",39,3)
et.gentity_set(cno,"ps.ammo",40,3)
end
end
et.CS_VOTE_STRING = 7
function et_Print(text)
check_guid_line(text)
local t = ParseString(text) --Vote Passed: Change map to suppLY
if t[2] == "Passed:" and t[4] == "map" then
if string.find(t[6],"%u") == nil or t[6] ~= getCS() then return 1 end
local mapfixed = string.lower(t[6])
et.trap_SendConsoleCommand( et.EXEC_APPEND, "wait ;ref map " .. mapfixed .. ";wait 100;ref config " .. config .. "\n" )
end
end
-- helper functions
function ParseString(inputString)
local i = 1
local t = {}
for w in string.gfind(inputString, "([^%s]+)%s*") do
t[i]=w
i=i+1
end
return t
end
function getCS()
local cs = et.trap_GetConfigstring(et.CS_VOTE_STRING)
local t = ParseString(cs)
return t[4]
end
function getWeapon(playerID)
return et.gentity_get(playerID, "sess.playerWeapon")
end
function getTeam(playerID)
return et.gentity_get(playerID, "sess.sessionTeam")
end
function setPlayerWeapon(playerID , weapon)
et.gentity_set(playerID, "sess.latchPlayerWeapon", weapon)
end