Debian Codegraph @

code/game/g_admin.c

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 ===========================================================================
3 Copyright (C) 2004-2006 Tony J. White
4
5 This file is part of the Open Arena source code.
6
7 Originally copied from Tremulous under GPL version 2 including any later version.
8
9 Several modifications, additions, and deletions were made by developers of the
10 Open Arena source code.
11
12 This shrubbot implementation is the original work of Tony J. White.
13
14 Contains contributions from Wesley van Beelen, Chris Bajumpaa, Josh Menke,
15 and Travis Maurer.
16
17 The functionality of this code mimics the behaviour of the currently
18 inactive project shrubet (http://www.etstats.com/shrubet/index.php?ver=2)
19 by Ryan Mannion. However, shrubet was a closed-source project and
20 none of it's code has been copied, only it's functionality.
21
22 Open Arena Source code is free software; you can redistribute it
23 and/or modify it under the terms of the GNU General Public License as
24 published by the Free Software Foundation; either version 2 of the License,
25 or (at your option) any later version.
26
27 Open Arena Source code is distributed in the hope that it will be
28 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31
32 You should have received a copy of the GNU General Public License
33 along with Open Arena Source code; if not, write to the Free Software
34 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 ===========================================================================
36 */
37 /* KK-OAX TODO
38 1. Clean up the default admin levels to include the commands which I have added
39 3. Implement Disorientation in Code
40 4. DEBUG, DEBUG, DEBUG
41 */
42
43 #include "g_local.h"
44
45 // big ugly global buffer for use with buffered printing of long outputs
46 static char g_bfb[ 32000 ];
47
48 // note: list ordered alphabetically
49 g_admin_cmd_t g_admin_cmds[ ] =
50 {
51 {"adjustban", G_admin_adjustban, "b",
52 "change the duration or reason of a ban. duration is specified as "
53 "numbers followed by units 'w' (weeks), 'd' (days), 'h' (hours) or "
54 "'m' (minutes), or seconds if no units are specified. if the duration is"
55 " preceded by a + or -, the ban duration will be extended or shortened by"
56 " the specified amount",
57 "[^3ban#^7] (^5duration^7) (^5reason^7)"
58 },
59
60 {"admintest", G_admin_admintest, "a",
61 "display your current admin level",
62 ""
63 },
64
65 {"allready", G_admin_allready, "y",
66 "makes everyone ready in intermission",
67 ""
68 },
69
70 {"ban", G_admin_ban, "b",
71 "ban a player by IP and GUID with an optional expiration time and reason."
72 " duration is specified as numbers followed by units 'w' (weeks), 'd' "
73 "(days), 'h' (hours) or 'm' (minutes), or seconds if no units are "
74 "specified",
75 "[^3name|slot#|IP^7] (^5duration^7) (^5reason^7)"
76 },
77
78 {"cancelvote", G_admin_cancelvote, "c",
79 "cancel a vote taking place",
80 ""
81 },
82 //KK-OAX
83 {"disorient", G_admin_disorient, "d",
84 "disorient a player by flipping player's view and controls",
85 "[^3name|slot#^7] (^hreason^7)"
86 },
87 //{"fling", G_admin_fling, "d",
88 // "throws the player specified",
89 // "[^3name|slot#^7]"
90 //},
91
92 {"help", G_admin_help, "h",
93 "display commands available to you or help on a specific command",
94 "(^5command^7)"
95 },
96
97 {"kick", G_admin_kick, "k",
98 "kick a player with an optional reason",
99 "[^3name|slot#^7] (^5reason^7)"
100 },
101
102 {"listadmins", G_admin_listadmins, "D",
103 "display a list of all server admins and their levels",
104 "(^5name|start admin#^7)"
105 },
106
107 {"listplayers", G_admin_listplayers, "i",
108 "display a list of players, their client numbers and their levels",
109 ""
110 },
111
112 {"lock", G_admin_lock, "K",
113 "lock a team to prevent anyone from joining it",
114 "[^3a|h^7]"
115 },
116 //KK-OAX
117 {"map", G_admin_map, "M",
118 "load a map",
119 "[^3mapname^7]"
120 },
121
122 {"mute", G_admin_mute, "m",
123 "mute a player",
124 "[^3name|slot#^7]"
125 },
126
127 {"namelog", G_admin_namelog, "e",
128 "display a list of names used by recently connected players",
129 "(^5name^7)"
130 },
131
132 {"nextmap", G_admin_nextmap, "n",
133 "go to the next map in the cycle",
134 ""
135 },
136 //KK-OAX
137 {"orient", G_admin_orient, "d",
138 "orient a player after a !disorient", "[^3name|slot#^7]"
139 },
140
141 {"passvote", G_admin_passvote, "V",
142 "pass a vote currently taking place",
143 ""
144 },
145
146 {"putteam", G_admin_putteam, "p",
147 "move a player to a specified team",
148 "[^3name|slot#^7] [^3h|a|s^7]"
149 },
150
151 {"readconfig", G_admin_readconfig, "G",
152 "reloads the admin config file and refreshes permission flags",
153 ""
154 },
155
156 {"rename", G_admin_rename, "N",
157 "rename a player",
158 "[^3name|slot#^7] [^3new name^7]"
159 },
160
161 {"restart", G_admin_restart, "r",
162 "restart the current map (optionally using named layout)",
163 ""
164 },
165
166 {"setlevel", G_admin_setlevel, "s",
167 "sets the admin level of a player",
168 "[^3name|slot#|admin#^7] [^3level^7]"
169 },
170
171 {"showbans", G_admin_showbans, "B",
172 "display a (partial) list of active bans",
173 "(^5start at ban#^7) (^5name|IP^7)"
174 },
175 //KK-OAX
176 {"shuffle", G_admin_shuffle, "f",
177 "Shuffles the teams"
178 ""
179 },
180
181 {"slap", G_admin_slap, "S",
182 "Reduces the health of the selected player by the damage specified",
183 "[^3name|slot#] [damage] [reason]"
184 },
185
186 {"spec999", G_admin_spec999, "P",
187 "move 999 pingers to the spectator team",
188 ""},
189
190 {"time", G_admin_time, "C",
191 "show the current local server time",
192 ""},
193
194 {"unban", G_admin_unban, "b",
195 "unbans a player specified by the slot as seen in showbans",
196 "[^3ban#^7]"
197 },
198
199 {"unlock", G_admin_unlock, "K",
200 "unlock a locked team",
201 "[^3a|h^7]"
202 },
203
204 {"unmute", G_admin_mute, "m",
205 "unmute a muted player",
206 "[^3name|slot#^7]"
207 },
208
209 //KK-OAX
210 {"warn", G_admin_warn, "w",
211 "warn a player",
212 "[^3name|slot#^7] [reason]"
213 }
214
215 };
216
217 static int adminNumCmds = sizeof( g_admin_cmds ) / sizeof( g_admin_cmds[ 0 ] );
218
219 static int admin_level_maxname = 0;
220 g_admin_level_t *g_admin_levels[ MAX_ADMIN_LEVELS ];
221 g_admin_admin_t *g_admin_admins[ MAX_ADMIN_ADMINS ];
222 g_admin_ban_t *g_admin_bans[ MAX_ADMIN_BANS ];
223 g_admin_command_t *g_admin_commands[ MAX_ADMIN_COMMANDS ];
224 g_admin_namelog_t *g_admin_namelog[ MAX_ADMIN_NAMELOGS ];
225 //KK-OAX Load us up some warnings here....
226 g_admin_warning_t *g_admin_warnings[ MAX_ADMIN_WARNINGS ];
227
228 qboolean G_admin_permission( gentity_t *ent, char flag )
229 {
230 int i;
231 int l = 0;
232 char *flags;
233
234 // console always wins
235 if( !ent )
236 return qtrue;
237
238 for( i = 0; i < MAX_ADMIN_ADMINS && g_admin_admins[ i ]; i++ )
239 {
240 if( !Q_stricmp( ent->client->pers.guid, g_admin_admins[ i ]->guid ) )
241 {
242 flags = g_admin_admins[ i ]->flags;
243 while( *flags )
244 {
245 if( *flags == flag )
246 return qtrue;
247 else if( *flags == '-' )
248 {
249 while( *flags++ )
250 {
251 if( *flags == flag )
252 return qfalse;
253 if( *flags == '+' )
254 break;
255 }
256 }
257 else if( *flags == '*' )
258 {
259 while( *flags++ )
260 {
261 if( *flags == flag )
262 return qfalse;
263 }
264 // flags with significance only for individuals (
265 // like ADMF_INCOGNITO and ADMF_IMMUTABLE are NOT covered
266 // by the '*' wildcard. They must be specified manually.
267 return ( flag != ADMF_INCOGNITO && flag != ADMF_IMMUTABLE );
268 }
269 flags++;
270 }
271 l = g_admin_admins[ i ]->level;
272 }
273 }
274 for( i = 0; i < MAX_ADMIN_LEVELS && g_admin_levels[ i ]; i++ )
275 {
276 if( g_admin_levels[ i ]->level == l )
277 {
278 flags = g_admin_levels[ i ]->flags;
279 while( *flags )
280 {
281 if( *flags == flag )
282 return qtrue;
283 if( *flags == '*' )
284 {
285 while( *flags++ )
286 {
287 if( *flags == flag )
288 return qfalse;
289 }
290 // flags with significance only for individuals (
291 // like ADMF_INCOGNITO and ADMF_IMMUTABLE are NOT covered
292 // by the '*' wildcard. They must be specified manually.
293 return ( flag != ADMF_INCOGNITO && flag != ADMF_IMMUTABLE );
294 }
295 flags++;
296 }
297 }
298 }
299 return qfalse;
300 }
301
302 qboolean G_admin_name_check( gentity_t *ent, char *name, char *err, int len )
303 {
304 int i;
305 gclient_t *client;
306 char testName[ MAX_NAME_LENGTH ] = {""};
307 char name2[ MAX_NAME_LENGTH ] = {""};
308
309 G_SanitiseString( name, name2, sizeof( name2 ) );
310
311 if( !Q_stricmp( name2, "UnnamedPlayer" ) )
312 return qtrue;
313
314 for( i = 0; i < level.maxclients; i++ )
315 {
316 client = &level.clients[ i ];
317 if( client->pers.connected == CON_DISCONNECTED )
318 continue;
319
320 // can rename ones self to the same name using different colors
321 if( i == ( ent - g_entities ) )
322 continue;
323
324 G_SanitiseString( client->pers.netname, testName, sizeof( testName ) );
325 if( !Q_stricmp( name2, testName ) )
326 {
327 Com_sprintf( err, len, "The name '%s^7' is already in use", name );
328 return qfalse;
329 }
330 }
331
332 if( !g_adminNameProtect.integer )
333 return qtrue;
334
335 for( i = 0; i < MAX_ADMIN_ADMINS && g_admin_admins[ i ]; i++ )
336 {
337 if( g_admin_admins[ i ]->level < 1 )
338 continue;
339 G_SanitiseString( g_admin_admins[ i ]->name, testName, sizeof( testName ) );
340 if( !Q_stricmp( name2, testName ) &&
341 Q_stricmp( ent->client->pers.guid, g_admin_admins[ i ]->guid ) )
342 {
343 Com_sprintf( err, len, "The name '%s^7' belongs to an admin, "
344 "please use another name", name );
345 return qfalse;
346 }
347 }
348 return qtrue;
349 }
350
351 static qboolean admin_higher_guid( char *admin_guid, char *victim_guid )
352 {
353 int i;
354 int alevel = 0;
355
356 for( i = 0; i < MAX_ADMIN_ADMINS && g_admin_admins[ i ]; i++ )
357 {
358 if( !Q_stricmp( admin_guid, g_admin_admins[ i ]->guid ) )
359 {
360 alevel = g_admin_admins[ i ]->level;
361 break;
362 }
363 }
364 for( i = 0; i < MAX_ADMIN_ADMINS && g_admin_admins[ i ]; i++ )
365 {
366 if( !Q_stricmp( victim_guid, g_admin_admins[ i ]->guid ) )
367 {
368 if( alevel < g_admin_admins[ i ]->level )
369 return qfalse;
370 return !strstr( g_admin_admins[ i ]->flags, va( "%c", ADMF_IMMUTABLE ) );
371 }
372 }
373 return qtrue;
374 }
375
376 static qboolean admin_higher( gentity_t *admin, gentity_t *victim )
377 {
378
379 // console always wins
380 if( !admin )
381 return qtrue;
382 // just in case
383 if( !victim )
384 return qtrue;
385
386 return admin_higher_guid( admin->client->pers.guid,
387 victim->client->pers.guid );
388 }
389
390 //KK-OAX Moved the Read/Write int/String functions to g_fileops.c for portability
391 //across GAME
392
393 //KK-OAX Added Warnings
394 static void admin_writeconfig( void )
395 {
396 fileHandle_t f;
397 int len, i, j;
398 int t;
399 char levels[ MAX_STRING_CHARS ] = {""};
400
401 if( !g_admin.string[ 0 ] )
402 {
403 G_Printf( S_COLOR_YELLOW "WARNING: g_admin is not set. "
404 " configuration will not be saved to a file.\n" );
405 return;
406 }
407 t = trap_RealTime( NULL );
408 len = trap_FS_FOpenFile( g_admin.string, &f, FS_WRITE );
409 if( len < 0 )
410 {
411 G_Printf( "admin_writeconfig: could not open g_admin file \"%s\"\n",
412 g_admin.string );
413 return;
414 }
415 for( i = 0; i < MAX_ADMIN_LEVELS && g_admin_levels[ i ]; i++ )
416 {
417 trap_FS_Write( "[level]\n", 8, f );
418 trap_FS_Write( "level = ", 10, f );
419 writeFile_int( g_admin_levels[ i ]->level, f );
420 trap_FS_Write( "name = ", 10, f );
421 writeFile_string( g_admin_levels[ i ]->name, f );
422 trap_FS_Write( "flags = ", 10, f );
423 writeFile_string( g_admin_levels[ i ]->flags, f );
424 trap_FS_Write( "\n", 1, f );
425 }
426 for( i = 0; i < MAX_ADMIN_ADMINS && g_admin_admins[ i ]; i++ )
427 {
428 // don't write level 0 users
429 if( g_admin_admins[ i ]->level == 0 )
430 continue;
431
432 trap_FS_Write( "[admin]\n", 8, f );
433 trap_FS_Write( "name = ", 10, f );
434 writeFile_string( g_admin_admins[ i ]->name, f );
435 trap_FS_Write( "guid = ", 10, f );
436 writeFile_string( g_admin_admins[ i ]->guid, f );
437 trap_FS_Write( "level = ", 10, f );
438 writeFile_int( g_admin_admins[ i ]->level, f );
439 trap_FS_Write( "flags = ", 10, f );
440 writeFile_string( g_admin_admins[ i ]->flags, f );
441 trap_FS_Write( "\n", 1, f );
442 }
443 for( i = 0; i < MAX_ADMIN_BANS && g_admin_bans[ i ]; i++ )
444 {
445 // don't write expired bans
446 // if expires is 0, then it's a perm ban
447 if( g_admin_bans[ i ]->expires != 0 &&
448 ( g_admin_bans[ i ]->expires - t ) < 1 )
449 continue;
450
451 trap_FS_Write( "[ban]\n", 6, f );
452 trap_FS_Write( "name = ", 10, f );
453 writeFile_string( g_admin_bans[ i ]->name, f );
454 trap_FS_Write( "guid = ", 10, f );
455 writeFile_string( g_admin_bans[ i ]->guid, f );
456 trap_FS_Write( "ip = ", 10, f );
457 writeFile_string( g_admin_bans[ i ]->ip, f );
458 trap_FS_Write( "reason = ", 10, f );
459 writeFile_string( g_admin_bans[ i ]->reason, f );
460 trap_FS_Write( "made = ", 10, f );
461 writeFile_string( g_admin_bans[ i ]->made, f );
462 trap_FS_Write( "expires = ", 10, f );
463 writeFile_int( g_admin_bans[ i ]->expires, f );
464 trap_FS_Write( "banner = ", 10, f );
465 writeFile_string( g_admin_bans[ i ]->banner, f );
466 trap_FS_Write( "\n", 1, f );
467 }
468 for( i = 0; i < MAX_ADMIN_COMMANDS && g_admin_commands[ i ]; i++ )
469 {
470 levels[ 0 ] = '\0';
471 trap_FS_Write( "[command]\n", 10, f );
472 trap_FS_Write( "command = ", 10, f );
473 writeFile_string( g_admin_commands[ i ]->command, f );
474 trap_FS_Write( "exec = ", 10, f );
475 writeFile_string( g_admin_commands[ i ]->exec, f );
476 trap_FS_Write( "desc = ", 10, f );
477 writeFile_string( g_admin_commands[ i ]->desc, f );
478 trap_FS_Write( "levels = ", 10, f );
479 for( j = 0; g_admin_commands[ i ]->levels[ j ] != -1; j++ )
480 {
481 Q_strcat( levels, sizeof( levels ),
482 va( "%i ", g_admin_commands[ i ]->levels[ j ] ) );
483 }
484 writeFile_string( levels, f );
485 trap_FS_Write( "\n", 1, f );
486 }
487 for( i = 0; i < MAX_ADMIN_WARNINGS && g_admin_warnings[ i ]; i++ )
488 {
489 // don't write expired warnings
490 // if expires is 0, then it's a perm warning
491 // it will get loaded everytime they connect!!!!
492 if( g_admin_warnings[ i ]->expires != 0 &&
493 ( g_admin_warnings[ i ]->expires - t ) < 1 )
494 continue;
495
496 trap_FS_Write( "[warning]\n", 10, f );
497 trap_FS_Write( "name = ", 10, f );
498 writeFile_string( g_admin_warnings[ i ]->name, f );
499 trap_FS_Write( "guid = ", 10, f );
500 writeFile_string( g_admin_warnings[ i ]->guid, f );
501 trap_FS_Write( "ip = ", 10, f );
502 writeFile_string( g_admin_warnings[ i ]->ip, f );
503 trap_FS_Write( "warning = ", 10, f );
504 writeFile_string( g_admin_warnings[ i ]->warning, f );
505 trap_FS_Write( "made = ", 10, f );
506 writeFile_string( g_admin_warnings[ i ]->made, f );
507 trap_FS_Write( "expires = ", 10, f );
508 writeFile_int( g_admin_warnings[ i ]->expires, f );
509 trap_FS_Write( "warner = ", 10, f );
510 writeFile_string( g_admin_warnings[ i ]->warner, f );
511 trap_FS_Write( "\n", 1, f );
512 }
513 trap_FS_FCloseFile( f );
514 }
515
516
517 // if we can't parse any levels from readconfig, set up default
518 // ones to make new installs easier for admins
519 //KK-OAX TODO: Add all features to default levels...
520 static void admin_default_levels( void )
521 {
522 g_admin_level_t *l;
523 int i;
524
525 for( i = 0; i < MAX_ADMIN_LEVELS && g_admin_levels[ i ]; i++ )
526 {
527 BG_Free( g_admin_levels[ i ] );
528 g_admin_levels[ i ] = NULL;
529 }
530 for( i = 0; i <= 5; i++ )
531 {
532 l = BG_Alloc( sizeof( g_admin_level_t ) );
533 l->level = i;
534 *l->name = '\0';
535 *l->flags = '\0';
536 g_admin_levels[ i ] = l;
537 }
538 Q_strncpyz( g_admin_levels[ 0 ]->name, "^4Unknown Player",
539 sizeof( l->name ) );
540 Q_strncpyz( g_admin_levels[ 0 ]->flags, "ahC", sizeof( l->flags ) );
541
542 Q_strncpyz( g_admin_levels[ 1 ]->name, "^5Server Regular",
543 sizeof( l->name ) );
544 Q_strncpyz( g_admin_levels[ 1 ]->flags, "iahC", sizeof( l->flags ) );
545
546 Q_strncpyz( g_admin_levels[ 2 ]->name, "^6Team Manager",
547 sizeof( l->name ) );
548 Q_strncpyz( g_admin_levels[ 2 ]->flags, "iahCpPwr", sizeof( l->flags ) );
549
550 Q_strncpyz( g_admin_levels[ 3 ]->name, "^2Junior Admin",
551 sizeof( l->name ) );
552 Q_strncpyz( g_admin_levels[ 3 ]->flags, "iahCpPwrkmfKncN?", sizeof( l->flags ) );
553
554 Q_strncpyz( g_admin_levels[ 4 ]->name, "^3Senior Admin",
555 sizeof( l->name ) );
556 Q_strncpyz( g_admin_levels[ 4 ]->flags, "iahCpPwrkmfKncN?MVdBbeDS51", sizeof( l->flags ) );
557
558 Q_strncpyz( g_admin_levels[ 5 ]->name, "^1Server Operator",
559 sizeof( l->name ) );
560 Q_strncpyz( g_admin_levels[ 5 ]->flags, "*", sizeof( l->flags ) );
561 admin_level_maxname = 15;
562 }
563
564 // return a level for a player entity.
565 int G_admin_level( gentity_t *ent )
566 {
567 int i;
568
569 if( !ent )
570 {
571 return MAX_ADMIN_LEVELS;
572 }
573
574 for( i = 0; i < MAX_ADMIN_ADMINS && g_admin_admins[ i ]; i++ )
575 {
576 if( !Q_stricmp( g_admin_admins[ i ]->guid, ent->client->pers.guid ) )
577 return g_admin_admins[ i ]->level;
578 }
579
580 return 0;
581 }
582
583 static qboolean admin_command_permission( gentity_t *ent, char *command )
584 {
585 int i, j;
586 int level;
587
588 if( !ent )
589 return qtrue;
590 level = ent->client->pers.adminLevel;
591 for( i = 0; i < MAX_ADMIN_COMMANDS && g_admin_commands[ i ]; i++ )
592 {
593 if( !Q_stricmp( command, g_admin_commands[ i ]->command ) )
594 {
595 for( j = 0; g_admin_commands[ i ]->levels[ j ] != -1; j++ )
596 {
597 if( g_admin_commands[ i ]->levels[ j ] == level )
598 {
599 return qtrue;
600 }
601 }
602 }
603 }
604 return qfalse;
605 }
606
607 static void admin_log( gentity_t *admin, char *cmd, int skiparg )
608 {
609 fileHandle_t f;
610 int len, i, j;
611 char string[ MAX_STRING_CHARS ];
612 int min, tens, sec;
613 g_admin_admin_t *a;
614 g_admin_level_t *l;
615 char flags[ MAX_ADMIN_FLAGS * 2 ];
616 gentity_t *victim = NULL;
617 int pids[ MAX_CLIENTS ];
618 char name[ MAX_NAME_LENGTH ];
619
620 if( !g_adminLog.string[ 0 ] )
621 return;
622
623
624 len = trap_FS_FOpenFile( g_adminLog.string, &f, FS_APPEND );
625 if( len < 0 )
626 {
627 G_Printf( "admin_log: error could not open %s\n", g_adminLog.string );
628 return;
629 }
630
631 sec = level.time / 1000;
632 min = sec / 60;
633 sec -= min * 60;
634 tens = sec / 10;
635 sec -= tens * 10;
636
637 *flags = '\0';
638 if( admin )
639 {
640 for( i = 0; i < MAX_ADMIN_ADMINS && g_admin_admins[ i ]; i++ )
641 {
642 if( !Q_stricmp( g_admin_admins[ i ]->guid , admin->client->pers.guid ) )
643 {
644
645 a = g_admin_admins[ i ];
646 Q_strncpyz( flags, a->flags, sizeof( flags ) );
647 for( j = 0; j < MAX_ADMIN_LEVELS && g_admin_levels[ j ]; j++ )
648 {
649 if( g_admin_levels[ j ]->level == a->level )
650 {
651 l = g_admin_levels[ j ];
652 Q_strcat( flags, sizeof( flags ), l->flags );
653 break;
654 }
655 }
656 break;
657 }
658 }
659 }
660
661 if( G_SayArgc() > 1 + skiparg )
662 {
663 G_SayArgv( 1 + skiparg, name, sizeof( name ) );
664 if( G_ClientNumbersFromString( name, pids, MAX_CLIENTS ) == 1 )
665 {
666 victim = &g_entities[ pids[ 0 ] ];
667 }
668 }
669
670 if( victim && Q_stricmp( cmd, "attempted" ) )
671 {
672 Com_sprintf( string, sizeof( string ),
673 "%3i:%i%i: %i: %s: %s: %s: %s: %s: %s: \"%s\"\n",
674 min,
675 tens,
676 sec,
677 ( admin ) ? admin->s.clientNum : -1,
678 ( admin ) ? admin->client->pers.guid
679 : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
680 ( admin ) ? admin->client->pers.netname : "console",
681 flags,
682 cmd,
683 victim->client->pers.guid,
684 victim->client->pers.netname,
685 G_SayConcatArgs( 2 + skiparg ) );
686 }
687 else
688 {
689 Com_sprintf( string, sizeof( string ),
690 "%3i:%i%i: %i: %s: %s: %s: %s: \"%s\"\n",
691 min,
692 tens,
693 sec,
694 ( admin ) ? admin->s.clientNum : -1,
695 ( admin ) ? admin->client->pers.guid
696 : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
697 ( admin ) ? admin->client->pers.netname : "console",
698 flags,
699 cmd,
700 G_SayConcatArgs( 1 + skiparg ) );
701 }
702 trap_FS_Write( string, strlen( string ), f );
703 trap_FS_FCloseFile( f );
704 }
705
706 static int admin_listadmins( gentity_t *ent, int start, char *search )
707 {
708 int drawn = 0;
709 char guid_stub[9];
710 char name[ MAX_NAME_LENGTH ] = {""};
711 char name2[ MAX_NAME_LENGTH ] = {""};
712 char lname[ MAX_NAME_LENGTH ] = {""};
713 int i, j;
714 gentity_t *vic;
715 int l = 0;
716 qboolean dup = qfalse;
717
718 ADMBP_begin();
719
720 // print out all connected players regardless of level if name searching
721 for( i = 0; i < level.maxclients && search[ 0 ]; i++ )
722 {
723 vic = &g_entities[ i ];
724
725 if( !vic->client || vic->client->pers.connected != CON_CONNECTED )
726 continue;
727
728 l = vic->client->pers.adminLevel;
729
730 G_SanitiseString( vic->client->pers.netname, name, sizeof( name ) );
731 if( !strstr( name, search ) )
732 continue;
733
734 for( j = 0; j < 8; j++ )
735 guid_stub[ j ] = vic->client->pers.guid[ j + 24 ];
736 guid_stub[ j ] = '\0';
737
738 lname[ 0 ] = '\0';
739 for( j = 0; j < MAX_ADMIN_LEVELS && g_admin_levels[ j ]; j++ )
740 {
741 if( g_admin_levels[ j ]->level == l )
742 {
743 int k, colorlen;
744
745 for( colorlen = k = 0; g_admin_levels[ j ]->name[ k ]; k++ )
746 if( Q_IsColorString( &g_admin_levels[ j ]->name[ k ] ) )
747 colorlen += 2;
748 Com_sprintf( lname, sizeof( lname ), "%*s",
749 admin_level_maxname + colorlen,
750 g_admin_levels[ j ]->name );
751 break;
752 }
753 }
754 ADMBP( va( "%4i %4i %s^7 (*%s) %s^7\n",
755 i,
756 l,
757 lname,
758 guid_stub,
759 vic->client->pers.netname ) );
760 drawn++;
761 }
762
763 for( i = start; i < MAX_ADMIN_ADMINS && g_admin_admins[ i ] &&
764 drawn < MAX_ADMIN_LISTITEMS; i++ )
765 {
766 if( search[ 0 ] )
767 {
768 G_SanitiseString( g_admin_admins[ i ]->name, name, sizeof( name ) );
769 if( !strstr( name, search ) )
770 continue;
771
772 // verify we don't have the same guid/name pair in connected players
773 // since we don't want to draw the same player twice
774 dup = qfalse;
775 for( j = 0; j < level.maxclients; j++ )
776 {
777 vic = &g_entities[ j ];
778 if( !vic->client || vic->client->pers.connected != CON_CONNECTED )
779 continue;
780 G_SanitiseString( vic->client->pers.netname, name2, sizeof( name2 ) );
781 if( !Q_stricmp( vic->client->pers.guid, g_admin_admins[ i ]->guid ) &&
782 strstr( name2, search ) )
783 {
784 dup = qtrue;
785 break;
786 }
787 }
788 if( dup )
789 continue;
790 }
791 for( j = 0; j < 8; j++ )
792 guid_stub[ j ] = g_admin_admins[ i ]->guid[ j + 24 ];
793 guid_stub[ j ] = '\0';
794
795 lname[ 0 ] = '\0';
796 for( j = 0; j < MAX_ADMIN_LEVELS && g_admin_levels[ j ]; j++ )
797 {
798 if( g_admin_levels[ j ]->level == g_admin_admins[ i ]->level )
799 {
800 int k, colorlen;
801
802 for( colorlen = k = 0; g_admin_levels[ j ]->name[ k ]; k++ )
803 if( Q_IsColorString( &g_admin_levels[ j ]->name[ k ] ) )
804 colorlen += 2;
805 Com_sprintf( lname, sizeof( lname ), "%*s",
806 admin_level_maxname + colorlen,
807 g_admin_levels[ j ]->name );
808 break;
809 }
810 }
811 ADMBP( va( "%4i %4i %s^7 (*%s) %s^7\n",
812 ( i + MAX_CLIENTS ),
813 g_admin_admins[ i ]->level,
814 lname,
815 guid_stub,
816 g_admin_admins[ i ]->name ) );
817 drawn++;
818 }
819 ADMBP_end();
820 return drawn;
821 }
822
823 void G_admin_duration( int secs, char *duration, int dursize )
824 {
825
826 if( secs > ( 60 * 60 * 24 * 365 * 50 ) || secs < 0 )
827 Q_strncpyz( duration, "PERMANENT", dursize );
828 else if( secs >= ( 60 * 60 * 24 * 365 ) )
829 Com_sprintf( duration, dursize, "%1.1f years",
830 ( secs / ( 60 * 60 * 24 * 365.0f ) ) );
831 else if( secs >= ( 60 * 60 * 24 * 90 ) )
832 Com_sprintf( duration, dursize, "%1.1f weeks",
833 ( secs / ( 60 * 60 * 24 * 7.0f ) ) );
834 else if( secs >= ( 60 * 60 * 24 ) )
835 Com_sprintf( duration, dursize, "%1.1f days",
836 ( secs / ( 60 * 60 * 24.0f ) ) );
837 else if( secs >= ( 60 * 60 ) )
838 Com_sprintf( duration, dursize, "%1.1f hours",
839 ( secs / ( 60 * 60.0f ) ) );
840 else if( secs >= 60 )
841 Com_sprintf( duration, dursize, "%1.1f minutes",
842 ( secs / 60.0f ) );
843 else
844 Com_sprintf( duration, dursize, "%i seconds", secs );
845 }
846
847 qboolean G_admin_ban_check( char *userinfo, char *reason, int rlen )
848 {
849 char *guid, *ip;
850 int i;
851 int t;
852
853 *reason = '\0';
854 t = trap_RealTime( NULL );
855 if( !*userinfo )
856 return qfalse;
857 ip = Info_ValueForKey( userinfo, "ip" );
858 if( !*ip )
859 return qfalse;
860 guid = Info_ValueForKey( userinfo, "cl_guid" );
861 for( i = 0; i < MAX_ADMIN_BANS && g_admin_bans[ i ]; i++ )
862 {
863 // 0 is for perm ban
864 if( g_admin_bans[ i ]->expires != 0 &&
865 ( g_admin_bans[ i ]->expires - t ) < 1 )
866 continue;
867 if( strstr( ip, g_admin_bans[ i ]->ip ) )
868 {
869 char duration[ 32 ];
870 G_admin_duration( ( g_admin_bans[ i ]->expires - t ),
871 duration, sizeof( duration ) );
872 Com_sprintf(
873 reason,
874 rlen,
875 "You have been banned by %s^7 reason: %s^7 expires: %s",
876 g_admin_bans[ i ]->banner,
877 g_admin_bans[ i ]->reason,
878 duration
879 );
880 G_Printf( "Banned player tried to connect from IP %s\n", ip );
881 return qtrue;
882 }
883 if( *guid && !Q_stricmp( g_admin_bans[ i ]->guid, guid ) )
884 {
885 char duration[ 32 ];
886 G_admin_duration( ( g_admin_bans[ i ]->expires - t ),
887 duration, sizeof( duration ) );
888 Com_sprintf(
889 reason,
890 rlen,
891 "You have been banned by %s^7 reason: %s^7 expires: %s",
892 g_admin_bans[ i ]->banner,
893 g_admin_bans[ i ]->reason,
894 duration
895 );
896 G_Printf( "Banned player tried to connect with GUID %s\n", guid );
897 return qtrue;
898 }
899 }
900 return qfalse;
901 }
902
903 qboolean G_admin_cmd_check( gentity_t *ent, qboolean say )
904 {
905 int i;
906 char command[ MAX_ADMIN_CMD_LEN ];
907 char *cmd;
908 int skip = 0;
909
910 command[ 0 ] = '\0';
911 G_SayArgv( 0, command, sizeof( command ) );
912 if( !command[ 0 ] )
913 return qfalse;
914 if( !Q_stricmp( command, "say" ) ||
915 ( !Q_stricmp( command, "say_team" ) &&
916 G_admin_permission( ent, ADMF_TEAMCHAT_CMD ) ) )
917 {
918 skip = 1;
919 G_SayArgv( 1, command, sizeof( command ) );
920 }
921
922 if( command[ 0 ] == '!' )
923 {
924 cmd = &command[ 1 ];
925 }
926 else
927 {
928 return qfalse;
929 }
930
931 for( i = 0; i < MAX_ADMIN_COMMANDS && g_admin_commands[ i ]; i++ )
932 {
933 if( Q_stricmp( cmd, g_admin_commands[ i ]->command ) )
934 continue;
935
936 if( admin_command_permission( ent, cmd ) )
937 {
938 // flooding say will have already been accounted for in ClientCommand
939 if( !say && G_FloodLimited( ent ) )
940 return qtrue;
941 trap_SendConsoleCommand( EXEC_APPEND, g_admin_commands[ i ]->exec );
942 admin_log( ent, cmd, skip );
943 }
944 else
945 {
946 ADMP( va( "^3!%s: ^7permission denied\n", g_admin_commands[ i ]->command ) );
947 admin_log( ent, "attempted", skip - 1 );
948 }
949 return qtrue;
950 }
951
952 for( i = 0; i < adminNumCmds; i++ )
953 {
954 if( Q_stricmp( cmd, g_admin_cmds[ i ].keyword ) )
955 continue;
956
957 if( G_admin_permission( ent, g_admin_cmds[ i ].flag[ 0 ] ) )
958 {
959 // flooding say will have already been accounted for in ClientCommand
960 if( !say && G_FloodLimited( ent ) )
961 return qtrue;
962 g_admin_cmds[ i ].handler( ent, skip );
963 admin_log( ent, cmd, skip );
964 }
965 else
966 {
967 ADMP( va( "^3!%s: ^7permission denied\n", g_admin_cmds[ i ].keyword ) );
968 admin_log( ent, "attempted", skip - 1 );
969 }
970 return qtrue;
971 }
972 return qfalse;
973 }
974
975 void G_admin_namelog_cleanup( )
976 {
977 int i;
978
979 for( i = 0; i < MAX_ADMIN_NAMELOGS && g_admin_namelog[ i ]; i++ )
980 {
981 BG_Free( g_admin_namelog[ i ] );
982 g_admin_namelog[ i ] = NULL;
983 }
984 }
985
986 void G_admin_namelog_update( gclient_t *client, qboolean disconnect )
987 {
988 int i, j;
989 g_admin_namelog_t *namelog;
990 char n1[ MAX_NAME_LENGTH ];
991 char n2[ MAX_NAME_LENGTH ];
992 int clientNum = ( client - level.clients );
993
994 G_SanitiseString( client->pers.netname, n1, sizeof( n1 ) );
995 for( i = 0; i < MAX_ADMIN_NAMELOGS && g_admin_namelog[ i ]; i++ )
996 {
997 if( disconnect && g_admin_namelog[ i ]->slot != clientNum )
998 continue;
999
1000 if( !disconnect && !( g_admin_namelog[ i ]->slot == clientNum ||
1001 g_admin_namelog[ i ]->slot == -1 ) )
1002 {
1003 continue;
1004 }
1005
1006 if( !Q_stricmp( client->pers.ip, g_admin_namelog[ i ]->ip ) &&
1007 !Q_stricmp( client->pers.guid, g_admin_namelog[ i ]->guid ) )
1008 {
1009 for( j = 0; j < MAX_ADMIN_NAMELOG_NAMES &&
1010 g_admin_namelog[ i ]->name[ j ][ 0 ]; j++ )
1011 {
1012 G_SanitiseString( g_admin_namelog[ i ]->name[ j ], n2, sizeof( n2 ) );
1013 if( !Q_stricmp( n1, n2 ) )
1014 break;
1015 }
1016 if( j == MAX_ADMIN_NAMELOG_NAMES )
1017 j = MAX_ADMIN_NAMELOG_NAMES - 1;
1018 Q_strncpyz( g_admin_namelog[ i ]->name[ j ], client->pers.netname,
1019 sizeof( g_admin_namelog[ i ]->name[ j ] ) );
1020 g_admin_namelog[ i ]->slot = ( disconnect ) ? -1 : clientNum;
1021
1022 // if this player is connecting, they are no longer banned
1023 if( !disconnect )
1024 g_admin_namelog[ i ]->banned = qfalse;
1025
1026 return;
1027 }
1028 }
1029 if( i >= MAX_ADMIN_NAMELOGS )
1030 {
1031 G_Printf( "G_admin_namelog_update: warning, g_admin_namelogs overflow\n" );
1032 return;
1033 }
1034 namelog = BG_Alloc( sizeof( g_admin_namelog_t ) );
1035 memset( namelog, 0, sizeof( namelog ) );
1036 for( j = 0; j < MAX_ADMIN_NAMELOG_NAMES; j++ )
1037 namelog->name[ j ][ 0 ] = '\0';
1038 Q_strncpyz( namelog->ip, client->pers.ip, sizeof( namelog->ip ) );
1039 Q_strncpyz( namelog->guid, client->pers.guid, sizeof( namelog->guid ) );
1040 Q_strncpyz( namelog->name[ 0 ], client->pers.netname,
1041 sizeof( namelog->name[ 0 ] ) );
1042 namelog->slot = ( disconnect ) ? -1 : clientNum;
1043 g_admin_namelog[ i ] = namelog;
1044 }
1045
1046 //KK-OAX Added Parsing Warnings
1047 qboolean G_admin_readconfig( gentity_t *ent, int skiparg )
1048 {
1049 g_admin_level_t *l = NULL;
1050 g_admin_admin_t *a = NULL;
1051 g_admin_ban_t *b = NULL;
1052 g_admin_command_t *c = NULL;
1053 g_admin_warning_t *w = NULL;
1054 int lc = 0, ac = 0, bc = 0, cc = 0, wc = 0;
1055 fileHandle_t f;
1056 int len;
1057 char *cnf, *cnf2;
1058 char *t;
1059 qboolean level_open, admin_open, ban_open, command_open, warning_open;
1060 int i;
1061
1062 G_admin_cleanup();
1063
1064 if( !g_admin.string[ 0 ] )
1065 {
1066 ADMP( "^3!readconfig: g_admin is not set, not loading configuration "
1067 "from a file\n" );
1068 admin_default_levels();
1069 return qfalse;
1070 }
1071
1072 len = trap_FS_FOpenFile( g_admin.string, &f, FS_READ );
1073 if( len < 0 )
1074 {
1075 G_Printf( "^3!readconfig: ^7could not open admin config file %s\n",
1076 g_admin.string );
1077 admin_default_levels();
1078 return qfalse;
1079 }
1080 cnf = BG_Alloc( len + 1 );
1081 cnf2 = cnf;
1082 trap_FS_Read( cnf, len, f );
1083 *( cnf + len ) = '\0';
1084 trap_FS_FCloseFile( f );
1085
1086 admin_level_maxname = 0;
1087
1088 level_open = admin_open = ban_open = command_open = warning_open = qfalse;
1089 COM_BeginParseSession( g_admin.string );
1090 while( 1 )
1091 {
1092 t = COM_Parse( &cnf );
1093 if( !*t )
1094 break;
1095
1096 if( !Q_stricmp( t, "[level]" ) )
1097 {
1098 if( lc >= MAX_ADMIN_LEVELS )
1099 return qfalse;
1100 l = BG_Alloc( sizeof( g_admin_level_t ) );
1101 g_admin_levels[ lc++ ] = l;
1102 level_open = qtrue;
1103 admin_open = ban_open = command_open = warning_open = qfalse;
1104 }
1105 else if( !Q_stricmp( t, "[admin]" ) )
1106 {
1107 if( ac >= MAX_ADMIN_ADMINS )
1108 return qfalse;
1109 a = BG_Alloc( sizeof( g_admin_admin_t ) );
1110 g_admin_admins[ ac++ ] = a;
1111 admin_open = qtrue;
1112 level_open = ban_open = command_open = warning_open = qfalse;
1113 }
1114 else if( !Q_stricmp( t, "[ban]" ) )
1115 {
1116 if( bc >= MAX_ADMIN_BANS )
1117 return qfalse;
1118 b = BG_Alloc( sizeof( g_admin_ban_t ) );
1119 g_admin_bans[ bc++ ] = b;
1120 ban_open = qtrue;
1121 level_open = admin_open = command_open = warning_open = qfalse;
1122 }
1123 else if( !Q_stricmp( t, "[command]" ) )
1124 {
1125 if( cc >= MAX_ADMIN_COMMANDS )
1126 return qfalse;
1127 c = BG_Alloc( sizeof( g_admin_command_t ) );
1128 g_admin_commands[ cc++ ] = c;
1129 c->levels[ 0 ] = -1;
1130 command_open = qtrue;
1131 level_open = admin_open = ban_open = warning_open = qfalse;
1132 }
1133 else if( !Q_stricmp( t, "[warning]" ) )
1134 {
1135 if( wc >= MAX_ADMIN_WARNINGS )
1136 return qfalse;
1137 w = BG_Alloc( sizeof( g_admin_warning_t ) );
1138 g_admin_warnings[ wc++ ] = w;
1139 warning_open = qtrue;
1140 level_open = admin_open = ban_open = command_open = qfalse;
1141 }
1142 else if( level_open )
1143 {
1144 if( !Q_stricmp( t, "level" ) )
1145 {
1146 readFile_int( &cnf, &l->level );
1147 }
1148 else if( !Q_stricmp( t, "name" ) )
1149 {
1150 readFile_string( &cnf, l->name, sizeof( l->name ) );
1151 }
1152 else if( !Q_stricmp( t, "flags" ) )
1153 {
1154 readFile_string( &cnf, l->flags, sizeof( l->flags ) );
1155 }
1156 else
1157 {
1158 COM_ParseError( "[level] unrecognized token \"%s\"", t );
1159 }
1160 }
1161 else if( admin_open )
1162 {
1163 if( !Q_stricmp( t, "name" ) )
1164 {
1165 readFile_string( &cnf, a->name, sizeof( a->name ) );
1166 }
1167 else if( !Q_stricmp( t, "guid" ) )
1168 {
1169 readFile_string( &cnf, a->guid, sizeof( a->guid ) );
1170 }
1171 else if( !Q_stricmp( t, "level" ) )
1172 {
1173 readFile_int( &cnf, &a->level );
1174 }
1175 else if( !Q_stricmp( t, "flags" ) )
1176 {
1177 readFile_string( &cnf, a->flags, sizeof( a->flags ) );
1178 }
1179 else
1180 {
1181 COM_ParseError( "[admin] unrecognized token \"%s\"", t );
1182 }
1183
1184 }
1185 else if( ban_open )
1186 {
1187 if( !Q_stricmp( t, "name" ) )
1188 {
1189 readFile_string( &cnf, b->name, sizeof( b->name ) );
1190 }
1191 else if( !Q_stricmp( t, "guid" ) )
1192 {
1193 readFile_string( &cnf, b->guid, sizeof( b->guid ) );
1194 }
1195 else if( !Q_stricmp( t, "ip" ) )
1196 {
1197 readFile_string( &cnf, b->ip, sizeof( b->ip ) );
1198 }
1199 else if( !Q_stricmp( t, "reason" ) )
1200 {
1201 readFile_string( &cnf, b->reason, sizeof( b->reason ) );
1202 }
1203 else if( !Q_stricmp( t, "made" ) )
1204 {
1205 readFile_string( &cnf, b->made, sizeof( b->made ) );
1206 }
1207 else if( !Q_stricmp( t, "expires" ) )
1208 {
1209 readFile_int( &cnf, &b->expires );
1210 }
1211 else if( !Q_stricmp( t, "banner" ) )
1212 {
1213 readFile_string( &cnf, b->banner, sizeof( b->banner ) );
1214 }
1215 else
1216 {
1217 COM_ParseError( "[ban] unrecognized token \"%s\"", t );
1218 }
1219 }
1220 else if( command_open )
1221 {
1222 if( !Q_stricmp( t, "command" ) )
1223 {
1224 readFile_string( &cnf, c->command, sizeof( c->command ) );
1225 }
1226 else if( !Q_stricmp( t, "exec" ) )
1227 {
1228 readFile_string( &cnf, c->exec, sizeof( c->exec ) );
1229 }
1230 else if( !Q_stricmp( t, "desc" ) )
1231 {
1232 readFile_string( &cnf, c->desc, sizeof( c->desc ) );
1233 }
1234 else if( !Q_stricmp( t, "levels" ) )
1235 {
1236 char levels[ MAX_STRING_CHARS ] = {""};
1237 char *level = levels;
1238 char *lp;
1239 int cmdlevel = 0;
1240
1241 readFile_string( &cnf, levels, sizeof( levels ) );
1242 while( cmdlevel < MAX_ADMIN_LEVELS )
1243 {
1244 lp = COM_Parse( &level );
1245 if( !*lp )
1246 break;
1247 c->levels[ cmdlevel++ ] = atoi( lp );
1248 }
1249 // ensure the list is -1 terminated
1250 c->levels[ cmdlevel ] = -1;
1251 }
1252 else
1253 {
1254 COM_ParseError( "[command] unrecognized token \"%s\"", t );
1255 }
1256 }
1257 else if( warning_open )
1258 {
1259 if( !Q_stricmp( t, "name" ) )
1260 {
1261 readFile_string( &cnf, w->name, sizeof( w->name ) );
1262 }
1263 else if( !Q_stricmp( t, "guid" ) )
1264 {
1265 readFile_string( &cnf, w->guid, sizeof( w->guid ) );
1266 }
1267 else if( !Q_stricmp( t, "ip" ) )
1268 {
1269 readFile_string( &cnf, w->ip, sizeof( w->ip ) );
1270 }
1271 else if( !Q_stricmp( t, "warning" ) )
1272 {
1273 readFile_string( &cnf, w->warning, sizeof( w->warning ) );
1274 }
1275 else if( !Q_stricmp( t, "made" ) )
1276 {
1277 readFile_string( &cnf, w->made, sizeof( w->made ) );
1278 }
1279 else if( !Q_stricmp( t, "expires" ) )
1280 {
1281 readFile_int( &cnf, &w->expires );
1282 }
1283 else if( !Q_stricmp( t, "warner" ) )
1284 {
1285 readFile_string( &cnf, w->warner, sizeof( w->warner ) );
1286 }
1287 else
1288 {
1289 COM_ParseError( "[warning] unrecognized token \"%s\"", t );
1290 }
1291 }
1292 else
1293 {
1294 COM_ParseError( "unexpected token \"%s\"", t );
1295 }
1296 }
1297 BG_Free( cnf2 );
1298 ADMP( va( "^3!readconfig: ^7loaded %d levels, %d admins, %d bans, %d commands, %d warnings\n",
1299 lc, ac, bc, cc, wc ) );
1300 if( lc == 0 )
1301 admin_default_levels();
1302 else
1303 {
1304 // max printable name length for formatting
1305 for( i = 0; i < MAX_ADMIN_LEVELS && g_admin_levels[ i ]; i++ )
1306 {
1307 len = Q_PrintStrlen( g_admin_levels[ i ]->name );
1308 if( len > admin_level_maxname )
1309 admin_level_maxname = len;
1310 }
1311 }
1312 // reset adminLevel
1313 for( i = 0; i < level.maxclients; i++ )
1314 if( level.clients[ i ].pers.connected != CON_DISCONNECTED )
1315 level.clients[ i ].pers.adminLevel = G_admin_level( &g_entities[ i ] );
1316 return qtrue;
1317 }
1318
1319 qboolean G_admin_time( gentity_t *ent, int skiparg )
1320 {
1321 qtime_t qt;
1322
1323 trap_RealTime( &qt );
1324 ADMP( va( "^3!time: ^7local time is %02i:%02i:%02i\n",
1325 qt.tm_hour, qt.tm_min, qt.tm_sec ) );
1326 return qtrue;
1327 }
1328
1329 qboolean G_admin_setlevel( gentity_t *ent, int skiparg )
1330 {
1331 char name[ MAX_NAME_LENGTH ] = {""};
1332 char lstr[ 11 ]; // 10 is max strlen() for 32-bit int
1333 char adminname[ MAX_NAME_LENGTH ] = {""};
1334 char testname[ MAX_NAME_LENGTH ] = {""};
1335 char guid[ 33 ];
1336 int l, i;
1337 gentity_t *vic = NULL;
1338 qboolean updated = qfalse;
1339 g_admin_admin_t *a;
1340 qboolean found = qfalse;
1341 qboolean numeric = qtrue;
1342 int matches = 0;
1343 int id = -1;
1344
1345
1346 if( G_SayArgc() < 3 + skiparg )
1347 {
1348 ADMP( "^3!setlevel: ^7usage: !setlevel [name|slot#] [level]\n" );
1349 return qfalse;
1350 }
1351 G_SayArgv( 1 + skiparg, testname, sizeof( testname ) );
1352 G_SayArgv( 2 + skiparg, lstr, sizeof( lstr ) );
1353 l = atoi( lstr );
1354 G_SanitiseString( testname, name, sizeof( name ) );
1355 for( i = 0; i < sizeof( name ) && name[ i ]; i++ )
1356 {
1357 if( !isdigit( name[ i ] ) )
1358 {
1359 numeric = qfalse;
1360 break;
1361 }
1362 }
1363 if( numeric )
1364 id = atoi( name );
1365
1366 if( ent && l > ent->client->pers.adminLevel )
1367 {
1368 ADMP( "^3!setlevel: ^7you may not use !setlevel to set a level higher "
1369 "than your current level\n" );
1370 return qfalse;
1371 }
1372
1373 // if admin is activated for the first time on a running server, we need
1374 // to ensure at least the default levels get created
1375 if( !ent && !g_admin_levels[ 0 ] )
1376 G_admin_readconfig(NULL, 0);
1377
1378 for( i = 0; i < MAX_ADMIN_LEVELS && g_admin_levels[ i ]; i++ )
1379 {
1380 if( g_admin_levels[ i ]->level == l )
1381 {
1382 found = qtrue;
1383 break;
1384 }
1385 }
1386 if( !found )
1387 {
1388 ADMP( "^3!setlevel: ^7level is not defined\n" );
1389 return qfalse;
1390 }
1391
1392 if( numeric && id >= 0 && id < level.maxclients )
1393 vic = &g_entities[ id ];
1394
1395 if( vic && vic->client && vic->client->pers.connected != CON_DISCONNECTED )
1396 {
1397 Q_strncpyz( adminname, vic->client->pers.netname, sizeof( adminname ) );
1398 Q_strncpyz( guid, vic->client->pers.guid, sizeof( guid ) );
1399 matches = 1;
1400 }
1401 else if( numeric && id >= MAX_CLIENTS && id < MAX_CLIENTS + MAX_ADMIN_ADMINS
1402 && g_admin_admins[ id - MAX_CLIENTS ] )
1403 {
1404 Q_strncpyz( adminname, g_admin_admins[ id - MAX_CLIENTS ]->name,
1405 sizeof( adminname ) );
1406 Q_strncpyz( guid, g_admin_admins[ id - MAX_CLIENTS ]->guid,
1407 sizeof( guid ) );
1408 matches = 1;
1409 }
1410 else
1411 {
1412 for( i = 0; i < MAX_ADMIN_ADMINS && g_admin_admins[ i ] && matches < 2; i++ )
1413 {
1414 G_SanitiseString( g_admin_admins[ i ]->name, testname, sizeof( testname ) );
1415 if( strstr( testname, name ) )
1416 {
1417 Q_strncpyz( adminname, g_admin_admins[ i ]->name, sizeof( adminname ) );
1418 Q_strncpyz( guid, g_admin_admins[ i ]->guid, sizeof( guid ) );
1419 matches++;
1420 }
1421 }
1422 for( i = 0; i < level.maxclients && matches < 2; i++ )
1423 {
1424 if( level.clients[ i ].pers.connected == CON_DISCONNECTED )
1425 continue;
1426 if( matches && !Q_stricmp( level.clients[ i ].pers.guid, guid ) )
1427 {
1428 vic = &g_entities[ i ];
1429 continue;
1430 }
1431 G_SanitiseString( level.clients[ i ].pers.netname, testname,
1432 sizeof( testname ) );
1433 if( strstr( testname, name ) )
1434 {
1435 vic = &g_entities[ i ];
1436 matches++;
1437 Q_strncpyz( guid, vic->client->pers.guid, sizeof( guid ) );
1438 }
1439 }
1440 if( vic && vic->client)
1441 Q_strncpyz( adminname, vic->client->pers.netname, sizeof( adminname ) );
1442 }
1443
1444 if( matches == 0 )
1445 {
1446 ADMP( "^3!setlevel:^7 no match. use !listplayers or !listadmins to "
1447 "find an appropriate number to use instead of name.\n" );
1448 return qfalse;
1449 }
1450 if( matches > 1 )
1451 {
1452 ADMP( "^3!setlevel:^7 more than one match. Use the admin number "
1453 "instead:\n" );
1454 admin_listadmins( ent, 0, name );
1455 return qfalse;
1456 }
1457
1458 if( ent && !admin_higher_guid( ent->client->pers.guid, guid ) )
1459 {
1460 ADMP( "^3!setlevel: ^7sorry, but your intended victim has a higher"
1461 " admin level than you\n" );
1462 return qfalse;
1463 }
1464
1465 for( i = 0; i < MAX_ADMIN_ADMINS && g_admin_admins[ i ];i++ )
1466 {
1467 if( !Q_stricmp( g_admin_admins[ i ]->guid, guid ) )
1468 {
1469 g_admin_admins[ i ]->level = l;
1470 Q_strncpyz( g_admin_admins[ i ]->name, adminname,
1471 sizeof( g_admin_admins[ i ]->name ) );
1472 updated = qtrue;
1473 }
1474 }
1475 if( !updated )
1476 {
1477 if( i == MAX_ADMIN_ADMINS )
1478 {
1479 ADMP( "^3!setlevel: ^7too many admins\n" );
1480 return qfalse;
1481 }
1482 a = BG_Alloc( sizeof( g_admin_admin_t ) );
1483 a->level = l;
1484 Q_strncpyz( a->name, adminname, sizeof( a->name ) );
1485 Q_strncpyz( a->guid, guid, sizeof( a->guid ) );
1486 *a->flags = '\0';
1487 g_admin_admins[ i ] = a;
1488 }
1489
1490 AP( va(
1491 "print \"^3!setlevel: ^7%s^7 was given level %d admin rights by %s\n\"",
1492 adminname, l, ( ent ) ? ent->client->pers.netname : "console" ) );
1493 if( vic && vic->client )
1494 vic->client->pers.adminLevel = l;
1495
1496 if( !g_admin.string[ 0 ] )
1497 ADMP( "^3!setlevel: ^7WARNING g_admin not set, not saving admin record "
1498 "to a file\n" );
1499 else
1500 admin_writeconfig();
1501 return qtrue;
1502 }
1503
1504 static qboolean admin_create_ban( gentity_t *ent,
1505 char *netname,
1506 char *guid,
1507 char *ip,
1508 int seconds,
1509 char *reason )
1510 {
1511 g_admin_ban_t *b = NULL;
1512 qtime_t qt;
1513 int t;
1514 int i;
1515
1516 t = trap_RealTime( &qt );
1517 b = BG_Alloc( sizeof( g_admin_ban_t ) );
1518
1519 if( !b )
1520 return qfalse;
1521
1522 Q_strncpyz( b->name, netname, sizeof( b->name ) );
1523 Q_strncpyz( b->guid, guid, sizeof( b->guid ) );
1524 Q_strncpyz( b->ip, ip, sizeof( b->ip ) );
1525
1526 //strftime( b->made, sizeof( b->made ), "%m/%d/%y %H:%M:%S", lt );
1527 Com_sprintf( b->made, sizeof( b->made ), "%02i/%02i/%02i %02i:%02i:%02i",
1528 qt.tm_mon + 1, qt.tm_mday, qt.tm_year % 100,
1529 qt.tm_hour, qt.tm_min, qt.tm_sec );
1530
1531 if( ent )
1532 Q_strncpyz( b->banner, ent->client->pers.netname, sizeof( b->banner ) );
1533 else
1534 Q_strncpyz( b->banner, "console", sizeof( b->banner ) );
1535 if( !seconds )
1536 b->expires = 0;
1537 else
1538 b->expires = t + seconds;
1539 if( !*reason )
1540 Q_strncpyz( b->reason, "banned by admin", sizeof( b->reason ) );
1541 else
1542 Q_strncpyz( b->reason, reason, sizeof( b->reason ) );
1543 for( i = 0; i < MAX_ADMIN_BANS && g_admin_bans[ i ]; i++ )
1544 ;
1545 if( i == MAX_ADMIN_BANS )
1546 {
1547 ADMP( "^3!ban: ^7too many bans\n" );
1548 BG_Free( b );
1549 return qfalse;
1550 }
1551 g_admin_bans[ i ] = b;
1552 return qtrue;
1553 }
1554 //KK-OAX Copied create_ban to get Time Stuff Right (Didn't feel like writing code to parse it)
1555 static qboolean admin_create_warning( gentity_t *ent, char *netname, char *guid, char *ip, int seconds, char *warning )
1556 {
1557 g_admin_warning_t *w = NULL;
1558 qtime_t qt;
1559 int t;
1560 int i;
1561
1562 t = trap_RealTime( &qt );
1563 w = BG_Alloc( sizeof( g_admin_warning_t ) );
1564
1565 if( !w )
1566 return qfalse;
1567
1568 Q_strncpyz( w->name, netname, sizeof( w->name ) );
1569 Q_strncpyz( w->guid, guid, sizeof( w->guid ) );
1570 Q_strncpyz( w->ip, ip, sizeof( w->ip ) );
1571
1572 //strftime( b->made, sizeof( b->made ), "%m/%d/%y %H:%M:%S", lt );
1573 Com_sprintf( w->made, sizeof( w->made ), "%02i/%02i/%02i %02i:%02i:%02i",
1574 qt.tm_mon + 1, qt.tm_mday, qt.tm_year % 100,
1575 qt.tm_hour, qt.tm_min, qt.tm_sec );
1576
1577 if( ent )
1578 Q_strncpyz( w->warner, ent->client->pers.netname, sizeof( w->warner ) );
1579 else
1580 Q_strncpyz( w->warner, "console", sizeof( w->warner ) );
1581 if( !seconds )
1582 w->expires = 0;
1583 else
1584 w->expires = t + seconds;
1585 if( !*warning )
1586 Q_strncpyz( w->warning, "warned by admin", sizeof( w->warning ) );
1587 else
1588 Q_strncpyz( w->warning, warning, sizeof( w->warning ) );
1589 for( i = 0; i < MAX_ADMIN_WARNINGS && g_admin_warnings[ i ]; i++ )
1590 ;
1591 if( i == MAX_ADMIN_WARNINGS )
1592 {
1593 ADMP( "^3!warn: ^7too many warnings\n" );
1594 BG_Free( w );
1595 return qfalse;
1596 }
1597 g_admin_warnings[ i ] = w;
1598 return qtrue;
1599 }
1600
1601
1602 int G_admin_parse_time( const char *time )
1603 {
1604 int seconds = 0, num = 0;
1605 while( *time )
1606 {
1607 if( !isdigit( *time ) )
1608 return -1;
1609 while( isdigit( *time ) )
1610 num = num * 10 + *time++ - '0';
1611
1612 if( !*time )
1613 break;
1614 switch( *time++ )
1615 {
1616 case 'w': num *= 7;
1617 case 'd': num *= 24;
1618 case 'h': num *= 60;
1619 case 'm': num *= 60;
1620 case 's': break;
1621 default: return -1;
1622 }
1623 seconds += num;
1624 num = 0;
1625 }
1626 if( num )
1627 seconds += num;
1628 return seconds;
1629 }
1630
1631 qboolean G_admin_kick( gentity_t *ent, int skiparg )
1632 {
1633 int pids[ MAX_CLIENTS ], found;
1634 char name[ MAX_NAME_LENGTH ], *reason, err[ MAX_STRING_CHARS ];
1635 int minargc;
1636 gentity_t *vic;
1637
1638 minargc = 3 + skiparg;
1639 if( G_admin_permission( ent, ADMF_UNACCOUNTABLE ) )
1640 minargc = 2 + skiparg;
1641
1642 if( G_SayArgc() < minargc )
1643 {
1644 ADMP( "^3!kick: ^7usage: !kick [name] [reason]\n" );
1645 return qfalse;
1646 }
1647 G_SayArgv( 1 + skiparg, name, sizeof( name ) );
1648 reason = G_SayConcatArgs( 2 + skiparg );
1649 if( ( found = G_ClientNumbersFromString( name, pids, MAX_CLIENTS ) ) != 1 )
1650 {
1651 G_MatchOnePlayer( pids, found, err, sizeof( err ) );
1652 ADMP( va( "^3!kick: ^7%s\n", err ) );
1653 return qfalse;
1654 }
1655 vic = &g_entities[ pids[ 0 ] ];
1656 if( !admin_higher( ent, vic ) )
1657 {
1658 ADMP( "^3!kick: ^7sorry, but your intended victim has a higher admin"
1659 " level than you\n" );
1660 return qfalse;
1661 }
1662 if( vic->client->pers.localClient )
1663 {
1664 ADMP( "^3!kick: ^7disconnecting the host would end the game\n" );
1665 return qfalse;
1666 }
1667 admin_create_ban( ent,
1668 vic->client->pers.netname,
1669 vic->client->pers.guid,
1670 vic->client->pers.ip,
1671 G_admin_parse_time( va( "1s%s", g_adminTempBan.string ) ),
1672 ( *reason ) ? reason : "kicked by admin" );
1673 if( g_admin.string[ 0 ] )
1674 admin_writeconfig();
1675
1676 trap_SendServerCommand( pids[ 0 ],
1677 va( "disconnect \"You have been kicked.\n%s^7\nreason:\n%s\"",
1678 ( ent ) ? va( "admin:\n%s", ent->client->pers.netname ) : "",
1679 ( *reason ) ? reason : "kicked by admin" ) );
1680
1681 trap_DropClient( pids[ 0 ], va( "has been kicked%s^7. reason: %s",
1682 ( ent ) ? va( " by %s", ent->client->pers.netname ) : "",
1683 ( *reason ) ? reason : "kicked by admin" ) );
1684
1685 return qtrue;
1686 }
1687
1688 qboolean G_admin_ban( gentity_t *ent, int skiparg )
1689 {
1690 int seconds;
1691 char search[ MAX_NAME_LENGTH ];
1692 char secs[ MAX_TOKEN_CHARS ];
1693 char *reason;
1694 int minargc;
1695 char duration[ 32 ];
1696 int logmatch = -1, logmatches = 0;
1697 int i, j;
1698 qboolean exactmatch = qfalse;
1699 char n2[ MAX_NAME_LENGTH ];
1700 char s2[ MAX_NAME_LENGTH ];
1701 char guid_stub[ 9 ];
1702
1703 if( G_admin_permission( ent, ADMF_CAN_PERM_BAN ) &&
1704 G_admin_permission( ent, ADMF_UNACCOUNTABLE ) )
1705 {
1706 minargc = 2 + skiparg;
1707 }
1708 else if( G_admin_permission( ent, ADMF_CAN_PERM_BAN ) ||
1709 G_admin_permission( ent, ADMF_UNACCOUNTABLE ) ||
1710 g_adminMaxBan.integer )
1711 {
1712 minargc = 3 + skiparg;
1713 }
1714 else
1715 {
1716 minargc = 4 + skiparg;
1717 }
1718 if( G_SayArgc() < minargc )
1719 {
1720 ADMP( "^3!ban: ^7usage: !ban [name|slot|ip] [duration] [reason]\n" );
1721 return qfalse;
1722 }
1723 G_SayArgv( 1 + skiparg, search, sizeof( search ) );
1724 G_SanitiseString( search, s2, sizeof( s2 ) );
1725 G_SayArgv( 2 + skiparg, secs, sizeof( secs ) );
1726
1727 seconds = G_admin_parse_time( secs );
1728 if( seconds <= 0 )
1729 {
1730 if( g_adminMaxBan.integer && !G_admin_permission( ent, ADMF_CAN_PERM_BAN) )
1731 {
1732 ADMP( va( "^3!ban: ^7using your admin level's maximum ban length of %s\n",
1733 g_adminMaxBan.string ) );
1734 seconds = G_admin_parse_time( g_adminMaxBan.string );
1735 }
1736 else if( G_admin_permission( ent, ADMF_CAN_PERM_BAN ) )
1737 {
1738 seconds = 0;
1739 }
1740 else
1741 {
1742 ADMP( "^3!ban: ^7you may not issue permanent bans\n" );
1743 return qfalse;
1744 }
1745 reason = G_SayConcatArgs( 2 + skiparg );
1746 }
1747 else
1748 {
1749 if( g_adminMaxBan.integer &&
1750 !G_admin_permission( ent, ADMF_CAN_PERM_BAN ) &&
1751 seconds > G_admin_parse_time( g_adminMaxBan.string ) )
1752 {
1753 ADMP( va( "^3!ban: ^7ban length limited to %s for your admin level\n",
1754 g_adminMaxBan.string ) );
1755 seconds = G_admin_parse_time( g_adminMaxBan.string );
1756 }
1757 reason = G_SayConcatArgs( 3 + skiparg );
1758 }
1759
1760 for( i = 0; i < MAX_ADMIN_NAMELOGS && g_admin_namelog[ i ]; i++ )
1761 {
1762 // skip players in the namelog who have already been banned
1763 if( g_admin_namelog[ i ]->banned )
1764 continue;
1765
1766 // skip disconnected players when banning on slot number
1767 if( g_admin_namelog[ i ]->slot == -1 )
1768 continue;
1769
1770 if( !Q_stricmp( va( "%d", g_admin_namelog[ i ]->slot ), search ) )
1771 {
1772 logmatches = 1;
1773 logmatch = i;
1774 exactmatch = qtrue;
1775 break;
1776 }
1777 }
1778
1779 for( i = 0;
1780 !exactmatch && i < MAX_ADMIN_NAMELOGS && g_admin_namelog[ i ];
1781 i++ )
1782 {
1783 // skip players in the namelog who have already been banned
1784 if( g_admin_namelog[ i ]->banned )
1785 continue;
1786
1787 if( !Q_stricmp( g_admin_namelog[ i ]->ip, search ) )
1788 {
1789 logmatches = 1;
1790 logmatch = i;
1791 exactmatch = qtrue;
1792 break;
1793 }
1794 for( j = 0; j < MAX_ADMIN_NAMELOG_NAMES &&
1795 g_admin_namelog[ i ]->name[ j ][ 0 ]; j++ )
1796 {
1797 G_SanitiseString( g_admin_namelog[ i ]->name[ j ], n2, sizeof( n2 ) );
1798 if( strstr( n2, s2 ) )
1799 {
1800 if( logmatch != i )
1801 logmatches++;
1802 logmatch = i;
1803 }
1804 }
1805 }
1806
1807 if( !logmatches )
1808 {
1809 ADMP( "^3!ban: ^7no player found by that name, IP, or slot number\n" );
1810 return qfalse;
1811 }
1812 if( logmatches > 1 )
1813 {
1814 ADMBP_begin();
1815 ADMBP( "^3!ban: ^7multiple recent clients match name, use IP or slot#:\n" );
1816 for( i = 0; i < MAX_ADMIN_NAMELOGS && g_admin_namelog[ i ]; i++ )
1817 {
1818 for( j = 0; j < 8; j++ )
1819 guid_stub[ j ] = g_admin_namelog[ i ]->guid[ j + 24 ];
1820 guid_stub[ j ] = '\0';
1821 for( j = 0; j < MAX_ADMIN_NAMELOG_NAMES &&
1822 g_admin_namelog[ i ]->name[ j ][ 0 ]; j++ )
1823 {
1824 G_SanitiseString( g_admin_namelog[ i ]->name[ j ], n2, sizeof( n2 ) );
1825 if( strstr( n2, s2 ) )
1826 {
1827 if( g_admin_namelog[ i ]->slot > -1 )
1828 ADMBP( "^3" );
1829 ADMBP( va( "%-2s (*%s) %15s ^7'%s^7'\n",
1830 ( g_admin_namelog[ i ]->slot > -1 ) ?
1831 va( "%d", g_admin_namelog[ i ]->slot ) : "-",
1832 guid_stub,
1833 g_admin_namelog[ i ]->ip,
1834 g_admin_namelog[ i ]->name[ j ] ) );
1835 }
1836 }
1837 }
1838 ADMBP_end();
1839 return qfalse;
1840 }
1841
1842 if( ent && !admin_higher_guid( ent->client->pers.guid,
1843 g_admin_namelog[ logmatch ]->guid ) )
1844 {
1845
1846 ADMP( "^3!ban: ^7sorry, but your intended victim has a higher admin"
1847 " level than you\n" );
1848 return qfalse;
1849 }
1850 if( !strcmp( g_admin_namelog[ logmatch ]->ip, "localhost" ) )
1851 {
1852 ADMP( "^3!ban: ^7disconnecting the host would end the game\n" );
1853 return qfalse;
1854 }
1855
1856 G_admin_duration( ( seconds ) ? seconds : -1,
1857 duration, sizeof( duration ) );
1858
1859 admin_create_ban( ent,
1860 g_admin_namelog[ logmatch ]->name[ 0 ],
1861 g_admin_namelog[ logmatch ]->guid,
1862 g_admin_namelog[ logmatch ]->ip,
1863 seconds, reason );
1864
1865 g_admin_namelog[ logmatch ]->banned = qtrue;
1866
1867 if( !g_admin.string[ 0 ] )
1868 ADMP( "^3!ban: ^7WARNING g_admin not set, not saving ban to a file\n" );
1869 else
1870 if(strlen(g_admin_namelog[ logmatch ]->guid)==0 || strlen(g_admin_namelog[ logmatch ]->ip) )
1871 ADMP( "^3!ban: ^7WARNING bot or without GUID or IP cannot write to ban file\n");
1872 else
1873 admin_writeconfig();
1874
1875 if( g_admin_namelog[ logmatch ]->slot == -1 )
1876 {
1877 // client is already disconnected so stop here
1878 AP( va( "print \"^3!ban:^7 %s^7 has been banned by %s^7, "
1879 "duration: %s, reason: %s\n\"",
1880 g_admin_namelog[ logmatch ]->name[ 0 ],
1881 ( ent ) ? ent->client->pers.netname : "console",
1882 duration,
1883 ( *reason ) ? reason : "banned by admin" ) );
1884 return qtrue;
1885 }
1886
1887 trap_SendServerCommand( g_admin_namelog[ logmatch ]->slot,
1888 va( "disconnect \"You have been banned.\n"
1889 "admin:\n%s^7\nduration:\n%s\nreason:\n%s\"",
1890 ( ent ) ? ent->client->pers.netname : "console",
1891 duration,
1892 ( *reason ) ? reason : "banned by admin" ) );
1893
1894 trap_DropClient( g_admin_namelog[ logmatch ]->slot,
1895 va( "has been banned by %s^7, duration: %s, reason: %s",
1896 ( ent ) ? ent->client->pers.netname : "console",
1897 duration,
1898 ( *reason ) ? reason : "banned by admin" ) );
1899 return qtrue;
1900 }
1901
1902 qboolean G_admin_unban( gentity_t *ent, int skiparg )
1903 {
1904 int bnum;
1905 int time = trap_RealTime( NULL );
1906 char bs[ 5 ];
1907
1908 if( G_SayArgc() < 2 + skiparg )
1909 {
1910 ADMP( "^3!unban: ^7usage: !unban [ban#]\n" );
1911 return qfalse;
1912 }
1913 G_SayArgv( 1 + skiparg, bs, sizeof( bs ) );
1914 bnum = atoi( bs );
1915 if( bnum < 1 || bnum > MAX_ADMIN_BANS || !g_admin_bans[ bnum - 1 ] )
1916 {
1917 ADMP( "^3!unban: ^7invalid ban#\n" );
1918 return qfalse;
1919 }
1920 if( g_admin_bans[ bnum - 1 ]->expires == 0 &&
1921 !G_admin_permission( ent, ADMF_CAN_PERM_BAN ) )
1922 {
1923 ADMP( "^3!unban: ^7you cannot remove permanent bans\n" );
1924 return qfalse;
1925 }
1926 if( g_adminMaxBan.integer &&
1927 !G_admin_permission( ent, ADMF_CAN_PERM_BAN ) &&
1928 g_admin_bans[ bnum - 1 ]->expires - time > G_admin_parse_time( g_adminMaxBan.string ) )
1929 {
1930 ADMP( va( "^3!unban: ^7your admin level cannot remove bans longer than %s\n",
1931 g_adminMaxBan.string ) );
1932 return qfalse;
1933 }
1934 g_admin_bans[ bnum - 1 ]->expires = time;
1935 AP( va( "print \"^3!unban: ^7ban #%d for %s^7 has been removed by %s\n\"",
1936 bnum,
1937 g_admin_bans[ bnum - 1 ]->name,
1938 ( ent ) ? ent->client->pers.netname : "console" ) );
1939 if( g_admin.string[ 0 ] )
1940 admin_writeconfig();
1941 return qtrue;
1942 }
1943
1944 qboolean G_admin_adjustban( gentity_t *ent, int skiparg )
1945 {
1946 int bnum;
1947 int length;
1948 int expires;
1949 int time = trap_RealTime( NULL );
1950 char duration[ 32 ] = {""};
1951 char *reason;
1952 char bs[ 5 ];
1953 char secs[ MAX_TOKEN_CHARS ];
1954 char mode = '\0';
1955 g_admin_ban_t *ban;
1956
1957 if( G_SayArgc() < 3 + skiparg )
1958 {
1959 ADMP( "^3!adjustban: ^7usage: !adjustban [ban#] [duration] [reason]\n" );
1960 return qfalse;
1961 }
1962 G_SayArgv( 1 + skiparg, bs, sizeof( bs ) );
1963 bnum = atoi( bs );
1964 if( bnum < 1 || bnum > MAX_ADMIN_BANS || !g_admin_bans[ bnum - 1 ] )
1965 {
1966 ADMP( "^3!adjustban: ^7invalid ban#\n" );
1967 return qfalse;
1968 }
1969 ban = g_admin_bans[ bnum - 1 ];
1970 if( ban->expires == 0 && !G_admin_permission( ent, ADMF_CAN_PERM_BAN ) )
1971 {
1972 ADMP( "^3!adjustban: ^7you cannot modify permanent bans\n" );
1973 return qfalse;
1974 }
1975 if( g_adminMaxBan.integer &&
1976 !G_admin_permission( ent, ADMF_CAN_PERM_BAN ) &&
1977 ban->expires - time > G_admin_parse_time( g_adminMaxBan.string ) )
1978 {
1979 ADMP( va( "^3!adjustban: ^7your admin level cannot modify bans longer than %s\n",
1980 g_adminMaxBan.string ) );
1981 return qfalse;
1982 }
1983 G_SayArgv( 2 + skiparg, secs, sizeof( secs ) );
1984 if( secs[ 0 ] == '+' || secs[ 0 ] == '-' )
1985 mode = secs[ 0 ];
1986 length = G_admin_parse_time( &secs[ mode ? 1 : 0 ] );
1987 if( length < 0 )
1988 skiparg--;
1989 else
1990 {
1991 if( length )
1992 {
1993 if( ban->expires == 0 && mode )
1994 {
1995 ADMP( "^3!adjustban: ^7new duration must be explicit\n" );
1996 return qfalse;
1997 }
1998 if( mode == '+' )
1999 expires = ban->expires + length;
2000 else if( mode == '-' )
2001 expires = ban->expires - length;
2002 else
2003 expires = time + length;
2004 if( expires <= time )
2005 {
2006 ADMP( "^3!adjustban: ^7ban duration must be positive\n" );
2007 return qfalse;
2008 }
2009 if( g_adminMaxBan.integer &&
2010 !G_admin_permission( ent, ADMF_CAN_PERM_BAN ) &&
2011 expires - time > G_admin_parse_time( g_adminMaxBan.string ) )
2012 {
2013 ADMP( va( "^3!adjustban: ^7ban length is limited to %s for your admin level\n",
2014 g_adminMaxBan.string ) );
2015 length = G_admin_parse_time( g_adminMaxBan.string );
2016 expires = time + length;
2017 }
2018 }
2019 else if( G_admin_permission( ent, ADMF_CAN_PERM_BAN ) )
2020 expires = 0;
2021 else
2022 {
2023 ADMP( "^3!adjustban: ^7ban duration must be positive\n" );
2024 return qfalse;
2025 }
2026
2027 ban->expires = expires;
2028 G_admin_duration( ( expires ) ? expires - time : -1, duration,
2029 sizeof( duration ) );
2030 }
2031 reason = G_SayConcatArgs( 3 + skiparg );
2032 if( *reason )
2033 Q_strncpyz( ban->reason, reason, sizeof( ban->reason ) );
2034 AP( va( "print \"^3!adjustban: ^7ban #%d for %s^7 has been updated by %s^7 "
2035 "%s%s%s%s%s\n\"",
2036 bnum,
2037 ban->name,
2038 ( ent ) ? ent->client->pers.netname : "console",
2039 ( length >= 0 ) ? "duration: " : "",
2040 duration,
2041 ( length >= 0 && *reason ) ? ", " : "",
2042 ( *reason ) ? "reason: " : "",
2043 reason ) );
2044 if( ent )
2045 Q_strncpyz( ban->banner, ent->client->pers.netname, sizeof( ban->banner ) );
2046 if( g_admin.string[ 0 ] )
2047 admin_writeconfig();
2048 return qtrue;
2049 }
2050
2051 qboolean G_admin_putteam( gentity_t *ent, int skiparg )
2052 {
2053 int pids[ MAX_CLIENTS ], found;
2054 //KK-OAPub Changed Team Name Length so "Spectator" doesn't crash Game
2055 char name[ MAX_NAME_LENGTH ], team[ MAX_NAME_LENGTH ], err[ MAX_STRING_CHARS ];
2056 gentity_t *vic;
2057 team_t teamnum = TEAM_NONE;
2058
2059 G_SayArgv( 1 + skiparg, name, sizeof( name ) );
2060 G_SayArgv( 2 + skiparg, team, sizeof( team ) );
2061 if( G_SayArgc() < 3 + skiparg )
2062 {
2063 ADMP( "^3!putteam: ^7usage: !putteam [name] [h|a|s]\n" );
2064 return qfalse;
2065 }
2066
2067 if( ( found = G_ClientNumbersFromString( name, pids, MAX_CLIENTS ) ) != 1 )
2068 {
2069 G_MatchOnePlayer( pids, found, err, sizeof( err ) );
2070 ADMP( va( "^3!putteam: ^7%s\n", err ) );
2071 return qfalse;
2072 }
2073 if( !admin_higher( ent, &g_entities[ pids[ 0 ] ] ) )
2074 {
2075 ADMP( "^3!putteam: ^7sorry, but your intended victim has a higher "
2076 " admin level than you\n" );
2077 return qfalse;
2078 }
2079 vic = &g_entities[ pids[ 0 ] ];
2080 teamnum = G_TeamFromString( team );
2081 if( teamnum == TEAM_NUM_TEAMS )
2082 {
2083 ADMP( va( "^3!putteam: ^7unknown team %s\n", team ) );
2084 return qfalse;
2085 }
2086 if( vic->client->sess.sessionTeam == teamnum )
2087 return qfalse;
2088
2089 SetTeam( vic, team );
2090
2091 AP( va( "print \"^3!putteam: ^7%s^7 put %s^7 on to the %s team\n\"",
2092 ( ent ) ? ent->client->pers.netname : "console",
2093 vic->client->pers.netname, BG_TeamName( teamnum ) ) );
2094 return qtrue;
2095 }
2096
2097 //KK-Fixed!!!!
2098 //KK-Removed Layouts from The command
2099 qboolean G_admin_map( gentity_t *ent, int skiparg )
2100 {
2101 char map[ MAX_QPATH ];
2102
2103 if( G_SayArgc( ) < 2 + skiparg )
2104 {
2105 ADMP( "^3!map: ^7usage: !map [map] (layout)\n" );
2106 return qfalse;
2107 }
2108
2109 G_SayArgv( skiparg + 1, map, sizeof( map ) );
2110
2111 if( !trap_FS_FOpenFile( va( "maps/%s.bsp", map ), NULL, FS_READ ) )
2112 {
2113 ADMP( va( "^3!map: ^7invalid map name '%s'\n", map ) );
2114 return qfalse;
2115 }
2116
2117 trap_SendConsoleCommand( EXEC_APPEND, va( "map %s", map ) );
2118 level.restarted = qtrue;
2119 AP( va( "print \"^3!map: ^7map '%s' started by %s\n\"", map,
2120 ( ent ) ? ent->client->pers.netname : "console" ) );
2121 return qtrue;
2122 }
2123
2124 qboolean G_admin_mute( gentity_t *ent, int skiparg )
2125 {
2126 int pids[ MAX_CLIENTS ], found;
2127 char name[ MAX_NAME_LENGTH ], err[ MAX_STRING_CHARS ];
2128 char command[ MAX_ADMIN_CMD_LEN ], *cmd;
2129 gentity_t *vic;
2130
2131 G_SayArgv( skiparg, command, sizeof( command ) );
2132 cmd = command;
2133 if( cmd && *cmd == '!' )
2134 cmd++;
2135 if( G_SayArgc() < 2 + skiparg )
2136 {
2137 ADMP( va( "^3!%s: ^7usage: !%s [name|slot#]\n", cmd, cmd ) );
2138 return qfalse;
2139 }
2140 G_SayArgv( 1 + skiparg, name, sizeof( name ) );
2141 if( ( found = G_ClientNumbersFromString( name, pids, MAX_CLIENTS ) ) != 1 )
2142 {
2143 G_MatchOnePlayer( pids, found, err, sizeof( err ) );
2144 ADMP( va( "^3!%s: ^7%s\n", cmd, err ) );
2145 return qfalse;
2146 }
2147 if( !admin_higher( ent, &g_entities[ pids[ 0 ] ] ) )
2148 {
2149 ADMP( va( "^3!%s: ^7sorry, but your intended victim has a higher admin"
2150 " level than you\n", cmd ) );
2151 return qfalse;
2152 }
2153 vic = &g_entities[ pids[ 0 ] ];
2154 if( vic->client->pers.muted == qtrue )
2155 {
2156 if( !Q_stricmp( cmd, "mute" ) )
2157 {
2158 ADMP( "^3!mute: ^7player is already muted\n" );
2159 return qtrue;
2160 }
2161 vic->client->pers.muted = qfalse;
2162 CPx( pids[ 0 ], "cp \"^1You have been unmuted\"" );
2163 AP( va( "print \"^3!unmute: ^7%s^7 has been unmuted by %s\n\"",
2164 vic->client->pers.netname,
2165 ( ent ) ? ent->client->pers.netname : "console" ) );
2166 }
2167 else
2168 {
2169 if( !Q_stricmp( cmd, "unmute" ) )
2170 {
2171 ADMP( "^3!unmute: ^7player is not currently muted\n" );
2172 return qtrue;
2173 }
2174 vic->client->pers.muted = qtrue;
2175 CPx( pids[ 0 ], "cp \"^1You've been muted\"" );
2176 AP( va( "print \"^3!mute: ^7%s^7 has been muted by ^7%s\n\"",
2177 vic->client->pers.netname,
2178 ( ent ) ? ent->client->pers.netname : "console" ) );
2179 }
2180 return qtrue;
2181 }
2182
2183
2184
2185 qboolean G_admin_listadmins( gentity_t *ent, int skiparg )
2186 {
2187 int i, found = 0;
2188 char search[ MAX_NAME_LENGTH ] = {""};
2189 char s[ MAX_NAME_LENGTH ] = {""};
2190 int start = 0;
2191 qboolean numeric = qtrue;
2192 int drawn = 0;
2193
2194 for( i = 0; i < MAX_ADMIN_ADMINS && g_admin_admins[ i ]; i++ )
2195 {
2196 if( g_admin_admins[ i ]->level == 0 )
2197 continue;
2198 found++;
2199 }
2200 if( !found )
2201 {
2202 ADMP( "^3!listadmins: ^7no admins defined\n" );
2203 return qfalse;
2204 }
2205
2206 if( G_SayArgc() == 2 + skiparg )
2207 {
2208 G_SayArgv( 1 + skiparg, s, sizeof( s ) );
2209 for( i = 0; i < sizeof( s ) && s[ i ]; i++ )
2210 {
2211 if( isdigit( s[ i ] ) )
2212 continue;
2213 numeric = qfalse;
2214 }
2215 if( numeric )
2216 {
2217 start = atoi( s );
2218 if( start > 0 )
2219 start -= 1;
2220 else if( start < 0 )
2221 start = found + start;
2222 }
2223 else
2224 G_SanitiseString( s, search, sizeof( search ) );
2225 }
2226
2227 if( start >= found || start < 0 )
2228 start = 0;
2229
2230 if( start >= found )
2231 {
2232 ADMP( va( "^3!listadmins: ^7listing %d admins\n", found ) );
2233 return qfalse;
2234 }
2235
2236 drawn = admin_listadmins( ent, start, search );
2237
2238 if( search[ 0 ] )
2239 {
2240 ADMP( va( "^3!listadmins:^7 found %d admins matching '%s^7'\n",
2241 drawn, search ) );
2242 }
2243 else
2244 {
2245 ADMBP_begin();
2246 ADMBP( va( "^3!listadmins:^7 showing admin %d - %d of %d. ",
2247 ( found ) ? ( start + 1 ) : 0,
2248 ( ( start + MAX_ADMIN_LISTITEMS ) > found ) ?
2249 found : ( start + MAX_ADMIN_LISTITEMS ),
2250 found ) );
2251 if( ( start + MAX_ADMIN_LISTITEMS ) < found )
2252 {
2253 ADMBP( va( "run '!listadmins %d' to see more",
2254 ( start + MAX_ADMIN_LISTITEMS + 1 ) ) );
2255 }
2256 ADMBP( "\n" );
2257 ADMBP_end();
2258 }
2259 return qtrue;
2260 }
2261
2262
2263 qboolean G_admin_listplayers( gentity_t *ent, int skiparg )
2264 {
2265 int i, j;
2266 gclient_t *p;
2267 char c[ 3 ], t[ 2 ]; // color and team letter
2268 char n[ MAX_NAME_LENGTH ] = {""};
2269 char n2[ MAX_NAME_LENGTH ] = {""};
2270 char n3[ MAX_NAME_LENGTH ] = {""};
2271 char lname[ MAX_NAME_LENGTH ];
2272 char guid_stub[ 9 ];
2273 char muted[ 2 ];
2274 int l;
2275
2276 ADMBP_begin();
2277 ADMBP( va( "^3!listplayers: ^7%d players connected:\n",
2278 level.numConnectedClients ) );
2279 for( i = 0; i < level.maxclients; i++ )
2280 {
2281 p = &level.clients[ i ];
2282 Q_strncpyz( t, "S", sizeof( t ) );
2283 Q_strncpyz( c, S_COLOR_YELLOW, sizeof( c ) );
2284 if( p->sess.sessionTeam == TEAM_BLUE )
2285 {
2286 Q_strncpyz( t, "B", sizeof( t ) );
2287 Q_strncpyz( c, S_COLOR_BLUE, sizeof( c ) );
2288 }
2289 else if( p->sess.sessionTeam == TEAM_RED )
2290 {
2291 Q_strncpyz( t, "R", sizeof( t ) );
2292 Q_strncpyz( c, S_COLOR_RED, sizeof( c ) );
2293 }
2294 else if( p->sess.sessionTeam == TEAM_FREE )
2295 {
2296 Q_strncpyz( t, "F", sizeof( t ) );
2297 Q_strncpyz( c, S_COLOR_GREEN, sizeof( c ) );
2298 }
2299 else if( p->sess.sessionTeam == TEAM_NONE )
2300 {
2301 Q_strncpyz( t, "S", sizeof( t ) );
2302 Q_strncpyz( c, S_COLOR_WHITE, sizeof( c ) );
2303 }
2304 if( p->pers.connected == CON_CONNECTING )
2305 {
2306 Q_strncpyz( t, "C", sizeof( t ) );
2307 Q_strncpyz( c, S_COLOR_CYAN, sizeof( c ) );
2308 }
2309 else if( p->pers.connected != CON_CONNECTED )
2310 {
2311 continue;
2312 }
2313
2314 for( j = 0; j < 8; j++ )
2315 guid_stub[ j ] = p->pers.guid[ j + 24 ];
2316 guid_stub[ j ] = '\0';
2317
2318 muted[ 0 ] = '\0';
2319 if( p->pers.muted )
2320 {
2321 Q_strncpyz( muted, "M", sizeof( muted ) );
2322 }
2323 //Put DisOriented Junk Here!!!
2324
2325 l = 0;
2326 G_SanitiseString( p->pers.netname, n2, sizeof( n2 ) );
2327 n[ 0 ] = '\0';
2328 for( j = 0; j < MAX_ADMIN_ADMINS && g_admin_admins[ j ]; j++ )
2329 {
2330 if( !Q_stricmp( g_admin_admins[ j ]->guid, p->pers.guid ) )
2331 {
2332 // don't gather aka or level info if the admin is incognito
2333 if( ent && G_admin_permission( &g_entities[ i ], ADMF_INCOGNITO ) )
2334 {
2335 break;
2336 }
2337 l = g_admin_admins[ j ]->level;
2338 G_SanitiseString( g_admin_admins[ j ]->name, n3, sizeof( n3 ) );
2339 if( Q_stricmp( n2, n3 ) )
2340 {
2341 Q_strncpyz( n, g_admin_admins[ j ]->name, sizeof( n ) );
2342 }
2343 break;
2344 }
2345 }
2346 lname[ 0 ] = '\0';
2347 for( j = 0; j < MAX_ADMIN_LEVELS && g_admin_levels[ j ]; j++ )
2348 {
2349 if( g_admin_levels[ j ]->level == l )
2350 {
2351 int k, colorlen;
2352
2353 for( colorlen = k = 0; g_admin_levels[ j ]->name[ k ]; k++ )
2354 if( Q_IsColorString( &g_admin_levels[ j ]->name[ k ] ) )
2355 colorlen += 2;
2356 Com_sprintf( lname, sizeof( lname ), "%*s",
2357 admin_level_maxname + colorlen,
2358 g_admin_levels[ j ]->name );
2359 break;
2360 }
2361 }
2362
2363 ADMBP( va( "%2i %s%s^7 %-2i %s^7 (*%s) ^1%1s^7 %s^7 %s%s^7%s\n",
2364 i,
2365 c,
2366 t,
2367 l,
2368 lname,
2369 guid_stub,
2370 muted,
2371 p->pers.netname,
2372 ( *n ) ? "(a.k.a. " : "",
2373 n,
2374 ( *n ) ? ")" : "" ) );
2375 }
2376 ADMBP_end();
2377 return qtrue;
2378 }
2379
2380 qboolean G_admin_showbans( gentity_t *ent, int skiparg )
2381 {
2382 int i, found = 0;
2383 int max = -1, count;
2384 int t;
2385 char duration[ 32 ];
2386 int max_name = 1, max_banner = 1, colorlen;
2387 int len;
2388 int secs;
2389 int start = 0;
2390 char filter[ MAX_NAME_LENGTH ] = {""};
2391 char date[ 11 ];
2392 char *made;
2393 int j, k;
2394 char n1[ MAX_NAME_LENGTH * 2 ] = {""};
2395 char n2[ MAX_NAME_LENGTH * 2 ] = {""};
2396 qboolean numeric = qtrue;
2397 char *ip_match = NULL;
2398 int ip_match_len = 0;
2399 char name_match[ MAX_NAME_LENGTH ] = {""};
2400
2401 t = trap_RealTime( NULL );
2402
2403 for( i = 0; i < MAX_ADMIN_BANS && g_admin_bans[ i ]; i++ )
2404 {
2405 if( g_admin_bans[ i ]->expires != 0 &&
2406 ( g_admin_bans[ i ]->expires - t ) < 1 )
2407 {
2408 continue;
2409 }
2410 found++;
2411 max = i;
2412 }
2413
2414 if( max < 0 )
2415 {
2416 ADMP( "^3!showbans: ^7no bans to display\n" );
2417 return qfalse;
2418 }
2419
2420 if( G_SayArgc() >= 2 + skiparg )
2421 {
2422 G_SayArgv( 1 + skiparg, filter, sizeof( filter ) );
2423 if( G_SayArgc() >= 3 + skiparg )
2424 {
2425 start = atoi( filter );
2426 G_SayArgv( 2 + skiparg, filter, sizeof( filter ) );
2427 }
2428 for( i = 0; i < sizeof( filter ) && filter[ i ] ; i++ )
2429 {
2430 if( !isdigit( filter[ i ] ) &&
2431 filter[ i ] != '.' && filter[ i ] != '-' )
2432 {
2433 numeric = qfalse;
2434 break;
2435 }
2436 }
2437 if( !numeric )
2438 {
2439 G_SanitiseString( filter, name_match, sizeof( name_match ) );
2440 }
2441 else if( strchr( filter, '.' ) )
2442 {
2443 ip_match = filter;
2444 ip_match_len = strlen(ip_match);
2445 }
2446 else
2447 {
2448 start = atoi( filter );
2449 filter[ 0 ] = '\0';
2450 }
2451 // showbans 1 means start with ban 0
2452 if( start > 0 )
2453 start--;
2454 else if( start < 0 )
2455 {
2456 for( i = max, count = 0; i >= 0 && count < -start; i-- )
2457 if( g_admin_bans[ i ]->expires == 0 ||
2458 ( g_admin_bans[ i ]->expires - t ) > 0 )
2459 count++;
2460 start = i + 1;
2461 }
2462 }
2463
2464 if( start < 0 )
2465 start = 0;
2466
2467 if( start > max )
2468 {
2469 ADMP( va( "^3!showbans: ^7%d is the last valid ban\n", max + 1 ) );
2470 return qfalse;
2471 }
2472
2473 for( i = start, count = 0; i <= max && count < MAX_ADMIN_SHOWBANS; i++ )
2474 {
2475 if( g_admin_bans[ i ]->expires != 0 &&
2476 ( g_admin_bans[ i ]->expires - t ) < 1 )
2477 continue;
2478
2479 if( name_match[ 0 ] )
2480 {
2481 G_SanitiseString( g_admin_bans[ i ]->name, n1, sizeof( n1 ) );
2482 if( !strstr( n1, name_match) )
2483 continue;
2484 }
2485 if( ip_match &&
2486 Q_strncmp( ip_match, g_admin_bans[ i ]->ip, ip_match_len ) )
2487 continue;
2488
2489 count++;
2490
2491 len = Q_PrintStrlen( g_admin_bans[ i ]->name );
2492 if( len > max_name )
2493 max_name = len;
2494 len = Q_PrintStrlen( g_admin_bans[ i ]->banner );
2495 if( len > max_banner )
2496 max_banner = len;
2497 }
2498
2499 ADMBP_begin();
2500 for( i = start, count = 0; i <= max && count < MAX_ADMIN_SHOWBANS; i++ )
2501 {
2502 if( g_admin_bans[ i ]->expires != 0 &&
2503 ( g_admin_bans[ i ]->expires - t ) < 1 )
2504 continue;
2505
2506 if( name_match[ 0 ] )
2507 {
2508 G_SanitiseString( g_admin_bans[ i ]->name, n1, sizeof( n1 ) );
2509 if( !strstr( n1, name_match) )
2510 continue;
2511 }
2512 if( ip_match &&
2513 Q_strncmp( ip_match, g_admin_bans[ i ]->ip, ip_match_len ) )
2514 continue;
2515
2516 count++;
2517
2518 // only print out the the date part of made
2519 date[ 0 ] = '\0';
2520 made = g_admin_bans[ i ]->made;
2521 for( j = 0; made && *made; j++ )
2522 {
2523 if( ( j + 1 ) >= sizeof( date ) )
2524 break;
2525 if( *made == ' ' )
2526 break;
2527 date[ j ] = *made;
2528 date[ j + 1 ] = '\0';
2529 made++;
2530 }
2531
2532 secs = ( g_admin_bans[ i ]->expires - t );
2533 G_admin_duration( secs, duration, sizeof( duration ) );
2534
2535 for( colorlen = k = 0; g_admin_bans[ i ]->name[ k ]; k++ )
2536 if( Q_IsColorString( &g_admin_bans[ i ]->name[ k ] ) )
2537 colorlen += 2;
2538 Com_sprintf( n1, sizeof( n1 ), "%*s", max_name + colorlen,
2539 g_admin_bans[ i ]->name );
2540
2541 for( colorlen = k = 0; g_admin_bans[ i ]->banner[ k ]; k++ )
2542 if( Q_IsColorString( &g_admin_bans[ i ]->banner[ k ] ) )
2543 colorlen += 2;
2544 Com_sprintf( n2, sizeof( n2 ), "%*s", max_banner + colorlen,
2545 g_admin_bans[ i ]->banner );
2546
2547 ADMBP( va( "%4i %s^7 %-15s %-8s %s^7 %-10s\n \\__ %s\n",
2548 ( i + 1 ),
2549 n1,
2550 g_admin_bans[ i ]->ip,
2551 date,
2552 n2,
2553 duration,
2554 g_admin_bans[ i ]->reason ) );
2555 }
2556
2557 if( name_match[ 0 ] || ip_match )
2558 {
2559 ADMBP( va( "^3!showbans:^7 found %d matching bans by %s. ",
2560 count,
2561 ( ip_match ) ? "IP" : "name" ) );
2562 }
2563 else
2564 {
2565 ADMBP( va( "^3!showbans:^7 showing bans %d - %d of %d (%d total).",
2566 ( found ) ? ( start + 1 ) : 0,
2567 i,
2568 max + 1,
2569 found ) );
2570 }
2571
2572 if( i <= max )
2573 ADMBP( va( " run !showbans %d%s%s to see more",
2574 i + 1,
2575 ( filter[ 0 ] ) ? " " : "",
2576 ( filter[ 0 ] ) ? filter : "" ) );
2577 ADMBP( "\n" );
2578 ADMBP_end();
2579 return qtrue;
2580 }
2581
2582 qboolean G_admin_help( gentity_t *ent, int skiparg )
2583 {
2584 int i;
2585
2586 if( G_SayArgc() < 2 + skiparg )
2587 {
2588 int j = 0;
2589 int count = 0;
2590
2591 ADMBP_begin();
2592 for( i = 0; i < adminNumCmds; i++ )
2593 {
2594 if( G_admin_permission( ent, g_admin_cmds[ i ].flag[ 0 ] ) )
2595 {
2596 ADMBP( va( "^3!%-12s", g_admin_cmds[ i ].keyword ) );
2597 j++;
2598 count++;
2599 }
2600 // show 6 commands per line
2601 if( j == 6 )
2602 {
2603 ADMBP( "\n" );
2604 j = 0;
2605 }
2606 }
2607 for( i = 0; i < MAX_ADMIN_COMMANDS && g_admin_commands[ i ]; i++ )
2608 {
2609 if( ! admin_command_permission( ent, g_admin_commands[ i ]->command ) )
2610 continue;
2611 ADMBP( va( "^3!%-12s", g_admin_commands[ i ]->command ) );
2612 j++;
2613 count++;
2614 // show 6 commands per line
2615 if( j == 6 )
2616 {
2617 ADMBP( "\n" );
2618 j = 0;
2619 }
2620 }
2621 if( count )
2622 ADMBP( "\n" );
2623 ADMBP( va( "^3!help: ^7%i available commands\n", count ) );
2624 ADMBP( "run !help [^3command^7] for help with a specific command.\n" );
2625 ADMBP_end();
2626
2627 return qtrue;
2628 }
2629 else
2630 {
2631 //!help param
2632 char param[ MAX_ADMIN_CMD_LEN ];
2633 char *cmd;
2634
2635 G_SayArgv( 1 + skiparg, param, sizeof( param ) );
2636 cmd = ( param[0] == '!' ) ? &param[1] : &param[0];
2637 ADMBP_begin();
2638 for( i = 0; i < adminNumCmds; i++ )
2639 {
2640 if( !Q_stricmp( cmd, g_admin_cmds[ i ].keyword ) )
2641 {
2642 if( !G_admin_permission( ent, g_admin_cmds[ i ].flag[ 0 ] ) )
2643 {
2644 ADMBP( va( "^3!help: ^7you do not have permission to use '%s'\n",
2645 g_admin_cmds[ i ].keyword ) );
2646 ADMBP_end();
2647 return qfalse;
2648 }
2649 ADMBP( va( "^3!help: ^7help for '!%s':\n",
2650 g_admin_cmds[ i ].keyword ) );
2651 ADMBP( va( " ^3Function: ^7%s\n", g_admin_cmds[ i ].function ) );
2652 ADMBP( va( " ^3Syntax: ^7!%s %s\n", g_admin_cmds[ i ].keyword,
2653 g_admin_cmds[ i ].syntax ) );
2654 ADMBP( va( " ^3Flag: ^7'%c'\n", g_admin_cmds[ i ].flag[ 0 ] ) );
2655 ADMBP_end();
2656 return qtrue;
2657 }
2658 }
2659 for( i = 0; i < MAX_ADMIN_COMMANDS && g_admin_commands[ i ]; i++ )
2660 {
2661 if( !Q_stricmp( cmd, g_admin_commands[ i ]->command ) )
2662 {
2663 if( !admin_command_permission( ent, g_admin_commands[ i ]->command ) )
2664 {
2665 ADMBP( va( "^3!help: ^7you do not have permission to use '%s'\n",
2666 g_admin_commands[ i ]->command ) );
2667 ADMBP_end();
2668 return qfalse;
2669 }
2670 ADMBP( va( "^3!help: ^7help for '%s':\n",
2671 g_admin_commands[ i ]->command ) );
2672 ADMBP( va( " ^3Description: ^7%s\n", g_admin_commands[ i ]->desc ) );
2673 ADMBP( va( " ^3Syntax: ^7!%s\n", g_admin_commands[ i ]->command ) );
2674 ADMBP_end();
2675 return qtrue;
2676 }
2677 }
2678 ADMBP( va( "^3!help: ^7no help found for '%s'\n", cmd ) );
2679 ADMBP_end();
2680 return qfalse;
2681 }
2682 }
2683
2684 qboolean G_admin_admintest( gentity_t *ent, int skiparg )
2685 {
2686 int i, l = 0;
2687 qboolean found = qfalse;
2688 qboolean lname = qfalse;
2689
2690 if( !ent )
2691 {
2692 ADMP( "^3!admintest: ^7you are on the console.\n" );
2693 return qtrue;
2694 }
2695 for( i = 0; i < MAX_ADMIN_ADMINS && g_admin_admins[ i ]; i++ )
2696 {
2697 if( !Q_stricmp( g_admin_admins[ i ]->guid, ent->client->pers.guid ) )
2698 {
2699 found = qtrue;
2700 break;
2701 }
2702 }
2703
2704 if( found )
2705 {
2706 l = g_admin_admins[ i ]->level;
2707 for( i = 0; i < MAX_ADMIN_LEVELS && g_admin_levels[ i ]; i++ )
2708 {
2709 if( g_admin_levels[ i ]->level != l )
2710 continue;
2711 if( *g_admin_levels[ i ]->name )
2712 {
2713 lname = qtrue;
2714 break;
2715 }
2716 }
2717 }
2718 AP( va( "print \"^3!admintest: ^7%s^7 is a level %d admin %s%s^7%s\n\"",
2719 ent->client->pers.netname,
2720 l,
2721 ( lname ) ? "(" : "",
2722 ( lname ) ? g_admin_levels[ i ]->name : "",
2723 ( lname ) ? ")" : "" ) );
2724 return qtrue;
2725 }
2726
2727 qboolean G_admin_allready( gentity_t *ent, int skiparg )
2728 {
2729 int i = 0;
2730 gclient_t *cl;
2731
2732 if( !level.intermissiontime )
2733 {
2734 ADMP( "^3!allready: ^7this command is only valid during intermission\n" );
2735 return qfalse;
2736 }
2737
2738 for( i = 0; i < g_maxclients.integer; i++ )
2739 {
2740 cl = level.clients + i;
2741 if( cl->pers.connected != CON_CONNECTED )
2742 continue;
2743
2744 if( cl->sess.sessionTeam == TEAM_NONE )
2745 continue;
2746
2747 cl->readyToExit = 1;
2748 }
2749 AP( va( "print \"^3!allready:^7 %s^7 says everyone is READY now\n\"",
2750 ( ent ) ? ent->client->pers.netname : "console" ) );
2751 return qtrue;
2752 }
2753
2754 qboolean G_admin_cancelvote( gentity_t *ent, int skiparg )
2755 {
2756
2757 if(!level.voteTime && !level.teamVoteTime[ 0 ] && !level.teamVoteTime[ 1 ] )
2758 {
2759 ADMP( "^3!cancelvote: ^7no vote in progress\n" );
2760 return qfalse;
2761 }
2762 level.voteNo = level.numConnectedClients;
2763 level.voteYes = 0;
2764 CheckVote( );
2765 level.teamVoteNo[ 0 ] = level.numConnectedClients;
2766 level.teamVoteYes[ 0 ] = 0;
2767 CheckTeamVote( TEAM_RED );
2768 level.teamVoteNo[ 1 ] = level.numConnectedClients;
2769 level.teamVoteYes[ 1 ] = 0;
2770 CheckTeamVote( TEAM_BLUE );
2771 AP( va( "print \"^3!cancelvote: ^7%s^7 decided that everyone voted No\n\"",
2772 ( ent ) ? ent->client->pers.netname : "console" ) );
2773 return qtrue;
2774 }
2775
2776 qboolean G_admin_passvote( gentity_t *ent, int skiparg )
2777 {
2778 if(!level.voteTime && !level.teamVoteTime[ 0 ] && !level.teamVoteTime[ 1 ] )
2779 {
2780 ADMP( "^3!passvote: ^7no vote in progress\n" );
2781 return qfalse;
2782 }
2783 level.voteYes = level.numConnectedClients;
2784 level.voteNo = 0;
2785 CheckVote( );
2786 level.teamVoteYes[ 0 ] = level.numConnectedClients;
2787 level.teamVoteNo[ 0 ] = 0;
2788 CheckTeamVote( TEAM_RED );
2789 level.teamVoteYes[ 1 ] = level.numConnectedClients;
2790 level.teamVoteNo[ 1 ] = 0;
2791 CheckTeamVote( TEAM_BLUE );
2792 AP( va( "print \"^3!passvote: ^7%s^7 decided that everyone voted Yes\n\"",
2793 ( ent ) ? ent->client->pers.netname : "console" ) );
2794 return qtrue;
2795 }
2796
2797 qboolean G_admin_spec999( gentity_t *ent, int skiparg )
2798 {
2799 int i;
2800 gentity_t *vic;
2801
2802 for( i = 0; i < level.maxclients; i++ )
2803 {
2804 vic = &g_entities[ i ];
2805 if( !vic->client )
2806 continue;
2807 if( vic->client->pers.connected != CON_CONNECTED )
2808 continue;
2809 if( vic->client->sess.sessionTeam == TEAM_NONE )
2810 continue;
2811 if( vic->client->ps.ping == 999 )
2812 {
2813 SetTeam( vic, "spectator" );
2814 AP( va( "print \"^3!spec999: ^7%s^7 moved ^7%s^7 to spectators\n\"",
2815 ( ent ) ? ent->client->pers.netname : "console",
2816 vic->client->pers.netname ) );
2817 }
2818 }
2819 return qtrue;
2820 }
2821
2822 qboolean G_admin_rename( gentity_t *ent, int skiparg )
2823 {
2824 int pids[ MAX_CLIENTS ], found;
2825 char name[ MAX_NAME_LENGTH ];
2826 char newname[ MAX_NAME_LENGTH ];
2827 char oldname[ MAX_NAME_LENGTH ];
2828 char err[ MAX_STRING_CHARS ];
2829 char userinfo[ MAX_INFO_STRING ];
2830 char *s;
2831 gentity_t *victim = NULL;
2832
2833 if( G_SayArgc() < 3 + skiparg )
2834 {
2835 ADMP( "^3!rename: ^7usage: !rename [name] [newname]\n" );
2836 return qfalse;
2837 }
2838 G_SayArgv( 1 + skiparg, name, sizeof( name ) );
2839 s = G_SayConcatArgs( 2 + skiparg );
2840 Q_strncpyz( newname, s, sizeof( newname ) );
2841 if( ( found = G_ClientNumbersFromString( name, pids, MAX_CLIENTS ) ) != 1 )
2842 {
2843 G_MatchOnePlayer( pids, found, err, sizeof( err ) );
2844 ADMP( va( "^3!rename: ^7%s\n", err ) );
2845 return qfalse;
2846 }
2847 victim = &g_entities[ pids[ 0 ] ];
2848 if( !admin_higher( ent, victim ) )
2849 {
2850 ADMP( "^3!rename: ^7sorry, but your intended victim has a higher admin"
2851 " level than you\n" );
2852 return qfalse;
2853 }
2854 if( !G_admin_name_check( victim, newname, err, sizeof( err ) ) )
2855 {
2856 ADMP( va( "^3!rename: ^7%s\n", err ) );
2857 return qfalse;
2858 }
2859
2860 //KK-OAX Since NameChanges are not going to be implemented just yet...let's ignore this.
2861 level.clients[ pids[ 0 ] ].pers.nameChanges--;
2862 level.clients[ pids[ 0 ] ].pers.nameChangeTime = 0;
2863
2864 trap_GetUserinfo( pids[ 0 ], userinfo, sizeof( userinfo ) );
2865 s = Info_ValueForKey( userinfo, "name" );
2866 Q_strncpyz( oldname, s, sizeof( oldname ) );
2867 Info_SetValueForKey( userinfo, "name", newname );
2868 trap_SetUserinfo( pids[ 0 ], userinfo );
2869 ClientUserinfoChanged( pids[ 0 ] );
2870 AP( va( "print \"^3!rename: ^7%s^7 has been renamed to %s^7 by %s\n\"",
2871 oldname,
2872 newname,
2873 ( ent ) ? ent->client->pers.netname : "console" ) );
2874 return qtrue;
2875 }
2876
2877 //KK-Will Fix this For OAPub
2878 qboolean G_admin_restart( gentity_t *ent, int skiparg )
2879 {
2880 char layout[ MAX_CVAR_VALUE_STRING ] = { "" };
2881
2882 if( G_SayArgc( ) > 1 + skiparg )
2883 {
2884 char map[ MAX_QPATH ];
2885
2886 trap_Cvar_VariableStringBuffer( "mapname", map, sizeof( map ) );
2887 G_SayArgv( skiparg + 1, layout, sizeof( layout ) );
2888
2889 }
2890
2891 trap_SendConsoleCommand( EXEC_APPEND, "map_restart" );
2892 AP( va( "print \"^3!restart: ^7map restarted by %s \n\"",
2893 ( ent ) ? ent->client->pers.netname : "console" ) );
2894 return qtrue;
2895 }
2896
2897 qboolean G_admin_nextmap( gentity_t *ent, int skiparg )
2898 {
2899 AP( va( "print \"^3!nextmap: ^7%s^7 decided to load the next map\n\"",
2900 ( ent ) ? ent->client->pers.netname : "console" ) );
2901 //level.lastWin = TEAM_NONE;
2902 //trap_SetConfigstring( CS_WINNER, "NextMap" );
2903 LogExit( va( "nextmap was run by %s", ( ent ) ? ent->client->pers.netname : "console" ) );
2904 return qtrue;
2905 }
2906
2907 qboolean G_admin_namelog( gentity_t *ent, int skiparg )
2908 {
2909 int i, j;
2910 char search[ MAX_NAME_LENGTH ] = {""};
2911 char s2[ MAX_NAME_LENGTH ] = {""};
2912 char n2[ MAX_NAME_LENGTH ] = {""};
2913 char guid_stub[ 9 ];
2914 qboolean found = qfalse;
2915 int printed = 0;
2916
2917 if( G_SayArgc() > 1 + skiparg )
2918 {
2919 G_SayArgv( 1 + skiparg, search, sizeof( search ) );
2920 G_SanitiseString( search, s2, sizeof( s2 ) );
2921 }
2922 ADMBP_begin();
2923 for( i = 0; i < MAX_ADMIN_NAMELOGS && g_admin_namelog[ i ]; i++ )
2924 {
2925 if( search[ 0 ] )
2926 {
2927 found = qfalse;
2928 for( j = 0; j < MAX_ADMIN_NAMELOG_NAMES &&
2929 g_admin_namelog[ i ]->name[ j ][ 0 ]; j++ )
2930 {
2931 G_SanitiseString( g_admin_namelog[ i ]->name[ j ], n2, sizeof( n2 ) );
2932 if( strstr( n2, s2 ) )
2933 {
2934 found = qtrue;
2935 break;
2936 }
2937 }
2938 if( !found )
2939 continue;
2940 }
2941 printed++;
2942 for( j = 0; j < 8; j++ )
2943 guid_stub[ j ] = g_admin_namelog[ i ]->guid[ j + 24 ];
2944 guid_stub[ j ] = '\0';
2945 if( g_admin_namelog[ i ]->slot > -1 )
2946 ADMBP( "^3" );
2947 ADMBP( va( "%-2s (*%s) %15s^7",
2948 ( g_admin_namelog[ i ]->slot > -1 ) ?
2949 va( "%d", g_admin_namelog[ i ]->slot ) : "-",
2950 guid_stub, g_admin_namelog[ i ]->ip ) );
2951 for( j = 0; j < MAX_ADMIN_NAMELOG_NAMES &&
2952 g_admin_namelog[ i ]->name[ j ][ 0 ]; j++ )
2953 {
2954 ADMBP( va( " '%s^7'", g_admin_namelog[ i ]->name[ j ] ) );
2955 }
2956 ADMBP( "\n" );
2957 }
2958 ADMBP( va( "^3!namelog:^7 %d recent clients found\n", printed ) );
2959 ADMBP_end();
2960 return qtrue;
2961 }
2962
2963 qboolean G_admin_lock( gentity_t *ent, int skiparg )
2964 {
2965 char teamName[2] = {""};
2966 team_t team;
2967
2968 if( G_SayArgc() < 2 + skiparg )
2969 {
2970 ADMP( "^3!lock: ^7usage: !lock [r|b|f]\n" );
2971 return qfalse;
2972 }
2973 G_SayArgv( 1 + skiparg, teamName, sizeof( teamName ) );
2974 team = G_TeamFromString( teamName );
2975
2976 if( team == TEAM_RED )
2977 {
2978 if( level.RedTeamLocked )
2979 {
2980 ADMP( "^3!lock: ^7the Red team is already locked\n" );
2981 return qfalse;
2982 }
2983 level.RedTeamLocked = qtrue;
2984 }
2985 else if( team == TEAM_BLUE ) {
2986 if( level.BlueTeamLocked )
2987 {
2988 ADMP( "^3!lock: ^7the Blue team is already locked\n" );
2989 return qfalse;
2990 }
2991 level.BlueTeamLocked = qtrue;
2992 }
2993 else if(team == TEAM_FREE ) {
2994 if( level.FFALocked )
2995 {
2996 ADMP( "^3!lock: ^7DeathMatch is already Locked!!!\n" );
2997 return qfalse;
2998 }
2999 level.FFALocked = qtrue;
3000 }
3001 else
3002 {
3003 ADMP( va( "^3!lock: ^7invalid team\"%c\"\n", teamName[0] ) );
3004 return qfalse;
3005 }
3006
3007 AP( va( "print \"^3!lock: ^7the %s team has been locked by %s\n\"",
3008 BG_TeamName( team ),
3009 ( ent ) ? ent->client->pers.netname : "console" ) );
3010 return qtrue;
3011 }
3012
3013 qboolean G_admin_unlock( gentity_t *ent, int skiparg )
3014 {
3015 char teamName[2] = {""};
3016 team_t team;
3017
3018 if( G_SayArgc() < 2 + skiparg )
3019 {
3020 ADMP( "^3!unlock: ^7usage: !unlock [r|b|f]\n" );
3021 return qfalse;
3022 }
3023 G_SayArgv( 1 + skiparg, teamName, sizeof( teamName ) );
3024 team = G_TeamFromString( teamName );
3025
3026 if( team == TEAM_RED )
3027 {
3028 if( !level.RedTeamLocked )
3029 {
3030 ADMP( "^3!unlock: ^7the Red team is not currently locked\n" );
3031 return qfalse;
3032 }
3033 level.RedTeamLocked = qfalse;
3034 }
3035 else if( team == TEAM_BLUE ) {
3036 if( !level.BlueTeamLocked )
3037 {
3038 ADMP( "^3!unlock: ^7the Blue team is not currently locked\n" );
3039 return qfalse;
3040 }
3041 level.BlueTeamLocked = qfalse;
3042 }
3043 else if( team == TEAM_FREE ) {
3044 if( !level.FFALocked )
3045 {
3046 ADMP( "^!unlock: ^7Deathmatch is not currently Locked!!!\n" );
3047 return qfalse;
3048 }
3049 level.FFALocked = qfalse;
3050 }
3051 else
3052 {
3053 ADMP( va( "^3!unlock: ^7invalid team\"%c\"\n", teamName[0] ) );
3054 return qfalse;
3055 }
3056 AP( va( "print \"^3!unlock: ^7the %s team has been unlocked by %s\n\"",
3057 BG_TeamName( team ),
3058 ( ent ) ? ent->client->pers.netname : "console" ) );
3059 return qtrue;
3060 }
3061 //KK-OAX Begin Addition
3062 qboolean G_admin_disorient(gentity_t *ent, int skiparg)
3063 {
3064 int pids[MAX_CLIENTS], found;
3065 char name[MAX_NAME_LENGTH], err[MAX_STRING_CHARS];
3066 char *reason;
3067 gentity_t *vic;
3068
3069 if(G_SayArgc() < 2+skiparg) {
3070 ADMP("^/disorient usage: ^7!disorient [name|slot#] [reason]");
3071 return qfalse;
3072 }
3073 G_SayArgv(1+skiparg, name, sizeof(name));
3074 reason = G_SayConcatArgs(2+skiparg);
3075
3076 if((found = G_ClientNumbersFromString(name, pids, MAX_CLIENTS)) != 1) {
3077 G_MatchOnePlayer(pids, found, err, sizeof(err));
3078 ADMP(va("^/disorient: ^7%s", err));
3079 return qfalse;
3080 }
3081 vic = &g_entities[pids[0]];
3082 if(!admin_higher(ent, vic)) {
3083 ADMP("^/disorient: ^7sorry, but your intended victim has a higher admin level than you do");
3084 return qfalse;
3085 }
3086
3087 if(!(vic->client->sess.sessionTeam == TEAM_RED ||
3088 vic->client->sess.sessionTeam == TEAM_BLUE ||
3089 vic->client->sess.sessionTeam == TEAM_FREE )) {
3090 ADMP("^/disorient: ^7player must be on a team");
3091 return qfalse;
3092 }
3093 if(vic->client->pers.disoriented) {
3094 ADMP(va("^/disorient: ^7%s^7 is already disoriented",
3095 vic->client->pers.netname));
3096 return qfalse;
3097 }
3098 vic->client->pers.disoriented = qtrue;
3099 AP(va("chat \"^/disorient: ^7%s ^7is disoriented\" -1",
3100 vic->client->pers.netname));
3101
3102 CPx(pids[0], va("cp \"%s ^7disoriented you%s%s\"",
3103 (ent?ent->client->pers.netname:"^3SERVER CONSOLE"),
3104 (*reason) ? " because:\n" : "",
3105 (*reason) ? reason : ""));
3106 return qtrue;
3107 }
3108 qboolean G_admin_orient(gentity_t *ent, int skiparg)
3109 {
3110 int pids[MAX_CLIENTS], found;
3111 char name[MAX_NAME_LENGTH], err[MAX_STRING_CHARS];
3112 gentity_t *vic;
3113
3114 if(G_SayArgc() < 2+skiparg) {
3115 ADMP("^/orient usage: ^7!orient [name|slot#]");
3116 return qfalse;
3117 }
3118 G_SayArgv(1+skiparg, name, sizeof(name));
3119 //Fix
3120 if((found = G_ClientNumbersFromString(name, pids, MAX_CLIENTS)) != 1) {
3121 G_MatchOnePlayer(pids, found, err, sizeof(err));
3122 ADMP(va("^/orient: ^7%s", err));
3123 return qfalse;
3124 }
3125 vic = &g_entities[pids[0]];
3126
3127 if(!vic->client->pers.disoriented) {
3128 ADMP(va("^/orient: ^7%s^7 is not currently disoriented",
3129 vic->client->pers.netname));
3130 return qfalse;
3131 }
3132 vic->client->pers.disoriented = qfalse;
3133 AP(va("chat \"^/orient: ^7%s ^7is no longer disoriented\" -1",
3134 vic->client->pers.netname));
3135
3136 CPx(pids[0], va("cp \"%s ^7oriented you\"",
3137 (ent?ent->client->pers.netname:"^3SERVER CONSOLE")));
3138 return qtrue;
3139 }
3140
3141 qboolean G_admin_slap( gentity_t *ent, int skiparg )
3142 {
3143 int pids[MAX_CLIENTS], found, dmg;
3144 char name[MAX_NAME_LENGTH], err[MAX_STRING_CHARS];
3145 char *reason;
3146 char damage[4];
3147 gentity_t *vic;
3148 int soundIndex;
3149
3150 //KK-Too many Parameters Check removed. It'll truncate the reason message.
3151
3152 if(G_SayArgc() < 2+skiparg)
3153 {
3154 ADMP("^/slap usage: ^7!slap [name|slot#] [reason] [damage]");
3155 return qfalse;
3156 }
3157
3158 G_SayArgv(1+skiparg, name, sizeof(name));
3159 G_SayArgv(2+skiparg, damage, sizeof(damage));
3160
3161 dmg = atoi(damage);
3162 if(!dmg)
3163 {
3164 dmg = 25;
3165 reason = G_SayConcatArgs(2+skiparg);
3166 }
3167 else
3168 {
3169 reason = G_SayConcatArgs(3+skiparg);
3170 }
3171
3172 if((found = G_ClientNumbersFromString(name, pids, MAX_CLIENTS)) != 1) {
3173 G_MatchOnePlayer(pids, found, err, sizeof(err));
3174 ADMP(va("^/slap: ^7%s", err));
3175 return qfalse;
3176 }
3177
3178 vic = &g_entities[pids[0]];
3179 if(!admin_higher(ent, vic)) {
3180 ADMP("^/slap: ^7sorry, but your intended victim has a higher admin level than you do");
3181 return qfalse;
3182 }
3183
3184 if(!(vic->client->sess.sessionTeam == TEAM_RED ||
3185 vic->client->sess.sessionTeam == TEAM_BLUE ||
3186 vic->client->sess.sessionTeam == TEAM_FREE )) {
3187 ADMP("^/slap: ^7player must be in the game!");
3188 return qfalse;
3189 }
3190 //Player Not Alive
3191 if( vic->health < 1 )
3192 {
3193 //Is Their Body Alive?
3194 if(vic->s.eType != ET_INVISIBLE)
3195 {
3196 //Make 'em a Bloody mess
3197 G_Damage(vic, NULL, NULL, NULL, NULL, 500, 0, MOD_UNKNOWN);
3198 }
3199 //Force Their Butt to Respawn
3200 ClientSpawn( vic );
3201 }
3202 // Will the Slap Kill them? (Obviously false if we Respawned 'em)
3203 if(!(vic->health > dmg ))
3204 {
3205 vic->health = 1;
3206 }
3207 else //If it won't kill em...Do the full Damage
3208 {
3209 vic->health -= dmg;
3210 }
3211
3212 //KK-OAX Play them the slap sound
3213 soundIndex = G_SoundIndex("sound/admin/slap.wav");
3214 G_Sound(vic, CHAN_VOICE, soundIndex );
3215
3216 //Print it to everybody
3217 AP(va("chat \"^/slap: ^7%s ^7was slapped\" -1", vic->client->pers.netname));
3218 //CenterPrint it to the Person Being Slapped
3219 CPx(pids[0], va("cp \"%s ^7slapped you%s%s\"",
3220 (ent?ent->client->pers.netname:"^3SERVER CONSOLE"),
3221 (*reason) ? " because:\n" : "",
3222 (*reason) ? reason : ""));
3223 return qtrue;
3224 }
3225
3226
3227 //Called Each Time a Warning is Created
3228 int G_admin_warn_check( gentity_t *ent )
3229 {
3230 char *ip, *guid;
3231 int i;
3232 int t;
3233 int numWarnings = 0;
3234
3235 t = trap_RealTime( NULL );
3236
3237 ip = ent->client->pers.ip;
3238
3239 //We Don't Want to Count Warnings for the LocalHost
3240 if( !*ip )
3241 return 0;
3242
3243 guid = ent->client->pers.guid;
3244
3245 //Just to make sure...Don't want to crash...Will Figure something better out later
3246 if( !*guid )
3247 return 0;
3248
3249 //For Each Warning, up to the max number of warnings
3250 for( i = 0; i < MAX_ADMIN_WARNINGS && g_admin_warnings[ i ]; i++ )
3251 {
3252 // Ignore Expired Warnings
3253 if( ( g_admin_warnings[ i ]->expires - t ) < 1 )
3254 continue;
3255 //If a warning matches their IP or GUID
3256 if( strstr( ip, g_admin_warnings[ i ]->ip ) || strstr( guid, g_admin_warnings[ i ]->guid ))
3257 {
3258 numWarnings++;
3259 }
3260 }
3261 //If we get here, return the number of warnings;
3262 return numWarnings;
3263 }
3264
3265
3266 qboolean G_admin_warn( gentity_t *ent, int skiparg )
3267 {
3268 int pids[MAX_CLIENTS], found;
3269 int seconds;
3270 char name[ MAX_NAME_LENGTH ], err[MAX_STRING_CHARS];
3271 char *reason;
3272 int minargc;
3273 char duration[ 32 ];
3274 char s2[ MAX_NAME_LENGTH ];
3275 gentity_t *vic;
3276 int totalWarnings;
3277 int soundIndex;
3278
3279 if( G_admin_permission( ent, ADMF_UNACCOUNTABLE ) )
3280 {
3281 minargc = 1 + skiparg;
3282 }
3283 else
3284 {
3285 minargc = 2 + skiparg;
3286 }
3287
3288 if( G_SayArgc() < minargc )
3289 {
3290 ADMP( "^3!warn: ^7usage: !warn [name|slot|ip] [reason]\n" );
3291 return qfalse;
3292 }
3293
3294 G_SayArgv( 1 + skiparg, name, sizeof( name ) );
3295 G_SanitiseString( name, s2, sizeof( s2 ) );
3296 reason = G_SayConcatArgs(2+skiparg);
3297
3298 seconds = g_warningExpire.integer;
3299
3300 if((found = G_ClientNumbersFromString(name, pids, MAX_CLIENTS)) != 1) {
3301 G_MatchOnePlayer(pids, found, err, sizeof(err));
3302 ADMP(va("^/warn: ^7%s", err));
3303 return qfalse;
3304 }
3305
3306 vic = &g_entities[pids[0]];
3307 if(!admin_higher(ent, vic)) {
3308 ADMP("^/slap: ^7sorry, but your intended victim has a higher admin level than you do");
3309 return qfalse;
3310 }
3311
3312 G_admin_duration( ( seconds ) ? seconds : -1,
3313 duration, sizeof( duration ) );
3314
3315 admin_create_warning( ent,
3316 vic->client->pers.netname,
3317 vic->client->pers.guid,
3318 vic->client->pers.ip,
3319 seconds, reason );
3320
3321 if( !g_admin.string[ 0 ] )
3322 ADMP( "^3!warn: ^7WARNING g_admin not set, not saving warning to a file\n" );
3323 else
3324 admin_writeconfig();
3325
3326 //KK, Use The Check Warnings Deal Here
3327 totalWarnings = G_admin_warn_check( vic );
3328
3329 // Play the whistle
3330 soundIndex = G_SoundIndex("sound/admin/whistle.wav");
3331 G_GlobalSound( soundIndex );
3332
3333 //First Check to make sure g_maxWarnings isn't a Null Value
3334 if( g_maxWarnings.integer )
3335 {
3336 //If they have gone over the max number of warnings...
3337 if( totalWarnings >= g_maxWarnings.integer )
3338 {
3339 //Give them The Boot till the Warning Expires
3340 admin_create_ban( ent,
3341 vic->client->pers.netname,
3342 vic->client->pers.guid,
3343 vic->client->pers.ip,
3344 seconds,
3345 "Too Many Warnings" );
3346
3347 if( g_admin.string[ 0 ] )
3348 admin_writeconfig();
3349
3350 trap_SendServerCommand( pids[ 0 ],
3351 va( "disconnect \"You have been kicked.\n%s^7\nreason:\n%s\"",
3352 ( ent ) ? va( "admin:\n%s", ent->client->pers.netname ) : "SERVER",
3353 "Too Many Warnings" ) );
3354
3355 trap_DropClient( pids[ 0 ], va( "has been kicked%s^7. reason: %s",
3356 "Auto-Admin System",
3357 "Too Many Warnings" ) );
3358 return qtrue;
3359 }
3360 else
3361 {
3362
3363 //Print it to everybody
3364 AP(va("chat \"^/warn: ^7%s ^7was warned\" -1", vic->client->pers.netname));
3365 //CenterPrint it to the Person Being Slapped
3366 CPx(pids[0], va("cp \"%s ^7warned you%s%s\"",
3367 (ent?ent->client->pers.netname:"^3SERVER CONSOLE"),
3368 (*reason) ? " because:\n" : "",
3369 (*reason) ? reason : ""));
3370 return qtrue;
3371 }
3372 }
3373 else //KK-OAX g_maxWarnings is null or 0
3374 {
3375 AP(va("chat \"^/warn: ^7%s ^7was warned\" -1", vic->client->pers.netname));
3376 //CenterPrint it to the Person Being Slapped
3377 CPx(pids[0], va("cp \"%s ^7warned you%s%s\"",
3378 (ent?ent->client->pers.netname:"^3SERVER CONSOLE"),
3379 (*reason) ? " because:\n" : "",
3380 (*reason) ? reason : ""));
3381 return qtrue;
3382 }
3383
3384 }
3385
3386 qboolean G_admin_shuffle( gentity_t *ent, int skipargs )
3387 {
3388 trap_SendConsoleCommand( EXEC_APPEND, "shuffle" );
3389 AP( va( "print \"^3!shuffle: ^7teams shuffled by %s \n\"",
3390 ( ent ) ? ent->client->pers.netname : "console" ) );
3391 return qtrue;
3392 }
3393
3394 //KK-OAX End Additions
3395
3396 /*
3397 ================
3398 G_admin_print
3399
3400 This function facilitates the ADMP define. ADMP() is similar to CP except
3401 that it prints the message to the server console if ent is not defined.
3402 ================
3403 */
3404 void G_admin_print( gentity_t *ent, char *m )
3405 {
3406 if( ent )
3407 trap_SendServerCommand( ent - level.gentities, va( "print \"%s\"", m ) );
3408 else
3409 {
3410 char m2[ MAX_STRING_CHARS ];
3411 if( !trap_Cvar_VariableIntegerValue( "com_ansiColor" ) )
3412 {
3413 G_DecolorString( m, m2, sizeof( m2 ) );
3414 trap_Printf( m2 );
3415 }
3416 else
3417 trap_Printf( m );
3418 }
3419 }
3420
3421 void G_admin_buffer_begin()
3422 {
3423 g_bfb[ 0 ] = '\0';
3424 }
3425
3426 void G_admin_buffer_end( gentity_t *ent )
3427 {
3428 ADMP( g_bfb );
3429 }
3430
3431 void G_admin_buffer_print( gentity_t *ent, char *m )
3432 {
3433 // 1022 - strlen("print 64 \"\"") - 1
3434 if( strlen( m ) + strlen( g_bfb ) >= 1009 )
3435 {
3436 ADMP( g_bfb );
3437 g_bfb[ 0 ] = '\0';
3438 }
3439 Q_strcat( g_bfb, sizeof( g_bfb ), m );
3440 }
3441
3442
3443 void G_admin_cleanup()
3444 {
3445 int i = 0;
3446
3447 for( i = 0; i < MAX_ADMIN_LEVELS && g_admin_levels[ i ]; i++ )
3448 {
3449 BG_Free( g_admin_levels[ i ] );
3450 g_admin_levels[ i ] = NULL;
3451 }
3452 for( i = 0; i < MAX_ADMIN_ADMINS && g_admin_admins[ i ]; i++ )
3453 {
3454 BG_Free( g_admin_admins[ i ] );
3455 g_admin_admins[ i ] = NULL;
3456 }
3457 for( i = 0; i < MAX_ADMIN_BANS && g_admin_bans[ i ]; i++ )
3458 {
3459 BG_Free( g_admin_bans[ i ] );
3460 g_admin_bans[ i ] = NULL;
3461 }
3462 for( i = 0; i < MAX_ADMIN_COMMANDS && g_admin_commands[ i ]; i++ )
3463 {
3464 BG_Free( g_admin_commands[ i ] );
3465 g_admin_commands[ i ] = NULL;
3466 }
3467 }
3468
3469
3470