| 1 |
/* |
| 2 |
=========================================================================== |
| 3 |
Copyright (C) 1999-2005 Id Software, Inc. |
| 4 |
|
| 5 |
This file is part of Quake III Arena source code. |
| 6 |
|
| 7 |
Quake III Arena source code is free software; you can redistribute it |
| 8 |
and/or modify it under the terms of the GNU General Public License as |
| 9 |
published by the Free Software Foundation; either version 2 of the License, |
| 10 |
or (at your option) any later version. |
| 11 |
|
| 12 |
Quake III Arena source code is distributed in the hope that it will be |
| 13 |
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with Quake III Arena source code; if not, write to the Free Software |
| 19 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
=========================================================================== |
| 21 |
*/ |
| 22 |
// |
| 23 |
#include "g_local.h" |
| 24 |
|
| 25 |
#include "../../ui/menudef.h" // for the voice chats |
| 26 |
|
| 27 |
/* |
| 28 |
================== |
| 29 |
DeathmatchScoreboardMessage |
| 30 |
|
| 31 |
================== |
| 32 |
*/ |
| 33 |
void DeathmatchScoreboardMessage( gentity_t *ent ) { |
| 34 |
char entry[1024]; |
| 35 |
char string[1400]; |
| 36 |
int stringlength; |
| 37 |
int i, j; |
| 38 |
gclient_t *cl; |
| 39 |
int numSorted, scoreFlags, accuracy, perfect; |
| 40 |
|
| 41 |
// send the latest information on all clients |
| 42 |
string[0] = 0; |
| 43 |
stringlength = 0; |
| 44 |
scoreFlags = 0; |
| 45 |
|
| 46 |
numSorted = level.numConnectedClients; |
| 47 |
|
| 48 |
for (i=0 ; i < numSorted ; i++) { |
| 49 |
int ping; |
| 50 |
|
| 51 |
cl = &level.clients[level.sortedClients[i]]; |
| 52 |
|
| 53 |
if ( cl->pers.connected == CON_CONNECTING ) { |
| 54 |
ping = -1; |
| 55 |
} else { |
| 56 |
//unlagged - true ping |
| 57 |
//ping = cl->ps.ping < 999 ? cl->ps.ping : 999; |
| 58 |
ping = cl->pers.realPing < 999 ? cl->pers.realPing : 999; |
| 59 |
//unlagged - true ping |
| 60 |
} |
| 61 |
|
| 62 |
if( cl->accuracy_shots ) { |
| 63 |
accuracy = cl->accuracy_hits * 100 / cl->accuracy_shots; |
| 64 |
} |
| 65 |
else { |
| 66 |
accuracy = 0; |
| 67 |
} |
| 68 |
perfect = ( cl->ps.persistant[PERS_RANK] == 0 && cl->ps.persistant[PERS_KILLED] == 0 ) ? 1 : 0; |
| 69 |
|
| 70 |
if(g_gametype.integer == GT_LMS) { |
| 71 |
Com_sprintf (entry, sizeof(entry), |
| 72 |
" %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i", level.sortedClients[i], |
| 73 |
cl->ps.persistant[PERS_SCORE], ping, (level.time - cl->pers.enterTime)/60000, |
| 74 |
scoreFlags, g_entities[level.sortedClients[i]].s.powerups, accuracy, |
| 75 |
cl->ps.persistant[PERS_IMPRESSIVE_COUNT], |
| 76 |
cl->ps.persistant[PERS_EXCELLENT_COUNT], |
| 77 |
cl->ps.persistant[PERS_GAUNTLET_FRAG_COUNT], |
| 78 |
cl->ps.persistant[PERS_DEFEND_COUNT], |
| 79 |
cl->ps.persistant[PERS_ASSIST_COUNT], |
| 80 |
perfect, |
| 81 |
cl->ps.persistant[PERS_CAPTURES], |
| 82 |
cl->pers.livesLeft + (cl->isEliminated?0:1)); |
| 83 |
} |
| 84 |
else { |
| 85 |
Com_sprintf (entry, sizeof(entry), |
| 86 |
" %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i", level.sortedClients[i], |
| 87 |
cl->ps.persistant[PERS_SCORE], ping, (level.time - cl->pers.enterTime)/60000, |
| 88 |
scoreFlags, g_entities[level.sortedClients[i]].s.powerups, accuracy, |
| 89 |
cl->ps.persistant[PERS_IMPRESSIVE_COUNT], |
| 90 |
cl->ps.persistant[PERS_EXCELLENT_COUNT], |
| 91 |
cl->ps.persistant[PERS_GAUNTLET_FRAG_COUNT], |
| 92 |
cl->ps.persistant[PERS_DEFEND_COUNT], |
| 93 |
cl->ps.persistant[PERS_ASSIST_COUNT], |
| 94 |
perfect, |
| 95 |
cl->ps.persistant[PERS_CAPTURES], |
| 96 |
cl->isEliminated); |
| 97 |
} |
| 98 |
j = strlen(entry); |
| 99 |
if (stringlength + j > 1024) |
| 100 |
break; |
| 101 |
strcpy (string + stringlength, entry); |
| 102 |
stringlength += j; |
| 103 |
} |
| 104 |
|
| 105 |
trap_SendServerCommand( ent-g_entities, va("scores %i %i %i %i%s", i, |
| 106 |
level.teamScores[TEAM_RED], level.teamScores[TEAM_BLUE], level.roundStartTime, |
| 107 |
string ) ); |
| 108 |
} |
| 109 |
|
| 110 |
/* |
| 111 |
================== |
| 112 |
AccMessage |
| 113 |
|
| 114 |
================== |
| 115 |
*/ |
| 116 |
void AccMessage( gentity_t *ent ) { |
| 117 |
char entry[1024]; |
| 118 |
|
| 119 |
Com_sprintf (entry, sizeof(entry), |
| 120 |
" %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i %i ", |
| 121 |
ent->client->accuracy[WP_MACHINEGUN][0], ent->client->accuracy[WP_MACHINEGUN][1], |
| 122 |
ent->client->accuracy[WP_SHOTGUN][0], ent->client->accuracy[WP_SHOTGUN][1], |
| 123 |
ent->client->accuracy[WP_GRENADE_LAUNCHER][0], ent->client->accuracy[WP_GRENADE_LAUNCHER][1], |
| 124 |
ent->client->accuracy[WP_ROCKET_LAUNCHER][0], ent->client->accuracy[WP_ROCKET_LAUNCHER][1], |
| 125 |
ent->client->accuracy[WP_LIGHTNING][0], ent->client->accuracy[WP_LIGHTNING][1], |
| 126 |
ent->client->accuracy[WP_RAILGUN][0], ent->client->accuracy[WP_RAILGUN][1], |
| 127 |
ent->client->accuracy[WP_PLASMAGUN][0], ent->client->accuracy[WP_PLASMAGUN][1], |
| 128 |
ent->client->accuracy[WP_BFG][0], ent->client->accuracy[WP_BFG][1], |
| 129 |
0,0, //Hook |
| 130 |
ent->client->accuracy[WP_NAILGUN][0], ent->client->accuracy[WP_NAILGUN][1], |
| 131 |
0,0, |
| 132 |
ent->client->accuracy[WP_CHAINGUN][0], ent->client->accuracy[WP_CHAINGUN][1] |
| 133 |
); |
| 134 |
|
| 135 |
trap_SendServerCommand( ent-g_entities, va("accs%s", entry )); |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
/* |
| 140 |
================== |
| 141 |
DominationPointStatusMessage |
| 142 |
|
| 143 |
================== |
| 144 |
*/ |
| 145 |
void DominationPointStatusMessage( gentity_t *ent ) { |
| 146 |
char entry[10]; //Will more likely be 2... in fact cannot be more since we are the server |
| 147 |
char string[10*(MAX_DOMINATION_POINTS+1)]; |
| 148 |
int stringlength; |
| 149 |
int i, j; |
| 150 |
|
| 151 |
string[0] = 0; |
| 152 |
stringlength = 0; |
| 153 |
|
| 154 |
for(i = 0;i<MAX_DOMINATION_POINTS && i<level.domination_points_count; i++) { |
| 155 |
Com_sprintf (entry, sizeof(entry)," %i",level.pointStatusDom[i]); |
| 156 |
j = strlen(entry); |
| 157 |
if (stringlength + j > 10*MAX_DOMINATION_POINTS) |
| 158 |
break; |
| 159 |
strcpy (string + stringlength, entry); |
| 160 |
stringlength += j; |
| 161 |
} |
| 162 |
|
| 163 |
trap_SendServerCommand( ent-g_entities, va("domStatus %i%s", level.domination_points_count, string ) ); |
| 164 |
} |
| 165 |
|
| 166 |
/* |
| 167 |
================== |
| 168 |
EliminationMessage |
| 169 |
|
| 170 |
================== |
| 171 |
*/ |
| 172 |
|
| 173 |
void EliminationMessage(gentity_t *ent) { |
| 174 |
trap_SendServerCommand( ent-g_entities, va("elimination %i %i %i", |
| 175 |
level.teamScores[TEAM_RED], level.teamScores[TEAM_BLUE], level.roundStartTime) ); |
| 176 |
} |
| 177 |
|
| 178 |
void RespawnTimeMessage(gentity_t *ent, int time) { |
| 179 |
trap_SendServerCommand( ent-g_entities, va("respawn %i", time) ); |
| 180 |
} |
| 181 |
|
| 182 |
/* |
| 183 |
================== |
| 184 |
DoubleDominationScoreTime |
| 185 |
|
| 186 |
================== |
| 187 |
*/ |
| 188 |
void DoubleDominationScoreTimeMessage( gentity_t *ent ) { |
| 189 |
trap_SendServerCommand( ent-g_entities, va("ddtaken %i", level.timeTaken)); |
| 190 |
} |
| 191 |
|
| 192 |
/* |
| 193 |
================== |
| 194 |
DominationPointNames |
| 195 |
================== |
| 196 |
*/ |
| 197 |
|
| 198 |
void DominationPointNamesMessage( gentity_t *ent ) { |
| 199 |
char text[MAX_DOMINATION_POINTS_NAMES*MAX_DOMINATION_POINTS]; |
| 200 |
int i,j; |
| 201 |
qboolean nullFound; |
| 202 |
for(i=0;i<MAX_DOMINATION_POINTS;i++) { |
| 203 |
Q_strncpyz(text+i*MAX_DOMINATION_POINTS_NAMES,level.domination_points_names[i],MAX_DOMINATION_POINTS_NAMES-1); |
| 204 |
if(i!=MAX_DOMINATION_POINTS-1) { |
| 205 |
//Don't allow "/0"! |
| 206 |
nullFound = qfalse; |
| 207 |
for(j=i*MAX_DOMINATION_POINTS_NAMES; j<(i+1)*MAX_DOMINATION_POINTS_NAMES;j++) { |
| 208 |
if(text[j]==0) |
| 209 |
nullFound = qtrue; |
| 210 |
if(nullFound) |
| 211 |
text[j] = ' '; |
| 212 |
} |
| 213 |
} |
| 214 |
text[MAX_DOMINATION_POINTS_NAMES*MAX_DOMINATION_POINTS-2]=0x19; |
| 215 |
text[MAX_DOMINATION_POINTS_NAMES*MAX_DOMINATION_POINTS-1]=0; |
| 216 |
} |
| 217 |
trap_SendServerCommand( ent-g_entities, va("dompointnames %i \"%s\"", level.domination_points_count, text)); |
| 218 |
} |
| 219 |
|
| 220 |
/* |
| 221 |
================== |
| 222 |
YourTeamMessage |
| 223 |
================== |
| 224 |
*/ |
| 225 |
|
| 226 |
void YourTeamMessage( gentity_t *ent) { |
| 227 |
int team = level.clients[ent-g_entities].sess.sessionTeam; |
| 228 |
|
| 229 |
switch(team) { |
| 230 |
case TEAM_RED: |
| 231 |
trap_SendServerCommand( ent-g_entities, va("team \"%s\"", g_redTeamClientNumbers.string)); |
| 232 |
break; |
| 233 |
case TEAM_BLUE: |
| 234 |
trap_SendServerCommand( ent-g_entities, va("team \"%s\"", g_blueTeamClientNumbers.string)); |
| 235 |
break; |
| 236 |
default: |
| 237 |
trap_SendServerCommand( ent-g_entities, "team \"all\""); |
| 238 |
}; |
| 239 |
} |
| 240 |
|
| 241 |
/* |
| 242 |
================== |
| 243 |
AttackingTeamMessage |
| 244 |
|
| 245 |
================== |
| 246 |
*/ |
| 247 |
void AttackingTeamMessage( gentity_t *ent ) { |
| 248 |
int team; |
| 249 |
if ( (level.eliminationSides+level.roundNumber)%2 == 0 ) |
| 250 |
team = TEAM_RED; |
| 251 |
else |
| 252 |
team = TEAM_BLUE; |
| 253 |
trap_SendServerCommand( ent-g_entities, va("attackingteam %i", team)); |
| 254 |
} |
| 255 |
|
| 256 |
/* |
| 257 |
|
| 258 |
*/ |
| 259 |
|
| 260 |
void ObeliskHealthMessage() { |
| 261 |
if(level.MustSendObeliskHealth) { |
| 262 |
trap_SendServerCommand( -1, va("oh %i %i",level.healthRedObelisk,level.healthBlueObelisk) ); |
| 263 |
level.MustSendObeliskHealth = qfalse; |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
/* |
| 268 |
================== |
| 269 |
ChallengeMessage |
| 270 |
|
| 271 |
================== |
| 272 |
*/ |
| 273 |
|
| 274 |
void ChallengeMessage(gentity_t *ent, int challenge) { |
| 275 |
if ( level.warmupTime != 0) |
| 276 |
return; //We don't send anything doring warmup |
| 277 |
trap_SendServerCommand( ent-g_entities, va("ch %u", challenge) ); |
| 278 |
G_LogPrintf( "Challenge: %i %i %i: Client %i got award %i\n",ent-g_entities,challenge,1,ent-g_entities,challenge); |
| 279 |
} |
| 280 |
|
| 281 |
/* |
| 282 |
================== |
| 283 |
SendCustomVoteCommands |
| 284 |
|
| 285 |
================== |
| 286 |
*/ |
| 287 |
|
| 288 |
void SendCustomVoteCommands(int clientNum) { |
| 289 |
trap_SendServerCommand( clientNum, va("customvotes %s", custom_vote_info) ); |
| 290 |
} |
| 291 |
|
| 292 |
/* |
| 293 |
================== |
| 294 |
Cmd_Score_f |
| 295 |
|
| 296 |
Request current scoreboard information |
| 297 |
================== |
| 298 |
*/ |
| 299 |
void Cmd_Score_f( gentity_t *ent ) { |
| 300 |
DeathmatchScoreboardMessage( ent ); |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
/* |
| 305 |
================== |
| 306 |
Cmd_Acc_f |
| 307 |
Request current scoreboard information |
| 308 |
================== |
| 309 |
*/ |
| 310 |
void Cmd_Acc_f( gentity_t *ent ) { |
| 311 |
AccMessage( ent ); |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
/* |
| 316 |
================== |
| 317 |
CheatsOk |
| 318 |
================== |
| 319 |
*/ |
| 320 |
qboolean CheatsOk( gentity_t *ent ) { |
| 321 |
if ( !g_cheats.integer ) { |
| 322 |
trap_SendServerCommand( ent-g_entities, va("print \"Cheats are not enabled on this server.\n\"")); |
| 323 |
return qfalse; |
| 324 |
} |
| 325 |
if ( ent->health <= 0 ) { |
| 326 |
trap_SendServerCommand( ent-g_entities, va("print \"You must be alive to use this command.\n\"")); |
| 327 |
return qfalse; |
| 328 |
} |
| 329 |
return qtrue; |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
/* |
| 334 |
================== |
| 335 |
ConcatArgs |
| 336 |
================== |
| 337 |
*/ |
| 338 |
char *ConcatArgs( int start ) { |
| 339 |
int i, c, tlen; |
| 340 |
static char line[MAX_STRING_CHARS]; |
| 341 |
int len; |
| 342 |
char arg[MAX_STRING_CHARS]; |
| 343 |
|
| 344 |
len = 0; |
| 345 |
c = trap_Argc(); |
| 346 |
for ( i = start ; i < c ; i++ ) { |
| 347 |
trap_Argv( i, arg, sizeof( arg ) ); |
| 348 |
tlen = strlen( arg ); |
| 349 |
if ( len + tlen >= MAX_STRING_CHARS - 1 ) { |
| 350 |
break; |
| 351 |
} |
| 352 |
memcpy( line + len, arg, tlen ); |
| 353 |
len += tlen; |
| 354 |
if ( i != c - 1 ) { |
| 355 |
line[len] = ' '; |
| 356 |
len++; |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 360 |
line[len] = 0; |
| 361 |
|
| 362 |
return line; |
| 363 |
} |
| 364 |
|
| 365 |
/* |
| 366 |
================== |
| 367 |
ClientNumberFromString |
| 368 |
|
| 369 |
Returns a player number for either a number or name string |
| 370 |
Returns -1 if invalid |
| 371 |
================== |
| 372 |
*/ |
| 373 |
int ClientNumberFromString( gentity_t *to, char *s ) { |
| 374 |
gclient_t *cl; |
| 375 |
int idnum; |
| 376 |
char cleanName[MAX_STRING_CHARS]; |
| 377 |
|
| 378 |
// numeric values are just slot numbers |
| 379 |
if (s[0] >= '0' && s[0] <= '9') { |
| 380 |
idnum = atoi( s ); |
| 381 |
if ( idnum < 0 || idnum >= level.maxclients ) { |
| 382 |
trap_SendServerCommand( to-g_entities, va("print \"Bad client slot: %i\n\"", idnum)); |
| 383 |
return -1; |
| 384 |
} |
| 385 |
|
| 386 |
cl = &level.clients[idnum]; |
| 387 |
if ( cl->pers.connected != CON_CONNECTED ) { |
| 388 |
trap_SendServerCommand( to-g_entities, va("print \"Client %i is not active\n\"", idnum)); |
| 389 |
return -1; |
| 390 |
} |
| 391 |
return idnum; |
| 392 |
} |
| 393 |
|
| 394 |
// check for a name match |
| 395 |
for ( idnum=0,cl=level.clients ; idnum < level.maxclients ; idnum++,cl++ ) { |
| 396 |
if ( cl->pers.connected != CON_CONNECTED ) { |
| 397 |
continue; |
| 398 |
} |
| 399 |
Q_strncpyz(cleanName, cl->pers.netname, sizeof(cleanName)); |
| 400 |
Q_CleanStr(cleanName); |
| 401 |
if ( Q_strequal( cleanName, s ) ) { |
| 402 |
return idnum; |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
trap_SendServerCommand( to-g_entities, va("print \"User %s is not on the server\n\"", s)); |
| 407 |
return -1; |
| 408 |
} |
| 409 |
|
| 410 |
/* |
| 411 |
================== |
| 412 |
Cmd_Give_f |
| 413 |
|
| 414 |
Give items to a client |
| 415 |
================== |
| 416 |
*/ |
| 417 |
void Cmd_Give_f (gentity_t *ent) |
| 418 |
{ |
| 419 |
char *name; |
| 420 |
gitem_t *it; |
| 421 |
int i; |
| 422 |
qboolean give_all; |
| 423 |
gentity_t *it_ent; |
| 424 |
trace_t trace; |
| 425 |
|
| 426 |
if ( !CheatsOk( ent ) ) { |
| 427 |
return; |
| 428 |
} |
| 429 |
|
| 430 |
name = ConcatArgs( 1 ); |
| 431 |
|
| 432 |
if Q_strequal(name, "all") |
| 433 |
give_all = qtrue; |
| 434 |
else |
| 435 |
give_all = qfalse; |
| 436 |
|
| 437 |
if (give_all || Q_strequal( name, "health")) |
| 438 |
{ |
| 439 |
ent->health = ent->client->ps.stats[STAT_MAX_HEALTH]; |
| 440 |
if (!give_all) |
| 441 |
return; |
| 442 |
} |
| 443 |
|
| 444 |
if (give_all || Q_strequal(name, "weapons")) |
| 445 |
{ |
| 446 |
ent->client->ps.stats[STAT_WEAPONS] = (1 << WP_NUM_WEAPONS) - 1 - |
| 447 |
( 1 << WP_GRAPPLING_HOOK ) - ( 1 << WP_NONE ); |
| 448 |
if (!give_all) |
| 449 |
return; |
| 450 |
} |
| 451 |
|
| 452 |
if (give_all || Q_strequal(name, "ammo")) |
| 453 |
{ |
| 454 |
for ( i = 0 ; i < MAX_WEAPONS ; i++ ) { |
| 455 |
ent->client->ps.ammo[i] = 999; |
| 456 |
} |
| 457 |
if (!give_all) |
| 458 |
return; |
| 459 |
} |
| 460 |
|
| 461 |
if (give_all || Q_strequal(name, "armor")) |
| 462 |
{ |
| 463 |
ent->client->ps.stats[STAT_ARMOR] = 200; |
| 464 |
|
| 465 |
if (!give_all) |
| 466 |
return; |
| 467 |
} |
| 468 |
|
| 469 |
if (Q_strequal(name, "excellent")) { |
| 470 |
ent->client->ps.persistant[PERS_EXCELLENT_COUNT]++; |
| 471 |
return; |
| 472 |
} |
| 473 |
if (Q_strequal(name, "impressive")) { |
| 474 |
ent->client->ps.persistant[PERS_IMPRESSIVE_COUNT]++; |
| 475 |
return; |
| 476 |
} |
| 477 |
if (Q_strequal(name, "gauntletaward")) { |
| 478 |
ent->client->ps.persistant[PERS_GAUNTLET_FRAG_COUNT]++; |
| 479 |
return; |
| 480 |
} |
| 481 |
if (Q_strequal(name, "defend")) { |
| 482 |
ent->client->ps.persistant[PERS_DEFEND_COUNT]++; |
| 483 |
return; |
| 484 |
} |
| 485 |
if (Q_strequal(name, "assist")) { |
| 486 |
ent->client->ps.persistant[PERS_ASSIST_COUNT]++; |
| 487 |
return; |
| 488 |
} |
| 489 |
|
| 490 |
// spawn a specific item right on the player |
| 491 |
if ( !give_all ) { |
| 492 |
it = BG_FindItem (name); |
| 493 |
if (!it) { |
| 494 |
return; |
| 495 |
} |
| 496 |
|
| 497 |
it_ent = G_Spawn(); |
| 498 |
VectorCopy( ent->r.currentOrigin, it_ent->s.origin ); |
| 499 |
it_ent->classname = it->classname; |
| 500 |
G_SpawnItem (it_ent, it); |
| 501 |
FinishSpawningItem(it_ent ); |
| 502 |
memset( &trace, 0, sizeof( trace ) ); |
| 503 |
Touch_Item (it_ent, ent, &trace); |
| 504 |
if (it_ent->inuse) { |
| 505 |
G_FreeEntity( it_ent ); |
| 506 |
} |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
/* |
| 512 |
================== |
| 513 |
Cmd_God_f |
| 514 |
|
| 515 |
Sets client to godmode |
| 516 |
|
| 517 |
argv(0) god |
| 518 |
================== |
| 519 |
*/ |
| 520 |
void Cmd_God_f (gentity_t *ent) |
| 521 |
{ |
| 522 |
char *msg; |
| 523 |
|
| 524 |
if ( !CheatsOk( ent ) ) { |
| 525 |
return; |
| 526 |
} |
| 527 |
|
| 528 |
ent->flags ^= FL_GODMODE; |
| 529 |
if (!(ent->flags & FL_GODMODE) ) |
| 530 |
msg = "godmode OFF\n"; |
| 531 |
else |
| 532 |
msg = "godmode ON\n"; |
| 533 |
|
| 534 |
trap_SendServerCommand( ent-g_entities, va("print \"%s\"", msg)); |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
/* |
| 539 |
================== |
| 540 |
Cmd_Notarget_f |
| 541 |
|
| 542 |
Sets client to notarget |
| 543 |
|
| 544 |
argv(0) notarget |
| 545 |
================== |
| 546 |
*/ |
| 547 |
void Cmd_Notarget_f( gentity_t *ent ) { |
| 548 |
char *msg; |
| 549 |
|
| 550 |
if ( !CheatsOk( ent ) ) { |
| 551 |
return; |
| 552 |
} |
| 553 |
|
| 554 |
ent->flags ^= FL_NOTARGET; |
| 555 |
if (!(ent->flags & FL_NOTARGET) ) |
| 556 |
msg = "notarget OFF\n"; |
| 557 |
else |
| 558 |
msg = "notarget ON\n"; |
| 559 |
|
| 560 |
trap_SendServerCommand( ent-g_entities, va("print \"%s\"", msg)); |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
/* |
| 565 |
================== |
| 566 |
Cmd_Noclip_f |
| 567 |
|
| 568 |
argv(0) noclip |
| 569 |
================== |
| 570 |
*/ |
| 571 |
void Cmd_Noclip_f( gentity_t *ent ) { |
| 572 |
char *msg; |
| 573 |
|
| 574 |
if ( !CheatsOk( ent ) ) { |
| 575 |
return; |
| 576 |
} |
| 577 |
|
| 578 |
if ( ent->client->noclip ) { |
| 579 |
msg = "noclip OFF\n"; |
| 580 |
} else { |
| 581 |
msg = "noclip ON\n"; |
| 582 |
} |
| 583 |
ent->client->noclip = !ent->client->noclip; |
| 584 |
|
| 585 |
trap_SendServerCommand( ent-g_entities, va("print \"%s\"", msg)); |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
/* |
| 590 |
================== |
| 591 |
Cmd_LevelShot_f |
| 592 |
|
| 593 |
This is just to help generate the level pictures |
| 594 |
for the menus. It goes to the intermission immediately |
| 595 |
and sends over a command to the client to resize the view, |
| 596 |
hide the scoreboard, and take a special screenshot |
| 597 |
================== |
| 598 |
*/ |
| 599 |
void Cmd_LevelShot_f( gentity_t *ent ) { |
| 600 |
if ( !CheatsOk( ent ) ) { |
| 601 |
return; |
| 602 |
} |
| 603 |
|
| 604 |
// doesn't work in single player |
| 605 |
if ( g_gametype.integer != 0 ) { |
| 606 |
trap_SendServerCommand( ent-g_entities, |
| 607 |
"print \"Must be in g_gametype 0 for levelshot\n\"" ); |
| 608 |
return; |
| 609 |
} |
| 610 |
|
| 611 |
if(!ent->client->pers.localClient) |
| 612 |
{ |
| 613 |
trap_SendServerCommand(ent-g_entities, |
| 614 |
"print \"The levelshot command must be executed by a local client\n\""); |
| 615 |
return; |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
BeginIntermission(); |
| 620 |
trap_SendServerCommand( ent-g_entities, "clientLevelShot" ); |
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
/* |
| 625 |
================== |
| 626 |
Cmd_LevelShot_f |
| 627 |
|
| 628 |
This is just to help generate the level pictures |
| 629 |
for the menus. It goes to the intermission immediately |
| 630 |
and sends over a command to the client to resize the view, |
| 631 |
hide the scoreboard, and take a special screenshot |
| 632 |
================== |
| 633 |
*/ |
| 634 |
void Cmd_TeamTask_f( gentity_t *ent ) { |
| 635 |
char userinfo[MAX_INFO_STRING]; |
| 636 |
char arg[MAX_TOKEN_CHARS]; |
| 637 |
int task; |
| 638 |
int client = ent->client - level.clients; |
| 639 |
|
| 640 |
if ( trap_Argc() != 2 ) { |
| 641 |
return; |
| 642 |
} |
| 643 |
trap_Argv( 1, arg, sizeof( arg ) ); |
| 644 |
task = atoi( arg ); |
| 645 |
|
| 646 |
trap_GetUserinfo(client, userinfo, sizeof(userinfo)); |
| 647 |
Info_SetValueForKey(userinfo, "teamtask", va("%d", task)); |
| 648 |
trap_SetUserinfo(client, userinfo); |
| 649 |
ClientUserinfoChanged(client); |
| 650 |
} |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
/* |
| 655 |
================= |
| 656 |
Cmd_Kill_f |
| 657 |
================= |
| 658 |
*/ |
| 659 |
void Cmd_Kill_f( gentity_t *ent ) { |
| 660 |
if ( (ent->client->sess.sessionTeam == TEAM_SPECTATOR) || ent->client->isEliminated ) { |
| 661 |
return; |
| 662 |
} |
| 663 |
if (ent->health <= 0) { |
| 664 |
return; |
| 665 |
} |
| 666 |
ent->flags &= ~FL_GODMODE; |
| 667 |
ent->client->ps.stats[STAT_HEALTH] = ent->health = -999; |
| 668 |
if(ent->client->lastSentFlying>-1) |
| 669 |
//If player is in the air because of knockback we give credit to the person who sent it flying |
| 670 |
player_die (ent, ent, &g_entities[ent->client->lastSentFlying], 100000, MOD_FALLING); |
| 671 |
else |
| 672 |
player_die (ent, ent, ent, 100000, MOD_SUICIDE); |
| 673 |
} |
| 674 |
|
| 675 |
/* |
| 676 |
================= |
| 677 |
BroadCastTeamChange |
| 678 |
|
| 679 |
Let everyone know about a team change |
| 680 |
================= |
| 681 |
*/ |
| 682 |
void BroadcastTeamChange( gclient_t *client, int oldTeam ) |
| 683 |
{ |
| 684 |
if ( client->sess.sessionTeam == TEAM_RED ) { |
| 685 |
trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " joined the red team.\n\"", |
| 686 |
client->pers.netname) ); |
| 687 |
} else if ( client->sess.sessionTeam == TEAM_BLUE ) { |
| 688 |
trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " joined the blue team.\n\"", |
| 689 |
client->pers.netname)); |
| 690 |
} else if ( client->sess.sessionTeam == TEAM_SPECTATOR && oldTeam != TEAM_SPECTATOR ) { |
| 691 |
trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " joined the spectators.\n\"", |
| 692 |
client->pers.netname)); |
| 693 |
} else if ( client->sess.sessionTeam == TEAM_FREE ) { |
| 694 |
trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " joined the battle.\n\"", |
| 695 |
client->pers.netname)); |
| 696 |
} |
| 697 |
} |
| 698 |
|
| 699 |
/* |
| 700 |
================= |
| 701 |
SetTeam |
| 702 |
KK-OAX Modded this to accept a forced admin change. |
| 703 |
================= |
| 704 |
*/ |
| 705 |
void SetTeam( gentity_t *ent, char *s ) { |
| 706 |
int team, oldTeam; |
| 707 |
gclient_t *client; |
| 708 |
int clientNum; |
| 709 |
spectatorState_t specState; |
| 710 |
int specClient; |
| 711 |
int teamLeader; |
| 712 |
char userinfo[MAX_INFO_STRING]; |
| 713 |
qboolean force; |
| 714 |
|
| 715 |
force = G_admin_permission(ent, ADMF_FORCETEAMCHANGE); |
| 716 |
|
| 717 |
// |
| 718 |
// see what change is requested |
| 719 |
// |
| 720 |
client = ent->client; |
| 721 |
|
| 722 |
clientNum = client - level.clients; |
| 723 |
trap_GetUserinfo( clientNum, userinfo, sizeof( userinfo ) ); |
| 724 |
specClient = 0; |
| 725 |
specState = SPECTATOR_NOT; |
| 726 |
if ( Q_strequal( s, "scoreboard" ) || Q_strequal( s, "score" ) ) { |
| 727 |
team = TEAM_SPECTATOR; |
| 728 |
specState = SPECTATOR_SCOREBOARD; |
| 729 |
} else if ( Q_strequal( s, "follow1" ) ) { |
| 730 |
team = TEAM_SPECTATOR; |
| 731 |
specState = SPECTATOR_FOLLOW; |
| 732 |
specClient = -1; |
| 733 |
} else if ( Q_strequal( s, "follow2" ) ) { |
| 734 |
team = TEAM_SPECTATOR; |
| 735 |
specState = SPECTATOR_FOLLOW; |
| 736 |
specClient = -2; |
| 737 |
} else if ( Q_strequal( s, "spectator" ) || Q_strequal( s, "s" ) ) { |
| 738 |
team = TEAM_SPECTATOR; |
| 739 |
specState = SPECTATOR_FREE; |
| 740 |
} else if ( g_gametype.integer >= GT_TEAM && g_ffa_gt!=1) { |
| 741 |
// if running a team game, assign player to one of the teams |
| 742 |
specState = SPECTATOR_NOT; |
| 743 |
if ( Q_strequal( s, "red" ) || Q_strequal( s, "r" ) ) { |
| 744 |
team = TEAM_RED; |
| 745 |
} else if ( Q_strequal( s, "blue" ) || Q_strequal( s, "b" ) ) { |
| 746 |
team = TEAM_BLUE; |
| 747 |
} else { |
| 748 |
// pick the team with the least number of players |
| 749 |
team = PickTeam( clientNum ); |
| 750 |
} |
| 751 |
if ( !force ) { |
| 752 |
if ( g_teamForceBalance.integer ) { |
| 753 |
int counts[TEAM_NUM_TEAMS]; |
| 754 |
|
| 755 |
counts[TEAM_BLUE] = TeamCount( ent->client->ps.clientNum, TEAM_BLUE ); |
| 756 |
counts[TEAM_RED] = TeamCount( ent->client->ps.clientNum, TEAM_RED ); |
| 757 |
|
| 758 |
// We allow a spread of two |
| 759 |
if ( team == TEAM_RED && counts[TEAM_RED] - counts[TEAM_BLUE] > 1 ) { |
| 760 |
trap_SendServerCommand( ent->client->ps.clientNum, |
| 761 |
"cp \"Red team has too many players.\n\"" ); |
| 762 |
return; // ignore the request |
| 763 |
} |
| 764 |
if ( team == TEAM_BLUE && counts[TEAM_BLUE] - counts[TEAM_RED] > 1 ) { |
| 765 |
trap_SendServerCommand( ent->client->ps.clientNum, |
| 766 |
"cp \"Blue team has too many players.\n\"" ); |
| 767 |
return; // ignore the request |
| 768 |
} |
| 769 |
|
| 770 |
// It's ok, the team we are switching to has less or same number of players |
| 771 |
} |
| 772 |
} |
| 773 |
} else { |
| 774 |
// force them to spectators if there aren't any spots free |
| 775 |
team = TEAM_FREE; |
| 776 |
} |
| 777 |
if ( !force ) { |
| 778 |
// override decision if limiting the players |
| 779 |
if ( (g_gametype.integer == GT_TOURNAMENT) |
| 780 |
&& level.numNonSpectatorClients >= 2 ) { |
| 781 |
team = TEAM_SPECTATOR; |
| 782 |
} else if ( g_maxGameClients.integer > 0 && |
| 783 |
level.numNonSpectatorClients >= g_maxGameClients.integer ) { |
| 784 |
team = TEAM_SPECTATOR; |
| 785 |
} |
| 786 |
} |
| 787 |
|
| 788 |
// |
| 789 |
// decide if we will allow the change |
| 790 |
// |
| 791 |
oldTeam = client->sess.sessionTeam; |
| 792 |
if ( team == oldTeam && team != TEAM_SPECTATOR ) { |
| 793 |
return; |
| 794 |
} |
| 795 |
//KK-OAX Check to make sure the team is not locked from Admin |
| 796 |
if ( !force ) { |
| 797 |
if ( team == TEAM_RED && level.RedTeamLocked ) { |
| 798 |
trap_SendServerCommand( ent->client->ps.clientNum, |
| 799 |
"cp \"The Red Team has been locked by the Admin! \n\"" ); |
| 800 |
return; |
| 801 |
} |
| 802 |
if ( team == TEAM_BLUE && level.BlueTeamLocked ) { |
| 803 |
trap_SendServerCommand( ent->client->ps.clientNum, |
| 804 |
"cp \"The Blue Team has been locked by the Admin! \n\"" ); |
| 805 |
return; |
| 806 |
} |
| 807 |
if ( team == TEAM_FREE && level.FFALocked ) { |
| 808 |
trap_SendServerCommand( ent->client->ps.clientNum, |
| 809 |
"cp \"This Deathmatch has been locked by the Admin! \n\"" ); |
| 810 |
return; |
| 811 |
} |
| 812 |
} |
| 813 |
// |
| 814 |
// execute the team change |
| 815 |
// |
| 816 |
|
| 817 |
// if the player was dead leave the body |
| 818 |
if ( client->ps.stats[STAT_HEALTH] <= 0 ) { |
| 819 |
CopyToBodyQue(ent); |
| 820 |
} |
| 821 |
|
| 822 |
// he starts at 'base' |
| 823 |
client->pers.teamState.state = TEAM_BEGIN; |
| 824 |
if ( oldTeam != TEAM_SPECTATOR ) { |
| 825 |
int teamscore = -99; |
| 826 |
//Prevent a team from loosing point because of player leaving team |
| 827 |
if(g_gametype.integer == GT_TEAM && ent->client->ps.stats[STAT_HEALTH]) |
| 828 |
teamscore = level.teamScores[ ent->client->sess.sessionTeam ]; |
| 829 |
// Kill him (makes sure he loses flags, etc) |
| 830 |
ent->flags &= ~FL_GODMODE; |
| 831 |
ent->client->ps.stats[STAT_HEALTH] = ent->health = 0; |
| 832 |
player_die (ent, ent, ent, 100000, MOD_SUICIDE); |
| 833 |
if(teamscore != -99) |
| 834 |
level.teamScores[ ent->client->sess.sessionTeam ] = teamscore; |
| 835 |
|
| 836 |
} |
| 837 |
|
| 838 |
if(oldTeam!=TEAM_SPECTATOR) |
| 839 |
PlayerStore_store(Info_ValueForKey(userinfo,"cl_guid"),client->ps); |
| 840 |
|
| 841 |
// they go to the end of the line for tournements |
| 842 |
if(team == TEAM_SPECTATOR && oldTeam != team) |
| 843 |
AddTournamentQueue(client); |
| 844 |
|
| 845 |
client->sess.sessionTeam = team; |
| 846 |
client->sess.spectatorState = specState; |
| 847 |
client->sess.spectatorClient = specClient; |
| 848 |
|
| 849 |
client->sess.teamLeader = qfalse; |
| 850 |
if ( team == TEAM_RED || team == TEAM_BLUE ) { |
| 851 |
teamLeader = TeamLeader( team ); |
| 852 |
// if there is no team leader or the team leader is a bot and this client is not a bot |
| 853 |
if ( teamLeader == -1 || ( !(g_entities[clientNum].r.svFlags & SVF_BOT) && (g_entities[teamLeader].r.svFlags & SVF_BOT) ) ) { |
| 854 |
SetLeader( team, clientNum ); |
| 855 |
} |
| 856 |
} |
| 857 |
// make sure there is a team leader on the team the player came from |
| 858 |
if ( oldTeam == TEAM_RED || oldTeam == TEAM_BLUE ) { |
| 859 |
CheckTeamLeader( oldTeam ); |
| 860 |
} |
| 861 |
|
| 862 |
BroadcastTeamChange( client, oldTeam ); |
| 863 |
|
| 864 |
// get and distribute relevent paramters |
| 865 |
ClientUserinfoChanged( clientNum ); |
| 866 |
|
| 867 |
ClientBegin( clientNum ); |
| 868 |
} |
| 869 |
|
| 870 |
/* |
| 871 |
================= |
| 872 |
StopFollowing |
| 873 |
|
| 874 |
If the client being followed leaves the game, or you just want to drop |
| 875 |
to free floating spectator mode |
| 876 |
================= |
| 877 |
*/ |
| 878 |
void StopFollowing( gentity_t *ent ) { |
| 879 |
if(g_gametype.integer<GT_ELIMINATION || g_gametype.integer>GT_LMS) |
| 880 |
{ |
| 881 |
//Shouldn't this already be the case? |
| 882 |
ent->client->ps.persistant[ PERS_TEAM ] = TEAM_SPECTATOR; |
| 883 |
ent->client->sess.sessionTeam = TEAM_SPECTATOR; |
| 884 |
} |
| 885 |
else { |
| 886 |
ent->client->ps.stats[STAT_HEALTH] = 0; |
| 887 |
ent->health = 0; |
| 888 |
} |
| 889 |
ent->client->sess.spectatorState = SPECTATOR_FREE; |
| 890 |
ent->client->ps.pm_flags &= ~PMF_FOLLOW; |
| 891 |
ent->r.svFlags &= ~SVF_BOT; |
| 892 |
ent->client->ps.clientNum = ent - g_entities; |
| 893 |
} |
| 894 |
|
| 895 |
/* |
| 896 |
================= |
| 897 |
Cmd_Team_f |
| 898 |
================= |
| 899 |
*/ |
| 900 |
void Cmd_Team_f( gentity_t *ent ) { |
| 901 |
int oldTeam; |
| 902 |
char s[MAX_TOKEN_CHARS]; |
| 903 |
qboolean force; |
| 904 |
|
| 905 |
if ( trap_Argc() != 2 ) { |
| 906 |
oldTeam = ent->client->sess.sessionTeam; |
| 907 |
switch ( oldTeam ) { |
| 908 |
case TEAM_BLUE: |
| 909 |
trap_SendServerCommand( ent-g_entities, "print \"Blue team\n\"" ); |
| 910 |
break; |
| 911 |
case TEAM_RED: |
| 912 |
trap_SendServerCommand( ent-g_entities, "print \"Red team\n\"" ); |
| 913 |
break; |
| 914 |
case TEAM_FREE: |
| 915 |
trap_SendServerCommand( ent-g_entities, "print \"Deathmatch-Playing\n\"" ); |
| 916 |
break; |
| 917 |
case TEAM_SPECTATOR: |
| 918 |
trap_SendServerCommand( ent-g_entities, "print \"Spectator team\n\"" ); |
| 919 |
break; |
| 920 |
} |
| 921 |
return; |
| 922 |
} |
| 923 |
|
| 924 |
force = G_admin_permission(ent, ADMF_FORCETEAMCHANGE); |
| 925 |
|
| 926 |
if( !force ) { |
| 927 |
if ( ent->client->switchTeamTime > level.time ) { |
| 928 |
trap_SendServerCommand( ent-g_entities, "print \"May not switch teams more than once per 5 seconds.\n\"" ); |
| 929 |
return; |
| 930 |
} |
| 931 |
} |
| 932 |
|
| 933 |
// if they are playing a tournement game, count as a loss |
| 934 |
if ( (g_gametype.integer == GT_TOURNAMENT ) |
| 935 |
&& ent->client->sess.sessionTeam == TEAM_FREE ) { |
| 936 |
ent->client->sess.losses++; |
| 937 |
} |
| 938 |
|
| 939 |
trap_Argv( 1, s, sizeof( s ) ); |
| 940 |
|
| 941 |
SetTeam( ent, s ); |
| 942 |
|
| 943 |
ent->client->switchTeamTime = level.time + 5000; |
| 944 |
} |
| 945 |
|
| 946 |
|
| 947 |
/* |
| 948 |
================= |
| 949 |
Cmd_Follow_f |
| 950 |
================= |
| 951 |
*/ |
| 952 |
void Cmd_Follow_f( gentity_t *ent ) { |
| 953 |
int i; |
| 954 |
char arg[MAX_TOKEN_CHARS]; |
| 955 |
|
| 956 |
if ( trap_Argc() != 2 ) { |
| 957 |
if ( ent->client->sess.spectatorState == SPECTATOR_FOLLOW ) { |
| 958 |
StopFollowing( ent ); |
| 959 |
} |
| 960 |
return; |
| 961 |
} |
| 962 |
|
| 963 |
|
| 964 |
trap_Argv( 1, arg, sizeof( arg ) ); |
| 965 |
i = ClientNumberFromString( ent, arg ); |
| 966 |
if ( i == -1 ) { |
| 967 |
return; |
| 968 |
} |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
// can't follow self |
| 973 |
if ( &level.clients[ i ] == ent->client ) { |
| 974 |
return; |
| 975 |
} |
| 976 |
|
| 977 |
// can't follow another spectator (or an eliminated player) |
| 978 |
if ( (level.clients[ i ].sess.sessionTeam == TEAM_SPECTATOR) || level.clients[ i ].isEliminated) { |
| 979 |
return; |
| 980 |
} |
| 981 |
|
| 982 |
if ( (g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION) && g_elimination_lockspectator.integer |
| 983 |
&& ((ent->client->sess.sessionTeam == TEAM_RED && level.clients[ i ].sess.sessionTeam == TEAM_BLUE) || |
| 984 |
(ent->client->sess.sessionTeam == TEAM_BLUE && level.clients[ i ].sess.sessionTeam == TEAM_RED) ) ) { |
| 985 |
return; |
| 986 |
} |
| 987 |
|
| 988 |
// if they are playing a tournement game, count as a loss |
| 989 |
if ( (g_gametype.integer == GT_TOURNAMENT ) |
| 990 |
&& ent->client->sess.sessionTeam == TEAM_FREE ) { |
| 991 |
ent->client->sess.losses++; |
| 992 |
} |
| 993 |
|
| 994 |
// first set them to spectator |
| 995 |
//if ( ent->client->sess.sessionTeam != TEAM_SPECTATOR ) { |
| 996 |
if ( ent->client->sess.spectatorState == SPECTATOR_NOT ) { |
| 997 |
SetTeam( ent, "spectator" ); |
| 998 |
} |
| 999 |
|
| 1000 |
ent->client->sess.spectatorState = SPECTATOR_FOLLOW; |
| 1001 |
ent->client->sess.spectatorClient = i; |
| 1002 |
} |
| 1003 |
|
| 1004 |
/* |
| 1005 |
================= |
| 1006 |
Cmd_FollowCycle_f |
| 1007 |
KK-OAX Modified to trap arguments. |
| 1008 |
================= |
| 1009 |
*/ |
| 1010 |
void Cmd_FollowCycle_f( gentity_t *ent ) { |
| 1011 |
int clientnum; |
| 1012 |
int original; |
| 1013 |
int count; |
| 1014 |
char args[11]; |
| 1015 |
int dir; |
| 1016 |
|
| 1017 |
if( ent->client->sess.sessionTeam == TEAM_NONE ) { |
| 1018 |
dir = 1; |
| 1019 |
} |
| 1020 |
|
| 1021 |
trap_Argv( 0, args, sizeof( args ) ); |
| 1022 |
if( Q_strequal( args, "followprev" )) { |
| 1023 |
dir = -1; |
| 1024 |
} else if( Q_strequal( args, "follownext" )) { |
| 1025 |
dir = 1; |
| 1026 |
} else { |
| 1027 |
dir = 1; |
| 1028 |
} |
| 1029 |
|
| 1030 |
// if they are playing a tournement game, count as a loss |
| 1031 |
if ( (g_gametype.integer == GT_TOURNAMENT ) |
| 1032 |
&& ent->client->sess.sessionTeam == TEAM_FREE ) { |
| 1033 |
ent->client->sess.losses++; |
| 1034 |
} |
| 1035 |
// first set them to spectator |
| 1036 |
if ( ent->client->sess.spectatorState == SPECTATOR_NOT ) { |
| 1037 |
SetTeam( ent, "spectator" ); |
| 1038 |
} |
| 1039 |
|
| 1040 |
if ( dir != 1 && dir != -1 ) { |
| 1041 |
G_Error( "Cmd_FollowCycle_f: bad dir %i", dir ); |
| 1042 |
} |
| 1043 |
|
| 1044 |
clientnum = ent->client->sess.spectatorClient; |
| 1045 |
original = clientnum; |
| 1046 |
count = 0; |
| 1047 |
do { |
| 1048 |
clientnum += dir; |
| 1049 |
count++; |
| 1050 |
if ( clientnum >= level.maxclients ) { |
| 1051 |
clientnum = 0; |
| 1052 |
} |
| 1053 |
if ( clientnum < 0 ) { |
| 1054 |
clientnum = level.maxclients - 1; |
| 1055 |
} |
| 1056 |
|
| 1057 |
if(count>level.maxclients) //We have looked at all clients at least once and found nothing |
| 1058 |
return; //We might end up in an infinite loop here. Stop it! |
| 1059 |
|
| 1060 |
// can only follow connected clients |
| 1061 |
if ( level.clients[ clientnum ].pers.connected != CON_CONNECTED ) { |
| 1062 |
continue; |
| 1063 |
} |
| 1064 |
|
| 1065 |
// can't follow another spectator |
| 1066 |
if ( (level.clients[ clientnum ].sess.sessionTeam == TEAM_SPECTATOR) || level.clients[ clientnum ].isEliminated) { |
| 1067 |
continue; |
| 1068 |
} |
| 1069 |
|
| 1070 |
//Stop players from spectating players on the enemy team in elimination modes. |
| 1071 |
if ( (g_gametype.integer == GT_ELIMINATION || g_gametype.integer == GT_CTF_ELIMINATION) && g_elimination_lockspectator.integer |
| 1072 |
&& ((ent->client->sess.sessionTeam == TEAM_RED && level.clients[ clientnum ].sess.sessionTeam == TEAM_BLUE) || |
| 1073 |
(ent->client->sess.sessionTeam == TEAM_BLUE && level.clients[ clientnum ].sess.sessionTeam == TEAM_RED) ) ) { |
| 1074 |
continue; |
| 1075 |
} |
| 1076 |
|
| 1077 |
// this is good, we can use it |
| 1078 |
ent->client->sess.spectatorClient = clientnum; |
| 1079 |
ent->client->sess.spectatorState = SPECTATOR_FOLLOW; |
| 1080 |
return; |
| 1081 |
} while ( clientnum != original ); |
| 1082 |
|
| 1083 |
// leave it where it was |
| 1084 |
} |
| 1085 |
|
| 1086 |
|
| 1087 |
/* |
| 1088 |
================== |
| 1089 |
G_Say |
| 1090 |
================== |
| 1091 |
*/ |
| 1092 |
|
| 1093 |
static void G_SayTo( gentity_t *ent, gentity_t *other, int mode, int color, const char *name, const char *message ) { |
| 1094 |
if (!other) { |
| 1095 |
return; |
| 1096 |
} |
| 1097 |
if (!other->inuse) { |
| 1098 |
return; |
| 1099 |
} |
| 1100 |
if (!other->client) { |
| 1101 |
return; |
| 1102 |
} |
| 1103 |
if ( other->client->pers.connected != CON_CONNECTED ) { |
| 1104 |
return; |
| 1105 |
} |
| 1106 |
if ( mode == SAY_TEAM && !OnSameTeam(ent, other) ) { |
| 1107 |
return; |
| 1108 |
} |
| 1109 |
|
| 1110 |
if ((ent->r.svFlags & SVF_BOT) && trap_Cvar_VariableValue( "bot_nochat" )>1) return; |
| 1111 |
|
| 1112 |
// no chatting to players in tournements |
| 1113 |
if ( (g_gametype.integer == GT_TOURNAMENT ) |
| 1114 |
&& other->client->sess.sessionTeam == TEAM_FREE |
| 1115 |
&& ent->client->sess.sessionTeam != TEAM_FREE ) { |
| 1116 |
return; |
| 1117 |
} |
| 1118 |
|
| 1119 |
trap_SendServerCommand( other-g_entities, va("%s \"%s%c%c%s\"", |
| 1120 |
mode == SAY_TEAM ? "tchat" : "chat", |
| 1121 |
name, Q_COLOR_ESCAPE, color, message)); |
| 1122 |
} |
| 1123 |
|
| 1124 |
#define EC "\x19" |
| 1125 |
|
| 1126 |
void G_Say( gentity_t *ent, gentity_t *target, int mode, const char *chatText ) { |
| 1127 |
int j; |
| 1128 |
gentity_t *other; |
| 1129 |
int color; |
| 1130 |
char name[64]; |
| 1131 |
// don't let text be too long for malicious reasons |
| 1132 |
char text[MAX_SAY_TEXT]; |
| 1133 |
char location[64]; |
| 1134 |
|
| 1135 |
if ((ent->r.svFlags & SVF_BOT) && trap_Cvar_VariableValue( "bot_nochat" )>1) return; |
| 1136 |
|
| 1137 |
if ( (g_gametype.integer < GT_TEAM || g_ffa_gt == 1) && mode == SAY_TEAM ) { |
| 1138 |
mode = SAY_ALL; |
| 1139 |
} |
| 1140 |
|
| 1141 |
switch ( mode ) { |
| 1142 |
default: |
| 1143 |
case SAY_ALL: |
| 1144 |
G_LogPrintf( "say: %s: %s\n", ent->client->pers.netname, chatText ); |
| 1145 |
Com_sprintf (name, sizeof(name), "%s%c%c"EC": ", ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE ); |
| 1146 |
color = COLOR_GREEN; |
| 1147 |
break; |
| 1148 |
case SAY_TEAM: |
| 1149 |
G_LogPrintf( "sayteam: %s: %s\n", ent->client->pers.netname, chatText ); |
| 1150 |
if (Team_GetLocationMsg(ent, location, sizeof(location))) |
| 1151 |
Com_sprintf (name, sizeof(name), EC"(%s%c%c"EC") (%s)"EC": ", |
| 1152 |
ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE, location); |
| 1153 |
else |
| 1154 |
Com_sprintf (name, sizeof(name), EC"(%s%c%c"EC")"EC": ", |
| 1155 |
ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE ); |
| 1156 |
color = COLOR_CYAN; |
| 1157 |
break; |
| 1158 |
case SAY_TELL: |
| 1159 |
if (target && g_gametype.integer >= GT_TEAM && g_ffa_gt != 1 && |
| 1160 |
target->client->sess.sessionTeam == ent->client->sess.sessionTeam && |
| 1161 |
Team_GetLocationMsg(ent, location, sizeof(location))) |
| 1162 |
Com_sprintf (name, sizeof(name), EC"[%s%c%c"EC"] (%s)"EC": ", ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE, location ); |
| 1163 |
else |
| 1164 |
Com_sprintf (name, sizeof(name), EC"[%s%c%c"EC"]"EC": ", ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE ); |
| 1165 |
color = COLOR_MAGENTA; |
| 1166 |
break; |
| 1167 |
} |
| 1168 |
|
| 1169 |
Q_strncpyz( text, chatText, sizeof(text) ); |
| 1170 |
|
| 1171 |
if ( target ) { |
| 1172 |
G_SayTo( ent, target, mode, color, name, text ); |
| 1173 |
return; |
| 1174 |
} |
| 1175 |
|
| 1176 |
// echo the text to the console |
| 1177 |
if ( g_dedicated.integer ) { |
| 1178 |
G_Printf( "%s%s\n", name, text); |
| 1179 |
} |
| 1180 |
|
| 1181 |
// send it to all the apropriate clients |
| 1182 |
for (j = 0; j < level.maxclients; j++) { |
| 1183 |
other = &g_entities[j]; |
| 1184 |
G_SayTo( ent, other, mode, color, name, text ); |
| 1185 |
} |
| 1186 |
//KK-OAX Admin Command Check from Say/SayTeam line |
| 1187 |
if( g_adminParseSay.integer ) |
| 1188 |
{ |
| 1189 |
G_admin_cmd_check ( ent, qtrue ); |
| 1190 |
} |
| 1191 |
} |
| 1192 |
|
| 1193 |
|
| 1194 |
/* |
| 1195 |
================== |
| 1196 |
Cmd_Say_f |
| 1197 |
KK-OAX Modified this to trap the additional arguments from console. |
| 1198 |
================== |
| 1199 |
*/ |
| 1200 |
static void Cmd_Say_f( gentity_t *ent ){ |
| 1201 |
char *p; |
| 1202 |
char arg[MAX_TOKEN_CHARS]; |
| 1203 |
int mode = SAY_ALL; |
| 1204 |
|
| 1205 |
trap_Argv( 0, arg, sizeof( arg ) ); |
| 1206 |
if( Q_strequal( arg, "say_team" ) ) |
| 1207 |
mode = SAY_TEAM ; |
| 1208 |
// KK-OAX Disabled until PM'ing is added |
| 1209 |
// support parsing /m out of say text since some people have a hard |
| 1210 |
// time figuring out what the console is. |
| 1211 |
/*if( !Q_stricmpn( args, "say /m ", 7 ) || |
| 1212 |
!Q_stricmpn( args, "say_team /m ", 12 ) || |
| 1213 |
!Q_stricmpn( args, "say /mt ", 8 ) || |
| 1214 |
!Q_stricmpn( args, "say_team /mt ", 13 ) ) |
| 1215 |
{ |
| 1216 |
Cmd_PrivateMessage_f( ent ); |
| 1217 |
return; |
| 1218 |
} |
| 1219 |
|
| 1220 |
// support parsing /a out of say text for the same reason |
| 1221 |
if( !Q_stricmpn( args, "say /a ", 7 ) || |
| 1222 |
!Q_stricmpn( args, "say_team /a ", 12 ) ) |
| 1223 |
{ |
| 1224 |
Cmd_AdminMessage_f( ent ); |
| 1225 |
return; |
| 1226 |
}*/ |
| 1227 |
|
| 1228 |
if( trap_Argc( ) < 2 ) |
| 1229 |
return; |
| 1230 |
|
| 1231 |
p = ConcatArgs( 1 ); |
| 1232 |
|
| 1233 |
G_Say( ent, NULL, mode, p ); |
| 1234 |
} |
| 1235 |
|
| 1236 |
/* |
| 1237 |
================== |
| 1238 |
Cmd_Tell_f |
| 1239 |
================== |
| 1240 |
*/ |
| 1241 |
static void Cmd_Tell_f( gentity_t *ent ) { |
| 1242 |
int targetNum; |
| 1243 |
gentity_t *target; |
| 1244 |
char *p; |
| 1245 |
char arg[MAX_TOKEN_CHARS]; |
| 1246 |
|
| 1247 |
if ( trap_Argc () < 2 ) { |
| 1248 |
return; |
| 1249 |
} |
| 1250 |
|
| 1251 |
trap_Argv( 1, arg, sizeof( arg ) ); |
| 1252 |
targetNum = atoi( arg ); |
| 1253 |
if ( targetNum < 0 || targetNum >= level.maxclients ) { |
| 1254 |
return; |
| 1255 |
} |
| 1256 |
|
| 1257 |
target = &g_entities[targetNum]; |
| 1258 |
if ( !target || !target->inuse || !target->client ) { |
| 1259 |
return; |
| 1260 |
} |
| 1261 |
|
| 1262 |
p = ConcatArgs( 2 ); |
| 1263 |
|
| 1264 |
G_LogPrintf( "tell: %s to %s: %s\n", ent->client->pers.netname, target->client->pers.netname, p ); |
| 1265 |
G_Say( ent, target, SAY_TELL, p ); |
| 1266 |
// don't tell to the player self if it was already directed to this player |
| 1267 |
// also don't send the chat back to a bot |
| 1268 |
if ( ent != target && !(ent->r.svFlags & SVF_BOT)) { |
| 1269 |
G_Say( ent, ent, SAY_TELL, p ); |
| 1270 |
} |
| 1271 |
} |
| 1272 |
|
| 1273 |
|
| 1274 |
static void G_VoiceTo( gentity_t *ent, gentity_t *other, int mode, const char *id, qboolean voiceonly ) { |
| 1275 |
int color; |
| 1276 |
char *cmd; |
| 1277 |
|
| 1278 |
if (!other) { |
| 1279 |
return; |
| 1280 |
} |
| 1281 |
if (!other->inuse) { |
| 1282 |
return; |
| 1283 |
} |
| 1284 |
if (!other->client) { |
| 1285 |
return; |
| 1286 |
} |
| 1287 |
if ( mode == SAY_TEAM && !OnSameTeam(ent, other) ) { |
| 1288 |
return; |
| 1289 |
} |
| 1290 |
// no chatting to players in tournements |
| 1291 |
if ( (g_gametype.integer == GT_TOURNAMENT )) { |
| 1292 |
return; |
| 1293 |
} |
| 1294 |
|
| 1295 |
if (mode == SAY_TEAM) { |
| 1296 |
color = COLOR_CYAN; |
| 1297 |
cmd = "vtchat"; |
| 1298 |
} |
| 1299 |
else if (mode == SAY_TELL) { |
| 1300 |
color = COLOR_MAGENTA; |
| 1301 |
cmd = "vtell"; |
| 1302 |
} |
| 1303 |
else { |
| 1304 |
color = COLOR_GREEN; |
| 1305 |
cmd = "vchat"; |
| 1306 |
} |
| 1307 |
|
| 1308 |
trap_SendServerCommand( other-g_entities, va("%s %d %d %d %s", cmd, voiceonly, ent->s.number, color, id)); |
| 1309 |
} |
| 1310 |
|
| 1311 |
void G_Voice( gentity_t *ent, gentity_t *target, int mode, const char *id, qboolean voiceonly ) { |
| 1312 |
int j; |
| 1313 |
gentity_t *other; |
| 1314 |
|
| 1315 |
if ( (g_gametype.integer < GT_TEAM || g_ffa_gt==1 ) && mode == SAY_TEAM ) { |
| 1316 |
mode = SAY_ALL; |
| 1317 |
} |
| 1318 |
|
| 1319 |
if ( target ) { |
| 1320 |
G_VoiceTo( ent, target, mode, id, voiceonly ); |
| 1321 |
return; |
| 1322 |
} |
| 1323 |
|
| 1324 |
// echo the text to the console |
| 1325 |
if ( g_dedicated.integer ) { |
| 1326 |
G_Printf( "voice: %s %s\n", ent->client->pers.netname, id); |
| 1327 |
} |
| 1328 |
|
| 1329 |
// send it to all the apropriate clients |
| 1330 |
for (j = 0; j < level.maxclients; j++) { |
| 1331 |
other = &g_entities[j]; |
| 1332 |
G_VoiceTo( ent, other, mode, id, voiceonly ); |
| 1333 |
} |
| 1334 |
} |
| 1335 |
|
| 1336 |
/* |
| 1337 |
================== |
| 1338 |
Cmd_Voice_f |
| 1339 |
KK-OAX Modified this to trap args. |
| 1340 |
|
| 1341 |
In the original, every call to this function would always set "arg0" to false, and it was |
| 1342 |
never passed along to other functions, so I removed/commented it out. |
| 1343 |
================== |
| 1344 |
*/ |
| 1345 |
static void Cmd_Voice_f( gentity_t *ent ) { |
| 1346 |
char *p; |
| 1347 |
char arg[MAX_TOKEN_CHARS]; |
| 1348 |
int mode = SAY_ALL; |
| 1349 |
qboolean voiceonly = qfalse; |
| 1350 |
|
| 1351 |
trap_Argv( 0, arg, sizeof( arg ) ); |
| 1352 |
if((Q_strequal( arg, "vsay_team" ) ) || |
| 1353 |
Q_strequal( arg, "vosay_team" ) ) |
| 1354 |
mode = SAY_TEAM; |
| 1355 |
|
| 1356 |
if((Q_strequal( arg, "vosay" ) ) || |
| 1357 |
Q_strequal( arg, "vosay_team" ) ) |
| 1358 |
voiceonly = qtrue; |
| 1359 |
|
| 1360 |
//KK-OAX Removed "arg0" since it will always be set to qfalse. |
| 1361 |
if ( trap_Argc () < 2 ) { |
| 1362 |
return; |
| 1363 |
} |
| 1364 |
//KK-OAX This was tricky to figure out, but since none of the original command handlings |
| 1365 |
//set it to "qtrue"... |
| 1366 |
|
| 1367 |
/*if (arg0) |
| 1368 |
{ |
| 1369 |
p = ConcatArgs( 0 ); |
| 1370 |
} |
| 1371 |
else |
| 1372 |
{*/ |
| 1373 |
p = ConcatArgs( 1 ); |
| 1374 |
//} |
| 1375 |
|
| 1376 |
G_Voice( ent, NULL, mode, p, voiceonly ); |
| 1377 |
} |
| 1378 |
|
| 1379 |
/* |
| 1380 |
================== |
| 1381 |
Cmd_VoiceTell_f |
| 1382 |
KK-OAX Modified this to trap args. |
| 1383 |
================== |
| 1384 |
*/ |
| 1385 |
static void Cmd_VoiceTell_f( gentity_t *ent ) { |
| 1386 |
int targetNum; |
| 1387 |
gentity_t *target; |
| 1388 |
char *id; |
| 1389 |
char arg[MAX_TOKEN_CHARS]; |
| 1390 |
qboolean voiceonly = qfalse; |
| 1391 |
|
| 1392 |
if ( trap_Argc () < 2 ) { |
| 1393 |
return; |
| 1394 |
} |
| 1395 |
|
| 1396 |
trap_Argv( 0, arg, sizeof( arg ) ); |
| 1397 |
if( Q_strequal( arg, "votell" ) ) |
| 1398 |
voiceonly = qtrue; |
| 1399 |
|
| 1400 |
trap_Argv( 1, arg, sizeof( arg ) ); |
| 1401 |
targetNum = atoi( arg ); |
| 1402 |
if ( targetNum < 0 || targetNum >= level.maxclients ) { |
| 1403 |
return; |
| 1404 |
} |
| 1405 |
|
| 1406 |
target = &g_entities[targetNum]; |
| 1407 |
if ( !target || !target->inuse || !target->client ) { |
| 1408 |
return; |
| 1409 |
} |
| 1410 |
|
| 1411 |
id = ConcatArgs( 2 ); |
| 1412 |
|
| 1413 |
G_LogPrintf( "vtell: %s to %s: %s\n", ent->client->pers.netname, target->client->pers.netname, id ); |
| 1414 |
G_Voice( ent, target, SAY_TELL, id, voiceonly ); |
| 1415 |
// don't tell to the player self if it was already directed to this player |
| 1416 |
// also don't send the chat back to a bot |
| 1417 |
if ( ent != target && !(ent->r.svFlags & SVF_BOT)) { |
| 1418 |
G_Voice( ent, ent, SAY_TELL, id, voiceonly ); |
| 1419 |
} |
| 1420 |
} |
| 1421 |
|
| 1422 |
|
| 1423 |
/* |
| 1424 |
================== |
| 1425 |
Cmd_VoiceTaunt_f |
| 1426 |
================== |
| 1427 |
*/ |
| 1428 |
static void Cmd_VoiceTaunt_f( gentity_t *ent ) { |
| 1429 |
gentity_t *who; |
| 1430 |
int i; |
| 1431 |
|
| 1432 |
if (!ent->client) { |
| 1433 |
return; |
| 1434 |
} |
| 1435 |
|
| 1436 |
// insult someone who just killed you |
| 1437 |
if (ent->enemy && ent->enemy->client && ent->enemy->client->lastkilled_client == ent->s.number) { |
| 1438 |
// i am a dead corpse |
| 1439 |
if (!(ent->enemy->r.svFlags & SVF_BOT)) { |
| 1440 |
G_Voice( ent, ent->enemy, SAY_TELL, VOICECHAT_DEATHINSULT, qfalse ); |
| 1441 |
} |
| 1442 |
if (!(ent->r.svFlags & SVF_BOT)) { |
| 1443 |
G_Voice( ent, ent, SAY_TELL, VOICECHAT_DEATHINSULT, qfalse ); |
| 1444 |
} |
| 1445 |
ent->enemy = NULL; |
| 1446 |
return; |
| 1447 |
} |
| 1448 |
// insult someone you just killed |
| 1449 |
if (ent->client->lastkilled_client >= 0 && ent->client->lastkilled_client != ent->s.number) { |
| 1450 |
who = g_entities + ent->client->lastkilled_client; |
| 1451 |
if (who->client) { |
| 1452 |
// who is the person I just killed |
| 1453 |
if (who->client->lasthurt_mod == MOD_GAUNTLET) { |
| 1454 |
if (!(who->r.svFlags & SVF_BOT)) { |
| 1455 |
G_Voice( ent, who, SAY_TELL, VOICECHAT_KILLGAUNTLET, qfalse ); // and I killed them with a gauntlet |
| 1456 |
} |
| 1457 |
if (!(ent->r.svFlags & SVF_BOT)) { |
| 1458 |
G_Voice( ent, ent, SAY_TELL, VOICECHAT_KILLGAUNTLET, qfalse ); |
| 1459 |
} |
| 1460 |
} else { |
| 1461 |
if (!(who->r.svFlags & SVF_BOT)) { |
| 1462 |
G_Voice( ent, who, SAY_TELL, VOICECHAT_KILLINSULT, qfalse ); // and I killed them with something else |
| 1463 |
} |
| 1464 |
if (!(ent->r.svFlags & SVF_BOT)) { |
| 1465 |
G_Voice( ent, ent, SAY_TELL, VOICECHAT_KILLINSULT, qfalse ); |
| 1466 |
} |
| 1467 |
} |
| 1468 |
ent->client->lastkilled_client = -1; |
| 1469 |
return; |
| 1470 |
} |
| 1471 |
} |
| 1472 |
|
| 1473 |
if (g_gametype.integer >= GT_TEAM && g_ffa_gt!=1) { |
| 1474 |
// praise a team mate who just got a reward |
| 1475 |
for(i = 0; i < MAX_CLIENTS; i++) { |
| 1476 |
who = g_entities + i; |
| 1477 |
if (who->client && who != ent && who->client->sess.sessionTeam == ent->client->sess.sessionTeam) { |
| 1478 |
if (who->client->rewardTime > level.time) { |
| 1479 |
if (!(who->r.svFlags & SVF_BOT)) { |
| 1480 |
G_Voice( ent, who, SAY_TELL, VOICECHAT_PRAISE, qfalse ); |
| 1481 |
} |
| 1482 |
if (!(ent->r.svFlags & SVF_BOT)) { |
| 1483 |
G_Voice( ent, ent, SAY_TELL, VOICECHAT_PRAISE, qfalse ); |
| 1484 |
} |
| 1485 |
return; |
| 1486 |
} |
| 1487 |
} |
| 1488 |
} |
| 1489 |
} |
| 1490 |
|
| 1491 |
// just say something |
| 1492 |
G_Voice( ent, NULL, SAY_ALL, VOICECHAT_TAUNT, qfalse ); |
| 1493 |
} |
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
static char *gc_orders[] = { |
| 1498 |
"hold your position", |
| 1499 |
"hold this position", |
| 1500 |
"come here", |
| 1501 |
"cover me", |
| 1502 |
"guard location", |
| 1503 |
"search and destroy", |
| 1504 |
"report" |
| 1505 |
}; |
| 1506 |
|
| 1507 |
void Cmd_GameCommand_f( gentity_t *ent ) { |
| 1508 |
int player; |
| 1509 |
int order; |
| 1510 |
char str[MAX_TOKEN_CHARS]; |
| 1511 |
|
| 1512 |
trap_Argv( 1, str, sizeof( str ) ); |
| 1513 |
player = atoi( str ); |
| 1514 |
trap_Argv( 2, str, sizeof( str ) ); |
| 1515 |
order = atoi( str ); |
| 1516 |
|
| 1517 |
if ( player < 0 || player >= MAX_CLIENTS ) { |
| 1518 |
return; |
| 1519 |
} |
| 1520 |
if ( order < 0 || order > sizeof(gc_orders)/sizeof(char *) ) { |
| 1521 |
return; |
| 1522 |
} |
| 1523 |
G_Say( ent, &g_entities[player], SAY_TELL, gc_orders[order] ); |
| 1524 |
G_Say( ent, ent, SAY_TELL, gc_orders[order] ); |
| 1525 |
} |
| 1526 |
|
| 1527 |
/* |
| 1528 |
================== |
| 1529 |
Cmd_Where_f |
| 1530 |
================== |
| 1531 |
*/ |
| 1532 |
void Cmd_Where_f( gentity_t *ent ) { |
| 1533 |
trap_SendServerCommand( ent-g_entities, va("print \"%s\n\"", vtos(ent->r.currentOrigin) ) ); |
| 1534 |
} |
| 1535 |
|
| 1536 |
static const char *gameNames[] = { |
| 1537 |
"Free For All", |
| 1538 |
"Tournament", |
| 1539 |
"Single Player", |
| 1540 |
"Team Deathmatch", |
| 1541 |
"Capture the Flag", |
| 1542 |
"One Flag CTF", |
| 1543 |
"Overload", |
| 1544 |
"Harvester", |
| 1545 |
"Elimination", |
| 1546 |
"CTF Elimination", |
| 1547 |
"Last Man Standing", |
| 1548 |
"Double Domination", |
| 1549 |
"Domination" |
| 1550 |
}; |
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
/* |
| 1555 |
================== |
| 1556 |
Cmd_CallVote_f |
| 1557 |
================== |
| 1558 |
*/ |
| 1559 |
void Cmd_CallVote_f( gentity_t *ent ) { |
| 1560 |
char* c; |
| 1561 |
int i; |
| 1562 |
char arg1[MAX_STRING_TOKENS]; |
| 1563 |
char arg2[MAX_STRING_TOKENS]; |
| 1564 |
char buffer[256]; |
| 1565 |
|
| 1566 |
if ( !g_allowVote.integer ) { |
| 1567 |
trap_SendServerCommand( ent-g_entities, "print \"Voting not allowed here.\n\"" ); |
| 1568 |
return; |
| 1569 |
} |
| 1570 |
|
| 1571 |
if ( level.voteTime ) { |
| 1572 |
trap_SendServerCommand( ent-g_entities, "print \"A vote is already in progress.\n\"" ); |
| 1573 |
return; |
| 1574 |
} |
| 1575 |
if ( ent->client->pers.voteCount >= g_maxvotes.integer ) { |
| 1576 |
trap_SendServerCommand( ent-g_entities, "print \"You have called the maximum number of votes.\n\"" ); |
| 1577 |
return; |
| 1578 |
} |
| 1579 |
if ( ent->client->sess.sessionTeam == TEAM_SPECTATOR ) { |
| 1580 |
trap_SendServerCommand( ent-g_entities, "print \"Not allowed to call a vote as spectator.\n\"" ); |
| 1581 |
return; |
| 1582 |
} |
| 1583 |
|
| 1584 |
// make sure it is a valid command to vote on |
| 1585 |
trap_Argv( 1, arg1, sizeof( arg1 ) ); |
| 1586 |
trap_Argv( 2, arg2, sizeof( arg2 ) ); |
| 1587 |
|
| 1588 |
// check for command separators in arg2 |
| 1589 |
for( c = arg2; *c; ++c) { |
| 1590 |
switch(*c) { |
| 1591 |
case '\n': |
| 1592 |
case '\r': |
| 1593 |
case ';': |
| 1594 |
trap_SendServerCommand( ent-g_entities, "print \"Invalid vote string.\n\"" ); |
| 1595 |
return; |
| 1596 |
break; |
| 1597 |
} |
| 1598 |
} |
| 1599 |
|
| 1600 |
|
| 1601 |
if ( !Q_stricmp( arg1, "map_restart" ) ) { |
| 1602 |
} else if ( !Q_stricmp( arg1, "nextmap" ) ) { |
| 1603 |
} else if ( !Q_stricmp( arg1, "map" ) ) { |
| 1604 |
} else if ( !Q_stricmp( arg1, "g_gametype" ) ) { |
| 1605 |
} else if ( !Q_stricmp( arg1, "kick" ) ) { |
| 1606 |
} else if ( !Q_stricmp( arg1, "clientkick" ) ) { |
| 1607 |
} else if ( !Q_stricmp( arg1, "g_doWarmup" ) ) { |
| 1608 |
} else if ( !Q_stricmp( arg1, "timelimit" ) ) { |
| 1609 |
} else if ( !Q_stricmp( arg1, "fraglimit" ) ) { |
| 1610 |
} else if ( !Q_stricmp( arg1, "custom" ) ) { |
| 1611 |
} else if ( !Q_stricmp( arg1, "shuffle" ) ) { |
| 1612 |
} else { |
| 1613 |
trap_SendServerCommand( ent-g_entities, "print \"Invalid vote string.\n\"" ); |
| 1614 |
//trap_SendServerCommand( ent-g_entities, "print \"Vote commands are: map_restart, nextmap, map <mapname>, g_gametype <n>, kick <player>, clientkick <clientnum>, g_doWarmup, timelimit <time>, fraglimit <frags>.\n\"" ); |
| 1615 |
buffer[0] = 0; |
| 1616 |
strcat(buffer,"print \"Vote commands are: "); |
| 1617 |
if(allowedVote("map_restart")) |
| 1618 |
strcat(buffer, "map_restart, "); |
| 1619 |
if(allowedVote("nextmap")) |
| 1620 |
strcat(buffer, "nextmap, "); |
| 1621 |
if(allowedVote("map")) |
| 1622 |
strcat(buffer, "map <mapname>, "); |
| 1623 |
if(allowedVote("g_gametype")) |
| 1624 |
strcat(buffer, "g_gametype <n>, "); |
| 1625 |
if(allowedVote("kick")) |
| 1626 |
strcat(buffer, "kick <player>, "); |
| 1627 |
if(allowedVote("clientkick")) |
| 1628 |
strcat(buffer, "clientkick <clientnum>, "); |
| 1629 |
if(allowedVote("g_doWarmup")) |
| 1630 |
strcat(buffer, "g_doWarmup, "); |
| 1631 |
if(allowedVote("timelimit")) |
| 1632 |
strcat(buffer, "timelimit <time>, "); |
| 1633 |
if(allowedVote("fraglimit")) |
| 1634 |
strcat(buffer, "fraglimit <frags>, "); |
| 1635 |
if(allowedVote("shuffle")) |
| 1636 |
strcat(buffer, "shuffle, "); |
| 1637 |
if(allowedVote("custom")) |
| 1638 |
strcat(buffer, "custom <special>, "); |
| 1639 |
buffer[strlen(buffer)-2] = 0; |
| 1640 |
strcat(buffer, ".\""); |
| 1641 |
trap_SendServerCommand( ent-g_entities, buffer); |
| 1642 |
return; |
| 1643 |
} |
| 1644 |
|
| 1645 |
if(!allowedVote(arg1)) { |
| 1646 |
trap_SendServerCommand( ent-g_entities, "print \"Not allowed here.\n\"" ); |
| 1647 |
buffer[0] = 0; |
| 1648 |
strcat(buffer,"print \"Vote commands are: "); |
| 1649 |
if(allowedVote("map_restart")) |
| 1650 |
strcat(buffer, "map_restart, "); |
| 1651 |
if(allowedVote("nextmap")) |
| 1652 |
strcat(buffer, "nextmap, "); |
| 1653 |
if(allowedVote("map")) |
| 1654 |
strcat(buffer, "map <mapname>, "); |
| 1655 |
if(allowedVote("g_gametype")) |
| 1656 |
strcat(buffer, "g_gametype <n>, "); |
| 1657 |
if(allowedVote("kick")) |
| 1658 |
strcat(buffer, "kick <player>, "); |
| 1659 |
if(allowedVote("clientkick")) |
| 1660 |
strcat(buffer, "clientkick <clientnum>, "); |
| 1661 |
if(allowedVote("shuffle")) |
| 1662 |
strcat(buffer, "shuffle, "); |
| 1663 |
if(allowedVote("g_doWarmup")) |
| 1664 |
strcat(buffer, "g_doWarmup, "); |
| 1665 |
if(allowedVote("timelimit")) |
| 1666 |
strcat(buffer, "timelimit <time>, "); |
| 1667 |
if(allowedVote("fraglimit")) |
| 1668 |
strcat(buffer, "fraglimit <frags>, "); |
| 1669 |
if(allowedVote("custom")) |
| 1670 |
strcat(buffer, "custom <special>, "); |
| 1671 |
buffer[strlen(buffer)-2] = 0; |
| 1672 |
strcat(buffer, ".\""); |
| 1673 |
trap_SendServerCommand( ent-g_entities, buffer); |
| 1674 |
return; |
| 1675 |
} |
| 1676 |
|
| 1677 |
// if there is still a vote to be executed |
| 1678 |
if ( level.voteExecuteTime ) { |
| 1679 |
level.voteExecuteTime = 0; |
| 1680 |
trap_SendConsoleCommand( EXEC_APPEND, va("%s\n", level.voteString ) ); |
| 1681 |
} |
| 1682 |
|
| 1683 |
level.voteKickClient = -1; //not a client |
| 1684 |
level.voteKickType = 0; //not a ban |
| 1685 |
|
| 1686 |
// special case for g_gametype, check for bad values |
| 1687 |
if ( !Q_stricmp( arg1, "g_gametype" ) ) { |
| 1688 |
char s[MAX_STRING_CHARS]; |
| 1689 |
i = atoi( arg2 ); |
| 1690 |
if( i == GT_SINGLE_PLAYER || i < GT_FFA || i >= GT_MAX_GAME_TYPE) { |
| 1691 |
trap_SendServerCommand( ent-g_entities, "print \"Invalid gametype.\n\"" ); |
| 1692 |
return; |
| 1693 |
} |
| 1694 |
|
| 1695 |
if( i== g_gametype.integer ) { |
| 1696 |
trap_SendServerCommand( ent-g_entities, "print \"This is current gametype\n\"" ); |
| 1697 |
return; |
| 1698 |
} |
| 1699 |
|
| 1700 |
if(!allowedGametype(arg2)){ |
| 1701 |
trap_SendServerCommand( ent-g_entities, "print \"Gametype is not available.\n\"" ); |
| 1702 |
return; |
| 1703 |
} |
| 1704 |
|
| 1705 |
trap_Cvar_VariableStringBuffer( "nextmap", s, sizeof(s) ); |
| 1706 |
if (*s) { |
| 1707 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "%s %d; map_restart; set nextmap \"%s\"", arg1, i,s ); |
| 1708 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Change gametype to: %s?", gameNames[i] ); |
| 1709 |
} else { |
| 1710 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "%s %d; mao_restart", arg1, i ); |
| 1711 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Change gametype to: %s?", gameNames[i] ); |
| 1712 |
} |
| 1713 |
} else if ( !Q_stricmp( arg1, "map" ) ) { |
| 1714 |
// special case for map changes, we want to reset the nextmap setting |
| 1715 |
// this allows a player to change maps, but not upset the map rotation |
| 1716 |
char s[MAX_STRING_CHARS]; |
| 1717 |
|
| 1718 |
if(!allowedMap(arg2)){ |
| 1719 |
trap_SendServerCommand( ent-g_entities, "print \"Map is not available.\n\"" ); |
| 1720 |
return; |
| 1721 |
} |
| 1722 |
|
| 1723 |
trap_Cvar_VariableStringBuffer( "nextmap", s, sizeof(s) ); |
| 1724 |
if (*s) { |
| 1725 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "%s %s; set nextmap \"%s\"", arg1, arg2, s ); |
| 1726 |
} else { |
| 1727 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "%s %s", arg1, arg2 ); |
| 1728 |
} |
| 1729 |
//Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "%s", level.voteString ); |
| 1730 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Change map to: %s?", arg2 ); |
| 1731 |
} else if ( !Q_stricmp( arg1, "nextmap" ) ) { |
| 1732 |
char s[MAX_STRING_CHARS]; |
| 1733 |
|
| 1734 |
//Sago: Needs to think about this, we miss code to parse if nextmap has arg2 |
| 1735 |
/*if(!allowedMap(arg2)){ |
| 1736 |
trap_SendServerCommand( ent-g_entities, "print \"Map is not available.\n\"" ); |
| 1737 |
return; |
| 1738 |
}*/ |
| 1739 |
|
| 1740 |
if(g_autonextmap.integer) { |
| 1741 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "endgamenow"); |
| 1742 |
} else { |
| 1743 |
trap_Cvar_VariableStringBuffer( "nextmap", s, sizeof(s) ); |
| 1744 |
if (!*s) { |
| 1745 |
trap_SendServerCommand( ent-g_entities, "print \"nextmap not set.\n\"" ); |
| 1746 |
return; |
| 1747 |
} |
| 1748 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "vstr nextmap"); |
| 1749 |
} |
| 1750 |
|
| 1751 |
//Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "%s", level.voteString ); |
| 1752 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "%s", "Next map?" ); |
| 1753 |
} else if ( !Q_stricmp( arg1, "fraglimit" ) ) { |
| 1754 |
i = atoi(arg2); |
| 1755 |
if(!allowedFraglimit(i)) { |
| 1756 |
trap_SendServerCommand( ent-g_entities, "print \"Cannot set fraglimit.\n\"" ); |
| 1757 |
return; |
| 1758 |
} |
| 1759 |
|
| 1760 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "%s \"%d\"", arg1, i ); |
| 1761 |
if(i) |
| 1762 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Change fraglimit to: %d", i ); |
| 1763 |
else |
| 1764 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Remove fraglimit?"); |
| 1765 |
} else if ( !Q_stricmp( arg1, "timelimit" ) ) { |
| 1766 |
i = atoi(arg2); |
| 1767 |
if(!allowedTimelimit(i)) { |
| 1768 |
trap_SendServerCommand( ent-g_entities, "print \"Cannot set timelimit.\n\"" ); |
| 1769 |
return; |
| 1770 |
} |
| 1771 |
|
| 1772 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "%s \"%d\"", arg1, i ); |
| 1773 |
if(i) |
| 1774 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Change timelimit to: %d", i ); |
| 1775 |
else |
| 1776 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Remove timelimit?" ); |
| 1777 |
} else if ( !Q_stricmp( arg1, "map_restart" ) ) { |
| 1778 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "map_restart" ); |
| 1779 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Restart map?" ); |
| 1780 |
} else if ( !Q_stricmp( arg1, "g_doWarmup" ) ) { |
| 1781 |
i = atoi(arg2); |
| 1782 |
if(i) { |
| 1783 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "g_doWarmup \"1\"" ); |
| 1784 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Enable warmup?" ); |
| 1785 |
} |
| 1786 |
else { |
| 1787 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "g_doWarmup \"0\"" ); |
| 1788 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Disable warmup?" ); |
| 1789 |
} |
| 1790 |
} else if ( !Q_stricmp( arg1, "clientkick" ) ) { |
| 1791 |
i = atoi(arg2); |
| 1792 |
|
| 1793 |
if(i>=MAX_CLIENTS) { //Only numbers <128 is clients |
| 1794 |
trap_SendServerCommand( ent-g_entities, "print \"Cannot kick that number.\n\"" ); |
| 1795 |
return; |
| 1796 |
} |
| 1797 |
level.voteKickClient = i; |
| 1798 |
if(g_voteBan.integer<1) { |
| 1799 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "clientkick_game \"%d\"", i ); |
| 1800 |
} else { |
| 1801 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "!ban \"%d\" \"%dm\" \"Banned by public vote\"", i, g_voteBan.integer ); |
| 1802 |
level.voteKickType = 1; //ban |
| 1803 |
} |
| 1804 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Kick %s?" , level.clients[i].pers.netname ); |
| 1805 |
} else if ( !Q_stricmp( arg1, "shuffle" ) ) { |
| 1806 |
if(g_gametype.integer<GT_TEAM || g_ffa_gt==1) { //Not a team game |
| 1807 |
trap_SendServerCommand( ent-g_entities, "print \"Can only be used in team games.\n\"" ); |
| 1808 |
return; |
| 1809 |
} |
| 1810 |
|
| 1811 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "shuffle" ); |
| 1812 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Shuffle teams?" ); |
| 1813 |
} else if ( !Q_stricmp( arg1, "kick" ) ) { |
| 1814 |
i = 0; |
| 1815 |
while(Q_stricmp(arg2,(g_entities+i)->client->pers.netname)) { |
| 1816 |
//Not client i, try next |
| 1817 |
i++; |
| 1818 |
if(i>=MAX_CLIENTS){ //Only numbers <128 is clients |
| 1819 |
trap_SendServerCommand( ent-g_entities, "print \"Cannot find the playername. Try clientkick instead.\n\"" ); |
| 1820 |
return; |
| 1821 |
} |
| 1822 |
} |
| 1823 |
level.voteKickClient = i; |
| 1824 |
if(g_voteBan.integer<1) { |
| 1825 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "clientkick_game \"%d\"", i ); |
| 1826 |
} else { |
| 1827 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "!ban \"%d\" \"%dm\" \"Banned by public vote\"", i, g_voteBan.integer ); |
| 1828 |
level.voteKickType = 1; //ban |
| 1829 |
} |
| 1830 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "Kick %s?" , level.clients[i].pers.netname ); |
| 1831 |
} else if ( !Q_stricmp( arg1, "custom" ) ) { |
| 1832 |
t_customvote customvote; |
| 1833 |
//Sago: There must always be a test to ensure that length(arg2) is non-zero or the client might be able to execute random commands. |
| 1834 |
if(strlen(arg2)<1) { |
| 1835 |
trap_SendServerCommand( ent-g_entities, va("print \"Custom vote commands are: %s\n\"",custom_vote_info) ); |
| 1836 |
return; |
| 1837 |
} |
| 1838 |
customvote = getCustomVote(arg2); |
| 1839 |
if(Q_stricmp(customvote.votename,arg2)) { |
| 1840 |
trap_SendServerCommand( ent-g_entities, "print \"Command could not be found\n\"" ); |
| 1841 |
return; |
| 1842 |
} |
| 1843 |
Com_sprintf( level.voteString, sizeof( level.voteString ), "%s", customvote.command ); |
| 1844 |
if(strlen(customvote.displayname)) |
| 1845 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "%s", customvote.displayname ); |
| 1846 |
else |
| 1847 |
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "%s", customvote.command ); |
| 1848 |
} else { |
| 1849 |
//Com_sprintf( level.voteString, sizeof( level.voteString ), "%s \"%s\"", arg1, arg2 ); |
| 1850 |
//Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "%s", level.voteString ); |
| 1851 |
trap_SendServerCommand( ent-g_entities, "print \"Server vality check failed, appears to be my fault. Sorry\n\"" ); |
| 1852 |
return; |
| 1853 |
} |
| 1854 |
|
| 1855 |
ent->client->pers.voteCount++; |
| 1856 |
trap_SendServerCommand( -1, va("print \"%s called a vote.\n\"", ent->client->pers.netname ) ); |
| 1857 |
|
| 1858 |
// start the voting, the caller autoamtically votes yes |
| 1859 |
level.voteTime = level.time; |
| 1860 |
level.voteYes = 1; |
| 1861 |
level.voteNo = 0; |
| 1862 |
|
| 1863 |
for ( i = 0 ; i < level.maxclients ; i++ ) { |
| 1864 |
level.clients[i].ps.eFlags &= ~EF_VOTED; |
| 1865 |
level.clients[i].vote = 0; |
| 1866 |
} |
| 1867 |
ent->client->ps.eFlags |= EF_VOTED; |
| 1868 |
ent->client->vote = 1; |
| 1869 |
//Do a first count to make sure that numvotingclients is correct! |
| 1870 |
CountVotes(); |
| 1871 |
|
| 1872 |
trap_SetConfigstring( CS_VOTE_TIME, va("%i", level.voteTime ) ); |
| 1873 |
trap_SetConfigstring( CS_VOTE_STRING, level.voteDisplayString ); |
| 1874 |
trap_SetConfigstring( CS_VOTE_YES, va("%i", level.voteYes ) ); |
| 1875 |
trap_SetConfigstring( CS_VOTE_NO, va("%i", level.voteNo ) ); |
| 1876 |
} |
| 1877 |
|
| 1878 |
/* |
| 1879 |
================== |
| 1880 |
Cmd_Vote_f |
| 1881 |
================== |
| 1882 |
*/ |
| 1883 |
void Cmd_Vote_f( gentity_t *ent ) { |
| 1884 |
char msg[64]; |
| 1885 |
|
| 1886 |
if ( !level.voteTime ) { |
| 1887 |
trap_SendServerCommand( ent-g_entities, "print \"No vote in progress.\n\"" ); |
| 1888 |
return; |
| 1889 |
} |
| 1890 |
/*if ( ent->client->ps.eFlags & EF_VOTED ) { |
| 1891 |
trap_SendServerCommand( ent-g_entities, "print \"Vote already cast.\n\"" ); |
| 1892 |
return; |
| 1893 |
}*/ |
| 1894 |
if ( ent->client->sess.sessionTeam == TEAM_SPECTATOR ) { |
| 1895 |
trap_SendServerCommand( ent-g_entities, "print \"Not allowed to vote as spectator.\n\"" ); |
| 1896 |
return; |
| 1897 |
} |
| 1898 |
|
| 1899 |
trap_SendServerCommand( ent-g_entities, "print \"Vote cast.\n\"" ); |
| 1900 |
|
| 1901 |
ent->client->ps.eFlags |= EF_VOTED; |
| 1902 |
|
| 1903 |
trap_Argv( 1, msg, sizeof( msg ) ); |
| 1904 |
|
| 1905 |
if ( msg[0] == 'y' || msg[1] == 'Y' || msg[1] == '1' ) { |
| 1906 |
ent->client->vote = 1; |
| 1907 |
} else { |
| 1908 |
ent->client->vote = -1; |
| 1909 |
} |
| 1910 |
|
| 1911 |
//Re count the votes |
| 1912 |
CountVotes(); |
| 1913 |
|
| 1914 |
// a majority will be determined in CheckVote, which will also account |
| 1915 |
// for players entering or leaving |
| 1916 |
} |
| 1917 |
|
| 1918 |
/* |
| 1919 |
================== |
| 1920 |
Cmd_CallTeamVote_f |
| 1921 |
================== |
| 1922 |
*/ |
| 1923 |
void Cmd_CallTeamVote_f( gentity_t *ent ) { |
| 1924 |
int i, team, cs_offset; |
| 1925 |
char arg1[MAX_STRING_TOKENS]; |
| 1926 |
char arg2[MAX_STRING_TOKENS]; |
| 1927 |
|
| 1928 |
team = ent->client->sess.sessionTeam; |
| 1929 |
if ( team == TEAM_RED ) |
| 1930 |
cs_offset = 0; |
| 1931 |
else if ( team == TEAM_BLUE ) |
| 1932 |
cs_offset = 1; |
| 1933 |
else |
| 1934 |
return; |
| 1935 |
|
| 1936 |
if ( !g_allowVote.integer ) { |
| 1937 |
trap_SendServerCommand( ent-g_entities, "print \"Voting not allowed here.\n\"" ); |
| 1938 |
return; |
| 1939 |
} |
| 1940 |
|
| 1941 |
if ( level.teamVoteTime[cs_offset] ) { |
| 1942 |
trap_SendServerCommand( ent-g_entities, "print \"A team vote is already in progress.\n\"" ); |
| 1943 |
return; |
| 1944 |
} |
| 1945 |
if ( ent->client->pers.teamVoteCount >= g_maxvotes.integer ) { |
| 1946 |
trap_SendServerCommand( ent-g_entities, "print \"You have called the maximum number of team votes.\n\"" ); |
| 1947 |
return; |
| 1948 |
} |
| 1949 |
if ( ent->client->sess.sessionTeam == TEAM_SPECTATOR ) { |
| 1950 |
trap_SendServerCommand( ent-g_entities, "print \"Not allowed to call a vote as spectator.\n\"" ); |
| 1951 |
return; |
| 1952 |
} |
| 1953 |
|
| 1954 |
// make sure it is a valid command to vote on |
| 1955 |
trap_Argv( 1, arg1, sizeof( arg1 ) ); |
| 1956 |
arg2[0] = '\0'; |
| 1957 |
for ( i = 2; i < trap_Argc(); i++ ) { |
| 1958 |
if (i > 2) |
| 1959 |
strcat(arg2, " "); |
| 1960 |
trap_Argv( i, &arg2[strlen(arg2)], sizeof( arg2 ) - strlen(arg2) ); |
| 1961 |
} |
| 1962 |
|
| 1963 |
if( strchr( arg1, ';' ) || strchr( arg2, ';' ) ) { |
| 1964 |
trap_SendServerCommand( ent-g_entities, "print \"Invalid vote string.\n\"" ); |
| 1965 |
return; |
| 1966 |
} |
| 1967 |
|
| 1968 |
if ( !Q_stricmp( arg1, "leader" ) ) { |
| 1969 |
char netname[MAX_NETNAME], leader[MAX_NETNAME]; |
| 1970 |
|
| 1971 |
if ( !arg2[0] ) { |
| 1972 |
i = ent->client->ps.clientNum; |
| 1973 |
} |
| 1974 |
else { |
| 1975 |
// numeric values are just slot numbers |
| 1976 |
for (i = 0; i < 3; i++) { |
| 1977 |
if ( !arg2[i] || arg2[i] < '0' || arg2[i] > '9' ) |
| 1978 |
break; |
| 1979 |
} |
| 1980 |
if ( i >= 3 || !arg2[i]) { |
| 1981 |
i = atoi( arg2 ); |
| 1982 |
if ( i < 0 || i >= level.maxclients ) { |
| 1983 |
trap_SendServerCommand( ent-g_entities, va("print \"Bad client slot: %i\n\"", i) ); |
| 1984 |
return; |
| 1985 |
} |
| 1986 |
|
| 1987 |
if ( !g_entities[i].inuse ) { |
| 1988 |
trap_SendServerCommand( ent-g_entities, va("print \"Client %i is not active\n\"", i) ); |
| 1989 |
return; |
| 1990 |
} |
| 1991 |
} |
| 1992 |
else { |
| 1993 |
Q_strncpyz(leader, arg2, sizeof(leader)); |
| 1994 |
Q_CleanStr(leader); |
| 1995 |
for ( i = 0 ; i < level.maxclients ; i++ ) { |
| 1996 |
if ( level.clients[i].pers.connected == CON_DISCONNECTED ) |
| 1997 |
continue; |
| 1998 |
if (level.clients[i].sess.sessionTeam != team) |
| 1999 |
continue; |
| 2000 |
Q_strncpyz(netname, level.clients[i].pers.netname, sizeof(netname)); |
| 2001 |
Q_CleanStr(netname); |
| 2002 |
if ( !Q_stricmp(netname, leader) ) { |
| 2003 |
break; |
| 2004 |
} |
| 2005 |
} |
| 2006 |
if ( i >= level.maxclients ) { |
| 2007 |
trap_SendServerCommand( ent-g_entities, va("print \"%s is not a valid player on your team.\n\"", arg2) ); |
| 2008 |
return; |
| 2009 |
} |
| 2010 |
} |
| 2011 |
} |
| 2012 |
Com_sprintf(arg2, sizeof(arg2), "%d", i); |
| 2013 |
} else { |
| 2014 |
trap_SendServerCommand( ent-g_entities, "print \"Invalid vote string.\n\"" ); |
| 2015 |
trap_SendServerCommand( ent-g_entities, "print \"Team vote commands are: leader <player>.\n\"" ); |
| 2016 |
return; |
| 2017 |
} |
| 2018 |
|
| 2019 |
Com_sprintf( level.teamVoteString[cs_offset], sizeof( level.teamVoteString[cs_offset] ), "%s %s", arg1, arg2 ); |
| 2020 |
|
| 2021 |
for ( i = 0 ; i < level.maxclients ; i++ ) { |
| 2022 |
if ( level.clients[i].pers.connected == CON_DISCONNECTED ) |
| 2023 |
continue; |
| 2024 |
if (level.clients[i].sess.sessionTeam == team) |
| 2025 |
trap_SendServerCommand( i, va("print \"%s called a team vote.\n\"", ent->client->pers.netname ) ); |
| 2026 |
} |
| 2027 |
|
| 2028 |
// start the voting, the caller autoamtically votes yes |
| 2029 |
level.teamVoteTime[cs_offset] = level.time; |
| 2030 |
level.teamVoteYes[cs_offset] = 1; |
| 2031 |
level.teamVoteNo[cs_offset] = 0; |
| 2032 |
|
| 2033 |
for ( i = 0 ; i < level.maxclients ; i++ ) { |
| 2034 |
if (level.clients[i].sess.sessionTeam == team) |
| 2035 |
level.clients[i].ps.eFlags &= ~EF_TEAMVOTED; |
| 2036 |
} |
| 2037 |
ent->client->ps.eFlags |= EF_TEAMVOTED; |
| 2038 |
|
| 2039 |
trap_SetConfigstring( CS_TEAMVOTE_TIME + cs_offset, va("%i", level.teamVoteTime[cs_offset] ) ); |
| 2040 |
trap_SetConfigstring( CS_TEAMVOTE_STRING + cs_offset, level.teamVoteString[cs_offset] ); |
| 2041 |
trap_SetConfigstring( CS_TEAMVOTE_YES + cs_offset, va("%i", level.teamVoteYes[cs_offset] ) ); |
| 2042 |
trap_SetConfigstring( CS_TEAMVOTE_NO + cs_offset, va("%i", level.teamVoteNo[cs_offset] ) ); |
| 2043 |
} |
| 2044 |
|
| 2045 |
/* |
| 2046 |
================== |
| 2047 |
Cmd_TeamVote_f |
| 2048 |
================== |
| 2049 |
*/ |
| 2050 |
void Cmd_TeamVote_f( gentity_t *ent ) { |
| 2051 |
int team, cs_offset; |
| 2052 |
char msg[64]; |
| 2053 |
|
| 2054 |
team = ent->client->sess.sessionTeam; |
| 2055 |
if ( team == TEAM_RED ) |
| 2056 |
cs_offset = 0; |
| 2057 |
else if ( team == TEAM_BLUE ) |
| 2058 |
cs_offset = 1; |
| 2059 |
else |
| 2060 |
return; |
| 2061 |
|
| 2062 |
if ( !level.teamVoteTime[cs_offset] ) { |
| 2063 |
trap_SendServerCommand( ent-g_entities, "print \"No team vote in progress.\n\"" ); |
| 2064 |
return; |
| 2065 |
} |
| 2066 |
if ( ent->client->ps.eFlags & EF_TEAMVOTED ) { |
| 2067 |
trap_SendServerCommand( ent-g_entities, "print \"Team vote already cast.\n\"" ); |
| 2068 |
return; |
| 2069 |
} |
| 2070 |
if ( ent->client->sess.sessionTeam == TEAM_SPECTATOR ) { |
| 2071 |
trap_SendServerCommand( ent-g_entities, "print \"Not allowed to vote as spectator.\n\"" ); |
| 2072 |
return; |
| 2073 |
} |
| 2074 |
|
| 2075 |
trap_SendServerCommand( ent-g_entities, "print \"Team vote cast.\n\"" ); |
| 2076 |
|
| 2077 |
ent->client->ps.eFlags |= EF_TEAMVOTED; |
| 2078 |
|
| 2079 |
trap_Argv( 1, msg, sizeof( msg ) ); |
| 2080 |
|
| 2081 |
if ( msg[0] == 'y' || msg[1] == 'Y' || msg[1] == '1' ) { |
| 2082 |
level.teamVoteYes[cs_offset]++; |
| 2083 |
trap_SetConfigstring( CS_TEAMVOTE_YES + cs_offset, va("%i", level.teamVoteYes[cs_offset] ) ); |
| 2084 |
} else { |
| 2085 |
level.teamVoteNo[cs_offset]++; |
| 2086 |
trap_SetConfigstring( CS_TEAMVOTE_NO + cs_offset, va("%i", level.teamVoteNo[cs_offset] ) ); |
| 2087 |
} |
| 2088 |
|
| 2089 |
// a majority will be determined in TeamCheckVote, which will also account |
| 2090 |
// for players entering or leaving |
| 2091 |
} |
| 2092 |
|
| 2093 |
|
| 2094 |
/* |
| 2095 |
================= |
| 2096 |
Cmd_SetViewpos_f |
| 2097 |
================= |
| 2098 |
*/ |
| 2099 |
void Cmd_SetViewpos_f( gentity_t *ent ) { |
| 2100 |
vec3_t origin, angles; |
| 2101 |
char buffer[MAX_TOKEN_CHARS]; |
| 2102 |
int i; |
| 2103 |
|
| 2104 |
if ( !g_cheats.integer ) { |
| 2105 |
trap_SendServerCommand( ent-g_entities, va("print \"Cheats are not enabled on this server.\n\"")); |
| 2106 |
return; |
| 2107 |
} |
| 2108 |
if ( trap_Argc() != 5 ) { |
| 2109 |
trap_SendServerCommand( ent-g_entities, va("print \"usage: setviewpos x y z yaw\n\"")); |
| 2110 |
return; |
| 2111 |
} |
| 2112 |
|
| 2113 |
VectorClear( angles ); |
| 2114 |
for ( i = 0 ; i < 3 ; i++ ) { |
| 2115 |
trap_Argv( i + 1, buffer, sizeof( buffer ) ); |
| 2116 |
origin[i] = atof( buffer ); |
| 2117 |
} |
| 2118 |
|
| 2119 |
trap_Argv( 4, buffer, sizeof( buffer ) ); |
| 2120 |
angles[YAW] = atof( buffer ); |
| 2121 |
|
| 2122 |
TeleportPlayer( ent, origin, angles ); |
| 2123 |
} |
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
/* |
| 2128 |
================= |
| 2129 |
Cmd_Stats_f |
| 2130 |
================= |
| 2131 |
*/ |
| 2132 |
void Cmd_Stats_f( gentity_t *ent ) { |
| 2133 |
/* |
| 2134 |
int max, n, i; |
| 2135 |
|
| 2136 |
max = trap_AAS_PointReachabilityAreaIndex( NULL ); |
| 2137 |
|
| 2138 |
n = 0; |
| 2139 |
for ( i = 0; i < max; i++ ) { |
| 2140 |
if ( ent->client->areabits[i >> 3] & (1 << (i & 7)) ) |
| 2141 |
n++; |
| 2142 |
} |
| 2143 |
|
| 2144 |
//trap_SendServerCommand( ent-g_entities, va("print \"visited %d of %d areas\n\"", n, max)); |
| 2145 |
trap_SendServerCommand( ent-g_entities, va("print \"%d%% level coverage\n\"", n * 100 / max)); |
| 2146 |
*/ |
| 2147 |
} |
| 2148 |
|
| 2149 |
void Cmd_GetMappage_f( gentity_t *ent ) { |
| 2150 |
t_mappage page; |
| 2151 |
char string[(MAX_MAPNAME+1)*MAPS_PER_PAGE+1]; |
| 2152 |
char arg[MAX_STRING_TOKENS]; |
| 2153 |
trap_Argv( 1, arg, sizeof( arg ) ); |
| 2154 |
page = getMappage(atoi(arg)); |
| 2155 |
Q_strncpyz(string,va("mappage %d %s %s %s %s %s %s %s %s %s %s",page.pagenumber,page.mapname[0],\ |
| 2156 |
page.mapname[1],page.mapname[2],page.mapname[3],page.mapname[4],page.mapname[5],\ |
| 2157 |
page.mapname[6],page.mapname[7],page.mapname[8],page.mapname[9]),sizeof(string)); |
| 2158 |
//G_Printf("Mappage sent: \"%s\"\n", string); |
| 2159 |
trap_SendServerCommand( ent-g_entities, string ); |
| 2160 |
} |
| 2161 |
|
| 2162 |
//KK-OAX This is the table that ClientCommands runs the console entry against. |
| 2163 |
commands_t cmds[ ] = |
| 2164 |
{ |
| 2165 |
// normal commands |
| 2166 |
{ "team", 0, Cmd_Team_f }, |
| 2167 |
{ "vote", 0, Cmd_Vote_f }, |
| 2168 |
/*{ "ignore", 0, Cmd_Ignore_f }, |
| 2169 |
{ "unignore", 0, Cmd_Ignore_f },*/ |
| 2170 |
|
| 2171 |
// communication commands |
| 2172 |
{ "tell", CMD_MESSAGE, Cmd_Tell_f }, |
| 2173 |
{ "callvote", CMD_MESSAGE, Cmd_CallVote_f }, |
| 2174 |
{ "callteamvote", CMD_MESSAGE|CMD_TEAM, Cmd_CallTeamVote_f }, |
| 2175 |
// can be used even during intermission |
| 2176 |
{ "say", CMD_MESSAGE|CMD_INTERMISSION, Cmd_Say_f }, |
| 2177 |
{ "say_team", CMD_MESSAGE|CMD_INTERMISSION, Cmd_Say_f }, |
| 2178 |
{ "vsay", CMD_MESSAGE|CMD_INTERMISSION, Cmd_Voice_f }, |
| 2179 |
{ "vsay_team", CMD_MESSAGE|CMD_INTERMISSION, Cmd_Voice_f }, |
| 2180 |
{ "vsay_local", CMD_MESSAGE|CMD_INTERMISSION, Cmd_Voice_f }, |
| 2181 |
{ "vtell", CMD_MESSAGE|CMD_INTERMISSION, Cmd_VoiceTell_f }, |
| 2182 |
{ "vosay", CMD_MESSAGE|CMD_INTERMISSION, Cmd_Voice_f }, |
| 2183 |
{ "vosay_team", CMD_MESSAGE|CMD_INTERMISSION, Cmd_Voice_f }, |
| 2184 |
{ "vosay_local", CMD_MESSAGE|CMD_INTERMISSION, Cmd_Voice_f }, |
| 2185 |
{ "votell", CMD_MESSAGE|CMD_INTERMISSION, Cmd_VoiceTell_f }, |
| 2186 |
{ "vtaunt", CMD_MESSAGE|CMD_INTERMISSION, Cmd_VoiceTaunt_f }, |
| 2187 |
/*{ "m", CMD_MESSAGE|CMD_INTERMISSION, Cmd_PrivateMessage_f }, |
| 2188 |
{ "mt", CMD_MESSAGE|CMD_INTERMISSION, Cmd_PrivateMessage_f }, |
| 2189 |
{ "a", CMD_MESSAGE|CMD_INTERMISSION, Cmd_AdminMessage_f },*/ |
| 2190 |
|
| 2191 |
{ "score", CMD_INTERMISSION, Cmd_Score_f }, |
| 2192 |
{ "acc", CMD_INTERMISSION, Cmd_Acc_f}, |
| 2193 |
|
| 2194 |
// cheats |
| 2195 |
{ "give", CMD_CHEAT|CMD_LIVING, Cmd_Give_f }, |
| 2196 |
{ "god", CMD_CHEAT|CMD_LIVING, Cmd_God_f }, |
| 2197 |
{ "notarget", CMD_CHEAT|CMD_LIVING, Cmd_Notarget_f }, |
| 2198 |
{ "levelshot", CMD_CHEAT, Cmd_LevelShot_f }, |
| 2199 |
{ "setviewpos", CMD_CHEAT, Cmd_SetViewpos_f }, |
| 2200 |
{ "noclip", CMD_CHEAT, Cmd_Noclip_f }, |
| 2201 |
|
| 2202 |
{ "kill", CMD_TEAM|CMD_LIVING, Cmd_Kill_f }, |
| 2203 |
{ "where", 0, Cmd_Where_f }, |
| 2204 |
|
| 2205 |
// game commands |
| 2206 |
|
| 2207 |
{ "follow", CMD_NOTEAM, Cmd_Follow_f }, |
| 2208 |
{ "follownext", CMD_NOTEAM, Cmd_FollowCycle_f }, |
| 2209 |
{ "followprev", CMD_NOTEAM, Cmd_FollowCycle_f }, |
| 2210 |
|
| 2211 |
{ "teamvote", CMD_TEAM, Cmd_TeamVote_f }, |
| 2212 |
{ "teamtask", CMD_TEAM, Cmd_TeamTask_f }, |
| 2213 |
//KK-OAX |
| 2214 |
{ "freespectator", CMD_NOTEAM, StopFollowing }, |
| 2215 |
{ "getmappage", 0, Cmd_GetMappage_f }, |
| 2216 |
{ "gc", 0, Cmd_GameCommand_f } |
| 2217 |
|
| 2218 |
}; |
| 2219 |
|
| 2220 |
static int numCmds = sizeof( cmds ) / sizeof( cmds[ 0 ] ); |
| 2221 |
|
| 2222 |
/* |
| 2223 |
================= |
| 2224 |
ClientCommand |
| 2225 |
KK-OAX, Takes the client command and runs it through a loop which matches |
| 2226 |
it against the table. |
| 2227 |
================= |
| 2228 |
*/ |
| 2229 |
void ClientCommand( int clientNum ) |
| 2230 |
{ |
| 2231 |
gentity_t *ent; |
| 2232 |
char cmd[ MAX_TOKEN_CHARS ]; |
| 2233 |
int i; |
| 2234 |
|
| 2235 |
ent = g_entities + clientNum; |
| 2236 |
if( !ent->client ) |
| 2237 |
return; // not fully in game yet |
| 2238 |
|
| 2239 |
trap_Argv( 0, cmd, sizeof( cmd ) ); |
| 2240 |
|
| 2241 |
for( i = 0; i < numCmds; i++ ) |
| 2242 |
{ |
| 2243 |
if( Q_stricmp( cmd, cmds[ i ].cmdName ) == 0 ) |
| 2244 |
break; |
| 2245 |
} |
| 2246 |
|
| 2247 |
if( i == numCmds ) |
| 2248 |
{ // KK-OAX Admin Command Check |
| 2249 |
if( !G_admin_cmd_check( ent, qfalse ) ) |
| 2250 |
trap_SendServerCommand( clientNum, |
| 2251 |
va( "print \"Unknown command %s\n\"", cmd ) ); |
| 2252 |
return; |
| 2253 |
} |
| 2254 |
|
| 2255 |
// do tests here to reduce the amount of repeated code |
| 2256 |
if( !( cmds[ i ].cmdFlags & CMD_INTERMISSION ) && level.intermissiontime ) |
| 2257 |
return; |
| 2258 |
|
| 2259 |
if( cmds[ i ].cmdFlags & CMD_CHEAT && !g_cheats.integer ) |
| 2260 |
{ |
| 2261 |
trap_SendServerCommand( clientNum, |
| 2262 |
"print \"Cheats are not enabled on this server\n\"" ); |
| 2263 |
return; |
| 2264 |
} |
| 2265 |
//KK-OAX When the corresponding code is integrated, I will activate these. |
| 2266 |
//if( cmds[ i ].cmdFlags & CMD_MESSAGE && |
| 2267 |
// ( ent->client->pers.muted || G_FloodLimited( ent ) ) ) |
| 2268 |
// return; |
| 2269 |
|
| 2270 |
//KK-OAX Do I need to change this for FFA gametype? |
| 2271 |
if( cmds[ i ].cmdFlags & CMD_TEAM && |
| 2272 |
ent->client->sess.sessionTeam == TEAM_SPECTATOR ) |
| 2273 |
{ |
| 2274 |
trap_SendServerCommand( clientNum, "print \"Join a team first\n\"" ); |
| 2275 |
return; |
| 2276 |
} |
| 2277 |
|
| 2278 |
if( ( cmds[ i ].cmdFlags & CMD_NOTEAM || |
| 2279 |
( cmds[ i ].cmdFlags & CMD_CHEAT_TEAM && !g_cheats.integer ) ) && |
| 2280 |
ent->client->sess.sessionTeam != TEAM_NONE ) |
| 2281 |
{ |
| 2282 |
trap_SendServerCommand( clientNum, |
| 2283 |
"print \"Cannot use this command when on a team\n\"" ); |
| 2284 |
return; |
| 2285 |
} |
| 2286 |
|
| 2287 |
if( cmds[ i ].cmdFlags & CMD_RED && |
| 2288 |
ent->client->sess.sessionTeam != TEAM_RED ) |
| 2289 |
{ |
| 2290 |
trap_SendServerCommand( clientNum, |
| 2291 |
"print \"Must be on the Red Team to use this command\n\"" ); |
| 2292 |
return; |
| 2293 |
} |
| 2294 |
|
| 2295 |
if( cmds[ i ].cmdFlags & CMD_BLUE && |
| 2296 |
ent->client->sess.sessionTeam != TEAM_BLUE ) |
| 2297 |
{ |
| 2298 |
trap_SendServerCommand( clientNum, |
| 2299 |
"print \"Must be on the Blue Team to use this command\n\"" ); |
| 2300 |
return; |
| 2301 |
} |
| 2302 |
|
| 2303 |
if( ( ent->client->ps.pm_type == PM_DEAD ) && ( cmds[ i ].cmdFlags & CMD_LIVING ) ) |
| 2304 |
{ |
| 2305 |
trap_SendServerCommand( clientNum, |
| 2306 |
"print \"Must be alive to use this command\n\"" ); |
| 2307 |
return; |
| 2308 |
} |
| 2309 |
|
| 2310 |
cmds[ i ].cmdHandler( ent ); |
| 2311 |
} |
| 2312 |
|