Debian Codegraph @

code/cgame/cg_servercmds.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 // cg_servercmds.c -- reliably sequenced text commands sent by the server
24 // these are processed at snapshot transition time, so there will definitely
25 // be a valid snapshot this frame
26
27 #include "cg_local.h"
28 #ifdef MISSIONPACK
29 #include "../../ui/menudef.h"
30
31 typedef struct {
32 const char *order;
33 int taskNum;
34 } orderTask_t;
35
36 static const orderTask_t validOrders[] = {
37 { VOICECHAT_GETFLAG, TEAMTASK_OFFENSE },
38 { VOICECHAT_OFFENSE, TEAMTASK_OFFENSE },
39 { VOICECHAT_DEFEND, TEAMTASK_DEFENSE },
40 { VOICECHAT_DEFENDFLAG, TEAMTASK_DEFENSE },
41 { VOICECHAT_PATROL, TEAMTASK_PATROL },
42 { VOICECHAT_CAMP, TEAMTASK_CAMP },
43 { VOICECHAT_FOLLOWME, TEAMTASK_FOLLOW },
44 { VOICECHAT_RETURNFLAG, TEAMTASK_RETRIEVE },
45 { VOICECHAT_FOLLOWFLAGCARRIER, TEAMTASK_ESCORT }
46 };
47
48 static const int numValidOrders = ARRAY_LEN(validOrders);
49
50 static int CG_ValidOrder(const char *p) {
51 int i;
52 for (i = 0; i < numValidOrders; i++) {
53 if (Q_stricmp(p, validOrders[i].order) == 0) {
54 return validOrders[i].taskNum;
55 }
56 }
57 return -1;
58 }
59 #endif
60
61 /*
62 =================
63 CG_ParseScores
64
65 =================
66 */
67 static void CG_ParseScores( void ) {
68 int i, powerups;
69
70 cg.numScores = atoi( CG_Argv( 1 ) );
71 if ( cg.numScores > MAX_CLIENTS ) {
72 cg.numScores = MAX_CLIENTS;
73 }
74
75 cg.teamScores[0] = atoi( CG_Argv( 2 ) );
76 cg.teamScores[1] = atoi( CG_Argv( 3 ) );
77
78 memset( cg.scores, 0, sizeof( cg.scores ) );
79 for ( i = 0 ; i < cg.numScores ; i++ ) {
80 //
81 cg.scores[i].client = atoi( CG_Argv( i * 14 + 4 ) );
82 cg.scores[i].score = atoi( CG_Argv( i * 14 + 5 ) );
83 cg.scores[i].ping = atoi( CG_Argv( i * 14 + 6 ) );
84 cg.scores[i].time = atoi( CG_Argv( i * 14 + 7 ) );
85 cg.scores[i].scoreFlags = atoi( CG_Argv( i * 14 + 8 ) );
86 powerups = atoi( CG_Argv( i * 14 + 9 ) );
87 cg.scores[i].accuracy = atoi(CG_Argv(i * 14 + 10));
88 cg.scores[i].impressiveCount = atoi(CG_Argv(i * 14 + 11));
89 cg.scores[i].excellentCount = atoi(CG_Argv(i * 14 + 12));
90 cg.scores[i].guantletCount = atoi(CG_Argv(i * 14 + 13));
91 cg.scores[i].defendCount = atoi(CG_Argv(i * 14 + 14));
92 cg.scores[i].assistCount = atoi(CG_Argv(i * 14 + 15));
93 cg.scores[i].perfect = atoi(CG_Argv(i * 14 + 16));
94 cg.scores[i].captures = atoi(CG_Argv(i * 14 + 17));
95
96 if ( cg.scores[i].client < 0 || cg.scores[i].client >= MAX_CLIENTS ) {
97 cg.scores[i].client = 0;
98 }
99 cgs.clientinfo[ cg.scores[i].client ].score = cg.scores[i].score;
100 cgs.clientinfo[ cg.scores[i].client ].powerups = powerups;
101
102 cg.scores[i].team = cgs.clientinfo[cg.scores[i].client].team;
103 }
104 #ifdef MISSIONPACK
105 CG_SetScoreSelection(NULL);
106 #endif
107
108 }
109
110 /*
111 =================
112 CG_ParseTeamInfo
113
114 =================
115 */
116 static void CG_ParseTeamInfo( void ) {
117 int i;
118 int client;
119
120 numSortedTeamPlayers = atoi( CG_Argv( 1 ) );
121 if( numSortedTeamPlayers < 0 || numSortedTeamPlayers > TEAM_MAXOVERLAY )
122 {
123 CG_Error( "CG_ParseTeamInfo: numSortedTeamPlayers out of range (%d)",
124 numSortedTeamPlayers );
125 return;
126 }
127
128 for ( i = 0 ; i < numSortedTeamPlayers ; i++ ) {
129 client = atoi( CG_Argv( i * 6 + 2 ) );
130 if( client < 0 || client >= MAX_CLIENTS )
131 {
132 CG_Error( "CG_ParseTeamInfo: bad client number: %d", client );
133 return;
134 }
135
136 sortedTeamPlayers[i] = client;
137
138 cgs.clientinfo[ client ].location = atoi( CG_Argv( i * 6 + 3 ) );
139 cgs.clientinfo[ client ].health = atoi( CG_Argv( i * 6 + 4 ) );
140 cgs.clientinfo[ client ].armor = atoi( CG_Argv( i * 6 + 5 ) );
141 cgs.clientinfo[ client ].curWeapon = atoi( CG_Argv( i * 6 + 6 ) );
142 cgs.clientinfo[ client ].powerups = atoi( CG_Argv( i * 6 + 7 ) );
143 }
144 }
145
146
147 /*
148 ================
149 CG_ParseServerinfo
150
151 This is called explicitly when the gamestate is first received,
152 and whenever the server updates any serverinfo flagged cvars
153 ================
154 */
155 void CG_ParseServerinfo( void ) {
156 const char *info;
157 char *mapname;
158
159 info = CG_ConfigString( CS_SERVERINFO );
160 cgs.gametype = atoi( Info_ValueForKey( info, "g_gametype" ) );
161 trap_Cvar_Set("g_gametype", va("%i", cgs.gametype));
162 cgs.dmflags = atoi( Info_ValueForKey( info, "dmflags" ) );
163 cgs.teamflags = atoi( Info_ValueForKey( info, "teamflags" ) );
164 cgs.fraglimit = atoi( Info_ValueForKey( info, "fraglimit" ) );
165 cgs.capturelimit = atoi( Info_ValueForKey( info, "capturelimit" ) );
166 cgs.timelimit = atoi( Info_ValueForKey( info, "timelimit" ) );
167 cgs.maxclients = atoi( Info_ValueForKey( info, "sv_maxclients" ) );
168 mapname = Info_ValueForKey( info, "mapname" );
169 Com_sprintf( cgs.mapname, sizeof( cgs.mapname ), "maps/%s.bsp", mapname );
170 Q_strncpyz( cgs.redTeam, Info_ValueForKey( info, "g_redTeam" ), sizeof(cgs.redTeam) );
171 trap_Cvar_Set("g_redTeam", cgs.redTeam);
172 Q_strncpyz( cgs.blueTeam, Info_ValueForKey( info, "g_blueTeam" ), sizeof(cgs.blueTeam) );
173 trap_Cvar_Set("g_blueTeam", cgs.blueTeam);
174 }
175
176 /*
177 ==================
178 CG_ParseWarmup
179 ==================
180 */
181 static void CG_ParseWarmup( void ) {
182 const char *info;
183 int warmup;
184
185 info = CG_ConfigString( CS_WARMUP );
186
187 warmup = atoi( info );
188 cg.warmupCount = -1;
189
190 if ( warmup == 0 && cg.warmup ) {
191
192 } else if ( warmup > 0 && cg.warmup <= 0 ) {
193 #ifdef MISSIONPACK
194 if (cgs.gametype >= GT_CTF && cgs.gametype <= GT_HARVESTER) {
195 trap_S_StartLocalSound( cgs.media.countPrepareTeamSound, CHAN_ANNOUNCER );
196 } else
197 #endif
198 {
199 trap_S_StartLocalSound( cgs.media.countPrepareSound, CHAN_ANNOUNCER );
200 }
201 }
202
203 cg.warmup = warmup;
204 }
205
206 /*
207 ================
208 CG_SetConfigValues
209
210 Called on load to set the initial values from configure strings
211 ================
212 */
213 void CG_SetConfigValues( void ) {
214 const char *s;
215
216 cgs.scores1 = atoi( CG_ConfigString( CS_SCORES1 ) );
217 cgs.scores2 = atoi( CG_ConfigString( CS_SCORES2 ) );
218 cgs.levelStartTime = atoi( CG_ConfigString( CS_LEVEL_START_TIME ) );
219 if( cgs.gametype == GT_CTF ) {
220 s = CG_ConfigString( CS_FLAGSTATUS );
221 cgs.redflag = s[0] - '0';
222 cgs.blueflag = s[1] - '0';
223 }
224 #ifdef MISSIONPACK
225 else if( cgs.gametype == GT_1FCTF ) {
226 s = CG_ConfigString( CS_FLAGSTATUS );
227 cgs.flagStatus = s[0] - '0';
228 }
229 #endif
230 cg.warmup = atoi( CG_ConfigString( CS_WARMUP ) );
231 }
232
233 /*
234 =====================
235 CG_ShaderStateChanged
236 =====================
237 */
238 void CG_ShaderStateChanged(void) {
239 char originalShader[MAX_QPATH];
240 char newShader[MAX_QPATH];
241 char timeOffset[16];
242 const char *o;
243 char *n,*t;
244 int length;
245
246 o = CG_ConfigString( CS_SHADERSTATE );
247 while (o && *o) {
248 n = strstr(o, "=");
249 if (n && *n) {
250 length = n-o+1;
251 if (length > sizeof(originalShader)) {
252 length = sizeof(originalShader);
253 }
254 Q_strncpyz(originalShader, o, length);
255 n++;
256 t = strstr(n, ":");
257 if (t && *t) {
258 length = t-n+1;
259 if (length > sizeof(newShader)) {
260 length = sizeof(newShader);
261 }
262 Q_strncpyz(newShader, n, length);
263 } else {
264 break;
265 }
266 t++;
267 o = strstr(t, "@");
268 if (o) {
269 length = o-t+1;
270 if (length > sizeof(timeOffset)) {
271 length = sizeof(timeOffset);
272 }
273 Q_strncpyz(timeOffset, t, length);
274 o++;
275 trap_R_RemapShader( originalShader, newShader, timeOffset );
276 }
277 } else {
278 break;
279 }
280 }
281 }
282
283 /*
284 ================
285 CG_ConfigStringModified
286
287 ================
288 */
289 static void CG_ConfigStringModified( void ) {
290 const char *str;
291 int num;
292
293 num = atoi( CG_Argv( 1 ) );
294
295 // get the gamestate from the client system, which will have the
296 // new configstring already integrated
297 trap_GetGameState( &cgs.gameState );
298
299 // look up the individual string that was modified
300 str = CG_ConfigString( num );
301
302 // do something with it if necessary
303 if ( num == CS_MUSIC ) {
304 CG_StartMusic();
305 } else if ( num == CS_SERVERINFO ) {
306 CG_ParseServerinfo();
307 } else if ( num == CS_WARMUP ) {
308 CG_ParseWarmup();
309 } else if ( num == CS_SCORES1 ) {
310 cgs.scores1 = atoi( str );
311 } else if ( num == CS_SCORES2 ) {
312 cgs.scores2 = atoi( str );
313 } else if ( num == CS_LEVEL_START_TIME ) {
314 cgs.levelStartTime = atoi( str );
315 } else if ( num == CS_VOTE_TIME ) {
316 cgs.voteTime = atoi( str );
317 cgs.voteModified = qtrue;
318 } else if ( num == CS_VOTE_YES ) {
319 cgs.voteYes = atoi( str );
320 cgs.voteModified = qtrue;
321 } else if ( num == CS_VOTE_NO ) {
322 cgs.voteNo = atoi( str );
323 cgs.voteModified = qtrue;
324 } else if ( num == CS_VOTE_STRING ) {
325 Q_strncpyz( cgs.voteString, str, sizeof( cgs.voteString ) );
326 #ifdef MISSIONPACK
327 trap_S_StartLocalSound( cgs.media.voteNow, CHAN_ANNOUNCER );
328 #endif //MISSIONPACK
329 } else if ( num >= CS_TEAMVOTE_TIME && num <= CS_TEAMVOTE_TIME + 1) {
330 cgs.teamVoteTime[num-CS_TEAMVOTE_TIME] = atoi( str );
331 cgs.teamVoteModified[num-CS_TEAMVOTE_TIME] = qtrue;
332 } else if ( num >= CS_TEAMVOTE_YES && num <= CS_TEAMVOTE_YES + 1) {
333 cgs.teamVoteYes[num-CS_TEAMVOTE_YES] = atoi( str );
334 cgs.teamVoteModified[num-CS_TEAMVOTE_YES] = qtrue;
335 } else if ( num >= CS_TEAMVOTE_NO && num <= CS_TEAMVOTE_NO + 1) {
336 cgs.teamVoteNo[num-CS_TEAMVOTE_NO] = atoi( str );
337 cgs.teamVoteModified[num-CS_TEAMVOTE_NO] = qtrue;
338 } else if ( num >= CS_TEAMVOTE_STRING && num <= CS_TEAMVOTE_STRING + 1) {
339 Q_strncpyz( cgs.teamVoteString[num-CS_TEAMVOTE_STRING], str, sizeof( cgs.teamVoteString[0] ) );
340 #ifdef MISSIONPACK
341 trap_S_StartLocalSound( cgs.media.voteNow, CHAN_ANNOUNCER );
342 #endif
343 } else if ( num == CS_INTERMISSION ) {
344 cg.intermissionStarted = atoi( str );
345 } else if ( num >= CS_MODELS && num < CS_MODELS+MAX_MODELS ) {
346 cgs.gameModels[ num-CS_MODELS ] = trap_R_RegisterModel( str );
347 } else if ( num >= CS_SOUNDS && num < CS_SOUNDS+MAX_SOUNDS ) {
348 if ( str[0] != '*' ) { // player specific sounds don't register here
349 cgs.gameSounds[ num-CS_SOUNDS] = trap_S_RegisterSound( str, qfalse );
350 }
351 } else if ( num >= CS_PLAYERS && num < CS_PLAYERS+MAX_CLIENTS ) {
352 CG_NewClientInfo( num - CS_PLAYERS );
353 CG_BuildSpectatorString();
354 } else if ( num == CS_FLAGSTATUS ) {
355 if( cgs.gametype == GT_CTF ) {
356 // format is rb where its red/blue, 0 is at base, 1 is taken, 2 is dropped
357 cgs.redflag = str[0] - '0';
358 cgs.blueflag = str[1] - '0';
359 }
360 #ifdef MISSIONPACK
361 else if( cgs.gametype == GT_1FCTF ) {
362 cgs.flagStatus = str[0] - '0';
363 }
364 #endif
365 }
366 else if ( num == CS_SHADERSTATE ) {
367 CG_ShaderStateChanged();
368 }
369
370 }
371
372
373 /*
374 =======================
375 CG_AddToTeamChat
376
377 =======================
378 */
379 static void CG_AddToTeamChat( const char *str ) {
380 int len;
381 char *p, *ls;
382 int lastcolor;
383 int chatHeight;
384
385 if (cg_teamChatHeight.integer < TEAMCHAT_HEIGHT) {
386 chatHeight = cg_teamChatHeight.integer;
387 } else {
388 chatHeight = TEAMCHAT_HEIGHT;
389 }
390
391 if (chatHeight <= 0 || cg_teamChatTime.integer <= 0) {
392 // team chat disabled, dump into normal chat
393 cgs.teamChatPos = cgs.teamLastChatPos = 0;
394 return;
395 }
396
397 len = 0;
398
399 p = cgs.teamChatMsgs[cgs.teamChatPos % chatHeight];
400 *p = 0;
401
402 lastcolor = '7';
403
404 ls = NULL;
405 while (*str) {
406 if (len > TEAMCHAT_WIDTH - 1) {
407 if (ls) {
408 str -= (p - ls);
409 str++;
410 p -= (p - ls);
411 }
412 *p = 0;
413
414 cgs.teamChatMsgTimes[cgs.teamChatPos % chatHeight] = cg.time;
415
416 cgs.teamChatPos++;
417 p = cgs.teamChatMsgs[cgs.teamChatPos % chatHeight];
418 *p = 0;
419 *p++ = Q_COLOR_ESCAPE;
420 *p++ = lastcolor;
421 len = 0;
422 ls = NULL;
423 }
424
425 if ( Q_IsColorString( str ) ) {
426 *p++ = *str++;
427 lastcolor = *str;
428 *p++ = *str++;
429 continue;
430 }
431 if (*str == ' ') {
432 ls = p;
433 }
434 *p++ = *str++;
435 len++;
436 }
437 *p = 0;
438
439 cgs.teamChatMsgTimes[cgs.teamChatPos % chatHeight] = cg.time;
440 cgs.teamChatPos++;
441
442 if (cgs.teamChatPos - cgs.teamLastChatPos > chatHeight)
443 cgs.teamLastChatPos = cgs.teamChatPos - chatHeight;
444 }
445
446 /*
447 ===============
448 CG_MapRestart
449
450 The server has issued a map_restart, so the next snapshot
451 is completely new and should not be interpolated to.
452
453 A tournement restart will clear everything, but doesn't
454 require a reload of all the media
455 ===============
456 */
457 static void CG_MapRestart( void ) {
458 if ( cg_showmiss.integer ) {
459 CG_Printf( "CG_MapRestart\n" );
460 }
461
462 CG_InitLocalEntities();
463 CG_InitMarkPolys();
464 CG_ClearParticles ();
465
466 // make sure the "3 frags left" warnings play again
467 cg.fraglimitWarnings = 0;
468
469 cg.timelimitWarnings = 0;
470 cg.rewardTime = 0;
471 cg.rewardStack = 0;
472 cg.intermissionStarted = qfalse;
473 cg.levelShot = qfalse;
474
475 cgs.voteTime = 0;
476
477 cg.mapRestart = qtrue;
478
479 CG_StartMusic();
480
481 trap_S_ClearLoopingSounds(qtrue);
482
483 // we really should clear more parts of cg here and stop sounds
484
485 // play the "fight" sound if this is a restart without warmup
486 if ( cg.warmup == 0 /* && cgs.gametype == GT_TOURNAMENT */) {
487 trap_S_StartLocalSound( cgs.media.countFightSound, CHAN_ANNOUNCER );
488 CG_CenterPrint( "FIGHT!", 120, GIANTCHAR_WIDTH*2 );
489 }
490 #ifdef MISSIONPACK
491 if (cg_singlePlayerActive.integer) {
492 trap_Cvar_Set("ui_matchStartTime", va("%i", cg.time));
493 if (cg_recordSPDemo.integer && *cg_recordSPDemoName.string) {
494 trap_SendConsoleCommand(va("set g_synchronousclients 1 ; record %s \n", cg_recordSPDemoName.string));
495 }
496 }
497 #endif
498 trap_Cvar_Set("cg_thirdPerson", "0");
499 }
500
501 #ifdef MISSIONPACK
502
503 #define MAX_VOICEFILESIZE 16384
504 #define MAX_VOICEFILES 8
505 #define MAX_VOICECHATS 64
506 #define MAX_VOICESOUNDS 64
507 #define MAX_CHATSIZE 64
508 #define MAX_HEADMODELS 64
509
510 typedef struct voiceChat_s
511 {
512 char id[64];
513 int numSounds;
514 sfxHandle_t sounds[MAX_VOICESOUNDS];
515 char chats[MAX_VOICESOUNDS][MAX_CHATSIZE];
516 } voiceChat_t;
517
518 typedef struct voiceChatList_s
519 {
520 char name[64];
521 int gender;
522 int numVoiceChats;
523 voiceChat_t voiceChats[MAX_VOICECHATS];
524 } voiceChatList_t;
525
526 typedef struct headModelVoiceChat_s
527 {
528 char headmodel[64];
529 int voiceChatNum;
530 } headModelVoiceChat_t;
531
532 voiceChatList_t voiceChatLists[MAX_VOICEFILES];
533 headModelVoiceChat_t headModelVoiceChat[MAX_HEADMODELS];
534
535 /*
536 =================
537 CG_ParseVoiceChats
538 =================
539 */
540 int CG_ParseVoiceChats( const char *filename, voiceChatList_t *voiceChatList, int maxVoiceChats ) {
541 int len, i;
542 fileHandle_t f;
543 char buf[MAX_VOICEFILESIZE];
544 char **p, *ptr;
545 char *token;
546 voiceChat_t *voiceChats;
547 qboolean compress;
548 sfxHandle_t sound;
549
550 compress = qtrue;
551 if (cg_buildScript.integer) {
552 compress = qfalse;
553 }
554
555 len = trap_FS_FOpenFile( filename, &f, FS_READ );
556 if ( !f ) {
557 trap_Print( va( S_COLOR_RED "voice chat file not found: %s\n", filename ) );
558 return qfalse;
559 }
560 if ( len >= MAX_VOICEFILESIZE ) {
561 trap_Print( va( S_COLOR_RED "voice chat file too large: %s is %i, max allowed is %i\n", filename, len, MAX_VOICEFILESIZE ) );
562 trap_FS_FCloseFile( f );
563 return qfalse;
564 }
565
566 trap_FS_Read( buf, len, f );
567 buf[len] = 0;
568 trap_FS_FCloseFile( f );
569
570 ptr = buf;
571 p = &ptr;
572
573 Com_sprintf(voiceChatList->name, sizeof(voiceChatList->name), "%s", filename);
574 voiceChats = voiceChatList->voiceChats;
575 for ( i = 0; i < maxVoiceChats; i++ ) {
576 voiceChats[i].id[0] = 0;
577 }
578 token = COM_ParseExt(p, qtrue);
579 if (!token[0]) {
580 return qtrue;
581 }
582 if (!Q_stricmp(token, "female")) {
583 voiceChatList->gender = GENDER_FEMALE;
584 }
585 else if (!Q_stricmp(token, "male")) {
586 voiceChatList->gender = GENDER_MALE;
587 }
588 else if (!Q_stricmp(token, "neuter")) {
589 voiceChatList->gender = GENDER_NEUTER;
590 }
591 else {
592 trap_Print( va( S_COLOR_RED "expected gender not found in voice chat file: %s\n", filename ) );
593 return qfalse;
594 }
595
596 voiceChatList->numVoiceChats = 0;
597 while ( 1 ) {
598 token = COM_ParseExt(p, qtrue);
599 if (!token[0]) {
600 return qtrue;
601 }
602 Com_sprintf(voiceChats[voiceChatList->numVoiceChats].id, sizeof( voiceChats[voiceChatList->numVoiceChats].id ), "%s", token);
603 token = COM_ParseExt(p, qtrue);
604 if (Q_stricmp(token, "{")) {
605 trap_Print( va( S_COLOR_RED "expected { found %s in voice chat file: %s\n", token, filename ) );
606 return qfalse;
607 }
608 voiceChats[voiceChatList->numVoiceChats].numSounds = 0;
609 while(1) {
610 token = COM_ParseExt(p, qtrue);
611 if (!token[0]) {
612 return qtrue;
613 }
614 if (!Q_stricmp(token, "}"))
615 break;
616 sound = trap_S_RegisterSound( token, compress );
617 voiceChats[voiceChatList->numVoiceChats].sounds[voiceChats[voiceChatList->numVoiceChats].numSounds] = sound;
618 token = COM_ParseExt(p, qtrue);
619 if (!token[0]) {
620 return qtrue;
621 }
622 Com_sprintf(voiceChats[voiceChatList->numVoiceChats].chats[
623 voiceChats[voiceChatList->numVoiceChats].numSounds], MAX_CHATSIZE, "%s", token);
624 if (sound)
625 voiceChats[voiceChatList->numVoiceChats].numSounds++;
626 if (voiceChats[voiceChatList->numVoiceChats].numSounds >= MAX_VOICESOUNDS)
627 break;
628 }
629 voiceChatList->numVoiceChats++;
630 if (voiceChatList->numVoiceChats >= maxVoiceChats)
631 return qtrue;
632 }
633 return qtrue;
634 }
635
636 /*
637 =================
638 CG_LoadVoiceChats
639 =================
640 */
641 void CG_LoadVoiceChats( void ) {
642 int size;
643
644 size = trap_MemoryRemaining();
645 CG_ParseVoiceChats( "scripts/female1.voice", &voiceChatLists[0], MAX_VOICECHATS );
646 CG_ParseVoiceChats( "scripts/female2.voice", &voiceChatLists[1], MAX_VOICECHATS );
647 CG_ParseVoiceChats( "scripts/female3.voice", &voiceChatLists[2], MAX_VOICECHATS );
648 CG_ParseVoiceChats( "scripts/male1.voice", &voiceChatLists[3], MAX_VOICECHATS );
649 CG_ParseVoiceChats( "scripts/male2.voice", &voiceChatLists[4], MAX_VOICECHATS );
650 CG_ParseVoiceChats( "scripts/male3.voice", &voiceChatLists[5], MAX_VOICECHATS );
651 CG_ParseVoiceChats( "scripts/male4.voice", &voiceChatLists[6], MAX_VOICECHATS );
652 CG_ParseVoiceChats( "scripts/male5.voice", &voiceChatLists[7], MAX_VOICECHATS );
653 CG_Printf("voice chat memory size = %d\n", size - trap_MemoryRemaining());
654 }
655
656 /*
657 =================
658 CG_HeadModelVoiceChats
659 =================
660 */
661 int CG_HeadModelVoiceChats( char *filename ) {
662 int len, i;
663 fileHandle_t f;
664 char buf[MAX_VOICEFILESIZE];
665 char **p, *ptr;
666 char *token;
667
668 len = trap_FS_FOpenFile( filename, &f, FS_READ );
669 if ( !f ) {
670 //trap_Print( va( "voice chat file not found: %s\n", filename ) );
671 return -1;
672 }
673 if ( len >= MAX_VOICEFILESIZE ) {
674 trap_Print( va( S_COLOR_RED "voice chat file too large: %s is %i, max allowed is %i\n", filename, len, MAX_VOICEFILESIZE ) );
675 trap_FS_FCloseFile( f );
676 return -1;
677 }
678
679 trap_FS_Read( buf, len, f );
680 buf[len] = 0;
681 trap_FS_FCloseFile( f );
682
683 ptr = buf;
684 p = &ptr;
685
686 token = COM_ParseExt(p, qtrue);
687 if ( !token[0] ) {
688 return -1;
689 }
690
691 for ( i = 0; i < MAX_VOICEFILES; i++ ) {
692 if ( !Q_stricmp(token, voiceChatLists[i].name) ) {
693 return i;
694 }
695 }
696
697 //FIXME: maybe try to load the .voice file which name is stored in token?
698
699 return -1;
700 }
701
702
703 /*
704 =================
705 CG_GetVoiceChat
706 =================
707 */
708 int CG_GetVoiceChat( voiceChatList_t *voiceChatList, const char *id, sfxHandle_t *snd, char **chat) {
709 int i, rnd;
710
711 for ( i = 0; i < voiceChatList->numVoiceChats; i++ ) {
712 if ( !Q_stricmp( id, voiceChatList->voiceChats[i].id ) ) {
713 rnd = random() * voiceChatList->voiceChats[i].numSounds;
714 *snd = voiceChatList->voiceChats[i].sounds[rnd];
715 *chat = voiceChatList->voiceChats[i].chats[rnd];
716 return qtrue;
717 }
718 }
719 return qfalse;
720 }
721
722 /*
723 =================
724 CG_VoiceChatListForClient
725 =================
726 */
727 voiceChatList_t *CG_VoiceChatListForClient( int clientNum ) {
728 clientInfo_t *ci;
729 int voiceChatNum, i, j, k, gender;
730 char filename[MAX_QPATH], headModelName[MAX_QPATH];
731
732 if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) {
733 clientNum = 0;
734 }
735 ci = &cgs.clientinfo[ clientNum ];
736
737 for ( k = 0; k < 2; k++ ) {
738 if ( k == 0 ) {
739 if (ci->headModelName[0] == '*') {
740 Com_sprintf( headModelName, sizeof(headModelName), "%s/%s", ci->headModelName+1, ci->headSkinName );
741 }
742 else {
743 Com_sprintf( headModelName, sizeof(headModelName), "%s/%s", ci->headModelName, ci->headSkinName );
744 }
745 }
746 else {
747 if (ci->headModelName[0] == '*') {
748 Com_sprintf( headModelName, sizeof(headModelName), "%s", ci->headModelName+1 );
749 }
750 else {
751 Com_sprintf( headModelName, sizeof(headModelName), "%s", ci->headModelName );
752 }
753 }
754 // find the voice file for the head model the client uses
755 for ( i = 0; i < MAX_HEADMODELS; i++ ) {
756 if (!Q_stricmp(headModelVoiceChat[i].headmodel, headModelName)) {
757 break;
758 }
759 }
760 if (i < MAX_HEADMODELS) {
761 return &voiceChatLists[headModelVoiceChat[i].voiceChatNum];
762 }
763 // find a <headmodelname>.vc file
764 for ( i = 0; i < MAX_HEADMODELS; i++ ) {
765 if (!strlen(headModelVoiceChat[i].headmodel)) {
766 Com_sprintf(filename, sizeof(filename), "scripts/%s.vc", headModelName);
767 voiceChatNum = CG_HeadModelVoiceChats(filename);
768 if (voiceChatNum == -1)
769 break;
770 Com_sprintf(headModelVoiceChat[i].headmodel, sizeof ( headModelVoiceChat[i].headmodel ),
771 "%s", headModelName);
772 headModelVoiceChat[i].voiceChatNum = voiceChatNum;
773 return &voiceChatLists[headModelVoiceChat[i].voiceChatNum];
774 }
775 }
776 }
777 gender = ci->gender;
778 for (k = 0; k < 2; k++) {
779 // just pick the first with the right gender
780 for ( i = 0; i < MAX_VOICEFILES; i++ ) {
781 if (strlen(voiceChatLists[i].name)) {
782 if (voiceChatLists[i].gender == gender) {
783 // store this head model with voice chat for future reference
784 for ( j = 0; j < MAX_HEADMODELS; j++ ) {
785 if (!strlen(headModelVoiceChat[j].headmodel)) {
786 Com_sprintf(headModelVoiceChat[j].headmodel, sizeof ( headModelVoiceChat[j].headmodel ),
787 "%s", headModelName);
788 headModelVoiceChat[j].voiceChatNum = i;
789 break;
790 }
791 }
792 return &voiceChatLists[i];
793 }
794 }
795 }
796 // fall back to male gender because we don't have neuter in the mission pack
797 if (gender == GENDER_MALE)
798 break;
799 gender = GENDER_MALE;
800 }
801 // store this head model with voice chat for future reference
802 for ( j = 0; j < MAX_HEADMODELS; j++ ) {
803 if (!strlen(headModelVoiceChat[j].headmodel)) {
804 Com_sprintf(headModelVoiceChat[j].headmodel, sizeof ( headModelVoiceChat[j].headmodel ),
805 "%s", headModelName);
806 headModelVoiceChat[j].voiceChatNum = 0;
807 break;
808 }
809 }
810 // just return the first voice chat list
811 return &voiceChatLists[0];
812 }
813
814 #define MAX_VOICECHATBUFFER 32
815
816 typedef struct bufferedVoiceChat_s
817 {
818 int clientNum;
819 sfxHandle_t snd;
820 int voiceOnly;
821 char cmd[MAX_SAY_TEXT];
822 char message[MAX_SAY_TEXT];
823 } bufferedVoiceChat_t;
824
825 bufferedVoiceChat_t voiceChatBuffer[MAX_VOICECHATBUFFER];
826
827 /*
828 =================
829 CG_PlayVoiceChat
830 =================
831 */
832 void CG_PlayVoiceChat( bufferedVoiceChat_t *vchat ) {
833 // if we are going into the intermission, don't start any voices
834 if ( cg.intermissionStarted ) {
835 return;
836 }
837
838 if ( !cg_noVoiceChats.integer ) {
839 trap_S_StartLocalSound( vchat->snd, CHAN_VOICE);
840 if (vchat->clientNum != cg.snap->ps.clientNum) {
841 int orderTask = CG_ValidOrder(vchat->cmd);
842 if (orderTask > 0) {
843 cgs.acceptOrderTime = cg.time + 5000;
844 Q_strncpyz(cgs.acceptVoice, vchat->cmd, sizeof(cgs.acceptVoice));
845 cgs.acceptTask = orderTask;
846 cgs.acceptLeader = vchat->clientNum;
847 }
848 // see if this was an order
849 CG_ShowResponseHead();
850 }
851 }
852 if (!vchat->voiceOnly && !cg_noVoiceText.integer) {
853 CG_AddToTeamChat( vchat->message );
854 CG_Printf( "%s\n", vchat->message );
855 }
856 voiceChatBuffer[cg.voiceChatBufferOut].snd = 0;
857 }
858
859 /*
860 =====================
861 CG_PlayBufferedVoieChats
862 =====================
863 */
864 void CG_PlayBufferedVoiceChats( void ) {
865 if ( cg.voiceChatTime < cg.time ) {
866 if (cg.voiceChatBufferOut != cg.voiceChatBufferIn && voiceChatBuffer[cg.voiceChatBufferOut].snd) {
867 //
868 CG_PlayVoiceChat(&voiceChatBuffer[cg.voiceChatBufferOut]);
869 //
870 cg.voiceChatBufferOut = (cg.voiceChatBufferOut + 1) % MAX_VOICECHATBUFFER;
871 cg.voiceChatTime = cg.time + 1000;
872 }
873 }
874 }
875
876 /*
877 =====================
878 CG_AddBufferedVoiceChat
879 =====================
880 */
881 void CG_AddBufferedVoiceChat( bufferedVoiceChat_t *vchat ) {
882 // if we are going into the intermission, don't start any voices
883 if ( cg.intermissionStarted ) {
884 return;
885 }
886
887 memcpy(&voiceChatBuffer[cg.voiceChatBufferIn], vchat, sizeof(bufferedVoiceChat_t));
888 cg.voiceChatBufferIn = (cg.voiceChatBufferIn + 1) % MAX_VOICECHATBUFFER;
889 if (cg.voiceChatBufferIn == cg.voiceChatBufferOut) {
890 CG_PlayVoiceChat( &voiceChatBuffer[cg.voiceChatBufferOut] );
891 cg.voiceChatBufferOut++;
892 }
893 }
894
895 /*
896 =================
897 CG_VoiceChatLocal
898 =================
899 */
900 void CG_VoiceChatLocal( int mode, qboolean voiceOnly, int clientNum, int color, const char *cmd ) {
901 char *chat;
902 voiceChatList_t *voiceChatList;
903 clientInfo_t *ci;
904 sfxHandle_t snd;
905 bufferedVoiceChat_t vchat;
906
907 // if we are going into the intermission, don't start any voices
908 if ( cg.intermissionStarted ) {
909 return;
910 }
911
912 if ( mode == SAY_ALL && cgs.gametype >= GT_TEAM && cg_teamChatsOnly.integer ) {
913 return;
914 }
915
916 if ( clientNum < 0 || clientNum >= MAX_CLIENTS ) {
917 clientNum = 0;
918 }
919 ci = &cgs.clientinfo[ clientNum ];
920
921 cgs.currentVoiceClient = clientNum;
922
923 voiceChatList = CG_VoiceChatListForClient( clientNum );
924
925 if ( CG_GetVoiceChat( voiceChatList, cmd, &snd, &chat ) ) {
926 vchat.clientNum = clientNum;
927 vchat.snd = snd;
928 vchat.voiceOnly = voiceOnly;
929 Q_strncpyz(vchat.cmd, cmd, sizeof(vchat.cmd));
930 if ( mode == SAY_TELL ) {
931 Com_sprintf(vchat.message, sizeof(vchat.message), "[%s]: %c%c%s", ci->name, Q_COLOR_ESCAPE, color, chat);
932 }
933 else if ( mode == SAY_TEAM ) {
934 Com_sprintf(vchat.message, sizeof(vchat.message), "(%s): %c%c%s", ci->name, Q_COLOR_ESCAPE, color, chat);
935 }
936 else {
937 Com_sprintf(vchat.message, sizeof(vchat.message), "%s: %c%c%s", ci->name, Q_COLOR_ESCAPE, color, chat);
938 }
939 CG_AddBufferedVoiceChat(&vchat);
940 }
941 }
942
943 /*
944 =================
945 CG_VoiceChat
946 =================
947 */
948 void CG_VoiceChat( int mode ) {
949 const char *cmd;
950 int clientNum, color;
951 qboolean voiceOnly;
952
953 voiceOnly = atoi(CG_Argv(1));
954 clientNum = atoi(CG_Argv(2));
955 color = atoi(CG_Argv(3));
956 cmd = CG_Argv(4);
957
958 if (cg_noTaunt.integer != 0) {
959 if (!strcmp(cmd, VOICECHAT_KILLINSULT) || !strcmp(cmd, VOICECHAT_TAUNT) || \
960 !strcmp(cmd, VOICECHAT_DEATHINSULT) || !strcmp(cmd, VOICECHAT_KILLGAUNTLET) || \
961 !strcmp(cmd, VOICECHAT_PRAISE)) {
962 return;
963 }
964 }
965
966 CG_VoiceChatLocal( mode, voiceOnly, clientNum, color, cmd );
967 }
968 #endif // MISSIONPACK
969
970 /*
971 =================
972 CG_RemoveChatEscapeChar
973 =================
974 */
975 static void CG_RemoveChatEscapeChar( char *text ) {
976 int i, l;
977
978 l = 0;
979 for ( i = 0; text[i]; i++ ) {
980 if (text[i] == '\x19')
981 continue;
982 text[l++] = text[i];
983 }
984 text[l] = '\0';
985 }
986
987 /*
988 =================
989 CG_ServerCommand
990
991 The string has been tokenized and can be retrieved with
992 Cmd_Argc() / Cmd_Argv()
993 =================
994 */
995 static void CG_ServerCommand( void ) {
996 const char *cmd;
997 char text[MAX_SAY_TEXT];
998
999 cmd = CG_Argv(0);
1000
1001 if ( !cmd[0] ) {
1002 // server claimed the command
1003 return;
1004 }
1005
1006 if ( !strcmp( cmd, "cp" ) ) {
1007 CG_CenterPrint( CG_Argv(1), SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH );
1008 return;
1009 }
1010
1011 if ( !strcmp( cmd, "cs" ) ) {
1012 CG_ConfigStringModified();
1013 return;
1014 }
1015
1016 if ( !strcmp( cmd, "print" ) ) {
1017 CG_Printf( "%s", CG_Argv(1) );
1018 #ifdef MISSIONPACK
1019 cmd = CG_Argv(1); // yes, this is obviously a hack, but so is the way we hear about
1020 // votes passing or failing
1021 if ( !Q_stricmpn( cmd, "vote failed", 11 ) || !Q_stricmpn( cmd, "team vote failed", 16 )) {
1022 trap_S_StartLocalSound( cgs.media.voteFailed, CHAN_ANNOUNCER );
1023 } else if ( !Q_stricmpn( cmd, "vote passed", 11 ) || !Q_stricmpn( cmd, "team vote passed", 16 ) ) {
1024 trap_S_StartLocalSound( cgs.media.votePassed, CHAN_ANNOUNCER );
1025 }
1026 #endif
1027 return;
1028 }
1029
1030 if ( !strcmp( cmd, "chat" ) ) {
1031 if ( cgs.gametype >= GT_TEAM && cg_teamChatsOnly.integer ) {
1032 return;
1033 }
1034
1035 trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND );
1036 Q_strncpyz( text, CG_Argv(1), MAX_SAY_TEXT );
1037 CG_RemoveChatEscapeChar( text );
1038 CG_Printf( "%s\n", text );
1039 return;
1040 }
1041
1042 if ( !strcmp( cmd, "tchat" ) ) {
1043 trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND );
1044 Q_strncpyz( text, CG_Argv(1), MAX_SAY_TEXT );
1045 CG_RemoveChatEscapeChar( text );
1046 CG_AddToTeamChat( text );
1047 CG_Printf( "%s\n", text );
1048 return;
1049 }
1050
1051 #ifdef MISSIONPACK
1052 if ( !strcmp( cmd, "vchat" ) ) {
1053 CG_VoiceChat( SAY_ALL );
1054 return;
1055 }
1056
1057 if ( !strcmp( cmd, "vtchat" ) ) {
1058 CG_VoiceChat( SAY_TEAM );
1059 return;
1060 }
1061
1062 if ( !strcmp( cmd, "vtell" ) ) {
1063 CG_VoiceChat( SAY_TELL );
1064 return;
1065 }
1066 #endif
1067
1068 if ( !strcmp( cmd, "scores" ) ) {
1069 CG_ParseScores();
1070 return;
1071 }
1072
1073 if ( !strcmp( cmd, "tinfo" ) ) {
1074 CG_ParseTeamInfo();
1075 return;
1076 }
1077
1078 if ( !strcmp( cmd, "map_restart" ) ) {
1079 CG_MapRestart();
1080 return;
1081 }
1082
1083 if ( Q_stricmp (cmd, "remapShader") == 0 )
1084 {
1085 if (trap_Argc() == 4)
1086 {
1087 char shader1[MAX_QPATH];
1088 char shader2[MAX_QPATH];
1089 char shader3[MAX_QPATH];
1090
1091 Q_strncpyz(shader1, CG_Argv(1), sizeof(shader1));
1092 Q_strncpyz(shader2, CG_Argv(2), sizeof(shader2));
1093 Q_strncpyz(shader3, CG_Argv(3), sizeof(shader3));
1094
1095 trap_R_RemapShader(shader1, shader2, shader3);
1096 }
1097
1098 return;
1099 }
1100
1101 // loaddeferred can be both a servercmd and a consolecmd
1102 if ( !strcmp( cmd, "loaddefered" ) ) { // FIXME: spelled wrong, but not changing for demo
1103 CG_LoadDeferredPlayers();
1104 return;
1105 }
1106
1107 // clientLevelShot is sent before taking a special screenshot for
1108 // the menu system during development
1109 if ( !strcmp( cmd, "clientLevelShot" ) ) {
1110 cg.levelShot = qtrue;
1111 return;
1112 }
1113
1114 CG_Printf( "Unknown client game command: %s\n", cmd );
1115 }
1116
1117
1118 /*
1119 ====================
1120 CG_ExecuteNewServerCommands
1121
1122 Execute all of the server commands that were received along
1123 with this this snapshot.
1124 ====================
1125 */
1126 void CG_ExecuteNewServerCommands( int latestSequence ) {
1127 while ( cgs.serverCommandSequence < latestSequence ) {
1128 if ( trap_GetServerCommand( ++cgs.serverCommandSequence ) ) {
1129 CG_ServerCommand();
1130 }
1131 }
1132 }