| 1 |
/* |
| 2 |
=========================================================================== |
| 3 |
Copyright (C) 2004-2006 Tony J. White |
| 4 |
|
| 5 |
This file is part of the Open Arena source code. |
| 6 |
|
| 7 |
Copied from Tremulous under GPL version 2 including any later version. |
| 8 |
|
| 9 |
Open Arena source code is free software; you can redistribute it |
| 10 |
and/or modify it under the terms of the GNU General Public License as |
| 11 |
published by the Free Software Foundation; either version 2 of the License, |
| 12 |
or (at your option) any later version. |
| 13 |
|
| 14 |
Open Arena source code is distributed in the hope that it will be |
| 15 |
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
GNU General Public License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License |
| 20 |
along with Open Arena source code; if not, write to the Free Software |
| 21 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 |
=========================================================================== |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "g_local.h" |
| 26 |
|
| 27 |
/* |
| 28 |
================= |
| 29 |
G_SayArgc |
| 30 |
G_SayArgv |
| 31 |
G_SayConcatArgs |
| 32 |
|
| 33 |
trap_Argc, trap_Argv, and ConcatArgs consider say text as a single argument |
| 34 |
These functions assemble the text and re-parse it on word boundaries |
| 35 |
================= |
| 36 |
*/ |
| 37 |
int G_SayArgc( void ) |
| 38 |
{ |
| 39 |
int c = 0; |
| 40 |
char *s; |
| 41 |
|
| 42 |
s = ConcatArgs( 0 ); |
| 43 |
while( 1 ) |
| 44 |
{ |
| 45 |
while( *s == ' ' ) |
| 46 |
s++; |
| 47 |
if( !*s ) |
| 48 |
break; |
| 49 |
c++; |
| 50 |
while( *s && *s != ' ' ) |
| 51 |
s++; |
| 52 |
} |
| 53 |
return c; |
| 54 |
} |
| 55 |
|
| 56 |
qboolean G_SayArgv( int n, char *buffer, int bufferLength ) |
| 57 |
{ |
| 58 |
char *s; |
| 59 |
|
| 60 |
if( bufferLength < 1 ) |
| 61 |
return qfalse; |
| 62 |
if( n < 0 ) |
| 63 |
return qfalse; |
| 64 |
s = ConcatArgs( 0 ); |
| 65 |
while( 1 ) |
| 66 |
{ |
| 67 |
while( *s == ' ' ) |
| 68 |
s++; |
| 69 |
if( !*s || n == 0 ) |
| 70 |
break; |
| 71 |
n--; |
| 72 |
while( *s && *s != ' ' ) |
| 73 |
s++; |
| 74 |
} |
| 75 |
if( n > 0 ) |
| 76 |
return qfalse; |
| 77 |
//memccpy( buffer, s, ' ', bufferLength ); |
| 78 |
while( *s && *s != ' ' && bufferLength > 1 ) |
| 79 |
{ |
| 80 |
*buffer++ = *s++; |
| 81 |
bufferLength--; |
| 82 |
} |
| 83 |
*buffer = 0; |
| 84 |
return qtrue; |
| 85 |
} |
| 86 |
|
| 87 |
char *G_SayConcatArgs( int start ) |
| 88 |
{ |
| 89 |
char *s; |
| 90 |
|
| 91 |
s = ConcatArgs( 0 ); |
| 92 |
while( 1 ) |
| 93 |
{ |
| 94 |
while( *s == ' ' ) |
| 95 |
s++; |
| 96 |
if( !*s || start == 0 ) |
| 97 |
break; |
| 98 |
start--; |
| 99 |
while( *s && *s != ' ' ) |
| 100 |
s++; |
| 101 |
} |
| 102 |
return s; |
| 103 |
} |
| 104 |
|
| 105 |
void G_DecolorString( char *in, char *out, int len ) |
| 106 |
{ |
| 107 |
len--; |
| 108 |
|
| 109 |
while( *in && len > 0 ) |
| 110 |
{ |
| 111 |
if( Q_IsColorString( in ) ) |
| 112 |
{ |
| 113 |
in++; |
| 114 |
if( *in ) |
| 115 |
in++; |
| 116 |
continue; |
| 117 |
} |
| 118 |
*out++ = *in++; |
| 119 |
len--; |
| 120 |
} |
| 121 |
*out = '\0'; |
| 122 |
} |
| 123 |
|
| 124 |
/* |
| 125 |
================== |
| 126 |
G_MatchOnePlayer |
| 127 |
|
| 128 |
This is a companion function to G_ClientNumbersFromString() |
| 129 |
|
| 130 |
err will be populated with an error message. |
| 131 |
================== |
| 132 |
*/ |
| 133 |
void G_MatchOnePlayer( int *plist, int num, char *err, int len ) |
| 134 |
{ |
| 135 |
gclient_t *cl; |
| 136 |
int i; |
| 137 |
char line[ MAX_NAME_LENGTH + 10 ] = {""}; |
| 138 |
|
| 139 |
err[ 0 ] = '\0'; |
| 140 |
if( num == 0 ) |
| 141 |
{ |
| 142 |
Q_strcat( err, len, "no connected player by that name or slot #" ); |
| 143 |
} |
| 144 |
else if( num > 1 ) |
| 145 |
{ |
| 146 |
Q_strcat( err, len, "more than one player name matches. Be more specific or use the slot #:\n" ); |
| 147 |
for( i = 0; i < num; i++ ) |
| 148 |
{ |
| 149 |
cl = &level.clients[ plist[ i ] ]; |
| 150 |
if( cl->pers.connected == CON_DISCONNECTED ) |
| 151 |
continue; |
| 152 |
Com_sprintf( line, sizeof( line ), "%2i - %s^7\n", |
| 153 |
plist[ i ], cl->pers.netname ); |
| 154 |
if( strlen( err ) + strlen( line ) > len ) |
| 155 |
break; |
| 156 |
Q_strcat( err, len, line ); |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
/* |
| 162 |
================== |
| 163 |
G_SanitiseString |
| 164 |
|
| 165 |
Remove case and control characters from a string |
| 166 |
================== |
| 167 |
*/ |
| 168 |
void G_SanitiseString( char *in, char *out, int len ) |
| 169 |
{ |
| 170 |
qboolean skip = qtrue; |
| 171 |
int spaces = 0; |
| 172 |
|
| 173 |
len--; |
| 174 |
|
| 175 |
while( *in && len > 0 ) |
| 176 |
{ |
| 177 |
// strip leading white space |
| 178 |
if( *in == ' ' ) |
| 179 |
{ |
| 180 |
if( skip ) |
| 181 |
{ |
| 182 |
in++; |
| 183 |
continue; |
| 184 |
} |
| 185 |
spaces++; |
| 186 |
} |
| 187 |
else |
| 188 |
{ |
| 189 |
spaces = 0; |
| 190 |
skip = qfalse; |
| 191 |
} |
| 192 |
|
| 193 |
if( Q_IsColorString( in ) ) |
| 194 |
{ |
| 195 |
in += 2; // skip color code |
| 196 |
continue; |
| 197 |
} |
| 198 |
|
| 199 |
if( *in < 32 ) |
| 200 |
{ |
| 201 |
in++; |
| 202 |
continue; |
| 203 |
} |
| 204 |
|
| 205 |
*out++ = tolower( *in++ ); |
| 206 |
len--; |
| 207 |
} |
| 208 |
out -= spaces; |
| 209 |
*out = 0; |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
/* |
| 214 |
================== |
| 215 |
G_ClientNumbersFromString |
| 216 |
|
| 217 |
Sets plist to an array of integers that represent client numbers that have |
| 218 |
names that are a partial match for s. |
| 219 |
|
| 220 |
Returns number of matching clientids up to max. |
| 221 |
================== |
| 222 |
*/ |
| 223 |
int G_ClientNumbersFromString( char *s, int *plist, int max ) |
| 224 |
{ |
| 225 |
gclient_t *p; |
| 226 |
int i, found = 0; |
| 227 |
char n2[ MAX_NAME_LENGTH ] = {""}; |
| 228 |
char s2[ MAX_NAME_LENGTH ] = {""}; |
| 229 |
|
| 230 |
if( max == 0 ) |
| 231 |
return 0; |
| 232 |
|
| 233 |
// if a number is provided, it is a clientnum |
| 234 |
for( i = 0; s[ i ] && isdigit( s[ i ] ); i++ ); |
| 235 |
if( !s[ i ] ) |
| 236 |
{ |
| 237 |
i = atoi( s ); |
| 238 |
if( i >= 0 && i < level.maxclients ) |
| 239 |
{ |
| 240 |
p = &level.clients[ i ]; |
| 241 |
if( p->pers.connected != CON_DISCONNECTED ) |
| 242 |
{ |
| 243 |
*plist = i; |
| 244 |
return 1; |
| 245 |
} |
| 246 |
} |
| 247 |
// we must assume that if only a number is provided, it is a clientNum |
| 248 |
return 0; |
| 249 |
} |
| 250 |
|
| 251 |
// now look for name matches |
| 252 |
G_SanitiseString( s, s2, sizeof( s2 ) ); |
| 253 |
if( strlen( s2 ) < 1 ) |
| 254 |
return 0; |
| 255 |
for( i = 0; i < level.maxclients && found < max; i++ ) |
| 256 |
{ |
| 257 |
p = &level.clients[ i ]; |
| 258 |
if( p->pers.connected == CON_DISCONNECTED ) |
| 259 |
{ |
| 260 |
continue; |
| 261 |
} |
| 262 |
G_SanitiseString( p->pers.netname, n2, sizeof( n2 ) ); |
| 263 |
if( strstr( n2, s2 ) ) |
| 264 |
{ |
| 265 |
*plist++ = i; |
| 266 |
found++; |
| 267 |
} |
| 268 |
} |
| 269 |
return found; |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
/* |
| 274 |
================== |
| 275 |
G_FloodLimited |
| 276 |
|
| 277 |
Determine whether a user is flood limited, and adjust their flood demerits |
| 278 |
Print them a warning message if they are over the limit |
| 279 |
Return is time in msec until the user can speak again |
| 280 |
================== |
| 281 |
*/ |
| 282 |
int G_FloodLimited( gentity_t *ent ) |
| 283 |
{ |
| 284 |
int deltatime, ms; |
| 285 |
|
| 286 |
if( g_floodMinTime.integer <= 0 ) |
| 287 |
return 0; |
| 288 |
|
| 289 |
// handles !ent |
| 290 |
if( G_admin_permission( ent, ADMF_NOCENSORFLOOD ) ) |
| 291 |
return 0; |
| 292 |
|
| 293 |
deltatime = level.time - ent->client->pers.floodTime; |
| 294 |
|
| 295 |
ent->client->pers.floodDemerits += g_floodMinTime.integer - deltatime; |
| 296 |
if( ent->client->pers.floodDemerits < 0 ) |
| 297 |
ent->client->pers.floodDemerits = 0; |
| 298 |
ent->client->pers.floodTime = level.time; |
| 299 |
|
| 300 |
ms = ent->client->pers.floodDemerits - g_floodMaxDemerits.integer; |
| 301 |
if( ms <= 0 ) |
| 302 |
return 0; |
| 303 |
trap_SendServerCommand( ent - g_entities, va( "print \"You are flooding: please wait %d second%s before trying again\n", |
| 304 |
( ms + 999 ) / 1000, ( ms > 1000 ) ? "s" : "" ) ); |
| 305 |
return ms; |
| 306 |
} |
| 307 |
|
| 308 |
//KK-Private Messaging Not implemented. |
| 309 |
/* |
| 310 |
void Cmd_PrivateMessage_f( gentity_t *ent ) |
| 311 |
{ |
| 312 |
int pids[ MAX_CLIENTS ]; |
| 313 |
int ignoreids[ MAX_CLIENTS ]; |
| 314 |
char name[ MAX_NAME_LENGTH ]; |
| 315 |
char cmd[ 12 ]; |
| 316 |
char str[ MAX_STRING_CHARS ]; |
| 317 |
char *msg; |
| 318 |
char color; |
| 319 |
int pcount, matches, ignored = 0; |
| 320 |
int i; |
| 321 |
int skipargs = 0; |
| 322 |
qboolean teamonly = qfalse; |
| 323 |
gentity_t *tmpent; |
| 324 |
|
| 325 |
if( !g_privateMessages.integer && ent ) |
| 326 |
{ |
| 327 |
ADMP( "Sorry, but private messages have been disabled\n" ); |
| 328 |
return; |
| 329 |
} |
| 330 |
|
| 331 |
G_SayArgv( 0, cmd, sizeof( cmd ) ); |
| 332 |
if( !Q_stricmp( cmd, "say" ) || !Q_stricmp( cmd, "say_team" ) ) |
| 333 |
{ |
| 334 |
skipargs = 1; |
| 335 |
G_SayArgv( 1, cmd, sizeof( cmd ) ); |
| 336 |
} |
| 337 |
if( G_SayArgc( ) < 3+skipargs ) |
| 338 |
{ |
| 339 |
ADMP( va( "usage: %s [name|slot#] [message]\n", cmd ) ); |
| 340 |
return; |
| 341 |
} |
| 342 |
|
| 343 |
if( !Q_stricmp( cmd, "mt" ) || !Q_stricmp( cmd, "/mt" ) ) |
| 344 |
teamonly = qtrue; |
| 345 |
|
| 346 |
G_SayArgv( 1+skipargs, name, sizeof( name ) ); |
| 347 |
msg = G_SayConcatArgs( 2+skipargs ); |
| 348 |
pcount = G_ClientNumbersFromString( name, pids, MAX_CLIENTS ); |
| 349 |
|
| 350 |
if( ent ) |
| 351 |
{ |
| 352 |
int count = 0; |
| 353 |
|
| 354 |
for( i = 0; i < pcount; i++ ) |
| 355 |
{ |
| 356 |
tmpent = &g_entities[ pids[ i ] ]; |
| 357 |
|
| 358 |
if( teamonly && !OnSameTeam( ent, tmpent ) ) |
| 359 |
continue; |
| 360 |
|
| 361 |
if( BG_ClientListTest( &tmpent->client->pers.ignoreList, |
| 362 |
ent-g_entities ) ) |
| 363 |
{ |
| 364 |
ignoreids[ ignored++ ] = pids[ i ]; |
| 365 |
continue; |
| 366 |
} |
| 367 |
|
| 368 |
pids[ count ] = pids[ i ]; |
| 369 |
count++; |
| 370 |
} |
| 371 |
matches = count; |
| 372 |
} |
| 373 |
else |
| 374 |
{ |
| 375 |
matches = pcount; |
| 376 |
} |
| 377 |
|
| 378 |
color = teamonly ? COLOR_CYAN : COLOR_YELLOW; |
| 379 |
|
| 380 |
Com_sprintf( str, sizeof( str ), "^%csent to %i player%s: ^7", color, matches, |
| 381 |
( matches == 1 ) ? "" : "s" ); |
| 382 |
|
| 383 |
for( i=0; i < matches; i++ ) |
| 384 |
{ |
| 385 |
tmpent = &g_entities[ pids[ i ] ]; |
| 386 |
|
| 387 |
if( i > 0 ) |
| 388 |
Q_strcat( str, sizeof( str ), "^7, " ); |
| 389 |
Q_strcat( str, sizeof( str ), tmpent->client->pers.netname ); |
| 390 |
trap_SendServerCommand( pids[ i ], va( |
| 391 |
"chat \"%s^%c -> ^7%s^7: (%d recipient%s): ^%c%s^7\" %i", |
| 392 |
( ent ) ? ent->client->pers.netname : "console", |
| 393 |
color, |
| 394 |
name, |
| 395 |
matches, |
| 396 |
( matches == 1 ) ? "" : "s", |
| 397 |
color, |
| 398 |
msg, |
| 399 |
ent ? ent-g_entities : -1 ) ); |
| 400 |
if( ent ) |
| 401 |
{ |
| 402 |
trap_SendServerCommand( pids[ i ], va( |
| 403 |
"print \">> to reply, say: /m %d [your message] <<\n\"", |
| 404 |
( ent - g_entities ) ) ); |
| 405 |
} |
| 406 |
trap_SendServerCommand( pids[ i ], va( |
| 407 |
"cp \"^%cprivate message from ^7%s^7\"", color, |
| 408 |
( ent ) ? ent->client->pers.netname : "console" ) ); |
| 409 |
} |
| 410 |
|
| 411 |
if( !matches ) |
| 412 |
ADMP( va( "^3No player matching ^7\'%s^7\' ^3to send message to.\n", |
| 413 |
name ) ); |
| 414 |
else |
| 415 |
{ |
| 416 |
ADMP( va( "^%cPrivate message: ^7%s\n", color, msg ) ); |
| 417 |
ADMP( va( "%s\n", str ) ); |
| 418 |
|
| 419 |
G_LogPrintf( "%s: %s^7: %s^7: %s\n", |
| 420 |
( teamonly ) ? "tprivmsg" : "privmsg", |
| 421 |
( ent ) ? ent->client->pers.netname : "console", |
| 422 |
name, msg ); |
| 423 |
} |
| 424 |
|
| 425 |
if( ignored ) |
| 426 |
{ |
| 427 |
Com_sprintf( str, sizeof( str ), "^%cignored by %i player%s: ^7", color, |
| 428 |
ignored, ( ignored == 1 ) ? "" : "s" ); |
| 429 |
for( i=0; i < ignored; i++ ) |
| 430 |
{ |
| 431 |
tmpent = &g_entities[ ignoreids[ i ] ]; |
| 432 |
if( i > 0 ) |
| 433 |
Q_strcat( str, sizeof( str ), "^7, " ); |
| 434 |
Q_strcat( str, sizeof( str ), tmpent->client->pers.netname ); |
| 435 |
} |
| 436 |
ADMP( va( "%s\n", str ) ); |
| 437 |
} |
| 438 |
} |
| 439 |
*/ |
| 440 |
|
| 441 |
/* |
| 442 |
================= |
| 443 |
G_AdminMessage |
| 444 |
|
| 445 |
Print to all active server admins, and to the logfile, and to the server console |
| 446 |
Prepend *prefix, or '[SERVER]' if no *prefix is given |
| 447 |
================= |
| 448 |
*/ |
| 449 |
void QDECL G_AdminMessage( const char *prefix, const char *fmt, ... ) |
| 450 |
{ |
| 451 |
va_list argptr; |
| 452 |
char string[ 1024 ]; |
| 453 |
char outstring[ 1024 ]; |
| 454 |
int i; |
| 455 |
|
| 456 |
// Format the text |
| 457 |
va_start( argptr, fmt ); |
| 458 |
Q_vsnprintf( string, sizeof( string ), fmt, argptr ); |
| 459 |
va_end( argptr ); |
| 460 |
|
| 461 |
// If there is no prefix, assume that this function was called directly |
| 462 |
// and we should add one |
| 463 |
if( !prefix || !prefix[ 0 ] ) |
| 464 |
{ |
| 465 |
prefix = "[SERVER]:"; |
| 466 |
} |
| 467 |
|
| 468 |
// Create the final string |
| 469 |
Com_sprintf( outstring, sizeof( outstring ), "%s " S_COLOR_MAGENTA "%s", |
| 470 |
prefix, string ); |
| 471 |
|
| 472 |
// Send to all appropriate clients |
| 473 |
for( i = 0; i < level.maxclients; i++ ) |
| 474 |
if( G_admin_permission( &g_entities[ i ], ADMF_ADMINCHAT ) ) |
| 475 |
trap_SendServerCommand( i, va( "chat \"%s\"", outstring ) ); |
| 476 |
|
| 477 |
// Send to the logfile and server console |
| 478 |
G_LogPrintf("adminmsg: %s\n", outstring ); |
| 479 |
} |
| 480 |
|
| 481 |
/* |
| 482 |
================= |
| 483 |
Cmd_AdminMessage_f |
| 484 |
|
| 485 |
Send a message to all active admins |
| 486 |
================= |
| 487 |
*/ |
| 488 |
void Cmd_AdminMessage_f( gentity_t *ent ) |
| 489 |
{ |
| 490 |
char cmd[ sizeof( "say_team" ) ]; |
| 491 |
char prefix[ 50 ]; |
| 492 |
char *msg; |
| 493 |
int skiparg = 0; |
| 494 |
|
| 495 |
// Check permissions and add the appropriate user [prefix] |
| 496 |
if( !ent ) |
| 497 |
{ |
| 498 |
Com_sprintf( prefix, sizeof( prefix ), "[CONSOLE]:" ); |
| 499 |
} |
| 500 |
else if( !G_admin_permission( ent, ADMF_ADMINCHAT ) ) |
| 501 |
{ |
| 502 |
if( !g_publicAdminMessages.integer ) |
| 503 |
{ |
| 504 |
ADMP( "Sorry, but use of /a by non-admins has been disabled.\n" ); |
| 505 |
return; |
| 506 |
} |
| 507 |
else |
| 508 |
{ |
| 509 |
Com_sprintf( prefix, sizeof( prefix ), "[PLAYER] %s" S_COLOR_WHITE ":", |
| 510 |
ent->client->pers.netname ); |
| 511 |
ADMP( "Your message has been sent to any available admins and to the server logs.\n" ); |
| 512 |
} |
| 513 |
} |
| 514 |
else |
| 515 |
{ |
| 516 |
Com_sprintf( prefix, sizeof( prefix ), "[ADMIN] %s" S_COLOR_WHITE ":", |
| 517 |
ent->client->pers.netname ); |
| 518 |
} |
| 519 |
|
| 520 |
// Skip say/say_team if this was used from one of those |
| 521 |
G_SayArgv( 0, cmd, sizeof( cmd ) ); |
| 522 |
if( !Q_stricmp( cmd, "say" ) || !Q_stricmp( cmd, "say_team" ) ) |
| 523 |
{ |
| 524 |
skiparg = 1; |
| 525 |
G_SayArgv( 1, cmd, sizeof( cmd ) ); |
| 526 |
} |
| 527 |
if( G_SayArgc( ) < 2 + skiparg ) |
| 528 |
{ |
| 529 |
ADMP( va( "usage: %s [message]\n", cmd ) ); |
| 530 |
return; |
| 531 |
} |
| 532 |
|
| 533 |
msg = G_SayConcatArgs( 1 + skiparg ); |
| 534 |
|
| 535 |
// Send it |
| 536 |
G_AdminMessage( prefix, "%s", msg ); |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
/* |
| 541 |
============== |
| 542 |
Cmd_Ignore_f |
| 543 |
KK-OAX Removed Static to Keep in Mod Files |
| 544 |
Currently Unused until I figure out how to implement it with voice chats. |
| 545 |
============== |
| 546 |
*/ |
| 547 |
/*void Cmd_Ignore_f( gentity_t *ent ) |
| 548 |
{ |
| 549 |
int pids[ MAX_CLIENTS ]; |
| 550 |
char name[ MAX_NAME_LENGTH ]; |
| 551 |
char cmd[ 9 ]; |
| 552 |
int matches = 0; |
| 553 |
int i; |
| 554 |
qboolean ignore = qfalse; |
| 555 |
|
| 556 |
trap_Argv( 0, cmd, sizeof( cmd ) ); |
| 557 |
if( Q_stricmp( cmd, "ignore" ) == 0 ) |
| 558 |
ignore = qtrue; |
| 559 |
|
| 560 |
if( trap_Argc() < 2 ) |
| 561 |
{ |
| 562 |
trap_SendServerCommand( ent-g_entities, va( "print \"[skipnotify]" |
| 563 |
"usage: %s [clientNum | partial name match]\n\"", cmd ) ); |
| 564 |
return; |
| 565 |
} |
| 566 |
|
| 567 |
Q_strncpyz( name, ConcatArgs( 1 ), sizeof( name ) ); |
| 568 |
matches = G_ClientNumbersFromString( name, pids, MAX_CLIENTS ); |
| 569 |
if( matches < 1 ) |
| 570 |
{ |
| 571 |
trap_SendServerCommand( ent-g_entities, va( "print \"[skipnotify]" |
| 572 |
"%s: no clients match the name '%s'\n\"", cmd, name ) ); |
| 573 |
return; |
| 574 |
} |
| 575 |
|
| 576 |
for( i = 0; i < matches; i++ ) |
| 577 |
{ |
| 578 |
if( ignore ) |
| 579 |
{ |
| 580 |
if( !BG_ClientListTest( &ent->client->pers.ignoreList, pids[ i ] ) ) |
| 581 |
{ |
| 582 |
BG_ClientListAdd( &ent->client->pers.ignoreList, pids[ i ] ); |
| 583 |
ClientUserinfoChanged( ent->client->ps.clientNum ); |
| 584 |
trap_SendServerCommand( ent-g_entities, va( "print \"[skipnotify]" |
| 585 |
"ignore: added %s^7 to your ignore list\n\"", |
| 586 |
level.clients[ pids[ i ] ].pers.netname ) ); |
| 587 |
} |
| 588 |
else |
| 589 |
{ |
| 590 |
trap_SendServerCommand( ent-g_entities, va( "print \"[skipnotify]" |
| 591 |
"ignore: %s^7 is already on your ignore list\n\"", |
| 592 |
level.clients[ pids[ i ] ].pers.netname ) ); |
| 593 |
} |
| 594 |
} |
| 595 |
else |
| 596 |
{ |
| 597 |
if( BG_ClientListTest( &ent->client->pers.ignoreList, pids[ i ] ) ) |
| 598 |
{ |
| 599 |
BG_ClientListRemove( &ent->client->pers.ignoreList, pids[ i ] ); |
| 600 |
ClientUserinfoChanged( ent->client->ps.clientNum ); |
| 601 |
trap_SendServerCommand( ent-g_entities, va( "print \"[skipnotify]" |
| 602 |
"unignore: removed %s^7 from your ignore list\n\"", |
| 603 |
level.clients[ pids[ i ] ].pers.netname ) ); |
| 604 |
} |
| 605 |
else |
| 606 |
{ |
| 607 |
trap_SendServerCommand( ent-g_entities, va( "print \"[skipnotify]" |
| 608 |
"unignore: %s^7 is not on your ignore list\n\"", |
| 609 |
level.clients[ pids[ i ] ].pers.netname ) ); |
| 610 |
} |
| 611 |
} |
| 612 |
} |
| 613 |
} |
| 614 |
*/ |
| 615 |
/* |
| 616 |
================== |
| 617 |
G_ClientNumberFromString |
| 618 |
|
| 619 |
Returns a player number for either a number or name string |
| 620 |
Returns -1 if invalid |
| 621 |
================== |
| 622 |
*/ |
| 623 |
int G_ClientNumberFromString( char *s ) |
| 624 |
{ |
| 625 |
gclient_t *cl; |
| 626 |
int i; |
| 627 |
char s2[ MAX_NAME_LENGTH ]; |
| 628 |
char n2[ MAX_NAME_LENGTH ]; |
| 629 |
|
| 630 |
// numeric values are just slot numbers |
| 631 |
for( i = 0; s[ i ] && isdigit( s[ i ] ); i++ ); |
| 632 |
if( !s[ i ] ) |
| 633 |
{ |
| 634 |
i = atoi( s ); |
| 635 |
|
| 636 |
if( i < 0 || i >= level.maxclients ) |
| 637 |
return -1; |
| 638 |
|
| 639 |
cl = &level.clients[ i ]; |
| 640 |
|
| 641 |
if( cl->pers.connected == CON_DISCONNECTED ) |
| 642 |
return -1; |
| 643 |
|
| 644 |
return i; |
| 645 |
} |
| 646 |
|
| 647 |
// check for a name match |
| 648 |
G_SanitiseString( s, s2, sizeof( s2 ) ); |
| 649 |
|
| 650 |
for( i = 0, cl = level.clients; i < level.maxclients; i++, cl++ ) |
| 651 |
{ |
| 652 |
if( cl->pers.connected == CON_DISCONNECTED ) |
| 653 |
continue; |
| 654 |
|
| 655 |
G_SanitiseString( cl->pers.netname, n2, sizeof( n2 ) ); |
| 656 |
|
| 657 |
if( !strcmp( n2, s2 ) ) |
| 658 |
return i; |
| 659 |
} |
| 660 |
|
| 661 |
return -1; |
| 662 |
} |
| 663 |
|
| 664 |
//KK-OAX Used to !spec999'ers |
| 665 |
/* |
| 666 |
============= |
| 667 |
G_ClientIsLagging |
| 668 |
============= |
| 669 |
*/ |
| 670 |
qboolean G_ClientIsLagging( gclient_t *client ) |
| 671 |
{ |
| 672 |
if( client ) |
| 673 |
{ |
| 674 |
if( client->ps.ping >= 999 ) |
| 675 |
return qtrue; |
| 676 |
else |
| 677 |
return qfalse; |
| 678 |
} |
| 679 |
|
| 680 |
return qfalse; //is a non-existant client lagging? woooo zen |
| 681 |
} |
| 682 |
|
| 683 |
/* |
| 684 |
================== |
| 685 |
SanitizeString |
| 686 |
|
| 687 |
Remove case and control characters |
| 688 |
================== |
| 689 |
*/ |
| 690 |
void SanitizeString( char *in, char *out ) { |
| 691 |
while ( *in ) { |
| 692 |
if ( *in == 27 ) { |
| 693 |
in += 2; // skip color code |
| 694 |
continue; |
| 695 |
} |
| 696 |
if ( *in < 32 ) { |
| 697 |
in++; |
| 698 |
continue; |
| 699 |
} |
| 700 |
*out++ = tolower( *in++ ); |
| 701 |
} |
| 702 |
|
| 703 |
*out = 0; |
| 704 |
} |
| 705 |
|