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