forked from packetflinger/q2admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathg_local.h
More file actions
584 lines (519 loc) · 19.4 KB
/
g_local.h
File metadata and controls
584 lines (519 loc) · 19.4 KB
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
/*
Copyright (C) 2000 Shane Powell
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "platform.h"
#include "shared.h"
#include "game.h"
#include "g_regex.h"
#include "g_cloud.h"
#include <ctype.h>
#include "g_json.h"
#include "g_net.h"
#include "g_admin.h"
#include "g_anticheat.h"
#include "g_ban.h"
#include "g_checkvar.h"
#include "g_client.h"
#include "g_cmd.h"
#include "g_crypto.h"
#include "g_disable.h"
#include "g_flood.h"
#include "g_http.h"
#include "g_init.h"
#include "g_log.h"
#include "g_lrcon.h"
#include "g_queue.h"
#include "g_spawn.h"
#include "g_timer.h"
#include "g_util.h"
#include "g_vote.h"
#include "g_vpn.h"
#include "g_whois.h"
#include "profile.h"
#define CFGFILE "q2admin.cfg"
#define NAME(x) (proxyinfo[x].name)
#define VALIDCLIENT(i) (i >= 0 || i < (int)maxclients->value) // proxyinfo index
extern game_import_t gi; // server access from inside game lib
extern game_export_t ge; // game access from inside server
extern game_export_t *ge_mod; // real game access from inside proxy game lib
extern edict_t *g_edicts;
#define getEntOffset(ent) (((char *)ent - (char *)ge.edicts) / ge.edict_size)
#define getEnt(entnum) (edict_t *)((char *)ge.edicts + (ge.edict_size * entnum))
#define PRIVATE_COMMANDS 8
#define ALLOWED_MAXCMDS 50
#define ALLOWED_MAXCMDS_SAFETY 45
// maximum length of random strings used to check for hacked quake2.exe
#define RANDOM_STRING_LENGTH 20
#define MAX_VERSION_CHARS 100
// protocol bytes that can be directly added to messages
#define SVC_STUFFTEXT 11
// variable server FPS
#if USE_FPS
#define HZ game.framerate
#define FRAMETIME game.frametime
#define FRAMEDIV game.framediv
#define FRAMESYNC !(level.framenum % game.framediv)
#else
#define HZ BASE_FRAMERATE
#define FRAMETIME BASE_FRAMETIME_1000
#define FRAMEDIV 1
#define FRAMESYNC 1
#endif
#define SECS_TO_FRAMES(seconds) (int)((seconds) * HZ)
#define FRAMES_TO_SECS(frames) (int)((frames) * FRAMETIME)
// memory tags to allow dynamic memory to be cleaned up
#define TAG_GAME 765 // clear when unloading the dll
#define TAG_LEVEL 766 // clear when loading a new level
#define G_Malloc(x) (gi.TagMalloc(x, TAG_GAME))
#define G_Free(x) (gi.TagFree(x))
// Contains the map entities string. This string is potentially a different
// size than the original entities string due to cvar-based substitutions.
extern char *finalentities;
#define random() ((rand() & 0x7fff) / ((float)0x7fff)) // between 0 and 1
#define RANDCHAR() (random() < 0.3) ? '0' + (int)(9.9 * random()) : 'A' + (int)(26.9 * random())
#define DEFAULTLOCKOUTMSG "This server is currently locked."
typedef struct {
qboolean admin; // player authed with !admin command
unsigned char retries;
unsigned char rbotretries;
cmd_queue_t cmdQueue[ALLOWED_MAXCMDS];
int maxCmds; // current command count
unsigned long clientcommand; // internal proxy commands
char teststr[9];
int charindex; // teststr index AND cheat type for logging
int logfilenum; // for displaying log files
char buffer[256]; // log buffer
byte impulse; // player's ucmd->impulse
byte inuse; // used by active player
char name[16]; // player name
char skin[40]; // player skin/model
int rate; // from userinfo
int maxfps; // from userinfo
int cl_pitchspeed; // value from userinfo
float cl_anglespeedkey; // value from userinfo
baninfo_t *baninfo; // the ban entry that matched this player
long namechangetimeout; // can't change name until after this
int namechangecount;
long skinchangetimeout; // can't change skin until after this
int skinchangecount;
long chattimeout;
int chatcount;
char userinfo[MAX_INFO_STRING + 45];
FILE *stuffFile; // fp for if "!stuff FILE" is used
int impulsesgenerated; // cumulative total
char lastcmd[8192]; // the latest command sent including args
struct chatflood_s floodinfo;
aimbot_t aim_assist; // for checking if player has an aimbot
int votescast; // cumulative total votes proposed
int votetimeout; // can't propose until ltime is greater
int msg; // player's msg level from userinfo
// used to test the alias (and connect) command with random strings
char hack_teststring1[RANDOM_STRING_LENGTH + 1];
char hack_teststring2[RANDOM_STRING_LENGTH + 1];
char hack_teststring3[RANDOM_STRING_LENGTH + 1];
char hack_timescale[RANDOM_STRING_LENGTH + 1];
int hacked_disconnect; // hack detected, disconnect the client
netadr_t hacked_disconnect_addr;
int checked_hacked_exe; // used in `rate` check
// used to test the variables check list
char hack_checkvar[RANDOM_STRING_LENGTH + 1];
int checkvar_idx;
char gl_driver[256]; // original GL drive reported
int gl_driver_changes; // cumulative total
int pmodver; // p_modified check (ltime related)
int pmod; // seemingly unused, checked but not set
int pmod_noreply_count;
int pcmd_noreply_count;
int pver; // seemingly unused, set but never checked
int q2a_admin; // admin level granted
int q2a_bypass; // bypass level granted
int frames_count; // used in ClientThink for FPS display
player_msec_t msec;
int done_server_and_blocklist;
int userinfo_changed_count;
int userinfo_changed_start;
int private_command; // ltime while waiting for responses
int timescale; // player's current timescale (from userinfo)
qboolean show_fps; // display fps to client every 0.5 sec
qboolean vid_restart; // if client already forced to vid_restart
qboolean private_command_got[PRIVATE_COMMANDS]; // if we received a response
char serverip[16]; // have player reconnect here instead of proxy
char cmdlist_stored[256];
int cmdlist;
int cmdlist_timeout;
int userid; // unique ID for whois stuff
int newcmd_timeout;
timers_t timers[TIMERS_MAX];
int blocklist;
int speedfreeze; // level time, hold until ltime is greater
int enteredgame; // level time entered (seconds)
edict_t *ent; // the associated player entity
int remote_reported; // unused, remove later
int next_report; // unused, remove later
int stifle_frame; // frames
int stifle_length; // frames
download_t dl;
vpn_t vpn; // vpn status for player
netadr_t address; // the actual IP address of the player
char address_str[135]; // unused, remove later
char version_test[6]; // random chars to force sending version
char client_version[MAX_VERSION_CHARS]; // build string
chatpest_t pest; // tracking annoying chat behavior
freeze_t freeze; // used to freeze a player in place
} proxyinfo_t;
typedef struct {
byte inuse;
char name[16];
} proxyreconnectinfo_t;
#define MAXDETECTRETRIES 3
#define CCMD_STARTUPTEST BIT(0)
#define CCMD_ZPROXYCHECK2 BIT(1)
#define CCMD_ZBOTDETECTED BIT(2)
#define CCMD_BANNED BIT(3)
#define CCMD_NCSILENCE BIT(4) // name change silence
#define CCMD_KICKED BIT(5)
#define CCMD_SELECTED BIT(6) // player targeted in cmd
#define CCMD_CSILENCE BIT(7) // temporarily muted
#define CCMD_PCSILENCE BIT(8) // permanently muted
#define CCMD_VOTED BIT(9)
#define CCMD_VOTEYES BIT(10)
#define CCMD_NITRO2PROXY BIT(11)
#define CCMD_RATBOTDETECT BIT(12)
#define CCMD_RATBOTDETECTNAME BIT(13)
#define CCMD_ZBOTCLEAR BIT(14)
#define CCMD_RBOTCLEAR BIT(15)
#define CCMD_SCSILENCE BIT(16) // skin change silence
#define CCMD_RECONNECT BIT(17)
#define CCMD_ALIASCHECKSTARTED BIT(18)
#define CCMD_WAITFORALIASREPLY1 BIT(19)
#define CCMD_WAITFORALIASREPLY2 BIT(20)
#define CCMD_WAITFORCONNECTREPLY BIT(21)
#define CCMD_REMEMBERHACK BIT(22)
#define CCMD_CLIENTOVERFLOWED BIT(23)
#define CCMD_STIFLED BIT(24) // half-muted
#define CCMD_WAITFORVERSION BIT(25)
#define LEVELCHANGE_KEEP (CCMD_SCSILENCE | CCMD_CSILENCE | CCMD_PCSILENCE | \
CCMD_ZBOTDETECTED | CCMD_KICKED | CCMD_NITRO2PROXY | \
CCMD_ZBOTCLEAR | CCMD_RBOTCLEAR | CCMD_BANNED | \
CCMD_RECONNECT | CCMD_REMEMBERHACK)
/**
* These are commands that the server should do for or to the client. Clients
* have no say or influence on these commands.
*/
enum _commands {
QCMD_STARTUP,
QCMD_STARTUPTEST,
QCMD_CLEAR, // clears the client's console/chat area
QCMD_DISCONNECT,
QCMD_CUSTOM, // stuff customClientCmd
QCMD_ZPROXYCHECK1,
QCMD_ZPROXYCHECK2,
QCMD_DISPLOGFILE,
QCMD_DISPLOGFILELIST,
QCMD_DISPLOGEVENTLIST,
QCMD_CONNECTCMD,
QCMD_LOGTOFILE1,
QCMD_LOGTOFILE2,
QCMD_LOGTOFILE3,
QCMD_RESTART,
QCMD_CLIPTOMAXRATE,
QCMD_CLIPTOMINRATE,
QCMD_SETUPMAXFPS,
QCMD_FORCEUDATAUPDATE,
QCMD_SETMAXFPS,
QCMD_SETMINFPS,
QCMD_DISPBANS,
QCMD_DISPLRCONS,
QCMD_DISPFLOOD,
QCMD_DISPSPAWN,
QCMD_DISPVOTE,
QCMD_DISPDISABLE,
QCMD_CHANGENAME,
QCMD_CHANGESKIN,
QCMD_BAN,
QCMD_DISPCHATBANS,
QCMD_STUFFCLIENT,
QCMD_TESTADMIN,
QCMD_TESTADMIN2,
QCMD_TESTADMIN3,
QCMD_RUNVOTECMD,
QCMD_TESTRATBOT,
QCMD_TESTRATBOT2,
QCMD_TESTRATBOT3,
QCMD_TESTRATBOT4,
QCMD_LETRATBOTQUIT,
QCMD_TESTTIMESCALE,
QCMD_TESTSTANDARDPROXY,
QCMD_TESTALIASCMD1,
QCMD_TESTALIASCMD2,
QCMD_SETUPCL_PITCHSPEED,
QCMD_FORCEUDATAUPDATEPS,
QCMD_SETUPCL_ANGLESPEEDKEY,
QCMD_FORCEUDATAUPDATEAS,
QCMD_RECONNECT,
QCMD_KICK,
QCMD_MSGDISCONNECT,
QCMD_DISPCHECKVAR,
QCMD_CHECKVARTESTS,
QCMD_AUTH,
QCMD_PMODVERTIMEOUT,
QCMD_PMODVERTIMEOUT_INGAME,
QCMD_SHOWMOTD,
QCMD_EXECMAPCFG,
QCMD_PRIVATECOMMAND,
QCMD_GL_CHECK,
QCMD_SETUPTIMESCALE,
QCMD_SETTIMESCALE,
QCMD_SPAMBYPASS,
QCMD_GETCMDQUEUE,
QCMD_TESTCMDQUEUE,
QCMD_CLIENTVERSION,
QCMD_FREEZEPLAYER,
QCMD_UNFREEZEPLAYER
};
// Internal Warnings for logging
#define IW_UNEXCEPTEDCMD 1
#define IW_UNKNOWNCMD 2
#define IW_ZBOTDETECT 3
#define IW_STARTUP 4
#define IW_STARTUPTEST 5
#define IW_ZBOTTEST 6
#define IW_OVERFLOWDETECT 7
#define IW_STARTUPFAIL 8
#define IW_Q2ADMINCFGLOAD 9
#define IW_LOGSETUPLOAD 10
#define IW_BANSETUPLOAD 11
#define IW_LRCONSETUPLOAD 12
#define IW_FLOODSETUPLOAD 13
#define IW_SPAWNSETUPLOAD 14
#define IW_VOTESETUPLOAD 15
#define IW_ZBCHECK 16
#define IW_DISABLESETUPLOAD 17
#define IW_CHECKVARSETUPLOAD 18
#define IW_INVALIDIPADDRESS 19
#define MINIMUMTIMEOUT 5
#define MAXSTARTTRY 500
extern cvar_t *rcon_password,
*gamedir,
*maxclients,
*logfile,
*rconpassword,
*port,
*serverbindip,
*q2aconfig,
*q2adminbantxt,
*q2adminbanremotetxt,
*q2adminbanremotetxt_enable,
*q2adminanticheat_enable,
*q2adminanticheat_file,
*q2adminhashlist_enable,
*q2adminhashlist_dir,
*tune_spawn_railgun,
*tune_spawn_bfg,
*tune_spawn_quad,
*tune_spawn_invulnerability,
*tune_spawn_powershield,
*tune_spawn_megahealth,
*tune_spawn_rocketlauncher,
*tune_spawn_hyperblaster,
*tune_spawn_grenadelauncher,
*tune_spawn_chaingun,
*tune_spawn_machinegun,
*tune_spawn_supershotgun,
*tune_spawn_shotgun,
*tune_spawn_machinegun,
*tune_spawn_grenades,
*configfile_ban,
*configfile_bypass,
*configfile_cloud,
*configfile_cvar,
*configfile_disable,
*configfile_flood,
*configfile_login,
*configfile_log,
*configfile_rcon,
*configfile_spawn,
*configfile_vote;
extern char dllname[256];
extern char gamelibrary[MAX_QPATH];
extern char zbotuserdisplay[256];
extern char timescaleuserdisplay[256];
extern char hackuserdisplay[256];
extern char skincrashmsg[256];
extern char defaultreconnectmessage[256];
extern char moddir[256];
extern char version[256];
extern qboolean soloadlazy;
extern qboolean dllloaded;
extern qboolean quake2dirsupport;
extern qboolean zbotdetect;
extern qboolean displayzbotuser;
extern qboolean displaynamechange;
extern qboolean dopversion;
extern qboolean disconnectuserimpulse;
extern qboolean disconnectuser;
extern qboolean mapcfgexec;
extern qboolean checkClientIpAddress;
extern qboolean votecountnovotes;
extern int votepasspercent;
extern int voteminclients;
extern int clientMaxVoteTimeout;
extern int clientMaxVotes;
extern int numofdisplays;
extern int maximpulses;
// 0 no limit, positive normal limit, negative vpn limit
extern int ip_limit;
extern byte impulsesToKickOn[MAXIMPULSESTOTEST];
extern byte maxImpulses;
extern qboolean displayimpulses;
extern qboolean printmessageonplaycmds;
extern qboolean say_person_enable;
extern qboolean say_group_enable;
extern qboolean extendedsay_enable;
extern qboolean spawnentities_enable;
extern qboolean spawnentities_internal_enable;
extern qboolean vote_enable;
extern qboolean consolechat_disable;
extern qboolean gamemaptomap;
extern qboolean banOnConnect;
extern qboolean lockDownServer;
extern qboolean serverinfoenable;
extern int clientVoteTimeout;
extern int clientRemindTimeout;
extern int randomwaitreporttime;
extern int proxy_bwproxy;
extern int proxy_nitro2;
extern int maxMsgLevel;
extern char zbotmotd[256];
extern char motd[4096];
extern char clientVoteCommand[256];
extern int testcharslength;
extern int runmode;
extern int maxclientsperframe;
extern int framesperprocess;
extern char buffer[0x10000];
extern char buffer2[256];
extern char adminpassword[256];
extern char customServerCmd[256];
extern char customClientCmd[256];
extern char customClientCmdConnect[256];
extern char customServerCmdConnect[256];
extern qboolean rcon_insecure;
extern qboolean rcon_random_password;
extern qboolean zbc_enable;
extern int maxlrcon_cmds;
extern int lrcon_timeout;
extern int logfilecheckcount;
extern qboolean kickOnNameChange;
extern qboolean disablecmds_enable;
extern qboolean checkvarcmds_enable;
extern qboolean swap_attack_use;
extern qboolean timescaledetect;
extern char *currentBanMsg;
extern proxyinfo_t *proxyinfo;
extern proxyinfo_t *proxyinfoBase;
extern proxyreconnectinfo_t *reconnectproxyinfo;
extern int clientsidetimeout;
extern int zbotdetectactivetimeout;
extern int lframenum;
extern float ltime;
extern char *impulsemessages[];
extern char cmdpassedvote[2048];
extern char cl_pitchspeed_kickmsg[256];
extern char cl_anglespeedkey_kickmsg[256];
extern qboolean cl_pitchspeed_enable;
extern qboolean cl_pitchspeed_kick;
extern qboolean cl_pitchspeed_display;
extern qboolean cl_anglespeedkey_enable;
extern qboolean cl_anglespeedkey_kick;
extern qboolean cl_anglespeedkey_display;
extern qboolean filternonprintabletext;
extern char lockoutmsg[256];
extern char gmapname[MAX_QPATH];
extern char reconnect_address[256];
extern char serverip[256];
extern char lanip[256];
extern int reconnect_time;
extern int reconnect_checklevel;
extern int entity_classname_offset;
extern int checkvar_poll_time;
typedef struct {
long reconnecttimeout;
int retrylistidx;
char userinfo[MAX_INFO_STRING + 45];
} reconnect_info;
typedef struct {
long retry;
char ip[MAX_INFO_STRING + 45];
} retrylist_info;
extern reconnect_info* reconnectlist;
extern retrylist_info* retrylist;
extern int maxReconnectList;
extern int maxretryList;
// zb_clib.c
#ifdef Q2ADMINCLIB
char *q2a_strcpy(char *strDestination, const char *strSource);
char *q2a_strncpy(char *strDest, const char *strSource, size_t count);
char *q2a_strcat(char *strDestination, const char *strSource);
char *q2a_strstr(const char *string, const char *strCharSet);
char *q2a_strchr(const char *string, int c);
int q2a_strcmp(const char *string1, const char *string2);
size_t q2a_strlen(const char *string);
int q2a_atoi(const char *string);
double q2a_atof(const char *string);
int q2a_memcmp(const void *buf1, const void *buf2, size_t count);
void *q2a_memcpy(void *dest, const void *src, size_t count);
void *q2a_memmove(void *dest, const void *src, size_t count);
void *q2a_memset(void *dest, int c, size_t count);
#else
#define q2a_strcpy strcpy
#define q2a_strncpy strncpy
#define q2a_strcat strcat
#define q2a_strcmp strcmp
#define q2a_strstr strstr
#define q2a_strchr strchr
#define q2a_strlen strlen
#define q2a_atoi atoi
#define q2a_atof atof
#define q2a_memcmp memcmp
#define q2a_memcpy memcpy
#define q2a_memmove memmove
#define q2a_memset memset
#endif
const char *q2a_inet_ntop (int af, const void *src, char *dst, socklen_t size);
// should be set at build time in Makefile
#ifndef Q2A_COMMIT
#define Q2A_COMMIT "00~000000"
#define Q2A_REVISION 0
#endif
#define DEFAULTQ2AMSG "\nThis server requires %s anti cheat client.\n"
#define NOMATCH_KICK_MSG "%s has not provided adequate authentication.\n"
#define MOD_KICK_MSG "%s failed the pmodified check on this map, error %d.\n"
#define PRV_KICK_MSG "%s is using a modified client.\n"
#define Q2A_MOD_KICK_MSG "Failed the pmodified check on this map.\n"
#define Q2A_PRV_KICK_MSG "Failed the private commands check.\n"
#define FRKQ2_KICK_MSG "Failed the client authentication.\n"
extern int client_map_cfg;
extern qboolean do_franck_check;
extern qboolean q2a_command_check;
extern qboolean do_vid_restart;
extern int gl_driver_check;
extern int USERINFOCHANGE_TIME;
extern int USERINFOCHANGE_COUNT;
extern int gl_driver_max_changes;
typedef struct {
char command[256];
} priv_t;
extern priv_t private_commands[PRIVATE_COMMANDS];
void stuff_private_commands(int client, edict_t *ent);