forked from packetflinger/q2admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathg_client.c
More file actions
344 lines (282 loc) · 10.3 KB
/
g_client.c
File metadata and controls
344 lines (282 loc) · 10.3 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
/*
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 "g_local.h"
int clientsidetimeout = 30; // 30 seconds should be good for internet play
int zbotdetectactivetimeout = 0; // -1 == random
// char testchars[] = "!@#%^&*()_=|?.>,<[{]}\':1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
char testchars[] = "!@#%^&*()_=|?.>,<[{]}\':";
// 012345678901234567890 1234567890123456789012345678901234567890123456789012345678901234
// 1 2 3 4 5 6 7 8
int testcharslength = sizeof (testchars) - 1;
int zbc_jittermax = 4;
int zbc_jittertime = 10;
int zbc_jittermove = 500;
qboolean zbc_enable = qtrue;
qboolean timescaledetect = qtrue;
qboolean swap_attack_use = qfalse;
qboolean dopversion = qtrue;
byte impulsesToKickOn[MAXIMPULSESTOTEST];
byte maxImpulses = 0;
char *impulsemessages[] ={
"169 (zbot toggle menu command)",
"170 (zbot toggle menu command)",
"171 (zbot toggle menu command)",
"172 (zbot toggle menu command)",
"173 (zbot toggle menu command)",
"174 (zbot toggles bot on/off command)",
"175 (zbot toggles scanner display command)"
};
qboolean checkImpulse(byte impulse) {
unsigned int i;
if (!maxImpulses) {
return qtrue;
}
for (i = 0; i < maxImpulses; i++) {
if (impulsesToKickOn[i] == impulse) {
return qtrue;
}
}
return qfalse;
}
void serverLogZBot(edict_t *ent, int client) {
addCmdQueue(client, QCMD_LOGTOFILE1, 0, 0, 0);
if (customServerCmd[0]) {
// copy string across to buffer, replacing %c with client number
char *cp = customServerCmd;
char *dp = buffer;
while (*cp) {
if (*cp == '%' && tolower(*(cp + 1)) == 'c') {
sprintf(dp, "%d", client);
dp += q2a_strlen(dp);
cp += 2;
} else {
*dp++ = *cp++;
}
}
*dp = 0x0;
gi.AddCommandString(buffer);
}
}
void Pmove_internal(pmove_t *pmove) {
if (runmode == 0) {
gi.Pmove(pmove);
return;
}
gi.Pmove(pmove);
}
/**
* Called for each client frame. This will called once per cl_maxfps value per
* second. The msec value in the usercmd_t arg should be approximately
* 1000/cl_maxfps. For an fps of 120, that equals roughly 8-9ms.
*
* The ucmd arg is movement/state data sent from the player's client.
*/
void ClientThink(edict_t *ent, usercmd_t *ucmd) {
int client;
char *msg = 0;
proxyinfo_t *cl;
profile_init_2(1);
profile_init_2(2);
if (!dllloaded) {
return;
}
if (runmode == 0) {
ge_mod->ClientThink(ent, ucmd);
G_MergeEdicts();
return;
}
client = getEntOffset(ent) - 1;
cl = &proxyinfo[client];
profile_start(1);
cl->frames_count++;
if (cl->freeze.frozen) {
if (cl->freeze.thaw > 0 && cl->freeze.thaw < ltime) {
q2a_memset(&cl->freeze, 0, sizeof(freeze_t));
} else {
ucmd->msec = 0;
}
}
if (lframenum > cl->msec.end_frame) {
if (cl->show_fps) {
if (cl->msec.total == 500) {
gi.cprintf(ent, PRINT_HIGH, "%3.2f fps\n", (float) cl->frames_count * 2);
}
}
if (cl->msec.total > msec.max_allowed) {
if (msec.max_violations) {
cl->msec.violations++;
if (cl->msec.violations >= msec.max_violations) {
if (msec.action != MVA_NOTHING) {
gi.bprintf(PRINT_HIGH, "Excessive msec consumption from %s\n", cl->name);
Q_snprintf(buffer, sizeof(buffer), "exceeded msec limit %d/%d in %d secs", cl->msec.total, msec.max_allowed, msec.timespan);
addCmdQueue(client, QCMD_DISCONNECT, 1, 0, buffer);
}
}
} else {
// let things stabilize after joining for a few seconds
if (cl->enteredgame + 5 < ltime) {
cl->speedfreeze = ltime + 3;
}
}
}
if (cl->msec.total < msec.min_required) {
cl->msec.violations++;
if (cl->msec.violations >= msec.max_violations) {
if (msec.action != MVA_NOTHING) {
gi.bprintf(PRINT_HIGH, "msec underflow from %s\n", cl->name);
Q_snprintf(buffer, sizeof(buffer), "something is fishy, didn't meet msec requirement - %d/%d in %d secs", cl->msec.total, msec.min_required, msec.timespan);
addCmdQueue(client, QCMD_DISCONNECT, 1, 0, buffer);
}
}
}
cl->msec.end_frame = lframenum + (msec.timespan * HZ);
cl->msec.previous = cl->msec.total;
cl->msec.total = 0;
cl->frames_count = 0;
}
cl->msec.total += ucmd->msec;
if (cl->speedfreeze) {
if (cl->speedfreeze > ltime) {
ucmd->msec = 0;
} else {
if (speedbot_check_type & 2) {
gi.bprintf(PRINT_HIGH, "%s has been frozen for exceeding the speed limit.\n", cl->name);
}
cl->speedfreeze = 0;
}
}
if (ucmd->impulse) {
if (client >= maxclients->value) return;
if (displayimpulses) {
if (ucmd->impulse >= 169 && ucmd->impulse <= 175) {
msg = impulsemessages[ucmd->impulse - 169];
gi.bprintf(PRINT_HIGH, "%s generated an impulse %s\n", cl->name, msg);
} else {
msg = "generated an impulse";
gi.bprintf(PRINT_HIGH, "%s generated an impulse %d\n", cl->name, ucmd->impulse);
}
}
if (ucmd->impulse >= 169 && ucmd->impulse <= 175) {
cl->impulse = ucmd->impulse;
addCmdQueue(client, QCMD_LOGTOFILE2, 0, 0, 0);
} else {
cl->impulse = ucmd->impulse;
addCmdQueue(client, QCMD_LOGTOFILE3, 0, 0, 0);
}
if (disconnectuserimpulse && checkImpulse(ucmd->impulse)) {
cl->impulsesgenerated++;
if (cl->impulsesgenerated >= maximpulses) {
addCmdQueue(client, QCMD_DISCONNECT, 1, 0, msg);
}
}
}
if (swap_attack_use) {
byte temp = (ucmd->buttons & BUTTON_ATTACK);
if (ucmd->buttons & BUTTON_USE) {
ucmd->buttons |= BUTTON_ATTACK;
} else {
ucmd->buttons &= ~BUTTON_ATTACK;
}
if (temp) {
ucmd->buttons |= BUTTON_USE;
} else {
ucmd->buttons &= ~BUTTON_USE;
}
}
if (!(cl->clientcommand & BANCHECK)) {
if (zbc_enable && !(cl->clientcommand & CCMD_ZBOTDETECTED)) {
if (AimbotCheck(client, ucmd)) {
cl->clientcommand |= (CCMD_ZBOTDETECTED | CCMD_ZPROXYCHECK2);
removeClientCommand(client, QCMD_ZPROXYCHECK1);
addCmdQueue(client, QCMD_ZPROXYCHECK2, 1, IW_ZBCHECK, 0);
addCmdQueue(client, QCMD_RESTART, 1, IW_ZBCHECK, 0);
}
}
profile_start(2);
ge_mod->ClientThink(ent, ucmd);
profile_stop_2(2, "mod->ClientThink", 0, NULL);
G_MergeEdicts();
}
profile_stop_2(1, "q2admin->ClientThink", 0, NULL);
}
// unused
void PMOD_TimerCheck(int client) {
edict_t *ent;
ent = getEnt((client + 1));
proxyinfo[client].pmodver = ltime + 10;
proxyinfo[client].pmod = 0;
proxyinfo[client].pver = 0;
addCmdQueue(client, QCMD_PMODVERTIMEOUT_INGAME, 10, 0, 0);
gi.cprintf(ent, PRINT_HIGH, "q2admin: p_modified Standard Proxy Test\r\n");
if (gl_driver_check & 1)
stuffcmd(ent, "say Q2ADMIN_GL_DRIVER_CHECK $gl_driver / $vid_ref / $gl_mode\n");
if (q2a_command_check) {
addCmdQueue(client, QCMD_GETCMDQUEUE, 5, 0, 0);
}
}
priv_t private_commands[PRIVATE_COMMANDS];
int private_command_count;
/**
* Send private_command[1-4] and inverted_command[1-4] to a players
*/
void stuff_private_commands(int client, edict_t *ent) {
unsigned int i;
char temp[256];
proxyinfo[client].private_command = ltime + 10;
for (i = 0; i < PRIVATE_COMMANDS; i++) {
if (private_commands[i].command[0]) {
Q_snprintf(temp, sizeof(temp), "%s\n", private_commands[i].command);
stuffcmd(ent, temp);
}
proxyinfo[client].private_command_got[i] = qfalse;
}
}
/**
* Check if a player is using some kind of aim assist. Checks client angles
* for a large jump between ClientThinks.
*
* Originally ZbotCheck v1.01 by Matt "WhiteFang" Ayres (matt@lithium.com)
*
* Called from ClientThink()
*/
qboolean AimbotCheck(int client, usercmd_t *ucmd) {
int prev, cur;
aimbot_t *a = &proxyinfo[client].aim_assist;
prev = a->toggle;
a->toggle ^= 1; // was 0 now 1, was 1 now 0
cur = a->toggle;
if (ucmd->angles[PITCH] == a->angles[cur][PITCH] &&
ucmd->angles[YAW] == a->angles[cur][YAW] &&
ucmd->angles[PITCH] != a->angles[prev][PITCH] &&
ucmd->angles[YAW] != a->angles[prev][YAW] &&
abs(ucmd->angles[PITCH] - a->angles[prev][PITCH]) +
abs(ucmd->angles[YAW] - a->angles[prev][YAW]) >= zbc_jittermove) {
if (ltime <= a->jitter_last + FRAMETIME) {
if (!a->jitter) {
a->jitter_time = ltime;
}
if (a->jitter++ >= zbc_jittermax) {
return qtrue;
}
}
a->jitter_last = ltime;
}
a->angles[cur][PITCH] = ucmd->angles[PITCH];
a->angles[cur][YAW] = ucmd->angles[YAW];
if (ltime > (a->jitter_time + zbc_jittertime)) {
a->jitter = 0;
}
return qfalse;
}