Debian Codegraph @

code/game/g_cmds.c

raw symbols SCIP
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 #ifdef MISSIONPACK
26 #include "../../ui/menudef.h" // for the voice chats
27 #endif
28
29 /*
30 ==================
31 DeathmatchScoreboardMessage
32
33 ==================
34 */
35 void DeathmatchScoreboardMessage( gentity_t *ent ) {
36 char entry[1024];
37 char string[1000];
38 int stringlength;
39 int i, j;
40 gclient_t *cl;
41 int numSorted, scoreFlags, accuracy, perfect;
42
43 // don't send scores to bots, they don't parse it
44 if ( ent->r.svFlags & SVF_BOT ) {
45 return;
46 }
47
48 // send the latest information on all clients
49 string[0] = 0;
50 stringlength = 0;
51 scoreFlags = 0;
52
53 numSorted = level.numConnectedClients;
54
55 for (i=0 ; i < numSorted ; i++) {
56 int ping;
57
58 cl = &level.clients[level.sortedClients[i]];
59
60 if ( cl->pers.connected == CON_CONNECTING ) {
61 ping = -1;
62 } else {
63 ping = cl->ps.ping < 999 ? cl->ps.ping : 999;
64 }
65
66 if( cl->accuracy_shots ) {
67 accuracy = cl->accuracy_hits * 100 / cl->accuracy_shots;
68 }
69 else {
70 accuracy = 0;
71 }
72 perfect = ( cl->ps.persistant[PERS_RANK] == 0 && cl->ps.persistant[PERS_KILLED] == 0 ) ? 1 : 0;
73
74 Com_sprintf (entry, sizeof(entry),
75 " %i %i %i %i %i %i %i %i %i %i %i %i %i %i", level.sortedClients[i],
76 cl->ps.persistant[PERS_SCORE], ping, (level.time - cl->pers.enterTime)/60000,
77 scoreFlags, g_entities[level.sortedClients[i]].s.powerups, accuracy,
78 cl->ps.persistant[PERS_IMPRESSIVE_COUNT],
79 cl->ps.persistant[PERS_EXCELLENT_COUNT],
80 cl->ps.persistant[PERS_GAUNTLET_FRAG_COUNT],
81 cl->ps.persistant[PERS_DEFEND_COUNT],
82 cl->ps.persistant[PERS_ASSIST_COUNT],
83 perfect,
84 cl->ps.persistant[PERS_CAPTURES]);
85 j = strlen(entry);
86 if (stringlength + j >= sizeof(string))
87 break;
88 strcpy (string + stringlength, entry);
89 stringlength += j;
90 }
91
92 trap_SendServerCommand( ent-g_entities, va("scores %i %i %i%s", i,
93 level.teamScores[TEAM_RED], level.teamScores[TEAM_BLUE],
94 string ) );
95 }
96
97
98 /*
99 ==================
100 Cmd_Score_f
101
102 Request current scoreboard information
103 ==================
104 */
105 void Cmd_Score_f( gentity_t *ent ) {
106 DeathmatchScoreboardMessage( ent );
107 }
108
109
110
111 /*
112 ==================
113 CheatsOk
114 ==================
115 */
116 qboolean CheatsOk( gentity_t *ent ) {
117 if ( !g_cheats.integer ) {
118 trap_SendServerCommand( ent-g_entities, "print \"Cheats are not enabled on this server.\n\"");
119 return qfalse;
120 }
121 if ( ent->health <= 0 ) {
122 trap_SendServerCommand( ent-g_entities, "print \"You must be alive to use this command.\n\"");
123 return qfalse;
124 }
125 return qtrue;
126 }
127
128
129 /*
130 ==================
131 ConcatArgs
132 ==================
133 */
134 char *ConcatArgs( int start ) {
135 int i, c, tlen;
136 static char line[MAX_STRING_CHARS];
137 int len;
138 char arg[MAX_STRING_CHARS];
139
140 len = 0;
141 c = trap_Argc();
142 for ( i = start ; i < c ; i++ ) {
143 trap_Argv( i, arg, sizeof( arg ) );
144 tlen = strlen( arg );
145 if ( len + tlen >= MAX_STRING_CHARS - 1 ) {
146 break;
147 }
148 memcpy( line + len, arg, tlen );
149 len += tlen;
150 if ( i != c - 1 ) {
151 line[len] = ' ';
152 len++;
153 }
154 }
155
156 line[len] = 0;
157
158 return line;
159 }
160
161
162 /*
163 ==================
164 StringIsInteger
165 ==================
166 */
167 qboolean StringIsInteger( const char * s ) {
168 int i;
169 int len;
170 qboolean foundDigit;
171
172 len = strlen( s );
173 foundDigit = qfalse;
174
175 for ( i=0 ; i < len ; i++ ) {
176 if ( !isdigit( s[i] ) ) {
177 return qfalse;
178 }
179
180 foundDigit = qtrue;
181 }
182
183 return foundDigit;
184 }
185
186
187 /*
188 ==================
189 ClientNumberFromString
190
191 Returns a player number for either a number or name string
192 Returns -1 if invalid
193 ==================
194 */
195 int ClientNumberFromString( gentity_t *to, char *s, qboolean checkNums, qboolean checkNames ) {
196 gclient_t *cl;
197 int idnum;
198 char cleanName[MAX_STRING_CHARS];
199
200 if ( checkNums ) {
201 // numeric values could be slot numbers
202 if ( StringIsInteger( s ) ) {
203 idnum = atoi( s );
204 if ( idnum >= 0 && idnum < level.maxclients ) {
205 cl = &level.clients[idnum];
206 if ( cl->pers.connected == CON_CONNECTED ) {
207 return idnum;
208 }
209 }
210 }
211 }
212
213 if ( checkNames ) {
214 // check for a name match
215 for ( idnum=0,cl=level.clients ; idnum < level.maxclients ; idnum++,cl++ ) {
216 if ( cl->pers.connected != CON_CONNECTED ) {
217 continue;
218 }
219 Q_strncpyz(cleanName, cl->pers.netname, sizeof(cleanName));
220 Q_CleanStr(cleanName);
221 if ( !Q_stricmp( cleanName, s ) ) {
222 return idnum;
223 }
224 }
225 }
226
227 trap_SendServerCommand( to-g_entities, va("print \"User %s is not on the server\n\"", s));
228 return -1;
229 }
230
231 /*
232 ==================
233 Cmd_Give_f
234
235 Give items to a client
236 ==================
237 */
238 void Cmd_Give_f (gentity_t *ent)
239 {
240 char *name;
241 gitem_t *it;
242 int i;
243 qboolean give_all;
244 gentity_t *it_ent;
245 trace_t trace;
246
247 if ( !CheatsOk( ent ) ) {
248 return;
249 }
250
251 name = ConcatArgs( 1 );
252
253 if (Q_stricmp(name, "all") == 0)
254 give_all = qtrue;
255 else
256 give_all = qfalse;
257
258 if (give_all || Q_stricmp( name, "health") == 0)
259 {
260 ent->health = ent->client->ps.stats[STAT_MAX_HEALTH];
261 if (!give_all)
262 return;
263 }
264
265 if (give_all || Q_stricmp(name, "weapons") == 0)
266 {
267 ent->client->ps.stats[STAT_WEAPONS] = (1 << WP_NUM_WEAPONS) - 1 -
268 ( 1 << WP_GRAPPLING_HOOK ) - ( 1 << WP_NONE );
269 if (!give_all)
270 return;
271 }
272
273 if (give_all || Q_stricmp(name, "ammo") == 0)
274 {
275 for ( i = 0 ; i < MAX_WEAPONS ; i++ ) {
276 ent->client->ps.ammo[i] = 999;
277 }
278 if (!give_all)
279 return;
280 }
281
282 if (give_all || Q_stricmp(name, "armor") == 0)
283 {
284 ent->client->ps.stats[STAT_ARMOR] = 200;
285
286 if (!give_all)
287 return;
288 }
289
290 if (Q_stricmp(name, "excellent") == 0) {
291 ent->client->ps.persistant[PERS_EXCELLENT_COUNT]++;
292 return;
293 }
294 if (Q_stricmp(name, "impressive") == 0) {
295 ent->client->ps.persistant[PERS_IMPRESSIVE_COUNT]++;
296 return;
297 }
298 if (Q_stricmp(name, "gauntletaward") == 0) {
299 ent->client->ps.persistant[PERS_GAUNTLET_FRAG_COUNT]++;
300 return;
301 }
302 if (Q_stricmp(name, "defend") == 0) {
303 ent->client->ps.persistant[PERS_DEFEND_COUNT]++;
304 return;
305 }
306 if (Q_stricmp(name, "assist") == 0) {
307 ent->client->ps.persistant[PERS_ASSIST_COUNT]++;
308 return;
309 }
310
311 // spawn a specific item right on the player
312 if ( !give_all ) {
313 it = BG_FindItem (name);
314 if (!it) {
315 return;
316 }
317
318 it_ent = G_Spawn();
319 VectorCopy( ent->r.currentOrigin, it_ent->s.origin );
320 it_ent->classname = it->classname;
321 G_SpawnItem (it_ent, it);
322 FinishSpawningItem(it_ent );
323 memset( &trace, 0, sizeof( trace ) );
324 Touch_Item (it_ent, ent, &trace);
325 if (it_ent->inuse) {
326 G_FreeEntity( it_ent );
327 }
328 }
329 }
330
331
332 /*
333 ==================
334 Cmd_God_f
335
336 Sets client to godmode
337
338 argv(0) god
339 ==================
340 */
341 void Cmd_God_f (gentity_t *ent)
342 {
343 char *msg;
344
345 if ( !CheatsOk( ent ) ) {
346 return;
347 }
348
349 ent->flags ^= FL_GODMODE;
350 if (!(ent->flags & FL_GODMODE) )
351 msg = "godmode OFF\n";
352 else
353 msg = "godmode ON\n";
354
355 trap_SendServerCommand( ent-g_entities, va("print \"%s\"", msg));
356 }
357
358
359 /*
360 ==================
361 Cmd_Notarget_f
362
363 Sets client to notarget
364
365 argv(0) notarget
366 ==================
367 */
368 void Cmd_Notarget_f( gentity_t *ent ) {
369 char *msg;
370
371 if ( !CheatsOk( ent ) ) {
372 return;
373 }
374
375 ent->flags ^= FL_NOTARGET;
376 if (!(ent->flags & FL_NOTARGET) )
377 msg = "notarget OFF\n";
378 else
379 msg = "notarget ON\n";
380
381 trap_SendServerCommand( ent-g_entities, va("print \"%s\"", msg));
382 }
383
384
385 /*
386 ==================
387 Cmd_Noclip_f
388
389 argv(0) noclip
390 ==================
391 */
392 void Cmd_Noclip_f( gentity_t *ent ) {
393 char *msg;
394
395 if ( !CheatsOk( ent ) ) {
396 return;
397 }
398
399 if ( ent->client->noclip ) {
400 msg = "noclip OFF\n";
401 } else {
402 msg = "noclip ON\n";
403 }
404 ent->client->noclip = !ent->client->noclip;
405
406 trap_SendServerCommand( ent-g_entities, va("print \"%s\"", msg));
407 }
408
409
410 /*
411 ==================
412 Cmd_LevelShot_f
413
414 This is just to help generate the level pictures
415 for the menus. It goes to the intermission immediately
416 and sends over a command to the client to resize the view,
417 hide the scoreboard, and take a special screenshot
418 ==================
419 */
420 void Cmd_LevelShot_f(gentity_t *ent)
421 {
422 if(!ent->client->pers.localClient)
423 {
424 trap_SendServerCommand(ent-g_entities,
425 "print \"The levelshot command must be executed by a local client\n\"");
426 return;
427 }
428
429 if(!CheatsOk(ent))
430 return;
431
432 // doesn't work in single player
433 if(g_gametype.integer == GT_SINGLE_PLAYER)
434 {
435 trap_SendServerCommand(ent-g_entities,
436 "print \"Must not be in singleplayer mode for levelshot\n\"" );
437 return;
438 }
439
440 BeginIntermission();
441 trap_SendServerCommand(ent-g_entities, "clientLevelShot");
442 }
443
444
445 /*
446 ==================
447 Cmd_TeamTask_f
448 ==================
449 */
450 void Cmd_TeamTask_f( gentity_t *ent ) {
451 char userinfo[MAX_INFO_STRING];
452 char arg[MAX_TOKEN_CHARS];
453 int task;
454 int client = ent->client - level.clients;
455
456 if ( trap_Argc() != 2 ) {
457 return;
458 }
459 trap_Argv( 1, arg, sizeof( arg ) );
460 task = atoi( arg );
461
462 trap_GetUserinfo(client, userinfo, sizeof(userinfo));
463 Info_SetValueForKey(userinfo, "teamtask", va("%d", task));
464 trap_SetUserinfo(client, userinfo);
465 ClientUserinfoChanged(client);
466 }
467
468
469 /*
470 =================
471 Cmd_Kill_f
472 =================
473 */
474 void Cmd_Kill_f( gentity_t *ent ) {
475 if ( ent->client->sess.sessionTeam == TEAM_SPECTATOR ) {
476 return;
477 }
478 if (ent->health <= 0) {
479 return;
480 }
481 ent->flags &= ~FL_GODMODE;
482 ent->client->ps.stats[STAT_HEALTH] = ent->health = -999;
483 player_die (ent, ent, ent, 100000, MOD_SUICIDE);
484 }
485
486 /*
487 =================
488 BroadcastTeamChange
489
490 Let everyone know about a team change
491 =================
492 */
493 void BroadcastTeamChange( gclient_t *client, int oldTeam )
494 {
495 if ( client->sess.sessionTeam == TEAM_RED ) {
496 trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " joined the red team.\n\"",
497 client->pers.netname) );
498 } else if ( client->sess.sessionTeam == TEAM_BLUE ) {
499 trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " joined the blue team.\n\"",
500 client->pers.netname));
501 } else if ( client->sess.sessionTeam == TEAM_SPECTATOR && oldTeam != TEAM_SPECTATOR ) {
502 trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " joined the spectators.\n\"",
503 client->pers.netname));
504 } else if ( client->sess.sessionTeam == TEAM_FREE ) {
505 trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " joined the battle.\n\"",
506 client->pers.netname));
507 }
508 }
509
510 /*
511 =================
512 SetTeam
513 =================
514 */
515 void SetTeam( gentity_t *ent, const char *s ) {
516 int team, oldTeam;
517 gclient_t *client;
518 int clientNum;
519 spectatorState_t specState;
520 int specClient;
521 int teamLeader;
522
523 //
524 // see what change is requested
525 //
526 client = ent->client;
527
528 clientNum = client - level.clients;
529 specClient = 0;
530 specState = SPECTATOR_NOT;
531 if ( !Q_stricmp( s, "scoreboard" ) || !Q_stricmp( s, "score" ) ) {
532 team = TEAM_SPECTATOR;
533 specState = SPECTATOR_SCOREBOARD;
534 } else if ( !Q_stricmp( s, "follow1" ) ) {
535 team = TEAM_SPECTATOR;
536 specState = SPECTATOR_FOLLOW;
537 specClient = -1;
538 } else if ( !Q_stricmp( s, "follow2" ) ) {
539 team = TEAM_SPECTATOR;
540 specState = SPECTATOR_FOLLOW;
541 specClient = -2;
542 } else if ( !Q_stricmp( s, "spectator" ) || !Q_stricmp( s, "s" ) ) {
543 team = TEAM_SPECTATOR;
544 specState = SPECTATOR_FREE;
545 } else if ( g_gametype.integer >= GT_TEAM ) {
546 // if running a team game, assign player to one of the teams
547 specState = SPECTATOR_NOT;
548 if ( !Q_stricmp( s, "red" ) || !Q_stricmp( s, "r" ) ) {
549 team = TEAM_RED;
550 } else if ( !Q_stricmp( s, "blue" ) || !Q_stricmp( s, "b" ) ) {
551 team = TEAM_BLUE;
552 } else {
553 // pick the team with the least number of players
554 team = PickTeam( clientNum );
555 }
556
557 if ( g_teamForceBalance.integer && !client->pers.localClient && !( ent->r.svFlags & SVF_BOT ) ) {
558 int counts[TEAM_NUM_TEAMS];
559
560 counts[TEAM_BLUE] = TeamCount( clientNum, TEAM_BLUE );
561 counts[TEAM_RED] = TeamCount( clientNum, TEAM_RED );
562
563 // We allow a spread of two
564 if ( team == TEAM_RED && counts[TEAM_RED] - counts[TEAM_BLUE] > 1 ) {
565 trap_SendServerCommand( clientNum,
566 "cp \"Red team has too many players.\n\"" );
567 return; // ignore the request
568 }
569 if ( team == TEAM_BLUE && counts[TEAM_BLUE] - counts[TEAM_RED] > 1 ) {
570 trap_SendServerCommand( clientNum,
571 "cp \"Blue team has too many players.\n\"" );
572 return; // ignore the request
573 }
574
575 // It's ok, the team we are switching to has less or same number of players
576 }
577
578 } else {
579 // force them to spectators if there aren't any spots free
580 team = TEAM_FREE;
581 }
582
583 // override decision if limiting the players
584 if ( (g_gametype.integer == GT_TOURNAMENT)
585 && level.numNonSpectatorClients >= 2 ) {
586 team = TEAM_SPECTATOR;
587 } else if ( g_maxGameClients.integer > 0 &&
588 level.numNonSpectatorClients >= g_maxGameClients.integer ) {
589 team = TEAM_SPECTATOR;
590 }
591
592 //
593 // decide if we will allow the change
594 //
595 oldTeam = client->sess.sessionTeam;
596 if ( team == oldTeam && team != TEAM_SPECTATOR ) {
597 return;
598 }
599
600 //
601 // execute the team change
602 //
603
604 // if the player was dead leave the body, but only if they're actually in game
605 if ( client->ps.stats[STAT_HEALTH] <= 0 && client->pers.connected == CON_CONNECTED ) {
606 CopyToBodyQue(ent);
607 }
608
609 // he starts at 'base'
610 client->pers.teamState.state = TEAM_BEGIN;
611 if ( oldTeam != TEAM_SPECTATOR ) {
612 // Kill him (makes sure he loses flags, etc)
613 ent->flags &= ~FL_GODMODE;
614 ent->client->ps.stats[STAT_HEALTH] = ent->health = 0;
615 player_die (ent, ent, ent, 100000, MOD_SUICIDE);
616
617 }
618
619 // they go to the end of the line for tournements
620 if(team == TEAM_SPECTATOR && oldTeam != team)
621 AddTournamentQueue(client);
622
623 client->sess.sessionTeam = team;
624 client->sess.spectatorState = specState;
625 client->sess.spectatorClient = specClient;
626
627 client->sess.teamLeader = qfalse;
628 if ( team == TEAM_RED || team == TEAM_BLUE ) {
629 teamLeader = TeamLeader( team );
630 // if there is no team leader or the team leader is a bot and this client is not a bot
631 if ( teamLeader == -1 || ( !(g_entities[clientNum].r.svFlags & SVF_BOT) && (g_entities[teamLeader].r.svFlags & SVF_BOT) ) ) {
632 SetLeader( team, clientNum );
633 }
634 }
635 // make sure there is a team leader on the team the player came from
636 if ( oldTeam == TEAM_RED || oldTeam == TEAM_BLUE ) {
637 CheckTeamLeader( oldTeam );
638 }
639
640 // get and distribute relevant parameters
641 ClientUserinfoChanged( clientNum );
642
643 // client hasn't spawned yet, they sent an early team command, teampref userinfo, or g_teamAutoJoin is enabled
644 if ( client->pers.connected != CON_CONNECTED ) {
645 return;
646 }
647
648 BroadcastTeamChange( client, oldTeam );
649
650 ClientBegin( clientNum );
651 }
652
653 /*
654 =================
655 StopFollowing
656
657 If the client being followed leaves the game, or you just want to drop
658 to free floating spectator mode
659 =================
660 */
661 void StopFollowing( gentity_t *ent ) {
662 ent->client->ps.persistant[ PERS_TEAM ] = TEAM_SPECTATOR;
663 ent->client->sess.sessionTeam = TEAM_SPECTATOR;
664 ent->client->sess.spectatorState = SPECTATOR_FREE;
665 ent->client->ps.pm_flags &= ~PMF_FOLLOW;
666 ent->r.svFlags &= ~SVF_BOT;
667 ent->client->ps.clientNum = ent - g_entities;
668
669 SetClientViewAngle( ent, ent->client->ps.viewangles );
670
671 // don't use dead view angles
672 if ( ent->client->ps.stats[STAT_HEALTH] <= 0 ) {
673 ent->client->ps.stats[STAT_HEALTH] = 1;
674 }
675 }
676
677 /*
678 =================
679 Cmd_Team_f
680 =================
681 */
682 void Cmd_Team_f( gentity_t *ent ) {
683 int oldTeam;
684 char s[MAX_TOKEN_CHARS];
685
686 if ( trap_Argc() != 2 ) {
687 oldTeam = ent->client->sess.sessionTeam;
688 switch ( oldTeam ) {
689 case TEAM_BLUE:
690 trap_SendServerCommand( ent-g_entities, "print \"Blue team\n\"" );
691 break;
692 case TEAM_RED:
693 trap_SendServerCommand( ent-g_entities, "print \"Red team\n\"" );
694 break;
695 case TEAM_FREE:
696 trap_SendServerCommand( ent-g_entities, "print \"Free team\n\"" );
697 break;
698 case TEAM_SPECTATOR:
699 trap_SendServerCommand( ent-g_entities, "print \"Spectator team\n\"" );
700 break;
701 }
702 return;
703 }
704
705 if ( ent->client->switchTeamTime > level.time ) {
706 trap_SendServerCommand( ent-g_entities, "print \"May not switch teams more than once per 5 seconds.\n\"" );
707 return;
708 }
709
710 // if they are playing a tournement game, count as a loss
711 if ( (g_gametype.integer == GT_TOURNAMENT )
712 && ent->client->sess.sessionTeam == TEAM_FREE ) {
713 ent->client->sess.losses++;
714 }
715
716 trap_Argv( 1, s, sizeof( s ) );
717
718 SetTeam( ent, s );
719
720 ent->client->switchTeamTime = level.time + 5000;
721 }
722
723
724 /*
725 =================
726 Cmd_Follow_f
727 =================
728 */
729 void Cmd_Follow_f( gentity_t *ent ) {
730 int i;
731 char arg[MAX_TOKEN_CHARS];
732
733 if ( trap_Argc() != 2 ) {
734 if ( ent->client->sess.spectatorState == SPECTATOR_FOLLOW ) {
735 StopFollowing( ent );
736 }
737 return;
738 }
739
740 trap_Argv( 1, arg, sizeof( arg ) );
741 i = ClientNumberFromString( ent, arg, qtrue, qtrue );
742 if ( i == -1 ) {
743 return;
744 }
745
746 // can't follow self
747 if ( &level.clients[ i ] == ent->client ) {
748 return;
749 }
750
751 // can't follow another spectator
752 if ( level.clients[ i ].sess.sessionTeam == TEAM_SPECTATOR ) {
753 return;
754 }
755
756 // if they are playing a tournement game, count as a loss
757 if ( (g_gametype.integer == GT_TOURNAMENT )
758 && ent->client->sess.sessionTeam == TEAM_FREE ) {
759 ent->client->sess.losses++;
760 }
761
762 // first set them to spectator
763 if ( ent->client->sess.sessionTeam != TEAM_SPECTATOR ) {
764 SetTeam( ent, "spectator" );
765 }
766
767 ent->client->sess.spectatorState = SPECTATOR_FOLLOW;
768 ent->client->sess.spectatorClient = i;
769 }
770
771 /*
772 =================
773 Cmd_FollowCycle_f
774 =================
775 */
776 void Cmd_FollowCycle_f( gentity_t *ent, int dir ) {
777 int clientnum;
778 int original;
779
780 // if they are playing a tournement game, count as a loss
781 if ( (g_gametype.integer == GT_TOURNAMENT )
782 && ent->client->sess.sessionTeam == TEAM_FREE ) {
783 ent->client->sess.losses++;
784 }
785 // first set them to spectator
786 if ( ent->client->sess.spectatorState == SPECTATOR_NOT ) {
787 SetTeam( ent, "spectator" );
788 }
789
790 if ( dir != 1 && dir != -1 ) {
791 G_Error( "Cmd_FollowCycle_f: bad dir %i", dir );
792 }
793
794 // if dedicated follow client, just switch between the two auto clients
795 if (ent->client->sess.spectatorClient < 0) {
796 if (ent->client->sess.spectatorClient == -1) {
797 ent->client->sess.spectatorClient = -2;
798 } else if (ent->client->sess.spectatorClient == -2) {
799 ent->client->sess.spectatorClient = -1;
800 }
801 return;
802 }
803
804 clientnum = ent->client->sess.spectatorClient;
805 original = clientnum;
806 do {
807 clientnum += dir;
808 if ( clientnum >= level.maxclients ) {
809 clientnum = 0;
810 }
811 if ( clientnum < 0 ) {
812 clientnum = level.maxclients - 1;
813 }
814
815 // can only follow connected clients
816 if ( level.clients[ clientnum ].pers.connected != CON_CONNECTED ) {
817 continue;
818 }
819
820 // can't follow another spectator
821 if ( level.clients[ clientnum ].sess.sessionTeam == TEAM_SPECTATOR ) {
822 continue;
823 }
824
825 // this is good, we can use it
826 ent->client->sess.spectatorClient = clientnum;
827 ent->client->sess.spectatorState = SPECTATOR_FOLLOW;
828 return;
829 } while ( clientnum != original );
830
831 // leave it where it was
832 }
833
834
835 /*
836 ==================
837 G_Say
838 ==================
839 */
840
841 static void G_SayTo( gentity_t *ent, gentity_t *other, int mode, int color, const char *name, const char *message ) {
842 if (!other) {
843 return;
844 }
845 if (!other->inuse) {
846 return;
847 }
848 if (!other->client) {
849 return;
850 }
851 if ( other->client->pers.connected != CON_CONNECTED ) {
852 return;
853 }
854 if ( mode == SAY_TEAM && !OnSameTeam(ent, other) ) {
855 return;
856 }
857 // no chatting to players in tournements
858 if ( (g_gametype.integer == GT_TOURNAMENT )
859 && other->client->sess.sessionTeam == TEAM_FREE
860 && ent->client->sess.sessionTeam != TEAM_FREE ) {
861 return;
862 }
863
864 trap_SendServerCommand( other-g_entities, va("%s \"%s%c%c%s\"",
865 mode == SAY_TEAM ? "tchat" : "chat",
866 name, Q_COLOR_ESCAPE, color, message));
867 }
868
869 #define EC "\x19"
870
871 void G_Say( gentity_t *ent, gentity_t *target, int mode, const char *chatText ) {
872 int j;
873 gentity_t *other;
874 int color;
875 char name[64];
876 // don't let text be too long for malicious reasons
877 char text[MAX_SAY_TEXT];
878 char location[64];
879
880 if ( g_gametype.integer < GT_TEAM && mode == SAY_TEAM ) {
881 mode = SAY_ALL;
882 }
883
884 switch ( mode ) {
885 default:
886 case SAY_ALL:
887 G_LogPrintf( "say: %s: %s\n", ent->client->pers.netname, chatText );
888 Com_sprintf (name, sizeof(name), "%s%c%c"EC": ", ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE );
889 color = COLOR_GREEN;
890 break;
891 case SAY_TEAM:
892 G_LogPrintf( "sayteam: %s: %s\n", ent->client->pers.netname, chatText );
893 if (Team_GetLocationMsg(ent, location, sizeof(location)))
894 Com_sprintf (name, sizeof(name), EC"(%s%c%c"EC") (%s)"EC": ",
895 ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE, location);
896 else
897 Com_sprintf (name, sizeof(name), EC"(%s%c%c"EC")"EC": ",
898 ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE );
899 color = COLOR_CYAN;
900 break;
901 case SAY_TELL:
902 if (target && target->inuse && target->client && g_gametype.integer >= GT_TEAM &&
903 target->client->sess.sessionTeam == ent->client->sess.sessionTeam &&
904 Team_GetLocationMsg(ent, location, sizeof(location)))
905 Com_sprintf (name, sizeof(name), EC"[%s%c%c"EC"] (%s)"EC": ", ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE, location );
906 else
907 Com_sprintf (name, sizeof(name), EC"[%s%c%c"EC"]"EC": ", ent->client->pers.netname, Q_COLOR_ESCAPE, COLOR_WHITE );
908 color = COLOR_MAGENTA;
909 break;
910 }
911
912 Q_strncpyz( text, chatText, sizeof(text) );
913
914 if ( target ) {
915 G_SayTo( ent, target, mode, color, name, text );
916 return;
917 }
918
919 // echo the text to the console
920 if ( g_dedicated.integer ) {
921 G_Printf( "%s%s\n", name, text);
922 }
923
924 // send it to all the appropriate clients
925 for (j = 0; j < level.maxclients; j++) {
926 other = &g_entities[j];
927 G_SayTo( ent, other, mode, color, name, text );
928 }
929 }
930
931 static void SanitizeChatText( char *text ) {
932 int i;
933
934 for ( i = 0; text[i]; i++ ) {
935 if ( text[i] == '\n' || text[i] == '\r' ) {
936 text[i] = ' ';
937 }
938 }
939 }
940
941
942 /*
943 ==================
944 Cmd_Say_f
945 ==================
946 */
947 static void Cmd_Say_f( gentity_t *ent, int mode, qboolean arg0 ) {
948 char *p;
949
950 if ( trap_Argc () < 2 && !arg0 ) {
951 return;
952 }
953
954 if (arg0)
955 {
956 p = ConcatArgs( 0 );
957 }
958 else
959 {
960 p = ConcatArgs( 1 );
961 }
962
963 SanitizeChatText( p );
964
965 G_Say( ent, NULL, mode, p );
966 }
967
968 /*
969 ==================
970 Cmd_Tell_f
971 ==================
972 */
973 static void Cmd_Tell_f( gentity_t *ent ) {
974 int targetNum;
975 gentity_t *target;
976 char *p;
977 char arg[MAX_TOKEN_CHARS];
978
979 if ( trap_Argc () < 3 ) {
980 trap_SendServerCommand( ent-g_entities, "print \"Usage: tell <player id> <message>\n\"" );
981 return;
982 }
983
984 trap_Argv( 1, arg, sizeof( arg ) );
985 targetNum = ClientNumberFromString( ent, arg, qtrue, qtrue );
986 if ( targetNum == -1 ) {
987 return;
988 }
989
990 target = &g_entities[targetNum];
991 if ( !target->inuse || !target->client ) {
992 return;
993 }
994
995 p = ConcatArgs( 2 );
996
997 SanitizeChatText( p );
998
999 G_LogPrintf( "tell: %s to %s: %s\n", ent->client->pers.netname, target->client->pers.netname, p );
1000 G_Say( ent, target, SAY_TELL, p );
1001 // don't tell to the player self if it was already directed to this player
1002 // also don't send the chat back to a bot
1003 if ( ent != target && !(ent->r.svFlags & SVF_BOT)) {
1004 G_Say( ent, ent, SAY_TELL, p );
1005 }
1006 }
1007
1008
1009 #ifdef MISSIONPACK
1010 static void G_VoiceTo( gentity_t *ent, gentity_t *other, int mode, const char *id, qboolean voiceonly ) {
1011 int color;
1012 char *cmd;
1013
1014 if (!other) {
1015 return;
1016 }
1017 if (!other->inuse) {
1018 return;
1019 }
1020 if (!other->client) {
1021 return;
1022 }
1023 if ( mode == SAY_TEAM && !OnSameTeam(ent, other) ) {
1024 return;
1025 }
1026 // no chatting to players in tournements
1027 if ( g_gametype.integer == GT_TOURNAMENT ) {
1028 return;
1029 }
1030
1031 if (mode == SAY_TEAM) {
1032 color = COLOR_CYAN;
1033 cmd = "vtchat";
1034 }
1035 else if (mode == SAY_TELL) {
1036 color = COLOR_MAGENTA;
1037 cmd = "vtell";
1038 }
1039 else {
1040 color = COLOR_GREEN;
1041 cmd = "vchat";
1042 }
1043
1044 trap_SendServerCommand( other-g_entities, va("%s %d %d %d %s", cmd, voiceonly, ent->s.number, color, id));
1045 }
1046
1047 void G_Voice( gentity_t *ent, gentity_t *target, int mode, const char *id, qboolean voiceonly ) {
1048 int j;
1049 gentity_t *other;
1050
1051 if ( g_gametype.integer < GT_TEAM && mode == SAY_TEAM ) {
1052 mode = SAY_ALL;
1053 }
1054
1055 if ( target ) {
1056 G_VoiceTo( ent, target, mode, id, voiceonly );
1057 return;
1058 }
1059
1060 // echo the text to the console
1061 if ( g_dedicated.integer ) {
1062 G_Printf( "voice: %s %s\n", ent->client->pers.netname, id);
1063 }
1064
1065 // send it to all the appropriate clients
1066 for (j = 0; j < level.maxclients; j++) {
1067 other = &g_entities[j];
1068 G_VoiceTo( ent, other, mode, id, voiceonly );
1069 }
1070 }
1071
1072 /*
1073 ==================
1074 Cmd_Voice_f
1075 ==================
1076 */
1077 static void Cmd_Voice_f( gentity_t *ent, int mode, qboolean arg0, qboolean voiceonly ) {
1078 char *p;
1079
1080 if ( trap_Argc () < 2 && !arg0 ) {
1081 return;
1082 }
1083
1084 if (arg0)
1085 {
1086 p = ConcatArgs( 0 );
1087 }
1088 else
1089 {
1090 p = ConcatArgs( 1 );
1091 }
1092
1093 SanitizeChatText( p );
1094
1095 G_Voice( ent, NULL, mode, p, voiceonly );
1096 }
1097
1098 /*
1099 ==================
1100 Cmd_VoiceTell_f
1101 ==================
1102 */
1103 static void Cmd_VoiceTell_f( gentity_t *ent, qboolean voiceonly ) {
1104 int targetNum;
1105 gentity_t *target;
1106 char *id;
1107 char arg[MAX_TOKEN_CHARS];
1108
1109 if ( trap_Argc () < 3 ) {
1110 trap_SendServerCommand( ent-g_entities, va( "print \"Usage: %s <player id> <voice id>\n\"", voiceonly ? "votell" : "vtell" ) );
1111 return;
1112 }
1113
1114 trap_Argv( 1, arg, sizeof( arg ) );
1115 targetNum = ClientNumberFromString( ent, arg, qtrue, qtrue );
1116 if ( targetNum == -1 ) {
1117 return;
1118 }
1119
1120 target = &g_entities[targetNum];
1121 if ( !target->inuse || !target->client ) {
1122 return;
1123 }
1124
1125 id = ConcatArgs( 2 );
1126
1127 SanitizeChatText( id );
1128
1129 G_LogPrintf( "vtell: %s to %s: %s\n", ent->client->pers.netname, target->client->pers.netname, id );
1130 G_Voice( ent, target, SAY_TELL, id, voiceonly );
1131 // don't tell to the player self if it was already directed to this player
1132 // also don't send the chat back to a bot
1133 if ( ent != target && !(ent->r.svFlags & SVF_BOT)) {
1134 G_Voice( ent, ent, SAY_TELL, id, voiceonly );
1135 }
1136 }
1137
1138
1139 /*
1140 ==================
1141 Cmd_VoiceTaunt_f
1142 ==================
1143 */
1144 static void Cmd_VoiceTaunt_f( gentity_t *ent ) {
1145 gentity_t *who;
1146 int i;
1147
1148 if (!ent->client) {
1149 return;
1150 }
1151
1152 // insult someone who just killed you
1153 if (ent->enemy && ent->enemy->client && ent->enemy->client->lastkilled_client == ent->s.number) {
1154 // i am a dead corpse
1155 if (!(ent->enemy->r.svFlags & SVF_BOT)) {
1156 G_Voice( ent, ent->enemy, SAY_TELL, VOICECHAT_DEATHINSULT, qfalse );
1157 }
1158 if (!(ent->r.svFlags & SVF_BOT)) {
1159 G_Voice( ent, ent, SAY_TELL, VOICECHAT_DEATHINSULT, qfalse );
1160 }
1161 ent->enemy = NULL;
1162 return;
1163 }
1164 // insult someone you just killed
1165 if (ent->client->lastkilled_client >= 0 && ent->client->lastkilled_client != ent->s.number) {
1166 who = g_entities + ent->client->lastkilled_client;
1167 if (who->client) {
1168 // who is the person I just killed
1169 if (who->client->lasthurt_mod == MOD_GAUNTLET) {
1170 if (!(who->r.svFlags & SVF_BOT)) {
1171 G_Voice( ent, who, SAY_TELL, VOICECHAT_KILLGAUNTLET, qfalse ); // and I killed them with a gauntlet
1172 }
1173 if (!(ent->r.svFlags & SVF_BOT)) {
1174 G_Voice( ent, ent, SAY_TELL, VOICECHAT_KILLGAUNTLET, qfalse );
1175 }
1176 } else {
1177 if (!(who->r.svFlags & SVF_BOT)) {
1178 G_Voice( ent, who, SAY_TELL, VOICECHAT_KILLINSULT, qfalse ); // and I killed them with something else
1179 }
1180 if (!(ent->r.svFlags & SVF_BOT)) {
1181 G_Voice( ent, ent, SAY_TELL, VOICECHAT_KILLINSULT, qfalse );
1182 }
1183 }
1184 ent->client->lastkilled_client = -1;
1185 return;
1186 }
1187 }
1188
1189 if (g_gametype.integer >= GT_TEAM) {
1190 // praise a team mate who just got a reward
1191 for(i = 0; i < MAX_CLIENTS; i++) {
1192 who = g_entities + i;
1193 if (who->client && who != ent && who->client->sess.sessionTeam == ent->client->sess.sessionTeam) {
1194 if (who->client->rewardTime > level.time) {
1195 if (!(who->r.svFlags & SVF_BOT)) {
1196 G_Voice( ent, who, SAY_TELL, VOICECHAT_PRAISE, qfalse );
1197 }
1198 if (!(ent->r.svFlags & SVF_BOT)) {
1199 G_Voice( ent, ent, SAY_TELL, VOICECHAT_PRAISE, qfalse );
1200 }
1201 return;
1202 }
1203 }
1204 }
1205 }
1206
1207 // just say something
1208 G_Voice( ent, NULL, SAY_ALL, VOICECHAT_TAUNT, qfalse );
1209 }
1210 #endif
1211
1212
1213
1214 static char *gc_orders[] = {
1215 "hold your position",
1216 "hold this position",
1217 "come here",
1218 "cover me",
1219 "guard location",
1220 "search and destroy",
1221 "report"
1222 };
1223
1224 static const int numgc_orders = ARRAY_LEN( gc_orders );
1225
1226 void Cmd_GameCommand_f( gentity_t *ent ) {
1227 int targetNum;
1228 gentity_t *target;
1229 int order;
1230 char arg[MAX_TOKEN_CHARS];
1231
1232 if ( trap_Argc() != 3 ) {
1233 trap_SendServerCommand( ent-g_entities, va( "print \"Usage: gc <player id> <order 0-%d>\n\"", numgc_orders - 1 ) );
1234 return;
1235 }
1236
1237 trap_Argv( 2, arg, sizeof( arg ) );
1238 order = atoi( arg );
1239
1240 if ( order < 0 || order >= numgc_orders ) {
1241 trap_SendServerCommand( ent-g_entities, va("print \"Bad order: %i\n\"", order));
1242 return;
1243 }
1244
1245 trap_Argv( 1, arg, sizeof( arg ) );
1246 targetNum = ClientNumberFromString( ent, arg, qtrue, qtrue );
1247 if ( targetNum == -1 ) {
1248 return;
1249 }
1250
1251 target = &g_entities[targetNum];
1252 if ( !target->inuse || !target->client ) {
1253 return;
1254 }
1255
1256 G_LogPrintf( "tell: %s to %s: %s\n", ent->client->pers.netname, target->client->pers.netname, gc_orders[order] );
1257 G_Say( ent, target, SAY_TELL, gc_orders[order] );
1258 // don't tell to the player self if it was already directed to this player
1259 // also don't send the chat back to a bot
1260 if ( ent != target && !(ent->r.svFlags & SVF_BOT)) {
1261 G_Say( ent, ent, SAY_TELL, gc_orders[order] );
1262 }
1263 }
1264
1265 /*
1266 ==================
1267 Cmd_Where_f
1268 ==================
1269 */
1270 void Cmd_Where_f( gentity_t *ent ) {
1271 trap_SendServerCommand( ent-g_entities, va("print \"%s\n\"", vtos(ent->r.currentOrigin) ) );
1272 }
1273
1274 static const char *gameNames[] = {
1275 "Free For All",
1276 "Tournament",
1277 "Single Player",
1278 "Team Deathmatch",
1279 "Capture the Flag",
1280 "One Flag CTF",
1281 "Overload",
1282 "Harvester"
1283 };
1284
1285 /*
1286 ==================
1287 Cmd_CallVote_f
1288 ==================
1289 */
1290 void Cmd_CallVote_f( gentity_t *ent ) {
1291 char* c;
1292 int i;
1293 char arg1[MAX_STRING_TOKENS];
1294 char arg2[MAX_STRING_TOKENS];
1295
1296 if ( !g_allowVote.integer ) {
1297 trap_SendServerCommand( ent-g_entities, "print \"Voting not allowed here.\n\"" );
1298 return;
1299 }
1300
1301 if ( level.voteTime ) {
1302 trap_SendServerCommand( ent-g_entities, "print \"A vote is already in progress.\n\"" );
1303 return;
1304 }
1305 if ( ent->client->pers.voteCount >= MAX_VOTE_COUNT ) {
1306 trap_SendServerCommand( ent-g_entities, "print \"You have called the maximum number of votes.\n\"" );
1307 return;
1308 }
1309 if ( ent->client->sess.sessionTeam == TEAM_SPECTATOR ) {
1310 trap_SendServerCommand( ent-g_entities, "print \"Not allowed to call a vote as spectator.\n\"" );
1311 return;
1312 }
1313
1314 // make sure it is a valid command to vote on
1315 trap_Argv( 1, arg1, sizeof( arg1 ) );
1316 trap_Argv( 2, arg2, sizeof( arg2 ) );
1317
1318 // check for command separators in arg2
1319 for( c = arg2; *c; ++c) {
1320 switch(*c) {
1321 case '\n':
1322 case '\r':
1323 case ';':
1324 trap_SendServerCommand( ent-g_entities, "print \"Invalid vote string.\n\"" );
1325 return;
1326 break;
1327 }
1328 }
1329
1330 if ( !Q_stricmp( arg1, "map_restart" ) ) {
1331 } else if ( !Q_stricmp( arg1, "nextmap" ) ) {
1332 } else if ( !Q_stricmp( arg1, "map" ) ) {
1333 } else if ( !Q_stricmp( arg1, "g_gametype" ) ) {
1334 } else if ( !Q_stricmp( arg1, "kick" ) ) {
1335 } else if ( !Q_stricmp( arg1, "clientkick" ) ) {
1336 } else if ( !Q_stricmp( arg1, "g_doWarmup" ) ) {
1337 } else if ( !Q_stricmp( arg1, "timelimit" ) ) {
1338 } else if ( !Q_stricmp( arg1, "fraglimit" ) ) {
1339 } else {
1340 trap_SendServerCommand( ent-g_entities, "print \"Invalid vote string.\n\"" );
1341 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\"" );
1342 return;
1343 }
1344
1345 // if there is still a vote to be executed
1346 if ( level.voteExecuteTime ) {
1347 // don't start a vote when map change or restart is in progress
1348 if ( !Q_stricmpn( level.voteString, "map", 3 )
1349 || !Q_stricmpn( level.voteString, "nextmap", 7 ) ) {
1350 trap_SendServerCommand( ent-g_entities, "print \"Vote after map change.\n\"" );
1351 return;
1352 }
1353
1354 level.voteExecuteTime = 0;
1355 trap_SendConsoleCommand( EXEC_APPEND, va("%s\n", level.voteString ) );
1356 }
1357
1358 // special case for g_gametype, check for bad values
1359 if ( !Q_stricmp( arg1, "g_gametype" ) ) {
1360 i = atoi( arg2 );
1361 if( i == GT_SINGLE_PLAYER || i < GT_FFA || i >= GT_MAX_GAME_TYPE) {
1362 trap_SendServerCommand( ent-g_entities, "print \"Invalid gametype.\n\"" );
1363 return;
1364 }
1365
1366 Com_sprintf( level.voteString, sizeof( level.voteString ), "%s %d", arg1, i );
1367 Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "%s %s", arg1, gameNames[i] );
1368 } else if ( !Q_stricmp( arg1, "map" ) ) {
1369 // special case for map changes, we want to reset the nextmap setting
1370 // this allows a player to change maps, but not upset the map rotation
1371 char s[MAX_STRING_CHARS];
1372
1373 trap_Cvar_VariableStringBuffer( "nextmap", s, sizeof(s) );
1374 if (*s) {
1375 Com_sprintf( level.voteString, sizeof( level.voteString ), "%s %s; set nextmap \"%s\"", arg1, arg2, s );
1376 } else {
1377 Com_sprintf( level.voteString, sizeof( level.voteString ), "%s %s", arg1, arg2 );
1378 }
1379 Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "%s", level.voteString );
1380 } else if ( !Q_stricmp( arg1, "nextmap" ) ) {
1381 char s[MAX_STRING_CHARS];
1382
1383 trap_Cvar_VariableStringBuffer( "nextmap", s, sizeof(s) );
1384 if (!*s) {
1385 trap_SendServerCommand( ent-g_entities, "print \"nextmap not set.\n\"" );
1386 return;
1387 }
1388 Com_sprintf( level.voteString, sizeof( level.voteString ), "vstr nextmap");
1389 Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "%s", level.voteString );
1390 } else if ( !Q_stricmp( arg1, "clientkick" ) || !Q_stricmp( arg1, "kick" ) ) {
1391 i = ClientNumberFromString( ent, arg2, !Q_stricmp( arg1, "clientkick" ), !Q_stricmp( arg1, "kick" ) );
1392 if ( i == -1 ) {
1393 return;
1394 }
1395
1396 if ( level.clients[i].pers.localClient ) {
1397 trap_SendServerCommand( ent - g_entities, "print \"Cannot kick host player.\n\"" );
1398 return;
1399 }
1400
1401 Com_sprintf( level.voteString, sizeof( level.voteString ), "clientkick %d", i );
1402 Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "kick %s", level.clients[i].pers.netname );
1403 } else {
1404 Com_sprintf( level.voteString, sizeof( level.voteString ), "%s \"%s\"", arg1, arg2 );
1405 Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "%s", level.voteString );
1406 }
1407
1408 trap_SendServerCommand( -1, va("print \"%s called a vote.\n\"", ent->client->pers.netname ) );
1409
1410 // start the voting, the caller automatically votes yes
1411 level.voteTime = level.time;
1412 level.voteYes = 1;
1413 level.voteNo = 0;
1414
1415 for ( i = 0 ; i < level.maxclients ; i++ ) {
1416 level.clients[i].ps.eFlags &= ~EF_VOTED;
1417 }
1418 ent->client->ps.eFlags |= EF_VOTED;
1419
1420 trap_SetConfigstring( CS_VOTE_TIME, va("%i", level.voteTime ) );
1421 trap_SetConfigstring( CS_VOTE_STRING, level.voteDisplayString );
1422 trap_SetConfigstring( CS_VOTE_YES, va("%i", level.voteYes ) );
1423 trap_SetConfigstring( CS_VOTE_NO, va("%i", level.voteNo ) );
1424 }
1425
1426 /*
1427 ==================
1428 Cmd_Vote_f
1429 ==================
1430 */
1431 void Cmd_Vote_f( gentity_t *ent ) {
1432 char msg[64];
1433
1434 if ( !level.voteTime ) {
1435 trap_SendServerCommand( ent-g_entities, "print \"No vote in progress.\n\"" );
1436 return;
1437 }
1438 if ( ent->client->ps.eFlags & EF_VOTED ) {
1439 trap_SendServerCommand( ent-g_entities, "print \"Vote already cast.\n\"" );
1440 return;
1441 }
1442 if ( ent->client->sess.sessionTeam == TEAM_SPECTATOR ) {
1443 trap_SendServerCommand( ent-g_entities, "print \"Not allowed to vote as spectator.\n\"" );
1444 return;
1445 }
1446
1447 trap_SendServerCommand( ent-g_entities, "print \"Vote cast.\n\"" );
1448
1449 ent->client->ps.eFlags |= EF_VOTED;
1450
1451 trap_Argv( 1, msg, sizeof( msg ) );
1452
1453 if ( tolower( msg[0] ) == 'y' || msg[0] == '1' ) {
1454 level.voteYes++;
1455 trap_SetConfigstring( CS_VOTE_YES, va("%i", level.voteYes ) );
1456 } else {
1457 level.voteNo++;
1458 trap_SetConfigstring( CS_VOTE_NO, va("%i", level.voteNo ) );
1459 }
1460
1461 // a majority will be determined in CheckVote, which will also account
1462 // for players entering or leaving
1463 }
1464
1465 /*
1466 ==================
1467 Cmd_CallTeamVote_f
1468 ==================
1469 */
1470 void Cmd_CallTeamVote_f( gentity_t *ent ) {
1471 char* c;
1472 int i, team, cs_offset;
1473 char arg1[MAX_STRING_TOKENS];
1474 char arg2[MAX_STRING_TOKENS];
1475
1476 team = ent->client->sess.sessionTeam;
1477 if ( team == TEAM_RED )
1478 cs_offset = 0;
1479 else if ( team == TEAM_BLUE )
1480 cs_offset = 1;
1481 else
1482 return;
1483
1484 if ( !g_allowVote.integer ) {
1485 trap_SendServerCommand( ent-g_entities, "print \"Voting not allowed here.\n\"" );
1486 return;
1487 }
1488
1489 if ( level.teamVoteTime[cs_offset] ) {
1490 trap_SendServerCommand( ent-g_entities, "print \"A team vote is already in progress.\n\"" );
1491 return;
1492 }
1493 if ( ent->client->pers.teamVoteCount >= MAX_VOTE_COUNT ) {
1494 trap_SendServerCommand( ent-g_entities, "print \"You have called the maximum number of team votes.\n\"" );
1495 return;
1496 }
1497 if ( ent->client->sess.sessionTeam == TEAM_SPECTATOR ) {
1498 trap_SendServerCommand( ent-g_entities, "print \"Not allowed to call a vote as spectator.\n\"" );
1499 return;
1500 }
1501
1502 // make sure it is a valid command to vote on
1503 trap_Argv( 1, arg1, sizeof( arg1 ) );
1504 arg2[0] = '\0';
1505 for ( i = 2; i < trap_Argc(); i++ ) {
1506 if (i > 2)
1507 strcat(arg2, " ");
1508 trap_Argv( i, &arg2[strlen(arg2)], sizeof( arg2 ) - strlen(arg2) );
1509 }
1510
1511 // check for command separators in arg2
1512 for( c = arg2; *c; ++c) {
1513 switch(*c) {
1514 case '\n':
1515 case '\r':
1516 case ';':
1517 trap_SendServerCommand( ent-g_entities, "print \"Invalid vote string.\n\"" );
1518 return;
1519 break;
1520 }
1521 }
1522
1523 if ( !Q_stricmp( arg1, "leader" ) ) {
1524 char netname[MAX_NETNAME], leader[MAX_NETNAME];
1525
1526 if ( !arg2[0] ) {
1527 i = ent->client->ps.clientNum;
1528 }
1529 else {
1530 // numeric values are just slot numbers
1531 for (i = 0; i < 3; i++) {
1532 if ( !arg2[i] || arg2[i] < '0' || arg2[i] > '9' )
1533 break;
1534 }
1535 if ( i >= 3 || !arg2[i]) {
1536 i = atoi( arg2 );
1537 if ( i < 0 || i >= level.maxclients ) {
1538 trap_SendServerCommand( ent-g_entities, va("print \"Bad client slot: %i\n\"", i) );
1539 return;
1540 }
1541
1542 if ( !g_entities[i].inuse ) {
1543 trap_SendServerCommand( ent-g_entities, va("print \"Client %i is not active\n\"", i) );
1544 return;
1545 }
1546 }
1547 else {
1548 Q_strncpyz(leader, arg2, sizeof(leader));
1549 Q_CleanStr(leader);
1550 for ( i = 0 ; i < level.maxclients ; i++ ) {
1551 if ( level.clients[i].pers.connected == CON_DISCONNECTED )
1552 continue;
1553 if (level.clients[i].sess.sessionTeam != team)
1554 continue;
1555 Q_strncpyz(netname, level.clients[i].pers.netname, sizeof(netname));
1556 Q_CleanStr(netname);
1557 if ( !Q_stricmp(netname, leader) ) {
1558 break;
1559 }
1560 }
1561 if ( i >= level.maxclients ) {
1562 trap_SendServerCommand( ent-g_entities, va("print \"%s is not a valid player on your team.\n\"", arg2) );
1563 return;
1564 }
1565 }
1566 }
1567 Com_sprintf(arg2, sizeof(arg2), "%d", i);
1568 } else {
1569 trap_SendServerCommand( ent-g_entities, "print \"Invalid vote string.\n\"" );
1570 trap_SendServerCommand( ent-g_entities, "print \"Team vote commands are: leader <player>.\n\"" );
1571 return;
1572 }
1573
1574 Com_sprintf( level.teamVoteString[cs_offset], sizeof( level.teamVoteString[cs_offset] ), "%s %s", arg1, arg2 );
1575
1576 for ( i = 0 ; i < level.maxclients ; i++ ) {
1577 if ( level.clients[i].pers.connected == CON_DISCONNECTED )
1578 continue;
1579 if (level.clients[i].sess.sessionTeam == team)
1580 trap_SendServerCommand( i, va("print \"%s called a team vote.\n\"", ent->client->pers.netname ) );
1581 }
1582
1583 // start the voting, the caller automatically votes yes
1584 level.teamVoteTime[cs_offset] = level.time;
1585 level.teamVoteYes[cs_offset] = 1;
1586 level.teamVoteNo[cs_offset] = 0;
1587
1588 for ( i = 0 ; i < level.maxclients ; i++ ) {
1589 if (level.clients[i].sess.sessionTeam == team)
1590 level.clients[i].ps.eFlags &= ~EF_TEAMVOTED;
1591 }
1592 ent->client->ps.eFlags |= EF_TEAMVOTED;
1593
1594 trap_SetConfigstring( CS_TEAMVOTE_TIME + cs_offset, va("%i", level.teamVoteTime[cs_offset] ) );
1595 trap_SetConfigstring( CS_TEAMVOTE_STRING + cs_offset, level.teamVoteString[cs_offset] );
1596 trap_SetConfigstring( CS_TEAMVOTE_YES + cs_offset, va("%i", level.teamVoteYes[cs_offset] ) );
1597 trap_SetConfigstring( CS_TEAMVOTE_NO + cs_offset, va("%i", level.teamVoteNo[cs_offset] ) );
1598 }
1599
1600 /*
1601 ==================
1602 Cmd_TeamVote_f
1603 ==================
1604 */
1605 void Cmd_TeamVote_f( gentity_t *ent ) {
1606 int team, cs_offset;
1607 char msg[64];
1608
1609 team = ent->client->sess.sessionTeam;
1610 if ( team == TEAM_RED )
1611 cs_offset = 0;
1612 else if ( team == TEAM_BLUE )
1613 cs_offset = 1;
1614 else
1615 return;
1616
1617 if ( !level.teamVoteTime[cs_offset] ) {
1618 trap_SendServerCommand( ent-g_entities, "print \"No team vote in progress.\n\"" );
1619 return;
1620 }
1621 if ( ent->client->ps.eFlags & EF_TEAMVOTED ) {
1622 trap_SendServerCommand( ent-g_entities, "print \"Team vote already cast.\n\"" );
1623 return;
1624 }
1625 if ( ent->client->sess.sessionTeam == TEAM_SPECTATOR ) {
1626 trap_SendServerCommand( ent-g_entities, "print \"Not allowed to vote as spectator.\n\"" );
1627 return;
1628 }
1629
1630 trap_SendServerCommand( ent-g_entities, "print \"Team vote cast.\n\"" );
1631
1632 ent->client->ps.eFlags |= EF_TEAMVOTED;
1633
1634 trap_Argv( 1, msg, sizeof( msg ) );
1635
1636 if ( tolower( msg[0] ) == 'y' || msg[0] == '1' ) {
1637 level.teamVoteYes[cs_offset]++;
1638 trap_SetConfigstring( CS_TEAMVOTE_YES + cs_offset, va("%i", level.teamVoteYes[cs_offset] ) );
1639 } else {
1640 level.teamVoteNo[cs_offset]++;
1641 trap_SetConfigstring( CS_TEAMVOTE_NO + cs_offset, va("%i", level.teamVoteNo[cs_offset] ) );
1642 }
1643
1644 // a majority will be determined in TeamCheckVote, which will also account
1645 // for players entering or leaving
1646 }
1647
1648
1649 /*
1650 =================
1651 Cmd_SetViewpos_f
1652 =================
1653 */
1654 void Cmd_SetViewpos_f( gentity_t *ent ) {
1655 vec3_t origin, angles;
1656 char buffer[MAX_TOKEN_CHARS];
1657 int i;
1658
1659 if ( !g_cheats.integer ) {
1660 trap_SendServerCommand( ent-g_entities, "print \"Cheats are not enabled on this server.\n\"");
1661 return;
1662 }
1663 if ( trap_Argc() != 5 ) {
1664 trap_SendServerCommand( ent-g_entities, "print \"usage: setviewpos x y z yaw\n\"");
1665 return;
1666 }
1667
1668 VectorClear( angles );
1669 for ( i = 0 ; i < 3 ; i++ ) {
1670 trap_Argv( i + 1, buffer, sizeof( buffer ) );
1671 origin[i] = atof( buffer );
1672 }
1673
1674 trap_Argv( 4, buffer, sizeof( buffer ) );
1675 angles[YAW] = atof( buffer );
1676
1677 TeleportPlayer( ent, origin, angles );
1678 }
1679
1680
1681
1682 /*
1683 =================
1684 Cmd_Stats_f
1685 =================
1686 */
1687 void Cmd_Stats_f( gentity_t *ent ) {
1688 /*
1689 int max, n, i;
1690
1691 max = trap_AAS_PointReachabilityAreaIndex( NULL );
1692
1693 n = 0;
1694 for ( i = 0; i < max; i++ ) {
1695 if ( ent->client->areabits[i >> 3] & (1 << (i & 7)) )
1696 n++;
1697 }
1698
1699 //trap_SendServerCommand( ent-g_entities, va("print \"visited %d of %d areas\n\"", n, max));
1700 trap_SendServerCommand( ent-g_entities, va("print \"%d%% level coverage\n\"", n * 100 / max));
1701 */
1702 }
1703
1704 /*
1705 =================
1706 ClientCommand
1707 =================
1708 */
1709 void ClientCommand( int clientNum ) {
1710 gentity_t *ent;
1711 char cmd[MAX_TOKEN_CHARS];
1712
1713 ent = g_entities + clientNum;
1714 if (!ent->client || ent->client->pers.connected != CON_CONNECTED) {
1715 if (ent->client && ent->client->pers.localClient) {
1716 // Handle early team command sent by UI when starting a local
1717 // team play game.
1718 trap_Argv( 0, cmd, sizeof( cmd ) );
1719 if (Q_stricmp (cmd, "team") == 0) {
1720 Cmd_Team_f (ent);
1721 }
1722 }
1723 return; // not fully in game yet
1724 }
1725
1726
1727 trap_Argv( 0, cmd, sizeof( cmd ) );
1728
1729 if (Q_stricmp (cmd, "say") == 0) {
1730 Cmd_Say_f (ent, SAY_ALL, qfalse);
1731 return;
1732 }
1733 if (Q_stricmp (cmd, "say_team") == 0) {
1734 Cmd_Say_f (ent, SAY_TEAM, qfalse);
1735 return;
1736 }
1737 if (Q_stricmp (cmd, "tell") == 0) {
1738 Cmd_Tell_f ( ent );
1739 return;
1740 }
1741 #ifdef MISSIONPACK
1742 if (Q_stricmp (cmd, "vsay") == 0) {
1743 Cmd_Voice_f (ent, SAY_ALL, qfalse, qfalse);
1744 return;
1745 }
1746 if (Q_stricmp (cmd, "vsay_team") == 0) {
1747 Cmd_Voice_f (ent, SAY_TEAM, qfalse, qfalse);
1748 return;
1749 }
1750 if (Q_stricmp (cmd, "vtell") == 0) {
1751 Cmd_VoiceTell_f ( ent, qfalse );
1752 return;
1753 }
1754 if (Q_stricmp (cmd, "vosay") == 0) {
1755 Cmd_Voice_f (ent, SAY_ALL, qfalse, qtrue);
1756 return;
1757 }
1758 if (Q_stricmp (cmd, "vosay_team") == 0) {
1759 Cmd_Voice_f (ent, SAY_TEAM, qfalse, qtrue);
1760 return;
1761 }
1762 if (Q_stricmp (cmd, "votell") == 0) {
1763 Cmd_VoiceTell_f ( ent, qtrue );
1764 return;
1765 }
1766 if (Q_stricmp (cmd, "vtaunt") == 0) {
1767 Cmd_VoiceTaunt_f ( ent );
1768 return;
1769 }
1770 #endif
1771 if (Q_stricmp (cmd, "score") == 0) {
1772 Cmd_Score_f (ent);
1773 return;
1774 }
1775
1776 // ignore all other commands when at intermission
1777 if (level.intermissiontime) {
1778 Cmd_Say_f (ent, qfalse, qtrue);
1779 return;
1780 }
1781
1782 if (Q_stricmp (cmd, "give") == 0)
1783 Cmd_Give_f (ent);
1784 else if (Q_stricmp (cmd, "god") == 0)
1785 Cmd_God_f (ent);
1786 else if (Q_stricmp (cmd, "notarget") == 0)
1787 Cmd_Notarget_f (ent);
1788 else if (Q_stricmp (cmd, "noclip") == 0)
1789 Cmd_Noclip_f (ent);
1790 else if (Q_stricmp (cmd, "kill") == 0)
1791 Cmd_Kill_f (ent);
1792 else if (Q_stricmp (cmd, "teamtask") == 0)
1793 Cmd_TeamTask_f (ent);
1794 else if (Q_stricmp (cmd, "levelshot") == 0)
1795 Cmd_LevelShot_f (ent);
1796 else if (Q_stricmp (cmd, "follow") == 0)
1797 Cmd_Follow_f (ent);
1798 else if (Q_stricmp (cmd, "follownext") == 0)
1799 Cmd_FollowCycle_f (ent, 1);
1800 else if (Q_stricmp (cmd, "followprev") == 0)
1801 Cmd_FollowCycle_f (ent, -1);
1802 else if (Q_stricmp (cmd, "team") == 0)
1803 Cmd_Team_f (ent);
1804 else if (Q_stricmp (cmd, "where") == 0)
1805 Cmd_Where_f (ent);
1806 else if (Q_stricmp (cmd, "callvote") == 0)
1807 Cmd_CallVote_f (ent);
1808 else if (Q_stricmp (cmd, "vote") == 0)
1809 Cmd_Vote_f (ent);
1810 else if (Q_stricmp (cmd, "callteamvote") == 0)
1811 Cmd_CallTeamVote_f (ent);
1812 else if (Q_stricmp (cmd, "teamvote") == 0)
1813 Cmd_TeamVote_f (ent);
1814 else if (Q_stricmp (cmd, "gc") == 0)
1815 Cmd_GameCommand_f( ent );
1816 else if (Q_stricmp (cmd, "setviewpos") == 0)
1817 Cmd_SetViewpos_f( ent );
1818 else if (Q_stricmp (cmd, "stats") == 0)
1819 Cmd_Stats_f( ent );
1820 else
1821 trap_SendServerCommand( clientNum, va("print \"unknown cmd %s\n\"", cmd ) );
1822 }