2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // cl_parse.c -- parse a message received from the server
24 #include "cl_collision.h"
28 char *svc_strings[128] =
34 "svc_version", // [int] server version
35 "svc_setview", // [short] entity number
36 "svc_sound", // <see code>
37 "svc_time", // [float] server time
38 "svc_print", // [string] null terminated string
39 "svc_stufftext", // [string] stuffed into client's console buffer
40 // the string should be \n terminated
41 "svc_setangle", // [vec3] set the view angle to this absolute value
43 "svc_serverinfo", // [int] version
44 // [string] signon string
45 // [string]..[0]model cache [string]...[0]sounds cache
46 // [string]..[0]item cache
47 "svc_lightstyle", // [byte] [string]
48 "svc_updatename", // [byte] [string]
49 "svc_updatefrags", // [byte] [short]
50 "svc_clientdata", // <shortbits + data>
51 "svc_stopsound", // <see code>
52 "svc_updatecolors", // [byte] [byte]
53 "svc_particle", // [vec3] <variable>
54 "svc_damage", // [byte] impact [byte] blood [vec3] from
57 "OBSOLETE svc_spawnbinary",
60 "svc_temp_entity", // <variable>
66 "svc_spawnstaticsound",
68 "svc_finale", // [string] music [string] text
69 "svc_cdtrack", // [byte] track [byte] looptrack
72 "svc_showlmp", // [string] iconlabel [string] lmpfile [short] x [short] y
73 "svc_hidelmp", // [string] iconlabel
74 "svc_skybox", // [string] skyname
87 "svc_downloaddata", // 50 // [int] start [short] size [variable length] data
88 "svc_updatestatubyte", // 51 // [byte] stat [byte] value
89 "svc_effect", // 52 // [vector] org [byte] modelindex [byte] startframe [byte] framecount [byte] framerate
90 "svc_effect2", // 53 // [vector] org [short] modelindex [short] startframe [byte] framecount [byte] framerate
91 "svc_sound2", // 54 // short soundindex instead of byte
92 "svc_spawnbaseline2", // 55 // short modelindex instead of byte
93 "svc_spawnstatic2", // 56 // short modelindex instead of byte
94 "svc_entities", // 57 // [int] deltaframe [int] thisframe [float vector] eye [variable length] entitydata
95 "svc_csqcentities", // 58 // [short] entnum [variable length] entitydata ... [short] 0x0000
96 "svc_spawnstaticsound2", // 59 // [coord3] [short] samp [byte] vol [byte] aten
99 char *qw_svc_strings[128] =
103 "qw_svc_disconnect", // 2
104 "qw_svc_updatestat", // 3 // [byte] [byte]
106 "qw_svc_setview", // 5 // [short] entity number
107 "qw_svc_sound", // 6 // <see code>
109 "qw_svc_print", // 8 // [byte] id [string] null terminated string
110 "qw_svc_stufftext", // 9 // [string] stuffed into client's console buffer
111 "qw_svc_setangle", // 10 // [angle3] set the view angle to this absolute value
112 "qw_svc_serverdata", // 11 // [long] protocol ...
113 "qw_svc_lightstyle", // 12 // [byte] [string]
115 "qw_svc_updatefrags", // 14 // [byte] [short]
117 "qw_svc_stopsound", // 16 // <see code>
120 "qw_svc_damage", // 19
121 "qw_svc_spawnstatic", // 20
123 "qw_svc_spawnbaseline", // 22
124 "qw_svc_temp_entity", // 23 // variable
125 "qw_svc_setpause", // 24 // [byte] on / off
127 "qw_svc_centerprint", // 26 // [string] to put in center of the screen
128 "qw_svc_killedmonster", // 27
129 "qw_svc_foundsecret", // 28
130 "qw_svc_spawnstaticsound", // 29 // [coord3] [byte] samp [byte] vol [byte] aten
131 "qw_svc_intermission", // 30 // [vec3_t] origin [vec3_t] angle
132 "qw_svc_finale", // 31 // [string] text
133 "qw_svc_cdtrack", // 32 // [byte] track
134 "qw_svc_sellscreen", // 33
135 "qw_svc_smallkick", // 34 // set client punchangle to 2
136 "qw_svc_bigkick", // 35 // set client punchangle to 4
137 "qw_svc_updateping", // 36 // [byte] [short]
138 "qw_svc_updateentertime", // 37 // [byte] [float]
139 "qw_svc_updatestatlong", // 38 // [byte] [long]
140 "qw_svc_muzzleflash", // 39 // [short] entity
141 "qw_svc_updateuserinfo", // 40 // [byte] slot [long] uid
142 "qw_svc_download", // 41 // [short] size [size bytes]
143 "qw_svc_playerinfo", // 42 // variable
144 "qw_svc_nails", // 43 // [byte] num [48 bits] xyzpy 12 12 12 4 8
145 "qw_svc_chokecount", // 44 // [byte] packets choked
146 "qw_svc_modellist", // 45 // [strings]
147 "qw_svc_soundlist", // 46 // [strings]
148 "qw_svc_packetentities", // 47 // [...]
149 "qw_svc_deltapacketentities", // 48 // [...]
150 "qw_svc_maxspeed", // 49 // maxspeed change, for prediction
151 "qw_svc_entgravity", // 50 // gravity change, for prediction
152 "qw_svc_setinfo", // 51 // setinfo on a client
153 "qw_svc_serverinfo", // 52 // serverinfo
154 "qw_svc_updatepl", // 53 // [byte] [byte]
157 //=============================================================================
159 cvar_t demo_nehahra = {0, "demo_nehahra", "0", "reads all quake demos as nehahra movie protocol"};
160 cvar_t developer_networkentities = {0, "developer_networkentities", "0", "prints received entities, value is 0-4 (higher for more info)"};
161 cvar_t cl_sound_wizardhit = {0, "cl_sound_wizardhit", "wizard/hit.wav", "sound to play during TE_WIZSPIKE (empty cvar disables sound)"};
162 cvar_t cl_sound_hknighthit = {0, "cl_sound_hknighthit", "hknight/hit.wav", "sound to play during TE_KNIGHTSPIKE (empty cvar disables sound)"};
163 cvar_t cl_sound_tink1 = {0, "cl_sound_tink1", "weapons/tink1.wav", "sound to play with 80% chance during TE_SPIKE/TE_SUPERSPIKE (empty cvar disables sound)"};
164 cvar_t cl_sound_ric1 = {0, "cl_sound_ric1", "weapons/ric1.wav", "sound to play with 5% chance during TE_SPIKE/TE_SUPERSPIKE (empty cvar disables sound)"};
165 cvar_t cl_sound_ric2 = {0, "cl_sound_ric2", "weapons/ric2.wav", "sound to play with 5% chance during TE_SPIKE/TE_SUPERSPIKE (empty cvar disables sound)"};
166 cvar_t cl_sound_ric3 = {0, "cl_sound_ric3", "weapons/ric3.wav", "sound to play with 10% chance during TE_SPIKE/TE_SUPERSPIKE (empty cvar disables sound)"};
168 #define RIC_GUNSHOT 1
169 #define RIC_GUNSHOTQUAD 2
170 cvar_t cl_sound_ric_gunshot = {0, "cl_sound_ric_gunshot", "0", "specifies if and when the related cl_sound_ric and cl_sound_tink sounds apply to TE_GUNSHOT/TE_GUNSHOTQUAD, 0 = no sound, 1 = TE_GUNSHOT, 2 = TE_GUNSHOTQUAD, 3 = TE_GUNSHOT and TE_GUNSHOTQUAD"};
171 cvar_t cl_sound_r_exp3 = {0, "cl_sound_r_exp3", "weapons/r_exp3.wav", "sound to play during TE_EXPLOSION and related effects (empty cvar disables sound)"};
172 cvar_t cl_serverextension_download = {0, "cl_serverextension_download", "0", "indicates whether the server supports the download command"};
173 cvar_t cl_joinbeforedownloadsfinish = {CVAR_SAVE, "cl_joinbeforedownloadsfinish", "1", "if non-zero the game will begin after the map is loaded before other downloads finish"};
174 cvar_t cl_nettimesyncfactor = {CVAR_SAVE, "cl_nettimesyncfactor", "0", "rate at which client time adapts to match server time, 1 = instantly, 0.125 = slowly, 0 = not at all (bounding still applies)"};
175 cvar_t cl_nettimesyncboundmode = {CVAR_SAVE, "cl_nettimesyncboundmode", "6", "method of restricting client time to valid values, 0 = no correction, 1 = tight bounding (jerky with packet loss), 2 = loose bounding (corrects it if out of bounds), 3 = leniant bounding (ignores temporary errors due to varying framerate), 4 = slow adjustment method from Quake3, 5 = slighttly nicer version of Quake3 method, 6 = bounding + Quake3"};
176 cvar_t cl_nettimesyncboundtolerance = {CVAR_SAVE, "cl_nettimesyncboundtolerance", "0.25", "how much error is tolerated by bounding check, as a fraction of frametime, 0.25 = up to 25% margin of error tolerated, 1 = use only new time, 0 = use only old time (same effect as setting cl_nettimesyncfactor to 1)"};
177 cvar_t cl_iplog_name = {CVAR_SAVE, "cl_iplog_name", "darkplaces_iplog.txt", "name of iplog file containing player addresses for iplog_list command and automatic ip logging when parsing status command"};
179 static qboolean QW_CL_CheckOrDownloadFile(const char *filename);
180 static void QW_CL_RequestNextDownload(void);
181 static void QW_CL_NextUpload(void);
182 void QW_CL_StartUpload(unsigned char *data, int size);
183 //static qboolean QW_CL_IsUploading(void);
184 static void QW_CL_StopUpload(void);
188 CL_ParseStartSoundPacket
191 void CL_ParseStartSoundPacket(int largesoundindex)
200 if (cls.protocol == PROTOCOL_QUAKEWORLD)
202 channel = MSG_ReadShort();
204 if (channel & (1<<15))
205 volume = MSG_ReadByte ();
207 volume = DEFAULT_SOUND_PACKET_VOLUME;
209 if (channel & (1<<14))
210 attenuation = MSG_ReadByte () / 64.0;
212 attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
214 ent = (channel>>3)&1023;
217 sound_num = MSG_ReadByte ();
221 field_mask = MSG_ReadByte();
223 if (field_mask & SND_VOLUME)
224 volume = MSG_ReadByte ();
226 volume = DEFAULT_SOUND_PACKET_VOLUME;
228 if (field_mask & SND_ATTENUATION)
229 attenuation = MSG_ReadByte () / 64.0;
231 attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
233 if (field_mask & SND_LARGEENTITY)
235 ent = (unsigned short) MSG_ReadShort ();
236 channel = MSG_ReadByte ();
240 channel = (unsigned short) MSG_ReadShort ();
245 if (largesoundindex || field_mask & SND_LARGESOUND)
246 sound_num = (unsigned short) MSG_ReadShort ();
248 sound_num = MSG_ReadByte ();
251 MSG_ReadVector(pos, cls.protocol);
253 if (sound_num >= MAX_SOUNDS)
255 Con_Printf("CL_ParseStartSoundPacket: sound_num (%i) >= MAX_SOUNDS (%i)\n", sound_num, MAX_SOUNDS);
259 if (ent >= MAX_EDICTS)
261 Con_Printf("CL_ParseStartSoundPacket: ent = %i", ent);
265 S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0f, attenuation);
272 When the client is taking a long time to load stuff, send keepalive messages
273 so the server doesn't disconnect.
277 static unsigned char olddata[NET_MAXMESSAGE];
278 void CL_KeepaliveMessage (qboolean readmessages)
281 static double nextmsg = -1;
286 // no need if server is local and definitely not if this is a demo
287 if (sv.active || !cls.netcon || cls.protocol == PROTOCOL_QUAKEWORLD)
292 // read messages from server, should just be nops
293 oldreadcount = msg_readcount;
294 oldbadread = msg_badread;
296 memcpy(olddata, net_message.data, net_message.cursize);
298 NetConn_ClientFrame();
300 msg_readcount = oldreadcount;
301 msg_badread = oldbadread;
303 memcpy(net_message.data, olddata, net_message.cursize);
306 if (cls.netcon && (time = Sys_DoubleTime()) >= nextmsg)
309 unsigned char buf[4];
312 // LordHavoc: must use unreliable because reliable could kill the sigon message!
313 Con_Print("--> client to server keepalive\n");
314 memset(&msg, 0, sizeof(msg));
316 msg.maxsize = sizeof(buf);
317 MSG_WriteChar(&msg, clc_nop);
318 NetConn_SendUnreliableMessage(cls.netcon, &msg, cls.protocol, 10000);
322 void CL_ParseEntityLump(char *entdata)
325 char key[128], value[MAX_INPUTLINE];
326 FOG_clear(); // LordHavoc: no fog until set
327 // LordHavoc: default to the map's sky (q3 shader parsing sets this)
328 R_SetSkyBox(cl.worldmodel->brush.skybox);
332 if (!COM_ParseToken_Simple(&data, false))
334 if (com_token[0] != '{')
338 if (!COM_ParseToken_Simple(&data, false))
340 if (com_token[0] == '}')
341 break; // end of worldspawn
342 if (com_token[0] == '_')
343 strlcpy (key, com_token + 1, sizeof (key));
345 strlcpy (key, com_token, sizeof (key));
346 while (key[strlen(key)-1] == ' ') // remove trailing spaces
347 key[strlen(key)-1] = 0;
348 if (!COM_ParseToken_Simple(&data, false))
350 strlcpy (value, com_token, sizeof (value));
351 if (!strcmp("sky", key))
353 else if (!strcmp("skyname", key)) // non-standard, introduced by QuakeForge... sigh.
355 else if (!strcmp("qlsky", key)) // non-standard, introduced by QuakeLives (EEK)
357 else if (!strcmp("fog", key))
358 sscanf(value, "%f %f %f %f", &r_refdef.fog_density, &r_refdef.fog_red, &r_refdef.fog_green, &r_refdef.fog_blue);
359 else if (!strcmp("fog_density", key))
360 r_refdef.fog_density = atof(value);
361 else if (!strcmp("fog_red", key))
362 r_refdef.fog_red = atof(value);
363 else if (!strcmp("fog_green", key))
364 r_refdef.fog_green = atof(value);
365 else if (!strcmp("fog_blue", key))
366 r_refdef.fog_blue = atof(value);
370 static qboolean QW_CL_CheckOrDownloadFile(const char *filename)
374 // see if the file already exists
375 file = FS_Open(filename, "rb", true, false);
382 // download messages in a demo would be bad
383 if (cls.demorecording)
385 Con_Printf("Unable to download \"%s\" when recording.\n", filename);
389 // don't try to download when playing a demo
393 strlcpy(cls.qw_downloadname, filename, sizeof(cls.qw_downloadname));
394 Con_Printf("Downloading %s\n", filename);
396 if (!cls.qw_downloadmemory)
398 cls.qw_downloadmemory = NULL;
399 cls.qw_downloadmemorycursize = 0;
400 cls.qw_downloadmemorymaxsize = 1024*1024; // start out with a 1MB buffer
403 MSG_WriteByte(&cls.netcon->message, qw_clc_stringcmd);
404 MSG_WriteString(&cls.netcon->message, va("download %s", filename));
406 cls.qw_downloadnumber++;
407 cls.qw_downloadpercent = 0;
408 cls.qw_downloadmemorycursize = 0;
413 extern void CL_Locs_Reload_f(void);
414 static void QW_CL_ProcessUserInfo(int slot);
415 static void QW_CL_RequestNextDownload(void)
419 // clear name of file that just finished
420 cls.qw_downloadname[0] = 0;
422 switch (cls.qw_downloadtype)
427 if (cls.qw_downloadnumber == 0)
428 Con_Printf("Checking skins...\n");
429 for (;cls.qw_downloadnumber < cl.maxclients;cls.qw_downloadnumber++)
431 if (!cl.scores[cls.qw_downloadnumber].name[0])
433 // check if we need to download the file, and return if so
434 if (!QW_CL_CheckOrDownloadFile(va("skins/%s.pcx", cl.scores[cls.qw_downloadnumber].qw_skin)))
438 cls.qw_downloadtype = dl_none;
440 // load any newly downloaded skins
441 for (i = 0;i < cl.maxclients;i++)
442 QW_CL_ProcessUserInfo(i);
444 // if we're still in signon stages, request the next one
445 if (cls.signon != SIGNONS)
447 cls.signon = SIGNONS-1;
448 // we'll go to SIGNONS when the first entity update is received
449 MSG_WriteByte(&cls.netcon->message, qw_clc_stringcmd);
450 MSG_WriteString(&cls.netcon->message, va("begin %i", cl.qw_servercount));
454 if (cls.qw_downloadnumber == 0)
456 Con_Printf("Checking models...\n");
457 cls.qw_downloadnumber = 1;
460 for (;cls.qw_downloadnumber < MAX_MODELS && cl.model_name[cls.qw_downloadnumber][0];cls.qw_downloadnumber++)
463 if (cl.model_name[cls.qw_downloadnumber][0] == '*')
465 if (!strcmp(cl.model_name[cls.qw_downloadnumber], "progs/spike.mdl"))
466 cl.qw_modelindex_spike = cls.qw_downloadnumber;
467 if (!strcmp(cl.model_name[cls.qw_downloadnumber], "progs/player.mdl"))
468 cl.qw_modelindex_player = cls.qw_downloadnumber;
469 if (!strcmp(cl.model_name[cls.qw_downloadnumber], "progs/flag.mdl"))
470 cl.qw_modelindex_flag = cls.qw_downloadnumber;
471 if (!strcmp(cl.model_name[cls.qw_downloadnumber], "progs/s_explod.spr"))
472 cl.qw_modelindex_s_explod = cls.qw_downloadnumber;
473 // check if we need to download the file, and return if so
474 if (!QW_CL_CheckOrDownloadFile(cl.model_name[cls.qw_downloadnumber]))
478 cls.qw_downloadtype = dl_none;
480 // parse the Q3 shader files
483 // touch all of the precached models that are still loaded so we can free
484 // anything that isn't needed
487 for (i = 1;i < MAX_MODELS && cl.model_name[i][0];i++)
488 Mod_FindName(cl.model_name[i]);
489 // precache any models used by the client (this also marks them used)
490 cl.model_bolt = Mod_ForName("progs/bolt.mdl", false, false, false);
491 cl.model_bolt2 = Mod_ForName("progs/bolt2.mdl", false, false, false);
492 cl.model_bolt3 = Mod_ForName("progs/bolt3.mdl", false, false, false);
493 cl.model_beam = Mod_ForName("progs/beam.mdl", false, false, false);
496 // now we try to load everything that is new
499 cl.model_precache[1] = Mod_ForName(cl.model_name[1], false, false, true);
500 if (cl.model_precache[1]->Draw == NULL)
501 Con_Printf("Map %s could not be found or downloaded\n", cl.model_name[1]);
504 for (i = 2;i < MAX_MODELS && cl.model_name[i][0];i++)
505 if ((cl.model_precache[i] = Mod_ForName(cl.model_name[i], false, false, false))->Draw == NULL)
506 Con_Printf("Model %s could not be found or downloaded\n", cl.model_name[i]);
508 // check memory integrity
509 Mem_CheckSentinelsGlobal();
511 // now that we have a world model, set up the world entity, renderer
513 cl.entities[0].render.model = cl.worldmodel = cl.model_precache[1];
514 CL_UpdateRenderEntity(&cl.entities[0].render);
519 cl.foundtalk2wav = FS_FileExists("sound/misc/talk2.wav");
521 // add pmodel/emodel CRCs to userinfo
522 CL_SetInfo("pmodel", va("%i", FS_CRCFile("progs/player.mdl", NULL)), true, true, true, true);
523 CL_SetInfo("emodel", va("%i", FS_CRCFile("progs/eyes.mdl", NULL)), true, true, true, true);
525 // done checking sounds and models, send a prespawn command now
526 MSG_WriteByte(&cls.netcon->message, qw_clc_stringcmd);
527 MSG_WriteString(&cls.netcon->message, va("prespawn %i 0 %i", cl.qw_servercount, cl.model_precache[1]->brush.qw_md4sum2));
529 if (cls.qw_downloadmemory)
531 Mem_Free(cls.qw_downloadmemory);
532 cls.qw_downloadmemory = NULL;
536 cl.loadfinished = true;
539 if (cls.qw_downloadnumber == 0)
541 Con_Printf("Checking sounds...\n");
542 cls.qw_downloadnumber = 1;
545 for (;cl.sound_name[cls.qw_downloadnumber][0];cls.qw_downloadnumber++)
547 // check if we need to download the file, and return if so
548 if (!QW_CL_CheckOrDownloadFile(va("sound/%s", cl.sound_name[cls.qw_downloadnumber])))
552 cls.qw_downloadtype = dl_none;
554 // load new sounds and unload old ones
555 // FIXME: S_ServerSounds does not know about cl.sfx_ sounds
556 S_ServerSounds(cl.sound_name, cls.qw_downloadnumber);
558 // precache any sounds used by the client
559 cl.sfx_wizhit = S_PrecacheSound(cl_sound_wizardhit.string, false, true);
560 cl.sfx_knighthit = S_PrecacheSound(cl_sound_hknighthit.string, false, true);
561 cl.sfx_tink1 = S_PrecacheSound(cl_sound_tink1.string, false, true);
562 cl.sfx_ric1 = S_PrecacheSound(cl_sound_ric1.string, false, true);
563 cl.sfx_ric2 = S_PrecacheSound(cl_sound_ric2.string, false, true);
564 cl.sfx_ric3 = S_PrecacheSound(cl_sound_ric3.string, false, true);
565 cl.sfx_r_exp3 = S_PrecacheSound(cl_sound_r_exp3.string, false, true);
568 for (i = 1;i < MAX_SOUNDS && cl.sound_name[i][0];i++)
570 // Don't lock the sfx here, S_ServerSounds already did that
571 cl.sound_precache[i] = S_PrecacheSound(cl.sound_name[i], true, false);
574 // check memory integrity
575 Mem_CheckSentinelsGlobal();
577 // done with sound downloads, next we check models
578 MSG_WriteByte(&cls.netcon->message, qw_clc_stringcmd);
579 MSG_WriteString(&cls.netcon->message, va("modellist %i %i", cl.qw_servercount, 0));
583 Con_Printf("Unknown download type.\n");
587 static void QW_CL_ParseDownload(void)
589 int size = (signed short)MSG_ReadShort();
590 int percent = MSG_ReadByte();
592 //Con_Printf("download %i %i%% (%i/%i)\n", size, percent, cls.qw_downloadmemorycursize, cls.qw_downloadmemorymaxsize);
594 // skip the download fragment if playing a demo
598 msg_readcount += size;
604 Con_Printf("File not found.\n");
605 QW_CL_RequestNextDownload();
609 if (msg_readcount + (unsigned short)size > net_message.cursize)
610 Host_Error("corrupt download message\n");
612 // make sure the buffer is big enough to include this new fragment
613 if (!cls.qw_downloadmemory || cls.qw_downloadmemorymaxsize < cls.qw_downloadmemorycursize + size)
616 while (cls.qw_downloadmemorymaxsize < cls.qw_downloadmemorycursize + size)
617 cls.qw_downloadmemorymaxsize *= 2;
618 old = cls.qw_downloadmemory;
619 cls.qw_downloadmemory = (unsigned char *)Mem_Alloc(cls.permanentmempool, cls.qw_downloadmemorymaxsize);
622 memcpy(cls.qw_downloadmemory, old, cls.qw_downloadmemorycursize);
627 // read the fragment out of the packet
628 MSG_ReadBytes(size, cls.qw_downloadmemory + cls.qw_downloadmemorycursize);
629 cls.qw_downloadmemorycursize += size;
630 cls.qw_downloadspeedcount += size;
632 cls.qw_downloadpercent = percent;
636 // request next fragment
637 MSG_WriteByte(&cls.netcon->message, qw_clc_stringcmd);
638 MSG_WriteString(&cls.netcon->message, "nextdl");
643 Con_Printf("Downloaded \"%s\"\n", cls.qw_downloadname);
645 FS_WriteFile(cls.qw_downloadname, cls.qw_downloadmemory, cls.qw_downloadmemorycursize);
647 cls.qw_downloadpercent = 0;
649 // start downloading the next file (or join the game)
650 QW_CL_RequestNextDownload();
654 static void QW_CL_ParseModelList(void)
657 int nummodels = MSG_ReadByte();
660 // parse model precache list
663 str = MSG_ReadString();
667 if (nummodels==MAX_MODELS)
668 Host_Error("Server sent too many model precaches");
669 if (strlen(str) >= MAX_QPATH)
670 Host_Error("Server sent a precache name of %i characters (max %i)", (int)strlen(str), MAX_QPATH - 1);
671 strlcpy(cl.model_name[nummodels], str, sizeof (cl.model_name[nummodels]));
677 MSG_WriteByte(&cls.netcon->message, qw_clc_stringcmd);
678 MSG_WriteString(&cls.netcon->message, va("modellist %i %i", cl.qw_servercount, n));
683 cls.qw_downloadnumber = 0;
684 cls.qw_downloadtype = dl_model;
685 QW_CL_RequestNextDownload();
688 static void QW_CL_ParseSoundList(void)
691 int numsounds = MSG_ReadByte();
694 // parse sound precache list
697 str = MSG_ReadString();
701 if (numsounds==MAX_SOUNDS)
702 Host_Error("Server sent too many sound precaches");
703 if (strlen(str) >= MAX_QPATH)
704 Host_Error("Server sent a precache name of %i characters (max %i)", (int)strlen(str), MAX_QPATH - 1);
705 strlcpy(cl.sound_name[numsounds], str, sizeof (cl.sound_name[numsounds]));
712 MSG_WriteByte(&cls.netcon->message, qw_clc_stringcmd);
713 MSG_WriteString(&cls.netcon->message, va("soundlist %i %i", cl.qw_servercount, n));
718 cls.qw_downloadnumber = 0;
719 cls.qw_downloadtype = dl_sound;
720 QW_CL_RequestNextDownload();
723 static void QW_CL_Skins_f(void)
725 cls.qw_downloadnumber = 0;
726 cls.qw_downloadtype = dl_skin;
727 QW_CL_RequestNextDownload();
730 static void QW_CL_Changing_f(void)
732 if (cls.qw_downloadmemory) // don't change when downloading
737 cls.signon = 1; // not active anymore, but not disconnected
738 Con_Printf("\nChanging map...\n");
741 void QW_CL_NextUpload(void)
743 int r, percent, size;
745 if (!cls.qw_uploaddata)
748 r = cls.qw_uploadsize - cls.qw_uploadpos;
751 size = min(1, cls.qw_uploadsize);
752 percent = (cls.qw_uploadpos+r)*100/size;
754 MSG_WriteByte(&cls.netcon->message, qw_clc_upload);
755 MSG_WriteShort(&cls.netcon->message, r);
756 MSG_WriteByte(&cls.netcon->message, percent);
757 SZ_Write(&cls.netcon->message, cls.qw_uploaddata + cls.qw_uploadpos, r);
759 Con_DPrintf("UPLOAD: %6d: %d written\n", cls.qw_uploadpos, r);
761 cls.qw_uploadpos += r;
763 if (cls.qw_uploadpos < cls.qw_uploadsize)
766 Con_Printf("Upload completed\n");
771 void QW_CL_StartUpload(unsigned char *data, int size)
773 // do nothing in demos or if not connected
777 // abort existing upload if in progress
780 Con_DPrintf("Starting upload of %d bytes...\n", size);
782 cls.qw_uploaddata = (unsigned char *)Mem_Alloc(cls.permanentmempool, size);
783 memcpy(cls.qw_uploaddata, data, size);
784 cls.qw_uploadsize = size;
785 cls.qw_uploadpos = 0;
791 qboolean QW_CL_IsUploading(void)
793 return cls.qw_uploaddata != NULL;
797 void QW_CL_StopUpload(void)
799 if (cls.qw_uploaddata)
800 Mem_Free(cls.qw_uploaddata);
801 cls.qw_uploaddata = NULL;
802 cls.qw_uploadsize = 0;
803 cls.qw_uploadpos = 0;
806 static void QW_CL_ProcessUserInfo(int slot)
808 int topcolor, bottomcolor;
810 InfoString_GetValue(cl.scores[slot].qw_userinfo, "name", cl.scores[slot].name, sizeof(cl.scores[slot].name));
811 InfoString_GetValue(cl.scores[slot].qw_userinfo, "topcolor", temp, sizeof(temp));topcolor = atoi(temp);
812 InfoString_GetValue(cl.scores[slot].qw_userinfo, "bottomcolor", temp, sizeof(temp));bottomcolor = atoi(temp);
813 cl.scores[slot].colors = topcolor * 16 + bottomcolor;
814 InfoString_GetValue(cl.scores[slot].qw_userinfo, "*spectator", temp, sizeof(temp));
815 cl.scores[slot].qw_spectator = temp[0] != 0;
816 InfoString_GetValue(cl.scores[slot].qw_userinfo, "team", cl.scores[slot].qw_team, sizeof(cl.scores[slot].qw_team));
817 InfoString_GetValue(cl.scores[slot].qw_userinfo, "skin", cl.scores[slot].qw_skin, sizeof(cl.scores[slot].qw_skin));
818 if (!cl.scores[slot].qw_skin[0])
819 strlcpy(cl.scores[slot].qw_skin, "base", sizeof(cl.scores[slot].qw_skin));
823 static void QW_CL_UpdateUserInfo(void)
826 slot = MSG_ReadByte();
827 if (slot >= cl.maxclients)
829 Con_Printf("svc_updateuserinfo >= cl.maxclients\n");
834 cl.scores[slot].qw_userid = MSG_ReadLong();
835 strlcpy(cl.scores[slot].qw_userinfo, MSG_ReadString(), sizeof(cl.scores[slot].qw_userinfo));
837 QW_CL_ProcessUserInfo(slot);
840 static void QW_CL_SetInfo(void)
845 slot = MSG_ReadByte();
846 strlcpy(key, MSG_ReadString(), sizeof(key));
847 strlcpy(value, MSG_ReadString(), sizeof(value));
848 if (slot >= cl.maxclients)
850 Con_Printf("svc_setinfo >= cl.maxclients\n");
853 InfoString_SetValue(cl.scores[slot].qw_userinfo, sizeof(cl.scores[slot].qw_userinfo), key, value);
855 QW_CL_ProcessUserInfo(slot);
858 static void QW_CL_ServerInfo(void)
863 strlcpy(key, MSG_ReadString(), sizeof(key));
864 strlcpy(value, MSG_ReadString(), sizeof(value));
865 Con_DPrintf("SERVERINFO: %s=%s\n", key, value);
866 InfoString_SetValue(cl.qw_serverinfo, sizeof(cl.qw_serverinfo), key, value);
867 InfoString_GetValue(cl.qw_serverinfo, "teamplay", temp, sizeof(temp));
868 cl.qw_teamplay = atoi(temp);
871 static void QW_CL_ParseNails(void)
874 int numnails = MSG_ReadByte();
876 unsigned char bits[6];
877 for (i = 0;i < numnails;i++)
879 for (j = 0;j < 6;j++)
880 bits[j] = MSG_ReadByte();
881 if (cl.qw_num_nails > 255)
883 v = cl.qw_nails[cl.qw_num_nails++];
884 v[0] = ( ( bits[0] + ((bits[1]&15)<<8) ) <<1) - 4096;
885 v[1] = ( ( (bits[1]>>4) + (bits[2]<<4) ) <<1) - 4096;
886 v[2] = ( ( bits[3] + ((bits[4]&15)<<8) ) <<1) - 4096;
887 v[3] = -360*(bits[4]>>4)/16;
888 v[4] = 360*bits[5]/256;
893 static void CL_UpdateItemsAndWeapon(void)
896 // check for important changes
899 if (cl.olditems != cl.stats[STAT_ITEMS])
900 for (j = 0;j < 32;j++)
901 if ((cl.stats[STAT_ITEMS] & (1<<j)) && !(cl.olditems & (1<<j)))
902 cl.item_gettime[j] = cl.time;
903 cl.olditems = cl.stats[STAT_ITEMS];
905 // GAME_NEXUIZ hud needs weapon change time
906 if (cl.activeweapon != cl.stats[STAT_ACTIVEWEAPON])
907 cl.weapontime = cl.time;
908 cl.activeweapon = cl.stats[STAT_ACTIVEWEAPON];
911 void CL_BeginDownloads(qboolean aborteddownload)
913 // quakeworld works differently
914 if (cls.protocol == PROTOCOL_QUAKEWORLD)
917 // this would be a good place to do curl downloads
918 if(Curl_Have_forthismap())
920 Curl_Register_predownload(); // come back later
925 // curl is done, so let's start with the business
928 // if already downloading something from the previous level, don't stop it
929 if (cls.qw_downloadname[0])
935 cl.downloadcsqc = false;
938 && csqc_progname.string
939 && csqc_progname.string[0]
940 && csqc_progcrc.integer >= 0
941 && cl_serverextension_download.integer
942 && (FS_CRCFile(csqc_progname.string, &progsize) != csqc_progcrc.integer || ((int)progsize != csqc_progsize.integer && csqc_progsize.integer != -1))
943 && !FS_FileExists(va("dlcache/%s.%i.%i", csqc_progname.string, csqc_progsize.integer, csqc_progcrc.integer)))
944 Cmd_ForwardStringToServer(va("download %s", csqc_progname.string));
947 if (cl.loadmodel_current < cl.loadmodel_total)
951 // parse the Q3 shader files
952 if (cl.loadmodel_current < 2)
955 for (;cl.loadmodel_current < cl.loadmodel_total;cl.loadmodel_current++)
957 if (cl.model_precache[cl.loadmodel_current] && cl.model_precache[cl.loadmodel_current]->Draw)
959 if (cls.signon < SIGNONS)
960 CL_KeepaliveMessage(true);
961 cl.model_precache[cl.loadmodel_current] = Mod_ForName(cl.model_name[cl.loadmodel_current], false, false, cl.loadmodel_current == 1);
962 if (cl.model_precache[cl.loadmodel_current] && cl.model_precache[cl.loadmodel_current]->Draw && cl.loadmodel_current == 1)
964 // we now have the worldmodel so we can set up the game world
965 cl.entities[0].render.model = cl.worldmodel = cl.model_precache[1];
966 CL_UpdateRenderEntity(&cl.entities[0].render);
969 cl.foundtalk2wav = FS_FileExists("sound/misc/talk2.wav");
970 // check memory integrity
971 Mem_CheckSentinelsGlobal();
972 if (!cl.loadfinished && cl_joinbeforedownloadsfinish.integer)
974 cl.loadfinished = true;
975 // now issue the spawn to move on to signon 2 like normal
977 Cmd_ForwardStringToServer("prespawn");
982 // finished loading models
985 if (cl.loadsound_current < cl.loadsound_total)
989 for (;cl.loadsound_current < cl.loadsound_total;cl.loadsound_current++)
991 if (cl.sound_precache[cl.loadsound_current] && S_IsSoundPrecached(cl.sound_precache[cl.loadsound_current]))
993 if (cls.signon < SIGNONS)
994 CL_KeepaliveMessage(true);
995 // Don't lock the sfx here, S_ServerSounds already did that
996 cl.sound_precache[cl.loadsound_current] = S_PrecacheSound(cl.sound_name[cl.loadsound_current], false, false);
999 // finished loading sounds
1002 // note: the reason these loops skip already-loaded things is that it
1003 // enables this command to be issued during the game if desired
1005 if (cl.downloadmodel_current < cl.loadmodel_total)
1009 for (;cl.downloadmodel_current < cl.loadmodel_total;cl.downloadmodel_current++)
1011 if (aborteddownload)
1013 if (cl.downloadmodel_current == 1)
1015 // the worldmodel failed, but we need to set up anyway
1016 cl.entities[0].render.model = cl.worldmodel = cl.model_precache[1];
1017 CL_UpdateRenderEntity(&cl.entities[0].render);
1020 cl.foundtalk2wav = FS_FileExists("sound/misc/talk2.wav");
1021 // check memory integrity
1022 Mem_CheckSentinelsGlobal();
1023 if (!cl.loadfinished && cl_joinbeforedownloadsfinish.integer)
1025 cl.loadfinished = true;
1026 // now issue the spawn to move on to signon 2 like normal
1028 Cmd_ForwardStringToServer("prespawn");
1031 aborteddownload = false;
1034 if (cl.model_precache[cl.downloadmodel_current] && cl.model_precache[cl.downloadmodel_current]->Draw)
1036 if (cls.signon < SIGNONS)
1037 CL_KeepaliveMessage(true);
1038 if (!FS_FileExists(cl.model_name[cl.downloadmodel_current]))
1040 if (cl.downloadmodel_current == 1)
1041 Con_Printf("Map %s not found\n", cl.model_name[cl.downloadmodel_current]);
1043 Con_Printf("Model %s not found\n", cl.model_name[cl.downloadmodel_current]);
1044 // regarding the * check: don't try to download submodels
1045 if (cl_serverextension_download.integer && cls.netcon && cl.model_name[cl.downloadmodel_current][0] != '*' && !sv.active)
1047 Cmd_ForwardStringToServer(va("download %s", cl.model_name[cl.downloadmodel_current]));
1048 // we'll try loading again when the download finishes
1052 cl.model_precache[cl.downloadmodel_current] = Mod_ForName(cl.model_name[cl.downloadmodel_current], false, false, cl.downloadmodel_current == 1);
1053 if (cl.downloadmodel_current == 1)
1055 // we now have the worldmodel so we can set up the game world
1056 cl.entities[0].render.model = cl.worldmodel = cl.model_precache[1];
1057 CL_UpdateRenderEntity(&cl.entities[0].render);
1060 cl.foundtalk2wav = FS_FileExists("sound/misc/talk2.wav");
1061 // check memory integrity
1062 Mem_CheckSentinelsGlobal();
1063 if (!cl.loadfinished && cl_joinbeforedownloadsfinish.integer)
1065 cl.loadfinished = true;
1066 // now issue the spawn to move on to signon 2 like normal
1068 Cmd_ForwardStringToServer("prespawn");
1073 // finished loading models
1076 if (cl.downloadsound_current < cl.loadsound_total)
1080 for (;cl.downloadsound_current < cl.loadsound_total;cl.downloadsound_current++)
1082 char soundname[MAX_QPATH];
1083 if (aborteddownload)
1085 aborteddownload = false;
1088 if (cl.sound_precache[cl.downloadsound_current] && S_IsSoundPrecached(cl.sound_precache[cl.downloadsound_current]))
1090 if (cls.signon < SIGNONS)
1091 CL_KeepaliveMessage(true);
1092 dpsnprintf(soundname, sizeof(soundname), "sound/%s", cl.sound_name[cl.downloadsound_current]);
1093 if (!FS_FileExists(soundname) && !FS_FileExists(cl.sound_name[cl.downloadsound_current]))
1095 Con_Printf("Sound %s not found\n", soundname);
1096 if (cl_serverextension_download.integer && cls.netcon && !sv.active)
1098 Cmd_ForwardStringToServer(va("download %s", soundname));
1099 // we'll try loading again when the download finishes
1103 // Don't lock the sfx here, S_ServerSounds already did that
1104 cl.sound_precache[cl.downloadsound_current] = S_PrecacheSound(cl.sound_name[cl.downloadsound_current], false, false);
1107 // finished loading sounds
1110 if (!cl.loadfinished)
1112 cl.loadfinished = true;
1114 // check memory integrity
1115 Mem_CheckSentinelsGlobal();
1117 // now issue the spawn to move on to signon 2 like normal
1119 Cmd_ForwardStringToServer("prespawn");
1123 void CL_BeginDownloads_f(void)
1125 // prevent cl_begindownloads from being issued multiple times in one match
1126 // to prevent accidentally cancelled downloads
1128 Con_DPrintf("cl_begindownloads is only valid once per match\n");
1130 CL_BeginDownloads(false);
1133 void CL_StopDownload(int size, int crc)
1135 if (cls.qw_downloadmemory && cls.qw_downloadmemorycursize == size && CRC_Block(cls.qw_downloadmemory, size) == crc)
1138 size_t existingsize;
1139 const char *extension;
1142 // save to disk only if we don't already have it
1143 // (this is mainly for playing back demos)
1144 existingcrc = FS_CRCFile(cls.qw_downloadname, &existingsize);
1147 if ((int)existingsize != size || existingcrc != crc)
1149 // we have a mismatching file, pick another name for it
1150 char name[MAX_QPATH*2];
1151 dpsnprintf(name, sizeof(name), "dlcache/%s.%i.%i", cls.qw_downloadname, size, crc);
1152 if (!FS_FileExists(name))
1154 Con_Printf("Downloaded \"%s\" (%i bytes, %i CRC)\n", name, size, crc);
1155 FS_WriteFile(name, cls.qw_downloadmemory, cls.qw_downloadmemorycursize);
1161 // we either don't have it or have a mismatching file...
1162 // so it's time to accept the file
1163 // but if we already have a mismatching file we need to rename
1164 // this new one, and if we already have this file in renamed form,
1166 Con_Printf("Downloaded \"%s\" (%i bytes, %i CRC)\n", cls.qw_downloadname, size, crc);
1167 FS_WriteFile(cls.qw_downloadname, cls.qw_downloadmemory, cls.qw_downloadmemorycursize);
1168 extension = FS_FileExtension(cls.qw_downloadname);
1169 if (!strcasecmp(extension, "pak") || !strcasecmp(extension, "pk3"))
1174 if (cls.qw_downloadmemory)
1175 Mem_Free(cls.qw_downloadmemory);
1176 cls.qw_downloadmemory = NULL;
1177 cls.qw_downloadname[0] = 0;
1178 cls.qw_downloadmemorymaxsize = 0;
1179 cls.qw_downloadmemorycursize = 0;
1180 cls.qw_downloadpercent = 0;
1183 void CL_ParseDownload(void)
1186 unsigned char data[65536];
1187 start = MSG_ReadLong();
1188 size = (unsigned short)MSG_ReadShort();
1190 // record the start/size information to ack in the next input packet
1191 for (i = 0;i < CL_MAX_DOWNLOADACKS;i++)
1193 if (!cls.dp_downloadack[i].start && !cls.dp_downloadack[i].size)
1195 cls.dp_downloadack[i].start = start;
1196 cls.dp_downloadack[i].size = size;
1201 MSG_ReadBytes(size, data);
1203 if (!cls.qw_downloadname[0])
1206 Con_Printf("CL_ParseDownload: received %i bytes with no download active\n", size);
1210 if (start + size > cls.qw_downloadmemorymaxsize)
1211 Host_Error("corrupt download message\n");
1213 // only advance cursize if the data is at the expected position
1214 // (gaps are unacceptable)
1215 memcpy(cls.qw_downloadmemory + start, data, size);
1216 cls.qw_downloadmemorycursize = start + size;
1217 cls.qw_downloadpercent = (int)floor((start+size) * 100.0 / cls.qw_downloadmemorymaxsize);
1218 cls.qw_downloadpercent = bound(0, cls.qw_downloadpercent, 100);
1219 cls.qw_downloadspeedcount += size;
1222 void CL_DownloadBegin_f(void)
1224 int size = atoi(Cmd_Argv(1));
1226 if (size < 0 || size > 1<<30 || FS_CheckNastyPath(Cmd_Argv(2), false))
1228 Con_Printf("cl_downloadbegin: received bogus information\n");
1229 CL_StopDownload(0, 0);
1233 if (cls.qw_downloadname[0])
1234 Con_Printf("Download of %s aborted\n", cls.qw_downloadname);
1236 CL_StopDownload(0, 0);
1238 // we're really beginning a download now, so initialize stuff
1239 strlcpy(cls.qw_downloadname, Cmd_Argv(2), sizeof(cls.qw_downloadname));
1240 cls.qw_downloadmemorymaxsize = size;
1241 cls.qw_downloadmemory = Mem_Alloc(cls.permanentmempool, cls.qw_downloadmemorymaxsize);
1242 cls.qw_downloadnumber++;
1244 Cmd_ForwardStringToServer("sv_startdownload");
1247 void CL_StopDownload_f(void)
1249 if (cls.qw_downloadname[0])
1251 Con_Printf("Download of %s aborted\n", cls.qw_downloadname);
1252 CL_StopDownload(0, 0);
1254 CL_BeginDownloads(true);
1257 void CL_DownloadFinished_f(void)
1261 Con_Printf("Malformed cl_downloadfinished command\n");
1264 CL_StopDownload(atoi(Cmd_Argv(1)), atoi(Cmd_Argv(2)));
1265 CL_BeginDownloads(false);
1268 static void CL_SendPlayerInfo(void)
1270 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
1271 MSG_WriteString (&cls.netcon->message, va("name \"%s\"", cl_name.string));
1273 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
1274 MSG_WriteString (&cls.netcon->message, va("color %i %i", cl_color.integer >> 4, cl_color.integer & 15));
1276 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
1277 MSG_WriteString (&cls.netcon->message, va("rate %i", cl_rate.integer));
1279 if (cl_pmodel.integer)
1281 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
1282 MSG_WriteString (&cls.netcon->message, va("pmodel %i", cl_pmodel.integer));
1284 if (*cl_playermodel.string)
1286 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
1287 MSG_WriteString (&cls.netcon->message, va("playermodel %s", cl_playermodel.string));
1289 if (*cl_playerskin.string)
1291 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
1292 MSG_WriteString (&cls.netcon->message, va("playerskin %s", cl_playerskin.string));
1297 =====================
1300 An svc_signonnum has been received, perform a client side setup
1301 =====================
1303 static void CL_SignonReply (void)
1305 Con_DPrintf("CL_SignonReply: %i\n", cls.signon);
1312 // send player info before we begin downloads
1313 // (so that the server can see the player name while downloading)
1314 CL_SendPlayerInfo();
1316 // execute cl_begindownloads next frame
1317 // (after any commands added by svc_stufftext have been executed)
1318 // when done with downloads the "prespawn" will be sent
1319 Cbuf_AddText("\ncl_begindownloads\n");
1321 //MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
1322 //MSG_WriteString (&cls.netcon->message, "prespawn");
1324 else // playing a demo... make sure loading occurs as soon as possible
1325 CL_BeginDownloads(false);
1331 // LordHavoc: quake sent the player info here but due to downloads
1332 // it is sent earlier instead
1333 // CL_SendPlayerInfo();
1335 // LordHavoc: changed to begin a loading stage and issue this when done
1336 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
1337 MSG_WriteString (&cls.netcon->message, "spawn");
1344 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
1345 MSG_WriteString (&cls.netcon->message, "begin");
1360 void CL_ParseServerInfo (void)
1364 protocolversion_t protocol;
1365 int nummodels, numsounds;
1367 Con_DPrint("Serverinfo packet received.\n");
1369 // if server is active, we already began a loading plaque
1371 SCR_BeginLoadingPlaque();
1373 // check memory integrity
1374 Mem_CheckSentinelsGlobal();
1376 // clear cl_serverextension cvars
1377 Cvar_SetValueQuick(&cl_serverextension_download, 0);
1380 // wipe the client_state_t struct
1384 // parse protocol version number
1385 i = MSG_ReadLong ();
1386 protocol = Protocol_EnumForNumber(i);
1387 if (protocol == PROTOCOL_UNKNOWN)
1389 Host_Error("CL_ParseServerInfo: Server is unrecognized protocol number (%i)", i);
1392 // hack for unmarked Nehahra movie demos which had a custom protocol
1393 if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
1394 protocol = PROTOCOL_NEHAHRAMOVIE;
1395 cls.protocol = protocol;
1396 Con_DPrintf("Server protocol is %s\n", Protocol_NameForEnum(cls.protocol));
1398 cl.num_entities = 1;
1400 if (protocol == PROTOCOL_QUAKEWORLD)
1402 char gamedir[1][MAX_QPATH];
1404 cl.qw_servercount = MSG_ReadLong();
1406 str = MSG_ReadString();
1407 Con_Printf("server gamedir is %s\n", str);
1408 strlcpy(gamedir[0], str, sizeof(gamedir[0]));
1410 // change gamedir if needed
1411 if (!FS_ChangeGameDirs(1, gamedir, true, false))
1412 Host_Error("CL_ParseServerInfo: unable to switch to server specified gamedir");
1414 cl.gametype = GAME_DEATHMATCH;
1417 // parse player number
1419 // cl.qw_spectator is an unneeded flag, cl.scores[cl.playerentity].qw_spectator works better (it can be updated by the server during the game)
1420 //cl.qw_spectator = (i & 128) != 0;
1421 cl.playerentity = cl.viewentity = (i & 127) + 1;
1422 cl.scores = (scoreboard_t *)Mem_Alloc(cls.levelmempool, cl.maxclients*sizeof(*cl.scores));
1424 // get the full level name
1425 str = MSG_ReadString ();
1426 strlcpy (cl.levelname, str, sizeof(cl.levelname));
1428 // get the movevars that are defined in the qw protocol
1429 cl.movevars_gravity = MSG_ReadFloat();
1430 cl.movevars_stopspeed = MSG_ReadFloat();
1431 cl.movevars_maxspeed = MSG_ReadFloat();
1432 cl.movevars_spectatormaxspeed = MSG_ReadFloat();
1433 cl.movevars_accelerate = MSG_ReadFloat();
1434 cl.movevars_airaccelerate = MSG_ReadFloat();
1435 cl.movevars_wateraccelerate = MSG_ReadFloat();
1436 cl.movevars_friction = MSG_ReadFloat();
1437 cl.movevars_waterfriction = MSG_ReadFloat();
1438 cl.movevars_entgravity = MSG_ReadFloat();
1440 // other movevars not in the protocol...
1441 cl.movevars_wallfriction = 0;
1442 cl.movevars_timescale = 1;
1443 cl.movevars_jumpvelocity = 270;
1444 cl.movevars_edgefriction = 2;
1445 cl.movevars_maxairspeed = 30;
1446 cl.movevars_stepheight = 18;
1447 cl.movevars_airaccel_qw = 1;
1448 cl.movevars_airaccel_sideways_friction = 0;
1450 // seperate the printfs so the server message can have a color
1451 Con_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n\2%s\n", str);
1453 // check memory integrity
1454 Mem_CheckSentinelsGlobal();
1458 MSG_WriteByte(&cls.netcon->message, qw_clc_stringcmd);
1459 MSG_WriteString(&cls.netcon->message, va("soundlist %i %i", cl.qw_servercount, 0));
1462 cl.loadbegun = false;
1463 cl.loadfinished = false;
1465 cls.state = ca_connected;
1468 // note: on QW protocol we can't set up the gameworld until after
1469 // downloads finish...
1470 // (we don't even know the name of the map yet)
1475 cl.maxclients = MSG_ReadByte ();
1476 if (cl.maxclients < 1 || cl.maxclients > MAX_SCOREBOARD)
1478 Host_Error("Bad maxclients (%u) from server", cl.maxclients);
1481 cl.scores = (scoreboard_t *)Mem_Alloc(cls.levelmempool, cl.maxclients*sizeof(*cl.scores));
1484 cl.gametype = MSG_ReadByte ();
1486 // parse signon message
1487 str = MSG_ReadString ();
1488 strlcpy (cl.levelname, str, sizeof(cl.levelname));
1490 // seperate the printfs so the server message can have a color
1491 if (cls.protocol != PROTOCOL_NEHAHRAMOVIE) // no messages when playing the Nehahra movie
1492 Con_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n\2%s\n", str);
1494 // check memory integrity
1495 Mem_CheckSentinelsGlobal();
1497 // parse model precache list
1498 for (nummodels=1 ; ; nummodels++)
1500 str = MSG_ReadString();
1503 if (nummodels==MAX_MODELS)
1504 Host_Error ("Server sent too many model precaches");
1505 if (strlen(str) >= MAX_QPATH)
1506 Host_Error ("Server sent a precache name of %i characters (max %i)", (int)strlen(str), MAX_QPATH - 1);
1507 strlcpy (cl.model_name[nummodels], str, sizeof (cl.model_name[nummodels]));
1509 // parse sound precache list
1510 for (numsounds=1 ; ; numsounds++)
1512 str = MSG_ReadString();
1515 if (numsounds==MAX_SOUNDS)
1516 Host_Error("Server sent too many sound precaches");
1517 if (strlen(str) >= MAX_QPATH)
1518 Host_Error("Server sent a precache name of %i characters (max %i)", (int)strlen(str), MAX_QPATH - 1);
1519 strlcpy (cl.sound_name[numsounds], str, sizeof (cl.sound_name[numsounds]));
1522 // touch all of the precached models that are still loaded so we can free
1523 // anything that isn't needed
1526 for (i = 1;i < nummodels;i++)
1527 Mod_FindName(cl.model_name[i]);
1528 // precache any models used by the client (this also marks them used)
1529 cl.model_bolt = Mod_ForName("progs/bolt.mdl", false, false, false);
1530 cl.model_bolt2 = Mod_ForName("progs/bolt2.mdl", false, false, false);
1531 cl.model_bolt3 = Mod_ForName("progs/bolt3.mdl", false, false, false);
1532 cl.model_beam = Mod_ForName("progs/beam.mdl", false, false, false);
1535 // do the same for sounds
1536 // FIXME: S_ServerSounds does not know about cl.sfx_ sounds
1537 S_ServerSounds (cl.sound_name, numsounds);
1539 // precache any sounds used by the client
1540 cl.sfx_wizhit = S_PrecacheSound(cl_sound_wizardhit.string, false, true);
1541 cl.sfx_knighthit = S_PrecacheSound(cl_sound_hknighthit.string, false, true);
1542 cl.sfx_tink1 = S_PrecacheSound(cl_sound_tink1.string, false, true);
1543 cl.sfx_ric1 = S_PrecacheSound(cl_sound_ric1.string, false, true);
1544 cl.sfx_ric2 = S_PrecacheSound(cl_sound_ric2.string, false, true);
1545 cl.sfx_ric3 = S_PrecacheSound(cl_sound_ric3.string, false, true);
1546 cl.sfx_r_exp3 = S_PrecacheSound(cl_sound_r_exp3.string, false, true);
1548 // now we try to load everything that is new
1549 cl.loadmodel_current = 1;
1550 cl.downloadmodel_current = 1;
1551 cl.loadmodel_total = nummodels;
1552 cl.loadsound_current = 1;
1553 cl.downloadsound_current = 1;
1554 cl.loadsound_total = numsounds;
1555 cl.downloadcsqc = true;
1556 cl.loadbegun = false;
1557 cl.loadfinished = false;
1560 // check memory integrity
1561 Mem_CheckSentinelsGlobal();
1563 // if cl_autodemo is set, automatically start recording a demo if one isn't being recorded already
1564 if (cl_autodemo.integer && cls.netcon && cls.protocol != PROTOCOL_QUAKEWORLD)
1566 char demofile[MAX_OSPATH];
1567 char levelname[MAX_QPATH];
1569 if (cls.demorecording)
1571 // finish the previous level's demo file
1575 // start a new demo file
1576 strlcpy(levelname, FS_FileWithoutPath(cl.model_name[1]), sizeof(levelname));
1577 if (strrchr(levelname, '.'))
1578 *(strrchr(levelname, '.')) = 0;
1579 dpsnprintf (demofile, sizeof(demofile), "%s_%s.dem", Sys_TimeString (cl_autodemo_nameformat.string), levelname);
1581 Con_Printf ("Auto-recording to %s.\n", demofile);
1583 cls.demofile = FS_Open (demofile, "wb", false, false);
1586 cls.forcetrack = -1;
1587 FS_Printf (cls.demofile, "%i\n", cls.forcetrack);
1588 cls.demorecording = true;
1591 Con_Print ("ERROR: couldn't open.\n");
1595 void CL_ValidateState(entity_state_t *s)
1602 if (s->modelindex >= MAX_MODELS)
1603 Host_Error("CL_ValidateState: modelindex (%i) >= MAX_MODELS (%i)\n", s->modelindex, MAX_MODELS);
1605 // colormap is client index + 1
1606 if ((!s->flags & RENDER_COLORMAPPED) && s->colormap > cl.maxclients)
1608 Con_DPrintf("CL_ValidateState: colormap (%i) > cl.maxclients (%i)\n", s->colormap, cl.maxclients);
1612 model = cl.model_precache[s->modelindex];
1613 if (model && model->type && s->frame >= model->numframes)
1615 Con_DPrintf("CL_ValidateState: no such frame %i in \"%s\" (which has %i frames)\n", s->frame, model->name, model->numframes);
1618 if (model && model->type && s->skin > 0 && s->skin >= model->numskins && !(s->lightpflags & PFLAGS_FULLDYNAMIC))
1620 Con_DPrintf("CL_ValidateState: no such skin %i in \"%s\" (which has %i skins)\n", s->skin, model->name, model->numskins);
1625 void CL_MoveLerpEntityStates(entity_t *ent)
1627 float odelta[3], adelta[3];
1628 CL_ValidateState(&ent->state_current);
1629 VectorSubtract(ent->state_current.origin, ent->persistent.neworigin, odelta);
1630 VectorSubtract(ent->state_current.angles, ent->persistent.newangles, adelta);
1631 if (!ent->state_previous.active || ent->state_previous.modelindex != ent->state_current.modelindex)
1633 // reset all persistent stuff if this is a new entity
1634 ent->persistent.lerpdeltatime = 0;
1635 ent->persistent.lerpstarttime = cl.mtime[1];
1636 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
1637 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
1638 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
1639 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
1640 // reset animation interpolation as well
1641 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
1642 ent->render.frame1time = ent->render.frame2time = cl.time;
1643 ent->render.framelerp = 1;
1644 // reset various persistent stuff
1645 ent->persistent.muzzleflash = 0;
1646 ent->persistent.trail_allowed = false;
1648 else if (DotProduct(odelta, odelta) > 1000*1000 || (cl.fixangle[0] && !cl.fixangle[1]))
1650 // don't interpolate the move
1651 // (the fixangle[] check detects teleports, but not constant fixangles
1652 // such as when spectating)
1653 ent->persistent.lerpdeltatime = 0;
1654 ent->persistent.lerpstarttime = cl.mtime[1];
1655 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
1656 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
1657 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
1658 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
1659 ent->persistent.trail_allowed = false;
1661 else if (ent->state_current.flags & RENDER_STEP)
1663 // monster interpolation
1664 if (DotProduct(odelta, odelta) + DotProduct(adelta, adelta) > 0.01)
1666 ent->persistent.lerpdeltatime = bound(0, cl.mtime[1] - ent->persistent.lerpstarttime, 0.1);
1667 ent->persistent.lerpstarttime = cl.mtime[1];
1668 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
1669 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
1670 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
1671 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
1677 ent->persistent.lerpstarttime = ent->state_previous.time;
1678 // no lerp if it's singleplayer
1679 if (cl.islocalgame && !sv_fixedframeratesingleplayer.integer)
1680 ent->persistent.lerpdeltatime = 0;
1682 ent->persistent.lerpdeltatime = bound(0, ent->state_current.time - ent->state_previous.time, 0.1);
1683 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
1684 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
1685 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
1686 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
1688 // trigger muzzleflash effect if necessary
1689 if (ent->state_current.effects & EF_MUZZLEFLASH)
1690 ent->persistent.muzzleflash = 1;
1698 void CL_ParseBaseline (entity_t *ent, int large)
1702 ent->state_baseline = defaultstate;
1703 // FIXME: set ent->state_baseline.number?
1704 ent->state_baseline.active = true;
1707 ent->state_baseline.modelindex = (unsigned short) MSG_ReadShort ();
1708 ent->state_baseline.frame = (unsigned short) MSG_ReadShort ();
1712 ent->state_baseline.modelindex = MSG_ReadByte ();
1713 ent->state_baseline.frame = MSG_ReadByte ();
1715 ent->state_baseline.colormap = MSG_ReadByte();
1716 ent->state_baseline.skin = MSG_ReadByte();
1717 for (i = 0;i < 3;i++)
1719 ent->state_baseline.origin[i] = MSG_ReadCoord(cls.protocol);
1720 ent->state_baseline.angles[i] = MSG_ReadAngle(cls.protocol);
1722 ent->state_previous = ent->state_current = ent->state_baseline;
1730 Server information pertaining to this client only
1733 void CL_ParseClientdata (void)
1737 VectorCopy (cl.mpunchangle[0], cl.mpunchangle[1]);
1738 VectorCopy (cl.mpunchvector[0], cl.mpunchvector[1]);
1739 VectorCopy (cl.mvelocity[0], cl.mvelocity[1]);
1740 cl.mviewzoom[1] = cl.mviewzoom[0];
1742 if (cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4 || cls.protocol == PROTOCOL_DARKPLACES5)
1744 cl.stats[STAT_VIEWHEIGHT] = DEFAULT_VIEWHEIGHT;
1745 cl.stats[STAT_ITEMS] = 0;
1746 cl.stats[STAT_VIEWZOOM] = 255;
1749 cl.mpunchangle[0][0] = 0;
1750 cl.mpunchangle[0][1] = 0;
1751 cl.mpunchangle[0][2] = 0;
1752 cl.mpunchvector[0][0] = 0;
1753 cl.mpunchvector[0][1] = 0;
1754 cl.mpunchvector[0][2] = 0;
1755 cl.mvelocity[0][0] = 0;
1756 cl.mvelocity[0][1] = 0;
1757 cl.mvelocity[0][2] = 0;
1758 cl.mviewzoom[0] = 1;
1760 bits = (unsigned short) MSG_ReadShort ();
1761 if (bits & SU_EXTEND1)
1762 bits |= (MSG_ReadByte() << 16);
1763 if (bits & SU_EXTEND2)
1764 bits |= (MSG_ReadByte() << 24);
1766 if (bits & SU_VIEWHEIGHT)
1767 cl.stats[STAT_VIEWHEIGHT] = MSG_ReadChar ();
1769 if (bits & SU_IDEALPITCH)
1770 cl.idealpitch = MSG_ReadChar ();
1772 for (i = 0;i < 3;i++)
1774 if (bits & (SU_PUNCH1<<i) )
1776 if (cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE)
1777 cl.mpunchangle[0][i] = MSG_ReadChar();
1779 cl.mpunchangle[0][i] = MSG_ReadAngle16i();
1781 if (bits & (SU_PUNCHVEC1<<i))
1783 if (cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4)
1784 cl.mpunchvector[0][i] = MSG_ReadCoord16i();
1786 cl.mpunchvector[0][i] = MSG_ReadCoord32f();
1788 if (bits & (SU_VELOCITY1<<i) )
1790 if (cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4)
1791 cl.mvelocity[0][i] = MSG_ReadChar()*16;
1793 cl.mvelocity[0][i] = MSG_ReadCoord32f();
1797 // LordHavoc: hipnotic demos don't have this bit set but should
1798 if (bits & SU_ITEMS || cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4 || cls.protocol == PROTOCOL_DARKPLACES5)
1799 cl.stats[STAT_ITEMS] = MSG_ReadLong ();
1801 cl.onground = (bits & SU_ONGROUND) != 0;
1802 cl.inwater = (bits & SU_INWATER) != 0;
1804 if (cls.protocol == PROTOCOL_DARKPLACES5)
1806 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadShort() : 0;
1807 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadShort() : 0;
1808 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadShort() : 0;
1809 cl.stats[STAT_HEALTH] = MSG_ReadShort();
1810 cl.stats[STAT_AMMO] = MSG_ReadShort();
1811 cl.stats[STAT_SHELLS] = MSG_ReadShort();
1812 cl.stats[STAT_NAILS] = MSG_ReadShort();
1813 cl.stats[STAT_ROCKETS] = MSG_ReadShort();
1814 cl.stats[STAT_CELLS] = MSG_ReadShort();
1815 cl.stats[STAT_ACTIVEWEAPON] = (unsigned short) MSG_ReadShort ();
1817 else if (cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4)
1819 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
1820 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
1821 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
1822 cl.stats[STAT_HEALTH] = MSG_ReadShort();
1823 cl.stats[STAT_AMMO] = MSG_ReadByte();
1824 cl.stats[STAT_SHELLS] = MSG_ReadByte();
1825 cl.stats[STAT_NAILS] = MSG_ReadByte();
1826 cl.stats[STAT_ROCKETS] = MSG_ReadByte();
1827 cl.stats[STAT_CELLS] = MSG_ReadByte();
1828 if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_NEXUIZ)
1829 cl.stats[STAT_ACTIVEWEAPON] = (1<<MSG_ReadByte ());
1831 cl.stats[STAT_ACTIVEWEAPON] = MSG_ReadByte ();
1834 if (bits & SU_VIEWZOOM)
1836 if (cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4)
1837 cl.stats[STAT_VIEWZOOM] = MSG_ReadByte();
1839 cl.stats[STAT_VIEWZOOM] = (unsigned short) MSG_ReadShort();
1842 // viewzoom interpolation
1843 cl.mviewzoom[0] = (float) max(cl.stats[STAT_VIEWZOOM], 2) * (1.0f / 255.0f);
1847 =====================
1849 =====================
1851 void CL_ParseStatic (int large)
1855 if (cl.num_static_entities >= cl.max_static_entities)
1856 Host_Error ("Too many static entities");
1857 ent = &cl.static_entities[cl.num_static_entities++];
1858 CL_ParseBaseline (ent, large);
1860 if (ent->state_baseline.modelindex == 0)
1862 Con_DPrintf("svc_parsestatic: static entity without model at %f %f %f\n", ent->state_baseline.origin[0], ent->state_baseline.origin[1], ent->state_baseline.origin[2]);
1863 cl.num_static_entities--;
1864 // This is definitely a cheesy way to conserve resources...
1868 // copy it to the current state
1869 ent->render.model = cl.model_precache[ent->state_baseline.modelindex];
1870 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_baseline.frame;
1871 ent->render.framelerp = 0;
1872 // make torchs play out of sync
1873 ent->render.frame1time = ent->render.frame2time = lhrandom(-10, -1);
1874 ent->render.colormap = -1; // no special coloring
1875 ent->render.skinnum = ent->state_baseline.skin;
1876 ent->render.effects = ent->state_baseline.effects;
1877 ent->render.alpha = 1;
1879 //VectorCopy (ent->state_baseline.origin, ent->render.origin);
1880 //VectorCopy (ent->state_baseline.angles, ent->render.angles);
1882 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, ent->state_baseline.origin[0], ent->state_baseline.origin[1], ent->state_baseline.origin[2], ent->state_baseline.angles[0], ent->state_baseline.angles[1], ent->state_baseline.angles[2], 1);
1883 CL_UpdateRenderEntity(&ent->render);
1891 void CL_ParseStaticSound (int large)
1894 int sound_num, vol, atten;
1896 MSG_ReadVector(org, cls.protocol);
1898 sound_num = (unsigned short) MSG_ReadShort ();
1900 sound_num = MSG_ReadByte ();
1901 vol = MSG_ReadByte ();
1902 atten = MSG_ReadByte ();
1904 S_StaticSound (cl.sound_precache[sound_num], org, vol/255.0f, atten);
1907 void CL_ParseEffect (void)
1910 int modelindex, startframe, framecount, framerate;
1912 MSG_ReadVector(org, cls.protocol);
1913 modelindex = MSG_ReadByte ();
1914 startframe = MSG_ReadByte ();
1915 framecount = MSG_ReadByte ();
1916 framerate = MSG_ReadByte ();
1918 CL_Effect(org, modelindex, startframe, framecount, framerate);
1921 void CL_ParseEffect2 (void)
1924 int modelindex, startframe, framecount, framerate;
1926 MSG_ReadVector(org, cls.protocol);
1927 modelindex = (unsigned short) MSG_ReadShort ();
1928 startframe = (unsigned short) MSG_ReadShort ();
1929 framecount = MSG_ReadByte ();
1930 framerate = MSG_ReadByte ();
1932 CL_Effect(org, modelindex, startframe, framecount, framerate);
1935 void CL_NewBeam (int ent, vec3_t start, vec3_t end, model_t *m, int lightning)
1940 if (ent >= MAX_EDICTS)
1942 Con_Printf("CL_NewBeam: invalid entity number %i\n", ent);
1946 if (ent >= cl.max_entities)
1947 CL_ExpandEntities(ent);
1949 // override any beam with the same entity
1952 for (i = 0, b = cl.beams;i < cl.max_beams;i++, b++)
1953 if (b->entity == ent)
1955 // if the entity was not found then just replace an unused beam
1956 if (i == cl.max_beams)
1957 for (i = 0, b = cl.beams;i < cl.max_beams;i++, b++)
1960 if (i < cl.max_beams)
1962 cl.num_beams = max(cl.num_beams, i + 1);
1964 b->lightning = lightning;
1966 b->endtime = cl.mtime[0] + 0.2;
1967 VectorCopy (start, b->start);
1968 VectorCopy (end, b->end);
1971 Con_Print("beam list overflow!\n");
1974 void CL_ParseBeam (model_t *m, int lightning)
1979 ent = (unsigned short) MSG_ReadShort ();
1980 MSG_ReadVector(start, cls.protocol);
1981 MSG_ReadVector(end, cls.protocol);
1983 if (ent >= MAX_EDICTS)
1985 Con_Printf("CL_ParseBeam: invalid entity number %i\n", ent);
1989 CL_NewBeam(ent, start, end, m, lightning);
1992 void CL_ParseTempEntity(void)
2000 int colorStart, colorLength, count;
2001 float velspeed, radius;
2002 unsigned char *tempcolor;
2003 matrix4x4_t tempmatrix;
2005 if (cls.protocol == PROTOCOL_QUAKEWORLD)
2007 type = MSG_ReadByte();
2010 case QW_TE_WIZSPIKE:
2011 // spike hitting wall
2012 MSG_ReadVector(pos, cls.protocol);
2013 CL_FindNonSolidLocation(pos, pos, 4);
2014 CL_ParticleEffect(EFFECT_TE_WIZSPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2015 S_StartSound(-1, 0, cl.sfx_wizhit, pos, 1, 1);
2018 case QW_TE_KNIGHTSPIKE:
2019 // spike hitting wall
2020 MSG_ReadVector(pos, cls.protocol);
2021 CL_FindNonSolidLocation(pos, pos, 4);
2022 CL_ParticleEffect(EFFECT_TE_KNIGHTSPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2023 S_StartSound(-1, 0, cl.sfx_knighthit, pos, 1, 1);
2027 // spike hitting wall
2028 MSG_ReadVector(pos, cls.protocol);
2029 CL_FindNonSolidLocation(pos, pos, 4);
2030 CL_ParticleEffect(EFFECT_TE_SPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2032 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
2037 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
2039 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
2041 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
2044 case QW_TE_SUPERSPIKE:
2045 // super spike hitting wall
2046 MSG_ReadVector(pos, cls.protocol);
2047 CL_FindNonSolidLocation(pos, pos, 4);
2048 CL_ParticleEffect(EFFECT_TE_SUPERSPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2050 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
2055 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
2057 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
2059 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
2063 case QW_TE_EXPLOSION:
2065 MSG_ReadVector(pos, cls.protocol);
2066 CL_FindNonSolidLocation(pos, pos, 10);
2067 CL_ParticleEffect(EFFECT_TE_EXPLOSION, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2068 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
2069 CL_Effect(pos, cl.qw_modelindex_s_explod, 0, 6, 10);
2072 case QW_TE_TAREXPLOSION:
2073 // tarbaby explosion
2074 MSG_ReadVector(pos, cls.protocol);
2075 CL_FindNonSolidLocation(pos, pos, 10);
2076 CL_ParticleEffect(EFFECT_TE_TAREXPLOSION, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2077 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
2080 case QW_TE_LIGHTNING1:
2082 CL_ParseBeam(cl.model_bolt, true);
2085 case QW_TE_LIGHTNING2:
2087 CL_ParseBeam(cl.model_bolt2, true);
2090 case QW_TE_LIGHTNING3:
2092 CL_ParseBeam(cl.model_bolt3, false);
2095 case QW_TE_LAVASPLASH:
2096 MSG_ReadVector(pos, cls.protocol);
2097 CL_ParticleEffect(EFFECT_TE_LAVASPLASH, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2100 case QW_TE_TELEPORT:
2101 MSG_ReadVector(pos, cls.protocol);
2102 CL_ParticleEffect(EFFECT_TE_TELEPORT, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2106 // bullet hitting wall
2107 radius = MSG_ReadByte();
2108 MSG_ReadVector(pos, cls.protocol);
2109 CL_FindNonSolidLocation(pos, pos, 4);
2110 VectorSet(pos2, pos[0] + radius, pos[1] + radius, pos[2] + radius);
2111 VectorSet(pos, pos[0] - radius, pos[1] - radius, pos[2] - radius);
2112 CL_ParticleEffect(EFFECT_TE_GUNSHOT, radius, pos, pos2, vec3_origin, vec3_origin, NULL, 0);
2113 if(cl_sound_ric_gunshot.integer & RIC_GUNSHOT)
2116 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
2121 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
2123 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
2125 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
2131 count = MSG_ReadByte();
2132 MSG_ReadVector(pos, cls.protocol);
2133 CL_FindNonSolidLocation(pos, pos, 4);
2134 CL_ParticleEffect(EFFECT_TE_BLOOD, count, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2137 case QW_TE_LIGHTNINGBLOOD:
2138 MSG_ReadVector(pos, cls.protocol);
2139 CL_FindNonSolidLocation(pos, pos, 4);
2140 CL_ParticleEffect(EFFECT_TE_BLOOD, 2.5, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2144 Host_Error("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
2149 type = MSG_ReadByte();
2153 // spike hitting wall
2154 MSG_ReadVector(pos, cls.protocol);
2155 CL_FindNonSolidLocation(pos, pos, 4);
2156 CL_ParticleEffect(EFFECT_TE_WIZSPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2157 S_StartSound(-1, 0, cl.sfx_wizhit, pos, 1, 1);
2160 case TE_KNIGHTSPIKE:
2161 // spike hitting wall
2162 MSG_ReadVector(pos, cls.protocol);
2163 CL_FindNonSolidLocation(pos, pos, 4);
2164 CL_ParticleEffect(EFFECT_TE_KNIGHTSPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2165 S_StartSound(-1, 0, cl.sfx_knighthit, pos, 1, 1);
2169 // spike hitting wall
2170 MSG_ReadVector(pos, cls.protocol);
2171 CL_FindNonSolidLocation(pos, pos, 4);
2172 CL_ParticleEffect(EFFECT_TE_SPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2174 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
2179 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
2181 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
2183 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
2187 // quad spike hitting wall
2188 MSG_ReadVector(pos, cls.protocol);
2189 CL_FindNonSolidLocation(pos, pos, 4);
2190 CL_ParticleEffect(EFFECT_TE_SPIKEQUAD, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2192 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
2197 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
2199 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
2201 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
2205 // super spike hitting wall
2206 MSG_ReadVector(pos, cls.protocol);
2207 CL_FindNonSolidLocation(pos, pos, 4);
2208 CL_ParticleEffect(EFFECT_TE_SUPERSPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2210 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
2215 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
2217 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
2219 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
2222 case TE_SUPERSPIKEQUAD:
2223 // quad super spike hitting wall
2224 MSG_ReadVector(pos, cls.protocol);
2225 CL_FindNonSolidLocation(pos, pos, 4);
2226 CL_ParticleEffect(EFFECT_TE_SUPERSPIKEQUAD, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2228 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
2233 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
2235 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
2237 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
2240 // LordHavoc: added for improved blood splatters
2243 MSG_ReadVector(pos, cls.protocol);
2244 CL_FindNonSolidLocation(pos, pos, 4);
2245 dir[0] = MSG_ReadChar();
2246 dir[1] = MSG_ReadChar();
2247 dir[2] = MSG_ReadChar();
2248 count = MSG_ReadByte();
2249 CL_ParticleEffect(EFFECT_TE_BLOOD, count, pos, pos, dir, dir, NULL, 0);
2253 MSG_ReadVector(pos, cls.protocol);
2254 CL_FindNonSolidLocation(pos, pos, 4);
2255 dir[0] = MSG_ReadChar();
2256 dir[1] = MSG_ReadChar();
2257 dir[2] = MSG_ReadChar();
2258 count = MSG_ReadByte();
2259 CL_ParticleEffect(EFFECT_TE_SPARK, count, pos, pos, dir, dir, NULL, 0);
2262 MSG_ReadVector(pos, cls.protocol);
2263 CL_FindNonSolidLocation(pos, pos, 4);
2264 CL_ParticleEffect(EFFECT_TE_PLASMABURN, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2266 // LordHavoc: added for improved gore
2267 case TE_BLOODSHOWER:
2269 MSG_ReadVector(pos, cls.protocol); // mins
2270 MSG_ReadVector(pos2, cls.protocol); // maxs
2271 velspeed = MSG_ReadCoord(cls.protocol); // speed
2272 count = (unsigned short) MSG_ReadShort(); // number of particles
2273 vel1[0] = -velspeed;
2274 vel1[1] = -velspeed;
2275 vel1[2] = -velspeed;
2279 CL_ParticleEffect(EFFECT_TE_BLOOD, count, pos, pos2, vel1, vel2, NULL, 0);
2282 case TE_PARTICLECUBE:
2283 // general purpose particle effect
2284 MSG_ReadVector(pos, cls.protocol); // mins
2285 MSG_ReadVector(pos2, cls.protocol); // maxs
2286 MSG_ReadVector(dir, cls.protocol); // dir
2287 count = (unsigned short) MSG_ReadShort(); // number of particles
2288 colorStart = MSG_ReadByte(); // color
2289 colorLength = MSG_ReadByte(); // gravity (1 or 0)
2290 velspeed = MSG_ReadCoord(cls.protocol); // randomvel
2291 CL_ParticleCube(pos, pos2, dir, count, colorStart, colorLength != 0, velspeed);
2294 case TE_PARTICLERAIN:
2295 // general purpose particle effect
2296 MSG_ReadVector(pos, cls.protocol); // mins
2297 MSG_ReadVector(pos2, cls.protocol); // maxs
2298 MSG_ReadVector(dir, cls.protocol); // dir
2299 count = (unsigned short) MSG_ReadShort(); // number of particles
2300 colorStart = MSG_ReadByte(); // color
2301 CL_ParticleRain(pos, pos2, dir, count, colorStart, 0);
2304 case TE_PARTICLESNOW:
2305 // general purpose particle effect
2306 MSG_ReadVector(pos, cls.protocol); // mins
2307 MSG_ReadVector(pos2, cls.protocol); // maxs
2308 MSG_ReadVector(dir, cls.protocol); // dir
2309 count = (unsigned short) MSG_ReadShort(); // number of particles
2310 colorStart = MSG_ReadByte(); // color
2311 CL_ParticleRain(pos, pos2, dir, count, colorStart, 1);
2315 // bullet hitting wall
2316 MSG_ReadVector(pos, cls.protocol);
2317 CL_FindNonSolidLocation(pos, pos, 4);
2318 CL_ParticleEffect(EFFECT_TE_GUNSHOT, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2319 if(cl_sound_ric_gunshot.integer & RIC_GUNSHOT)
2322 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
2327 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
2329 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
2331 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
2336 case TE_GUNSHOTQUAD:
2337 // quad bullet hitting wall
2338 MSG_ReadVector(pos, cls.protocol);
2339 CL_FindNonSolidLocation(pos, pos, 4);
2340 CL_ParticleEffect(EFFECT_TE_GUNSHOTQUAD, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2341 if(cl_sound_ric_gunshot.integer & RIC_GUNSHOTQUAD)
2344 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
2349 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
2351 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
2353 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
2360 MSG_ReadVector(pos, cls.protocol);
2361 CL_FindNonSolidLocation(pos, pos, 10);
2362 CL_ParticleEffect(EFFECT_TE_EXPLOSION, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2363 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
2366 case TE_EXPLOSIONQUAD:
2367 // quad rocket explosion
2368 MSG_ReadVector(pos, cls.protocol);
2369 CL_FindNonSolidLocation(pos, pos, 10);
2370 CL_ParticleEffect(EFFECT_TE_EXPLOSIONQUAD, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2371 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
2375 // Nehahra movie colored lighting explosion
2376 MSG_ReadVector(pos, cls.protocol);
2377 CL_FindNonSolidLocation(pos, pos, 10);
2378 color[0] = MSG_ReadCoord(cls.protocol) * (2.0f / 1.0f);
2379 color[1] = MSG_ReadCoord(cls.protocol) * (2.0f / 1.0f);
2380 color[2] = MSG_ReadCoord(cls.protocol) * (2.0f / 1.0f);
2381 CL_ParticleExplosion(pos);
2382 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
2383 CL_AllocLightFlash(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
2384 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
2387 case TE_EXPLOSIONRGB:
2388 // colored lighting explosion
2389 MSG_ReadVector(pos, cls.protocol);
2390 CL_FindNonSolidLocation(pos, pos, 10);
2391 CL_ParticleExplosion(pos);
2392 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
2393 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
2394 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
2395 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
2396 CL_AllocLightFlash(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
2397 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
2400 case TE_TAREXPLOSION:
2401 // tarbaby explosion
2402 MSG_ReadVector(pos, cls.protocol);
2403 CL_FindNonSolidLocation(pos, pos, 10);
2404 CL_ParticleEffect(EFFECT_TE_TAREXPLOSION, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2405 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
2409 MSG_ReadVector(pos, cls.protocol);
2410 CL_FindNonSolidLocation(pos, pos, 10);
2411 CL_ParticleEffect(EFFECT_TE_SMALLFLASH, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2414 case TE_CUSTOMFLASH:
2415 MSG_ReadVector(pos, cls.protocol);
2416 CL_FindNonSolidLocation(pos, pos, 4);
2417 radius = (MSG_ReadByte() + 1) * 8;
2418 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
2419 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
2420 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
2421 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
2422 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
2423 CL_AllocLightFlash(NULL, &tempmatrix, radius, color[0], color[1], color[2], radius / velspeed, velspeed, 0, -1, true, 1, 0.25, 1, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
2427 MSG_ReadVector(pos, cls.protocol);
2428 MSG_ReadVector(dir, cls.protocol);
2429 count = MSG_ReadByte();
2430 CL_ParticleEffect(EFFECT_TE_FLAMEJET, count, pos, pos, dir, dir, NULL, 0);
2435 CL_ParseBeam(cl.model_bolt, true);
2440 CL_ParseBeam(cl.model_bolt2, true);
2445 CL_ParseBeam(cl.model_bolt3, false);
2450 // grappling hook beam
2451 CL_ParseBeam(cl.model_beam, false);
2455 // LordHavoc: for compatibility with the Nehahra movie...
2456 case TE_LIGHTNING4NEH:
2457 CL_ParseBeam(Mod_ForName(MSG_ReadString(), true, false, false), false);
2461 MSG_ReadVector(pos, cls.protocol);
2462 CL_ParticleEffect(EFFECT_TE_LAVASPLASH, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2466 MSG_ReadVector(pos, cls.protocol);
2467 CL_ParticleEffect(EFFECT_TE_TELEPORT, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2471 // color mapped explosion
2472 MSG_ReadVector(pos, cls.protocol);
2473 CL_FindNonSolidLocation(pos, pos, 10);
2474 colorStart = MSG_ReadByte();
2475 colorLength = MSG_ReadByte();
2476 CL_ParticleExplosion2(pos, colorStart, colorLength);
2477 tempcolor = (unsigned char *)&palette_complete[(rand()%colorLength) + colorStart];
2478 color[0] = tempcolor[0] * (2.0f / 255.0f);
2479 color[1] = tempcolor[1] * (2.0f / 255.0f);
2480 color[2] = tempcolor[2] * (2.0f / 255.0f);
2481 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
2482 CL_AllocLightFlash(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
2483 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
2487 MSG_ReadVector(pos, cls.protocol);
2488 MSG_ReadVector(pos2, cls.protocol);
2489 MSG_ReadVector(dir, cls.protocol);
2490 CL_ParticleEffect(EFFECT_TE_TEI_G3, 1, pos, pos2, dir, dir, NULL, 0);
2494 MSG_ReadVector(pos, cls.protocol);
2495 MSG_ReadVector(dir, cls.protocol);
2496 count = MSG_ReadByte();
2497 CL_FindNonSolidLocation(pos, pos, 4);
2498 CL_ParticleEffect(EFFECT_TE_TEI_SMOKE, count, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2501 case TE_TEI_BIGEXPLOSION:
2502 MSG_ReadVector(pos, cls.protocol);
2503 CL_FindNonSolidLocation(pos, pos, 10);
2504 CL_ParticleEffect(EFFECT_TE_TEI_BIGEXPLOSION, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2505 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
2508 case TE_TEI_PLASMAHIT:
2509 MSG_ReadVector(pos, cls.protocol);
2510 MSG_ReadVector(dir, cls.protocol);
2511 count = MSG_ReadByte();
2512 CL_FindNonSolidLocation(pos, pos, 5);
2513 CL_ParticleEffect(EFFECT_TE_TEI_PLASMAHIT, count, pos, pos, vec3_origin, vec3_origin, NULL, 0);
2517 Host_Error("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
2522 void CL_ParseTrailParticles(void)
2527 entityindex = (unsigned short)MSG_ReadShort();
2528 if (entityindex >= MAX_EDICTS)
2530 if (entityindex >= cl.max_entities)
2531 CL_ExpandEntities(entityindex);
2532 effectindex = (unsigned short)MSG_ReadShort();
2533 MSG_ReadVector(start, cls.protocol);
2534 MSG_ReadVector(end, cls.protocol);
2535 CL_ParticleEffect(effectindex, VectorDistance(start, end), start, end, vec3_origin, vec3_origin, entityindex > 0 ? cl.entities + entityindex : NULL, 0);
2538 void CL_ParsePointParticles(void)
2540 int effectindex, count;
2541 vec3_t origin, velocity;
2542 effectindex = (unsigned short)MSG_ReadShort();
2543 MSG_ReadVector(origin, cls.protocol);
2544 MSG_ReadVector(velocity, cls.protocol);
2545 count = (unsigned short)MSG_ReadShort();
2546 CL_ParticleEffect(effectindex, count, origin, origin, velocity, velocity, NULL, 0);
2549 void CL_ParsePointParticles1(void)
2553 effectindex = (unsigned short)MSG_ReadShort();
2554 MSG_ReadVector(origin, cls.protocol);
2555 CL_ParticleEffect(effectindex, 1, origin, origin, vec3_origin, vec3_origin, NULL, 0);
2558 typedef struct cl_iplog_item_s
2565 static qboolean cl_iplog_loaded = false;
2566 static int cl_iplog_numitems = 0;
2567 static int cl_iplog_maxitems = 0;
2568 static cl_iplog_item_t *cl_iplog_items;
2570 static void CL_IPLog_Load(void);
2571 static void CL_IPLog_Add(const char *address, const char *name, qboolean checkexisting, qboolean addtofile)
2574 if (!address || !address[0] || !name || !name[0])
2576 if (!cl_iplog_loaded)
2578 if (developer.integer >= 100)
2579 Con_Printf("CL_IPLog_Add(\"%s\", \"%s\", %i, %i);\n", address, name, checkexisting, addtofile);
2580 // see if it already exists
2583 for (i = 0;i < cl_iplog_numitems;i++)
2585 if (!strcmp(cl_iplog_items[i].address, address) && !strcmp(cl_iplog_items[i].name, name))
2587 if (developer.integer >= 100)
2588 Con_Printf("... found existing \"%s\" \"%s\"\n", cl_iplog_items[i].address, cl_iplog_items[i].name);
2593 // it does not already exist in the iplog, so add it
2594 if (cl_iplog_maxitems <= cl_iplog_numitems || !cl_iplog_items)
2596 cl_iplog_item_t *olditems = cl_iplog_items;
2597 cl_iplog_maxitems = max(1024, cl_iplog_maxitems + 256);
2598 cl_iplog_items = Mem_Alloc(cls.permanentmempool, cl_iplog_maxitems * sizeof(cl_iplog_item_t));
2601 if (cl_iplog_numitems)
2602 memcpy(cl_iplog_items, olditems, cl_iplog_numitems * sizeof(cl_iplog_item_t));
2606 cl_iplog_items[cl_iplog_numitems].address = Mem_Alloc(cls.permanentmempool, strlen(address) + 1);
2607 cl_iplog_items[cl_iplog_numitems].name = Mem_Alloc(cls.permanentmempool, strlen(name) + 1);
2608 strlcpy(cl_iplog_items[cl_iplog_numitems].address, address, strlen(address) + 1);
2609 // TODO: maybe it would be better to strip weird characters from name when
2610 // copying it here rather than using a straight strcpy?
2611 strlcpy(cl_iplog_items[cl_iplog_numitems].name, name, strlen(name) + 1);
2612 cl_iplog_numitems++;
2615 // add it to the iplog.txt file
2616 // TODO: this ought to open the one in the userpath version of the base
2617 // gamedir, not the current gamedir
2618 Log_Printf(cl_iplog_name.string, "%s %s\n", address, name);
2619 if (developer.integer >= 100)
2620 Con_Printf("CL_IPLog_Add: appending this line to %s: %s %s\n", cl_iplog_name.string, address, name);
2624 static void CL_IPLog_Load(void)
2626 int i, len, linenumber;
2627 char *text, *textend;
2628 unsigned char *filedata;
2629 fs_offset_t filesize;
2630 char line[MAX_INPUTLINE];
2631 char address[MAX_INPUTLINE];
2632 cl_iplog_loaded = true;
2633 // TODO: this ought to open the one in the userpath version of the base
2634 // gamedir, not the current gamedir
2635 filedata = FS_LoadFile(cl_iplog_name.string, tempmempool, true, &filesize);
2638 text = (char *)filedata;
2639 textend = text + filesize;
2640 for (linenumber = 1;text < textend;linenumber++)
2642 for (len = 0;text < textend && *text != '\r' && *text != '\n';text++)
2643 if (len < (int)sizeof(line) - 1)
2644 line[len++] = *text;
2646 if (text < textend && *text == '\r' && text[1] == '\n')
2648 if (text < textend && *text == '\n')
2650 if (line[0] == '/' && line[1] == '/')
2651 continue; // skip comments if anyone happens to add them
2652 for (i = 0;i < len && line[i] > ' ';i++)
2653 address[i] = line[i];
2655 // skip exactly one space character
2657 // address contains the address with termination,
2658 // line + i contains the name with termination
2659 if (address[0] && line[i])
2660 CL_IPLog_Add(address, line + i, false, false);
2662 Con_Printf("%s:%i: could not parse address and name:\n%s\n", cl_iplog_name.string, linenumber, line);
2666 static void CL_IPLog_List_f(void)
2669 const char *addressprefix;
2672 Con_Printf("usage: %s 123.456.789.\n", Cmd_Argv(0));
2676 if (Cmd_Argc() >= 2)
2677 addressprefix = Cmd_Argv(1);
2678 if (!cl_iplog_loaded)
2680 if (addressprefix && addressprefix[0])
2681 Con_Printf("Listing iplog addresses beginning with %s\n", addressprefix);
2683 Con_Printf("Listing all iplog entries\n");
2684 Con_Printf("address name\n");
2685 for (i = 0;i < cl_iplog_numitems;i++)
2687 if (addressprefix && addressprefix[0])
2689 for (j = 0;addressprefix[j];j++)
2690 if (addressprefix[j] != cl_iplog_items[i].address[j])
2692 // if this address does not begin with the addressprefix string
2693 // simply omit it from the output
2694 if (addressprefix[j])
2697 // if name is less than 15 characters, left justify it and pad
2698 // if name is more than 15 characters, print all of it, not worrying
2699 // about the fact it will misalign the columns
2700 if (strlen(cl_iplog_items[i].address) < 15)
2701 Con_Printf("%-15s %s\n", cl_iplog_items[i].address, cl_iplog_items[i].name);
2703 Con_Printf("%5s %s\n", cl_iplog_items[i].address, cl_iplog_items[i].name);
2707 // look for anything interesting like player IP addresses or ping reports
2708 qboolean CL_ExaminePrintString(const char *text)
2712 char temp[MAX_INPUTLINE];
2713 if (!strcmp(text, "Client ping times:\n"))
2715 cl.parsingtextmode = CL_PARSETEXTMODE_PING;
2716 // hide ping reports in demos
2717 if (cls.demoplayback)
2718 cl.parsingtextexpectingpingforscores = 1;
2719 for(cl.parsingtextplayerindex = 0; cl.parsingtextplayerindex < cl.maxclients && !cl.scores[cl.parsingtextplayerindex].name[0]; cl.parsingtextplayerindex++)
2721 if (cl.parsingtextplayerindex >= cl.maxclients) // should never happen, since the client itself should be in cl.scores
2723 Con_Printf("ping reply but empty scoreboard?!?\n");
2724 cl.parsingtextmode = CL_PARSETEXTMODE_NONE;
2725 cl.parsingtextexpectingpingforscores = 0;
2727 cl.parsingtextexpectingpingforscores = cl.parsingtextexpectingpingforscores ? 2 : 0;
2728 return !cl.parsingtextexpectingpingforscores;
2730 if (!strncmp(text, "host: ", 9))
2732 // cl.parsingtextexpectingpingforscores = false; // really?
2733 cl.parsingtextmode = CL_PARSETEXTMODE_STATUS;
2734 cl.parsingtextplayerindex = 0;
2737 if (cl.parsingtextmode == CL_PARSETEXTMODE_PING)
2739 // if anything goes wrong, we'll assume this is not a ping report
2740 qboolean expected = cl.parsingtextexpectingpingforscores;
2741 cl.parsingtextexpectingpingforscores = 0;
2742 cl.parsingtextmode = CL_PARSETEXTMODE_NONE;
2746 if ((*t >= '0' && *t <= '9') || *t == '-')
2749 while ((*t >= '0' && *t <= '9') || *t == '-')
2755 if(cl.parsingtextplayerindex < cl.maxclients)
2757 for (charindex = 0;cl.scores[cl.parsingtextplayerindex].name[charindex] == t[charindex];charindex++)
2759 // note: the matching algorithm stops at the end of the player name because some servers append text such as " READY" after the player name in the scoreboard but not in the ping report
2760 //if (cl.scores[cl.parsingtextplayerindex].name[charindex] == 0 && t[charindex] == '\n')
2761 if (t[charindex] == '\n')
2763 cl.scores[cl.parsingtextplayerindex].qw_ping = bound(0, ping, 9999);
2764 for (cl.parsingtextplayerindex++;cl.parsingtextplayerindex < cl.maxclients && !cl.scores[cl.parsingtextplayerindex].name[0];cl.parsingtextplayerindex++)
2766 //if (cl.parsingtextplayerindex < cl.maxclients) // we could still get unconnecteds!
2768 // we parsed a valid ping entry, so expect another to follow
2769 cl.parsingtextmode = CL_PARSETEXTMODE_PING;
2770 cl.parsingtextexpectingpingforscores = expected;
2775 if (!strncmp(t, "unconnected\n", 12))
2778 cl.parsingtextmode = CL_PARSETEXTMODE_PING;
2779 cl.parsingtextexpectingpingforscores = expected;
2783 Con_DPrintf("player names '%s' and '%s' didn't match\n", cl.scores[cl.parsingtextplayerindex].name, t);
2787 if (cl.parsingtextmode == CL_PARSETEXTMODE_STATUS)
2789 if (!strncmp(text, "players: ", 9))
2791 cl.parsingtextmode = CL_PARSETEXTMODE_STATUS_PLAYERID;
2792 cl.parsingtextplayerindex = 0;
2795 else if (!strstr(text, ": "))
2797 cl.parsingtextmode = CL_PARSETEXTMODE_NONE; // status report ended
2801 if (cl.parsingtextmode == CL_PARSETEXTMODE_STATUS_PLAYERID)
2803 // if anything goes wrong, we'll assume this is not a status report
2804 cl.parsingtextmode = CL_PARSETEXTMODE_NONE;
2805 if (text[0] == '#' && text[1] >= '0' && text[1] <= '9')
2808 cl.parsingtextplayerindex = atoi(t) - 1;
2809 while (*t >= '0' && *t <= '9')
2813 cl.parsingtextmode = CL_PARSETEXTMODE_STATUS_PLAYERIP;
2816 // the player name follows here, along with frags and time
2819 if (cl.parsingtextmode == CL_PARSETEXTMODE_STATUS_PLAYERIP)
2821 // if anything goes wrong, we'll assume this is not a status report
2822 cl.parsingtextmode = CL_PARSETEXTMODE_NONE;
2828 for (len = 0;*t && *t != '\n';t++)
2829 if (len < (int)sizeof(temp) - 1)
2832 // botclient is perfectly valid, but we don't care about bots
2833 // also don't try to look up the name of an invalid player index
2834 if (strcmp(temp, "botclient")
2835 && cl.parsingtextplayerindex >= 0
2836 && cl.parsingtextplayerindex < cl.maxclients
2837 && cl.scores[cl.parsingtextplayerindex].name[0])
2839 // log the player name and IP address string
2840 // (this operates entirely on strings to avoid issues with the
2841 // nature of a network address)
2842 CL_IPLog_Add(temp, cl.scores[cl.parsingtextplayerindex].name, true, true);
2844 cl.parsingtextmode = CL_PARSETEXTMODE_STATUS_PLAYERID;
2851 extern cvar_t slowmo;
2852 static void CL_NetworkTimeReceived(double newtime)
2855 cl.mtime[1] = cl.mtime[0];
2856 cl.mtime[0] = newtime;
2857 if (cls.timedemo || (cl.islocalgame && !sv_fixedframeratesingleplayer.integer) || cl.mtime[1] == cl.mtime[0] || cls.signon < SIGNONS)
2858 cl.time = cl.mtime[1] = newtime;
2859 else if (cls.protocol != PROTOCOL_QUAKEWORLD && !cls.demoplayback)
2861 cl.mtime[1] = max(cl.mtime[1], cl.mtime[0] - 0.1);
2862 if (developer.integer >= 100 && vid_activewindow)
2864 if (cl.time < cl.mtime[1] - (cl.mtime[0] - cl.mtime[1]))
2865 Con_Printf("--- cl.time < cl.mtime[1] (%f < %f ... %f)\n", cl.time, cl.mtime[1], cl.mtime[0]);
2866 else if (cl.time > cl.mtime[0] + (cl.mtime[0] - cl.mtime[1]))
2867 Con_Printf("--- cl.time > cl.mtime[0] (%f > %f ... %f)\n", cl.time, cl.mtime[1], cl.mtime[0]);
2869 cl.time += (cl.mtime[1] - cl.time) * bound(0, cl_nettimesyncfactor.value, 1);
2870 timehigh = cl.mtime[1] + (cl.mtime[0] - cl.mtime[1]) * cl_nettimesyncboundtolerance.value;
2871 if (cl_nettimesyncboundmode.integer == 1)
2872 cl.time = bound(cl.mtime[1], cl.time, cl.mtime[0]);
2873 else if (cl_nettimesyncboundmode.integer == 2)
2875 if (cl.time < cl.mtime[1] || cl.time > timehigh)
2876 cl.time = cl.mtime[1];
2878 else if (cl_nettimesyncboundmode.integer == 3)
2880 if ((cl.time < cl.mtime[1] && cl.oldtime < cl.mtime[1]) || (cl.time > timehigh && cl.oldtime > timehigh))
2881 cl.time = cl.mtime[1];
2883 else if (cl_nettimesyncboundmode.integer == 4)
2885 if (fabs(cl.time - cl.mtime[1]) > 0.5)
2886 cl.time = cl.mtime[1]; // reset
2887 else if (fabs(cl.time - cl.mtime[1]) > 0.1)
2888 cl.time += 0.5 * (cl.mtime[1] - cl.time); // fast
2889 else if (cl.time > cl.mtime[1])
2890 cl.time -= 0.002 * cl.movevars_timescale; // fall into the past by 2ms
2892 cl.time += 0.001 * cl.movevars_timescale; // creep forward 1ms
2894 else if (cl_nettimesyncboundmode.integer == 5)
2896 if (fabs(cl.time - cl.mtime[1]) > 0.5)
2897 cl.time = cl.mtime[1]; // reset
2898 else if (fabs(cl.time - cl.mtime[1]) > 0.1)
2899 cl.time += 0.5 * (cl.mtime[1] - cl.time); // fast
2901 cl.time = bound(cl.time - 0.002 * cl.movevars_timescale, cl.mtime[1], cl.time + 0.001 * cl.movevars_timescale);
2903 else if (cl_nettimesyncboundmode.integer == 6)
2905 cl.time = bound(cl.mtime[1], cl.time, cl.mtime[0]);
2906 cl.time = bound(cl.time - 0.002 * cl.movevars_timescale, cl.mtime[1], cl.time + 0.001 * cl.movevars_timescale);
2909 // this packet probably contains a player entity update, so we will need
2910 // to update the prediction
2911 cl.movement_needupdate = true;
2912 // this may get updated later in parsing by svc_clientdata
2913 cl.onground = false;
2914 // if true the cl.viewangles are interpolated from cl.mviewangles[]
2915 // during this frame
2916 // (makes spectating players much smoother and prevents mouse movement from turning)
2917 cl.fixangle[1] = cl.fixangle[0];
2918 cl.fixangle[0] = false;
2919 if (!cls.demoplayback)
2920 VectorCopy(cl.mviewangles[0], cl.mviewangles[1]);
2923 #define SHOWNET(x) if(cl_shownet.integer==2)Con_Printf("%3i:%s\n", msg_readcount-1, x);
2926 void CL_VM_Init (void);
2927 qboolean CL_VM_Parse_TempEntity (void);
2928 void CL_VM_Parse_StuffCmd (const char *msg);
2929 void CL_VM_Parse_CenterPrint (const char *msg);
2930 void CSQC_AddPrintText (const char *msg);
2931 void CSQC_ReadEntities (void);
2934 =====================
2935 CL_ParseServerMessage
2936 =====================
2938 int parsingerror = false;
2939 extern void CL_UpdateMoveVars(void);
2940 void CL_ParseServerMessage(void)
2944 protocolversion_t protocol;
2945 unsigned char cmdlog[32];
2946 char *cmdlogname[32], *temp;
2947 int cmdindex, cmdcount = 0;
2949 // LordHavoc: moved demo message writing from before the packet parse to
2950 // after the packet parse so that CL_Stop_f can be called by cl_autodemo
2951 // code in CL_ParseServerinfo
2952 //if (cls.demorecording)
2953 // CL_WriteDemoMessage (&net_message);
2955 cl.last_received_message = realtime;
2957 if (cls.netcon && cls.signon < SIGNONS)
2958 CL_KeepaliveMessage(false);
2961 // if recording demos, copy the message out
2963 if (cl_shownet.integer == 1)
2964 Con_Printf("%f %i\n", realtime, net_message.cursize);
2965 else if (cl_shownet.integer == 2)
2966 Con_Print("------------------\n");
2969 // parse the message
2971 //MSG_BeginReading ();
2973 parsingerror = true;
2975 if (cls.protocol == PROTOCOL_QUAKEWORLD)
2977 CL_NetworkTimeReceived(realtime); // qw has no clock
2979 // slightly kill qw player entities each frame
2980 for (i = 1;i < cl.maxclients;i++)
2981 cl.entities_active[i] = false;
2983 // kill all qw nails
2984 cl.qw_num_nails = 0;
2986 // fade weapon view kick
2987 cl.qw_weaponkick = min(cl.qw_weaponkick + 10 * bound(0, cl.time - cl.oldtime, 0.1), 0);
2989 cls.servermovesequence = cls.netcon->qw.incoming_sequence;
2994 Host_Error ("CL_ParseServerMessage: Bad QW server message");
2996 cmd = MSG_ReadByte ();
3000 SHOWNET("END OF MESSAGE");
3001 break; // end of message
3004 cmdindex = cmdcount & 31;
3006 cmdlog[cmdindex] = cmd;
3008 SHOWNET(qw_svc_strings[cmd]);
3009 cmdlogname[cmdindex] = qw_svc_strings[cmd];
3010 if (!cmdlogname[cmdindex])
3012 // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
3014 cmdlogname[cmdindex] = temp;
3022 char description[32*64], temp[64];
3024 strlcpy(description, "packet dump: ", sizeof(description));
3028 count = cmdcount - i;
3032 dpsnprintf(temp, sizeof(temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
3033 strlcat(description, temp, sizeof(description));
3038 description[strlen(description)-1] = '\n'; // replace the last space with a newline
3039 Con_Print(description);
3040 Host_Error("CL_ParseServerMessage: Illegible server message");
3045 //Con_Printf("qw_svc_nop\n");
3048 case qw_svc_disconnect:
3049 Con_Printf("Server disconnected\n");
3050 if (cls.demonum != -1)
3058 temp = MSG_ReadString();
3059 if (CL_ExaminePrintString(temp)) // look for anything interesting like player IP addresses or ping reports
3062 CSQC_AddPrintText(va("\1%s", temp)); //[515]: csqc
3064 CSQC_AddPrintText(temp);
3068 case qw_svc_centerprint:
3069 CL_VM_Parse_CenterPrint(MSG_ReadString ()); //[515]: csqc
3072 case qw_svc_stufftext:
3073 CL_VM_Parse_StuffCmd(MSG_ReadString ()); //[515]: csqc
3077 // svc_damage protocol is identical to nq
3081 case qw_svc_serverdata:
3082 //Cbuf_Execute(); // make sure any stuffed commands are done
3083 CL_ParseServerInfo();
3084 CL_VM_Init(); //[515]: init csqc
3087 case qw_svc_setangle:
3088 for (i=0 ; i<3 ; i++)
3089 cl.viewangles[i] = MSG_ReadAngle (cls.protocol);
3090 if (!cls.demoplayback)
3092 cl.fixangle[0] = true;
3093 VectorCopy(cl.viewangles, cl.mviewangles[0]);
3094 // disable interpolation if this is new
3095 if (!cl.fixangle[1])
3096 VectorCopy(cl.viewangles, cl.mviewangles[1]);
3100 case qw_svc_lightstyle:
3101 i = MSG_ReadByte ();
3102 if (i >= cl.max_lightstyle)
3104 Con_Printf ("svc_lightstyle >= MAX_LIGHTSTYLES");
3107 strlcpy (cl.lightstyle[i].map, MSG_ReadString(), sizeof (cl.lightstyle[i].map));
3108 cl.lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
3109 cl.lightstyle[i].length = (int)strlen(cl.lightstyle[i].map);
3113 CL_ParseStartSoundPacket(false);
3116 case qw_svc_stopsound:
3117 i = (unsigned short) MSG_ReadShort();
3118 S_StopSound(i>>3, i&7);
3121 case qw_svc_updatefrags:
3123 if (i >= cl.maxclients)
3124 Host_Error("CL_ParseServerMessage: svc_updatefrags >= cl.maxclients");
3125 cl.scores[i].frags = (signed short) MSG_ReadShort();
3128 case qw_svc_updateping:
3130 if (i >= cl.maxclients)
3131 Host_Error("CL_ParseServerMessage: svc_updateping >= cl.maxclients");
3132 cl.scores[i].qw_ping = MSG_ReadShort();
3135 case qw_svc_updatepl:
3137 if (i >= cl.maxclients)
3138 Host_Error("CL_ParseServerMessage: svc_updatepl >= cl.maxclients");
3139 cl.scores[i].qw_packetloss = MSG_ReadByte();
3142 case qw_svc_updateentertime:
3144 if (i >= cl.maxclients)
3145 Host_Error("CL_ParseServerMessage: svc_updateentertime >= cl.maxclients");
3147 cl.scores[i].qw_entertime = cl.time - MSG_ReadFloat();
3150 case qw_svc_spawnbaseline:
3151 i = (unsigned short) MSG_ReadShort();
3152 if (i < 0 || i >= MAX_EDICTS)
3153 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
3154 if (i >= cl.max_entities)
3155 CL_ExpandEntities(i);
3156 CL_ParseBaseline(cl.entities + i, false);
3158 case qw_svc_spawnstatic:
3159 CL_ParseStatic(false);
3161 case qw_svc_temp_entity:
3162 if(!CL_VM_Parse_TempEntity())
3163 CL_ParseTempEntity ();
3166 case qw_svc_killedmonster:
3167 cl.stats[STAT_MONSTERS]++;
3170 case qw_svc_foundsecret:
3171 cl.stats[STAT_SECRETS]++;
3174 case qw_svc_updatestat:
3175 i = MSG_ReadByte ();
3176 if (i < 0 || i >= MAX_CL_STATS)
3177 Host_Error ("svc_updatestat: %i is invalid", i);
3178 cl.stats[i] = MSG_ReadByte ();
3181 case qw_svc_updatestatlong:
3182 i = MSG_ReadByte ();
3183 if (i < 0 || i >= MAX_CL_STATS)
3184 Host_Error ("svc_updatestatlong: %i is invalid", i);
3185 cl.stats[i] = MSG_ReadLong ();
3188 case qw_svc_spawnstaticsound:
3189 CL_ParseStaticSound (false);
3192 case qw_svc_cdtrack:
3193 cl.cdtrack = cl.looptrack = MSG_ReadByte ();
3194 if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
3195 CDAudio_Play ((unsigned char)cls.forcetrack, true);
3197 CDAudio_Play ((unsigned char)cl.cdtrack, true);
3200 case qw_svc_intermission:
3201 cl.intermission = 1;
3202 cl.completed_time = cl.time;
3203 MSG_ReadVector(cl.qw_intermission_origin, cls.protocol);
3204 for (i = 0;i < 3;i++)
3205 cl.qw_intermission_angles[i] = MSG_ReadAngle(cls.protocol);
3209 cl.intermission = 2;
3210 cl.completed_time = cl.time;
3211 SCR_CenterPrint(MSG_ReadString ());
3214 case qw_svc_sellscreen:
3215 Cmd_ExecuteString ("help", src_command);
3218 case qw_svc_smallkick:
3219 cl.qw_weaponkick = -2;
3221 case qw_svc_bigkick:
3222 cl.qw_weaponkick = -4;
3225 case qw_svc_muzzleflash:
3226 i = (unsigned short) MSG_ReadShort();
3227 // NOTE: in QW this only worked on clients
3228 if (i < 0 || i >= MAX_EDICTS)
3229 Host_Error("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
3230 if (i >= cl.max_entities)
3231 CL_ExpandEntities(i);
3232 cl.entities[i].persistent.muzzleflash = 1.0f;
3235 case qw_svc_updateuserinfo:
3236 QW_CL_UpdateUserInfo();
3239 case qw_svc_setinfo:
3243 case qw_svc_serverinfo:
3247 case qw_svc_download:
3248 QW_CL_ParseDownload();
3251 case qw_svc_playerinfo:
3252 EntityStateQW_ReadPlayerUpdate();
3259 case qw_svc_chokecount:
3261 // FIXME: apply to netgraph
3262 //for (j = 0;j < i;j++)
3263 // cl.frames[(cls.netcon->qw.incoming_acknowledged-1-j)&QW_UPDATE_MASK].receivedtime = -2;
3266 case qw_svc_modellist:
3267 QW_CL_ParseModelList();
3270 case qw_svc_soundlist:
3271 QW_CL_ParseSoundList();
3274 case qw_svc_packetentities:
3275 EntityFrameQW_CL_ReadFrame(false);
3276 // first update is the final signon stage
3277 if (cls.signon == SIGNONS - 1)
3278 cls.signon = SIGNONS;
3281 case qw_svc_deltapacketentities:
3282 EntityFrameQW_CL_ReadFrame(true);
3283 // first update is the final signon stage
3284 if (cls.signon == SIGNONS - 1)
3285 cls.signon = SIGNONS;
3288 case qw_svc_maxspeed:
3289 cl.movevars_maxspeed = MSG_ReadFloat();
3292 case qw_svc_entgravity:
3293 cl.movevars_entgravity = MSG_ReadFloat();
3294 if (!cl.movevars_entgravity)
3295 cl.movevars_entgravity = 1.0f;
3298 case qw_svc_setpause:
3299 cl.paused = MSG_ReadByte ();
3304 S_PauseGameSounds (cl.paused);
3309 // fully kill the still slightly dead qw player entities each frame,
3310 // but only if a player update was received
3311 for (i = 1;i <= cl.maxclients;i++)
3312 if (cl.entities_active[i])
3314 if (i <= cl.maxclients)
3316 // kill all non-updated entities this frame
3317 for (i = 1;i <= cl.maxclients;i++)
3318 if (!cl.entities_active[i])
3319 cl.entities[i].state_current.active = false;
3323 // no update this frame, restore the cl.entities_active for good measure
3324 for (i = 1;i <= cl.maxclients;i++)
3325 cl.entities_active[i] = cl.entities[i].state_current.active;
3333 Host_Error ("CL_ParseServerMessage: Bad server message");
3335 cmd = MSG_ReadByte ();
3339 SHOWNET("END OF MESSAGE");
3340 break; // end of message
3343 cmdindex = cmdcount & 31;
3345 cmdlog[cmdindex] = cmd;
3347 // if the high bit of the command byte is set, it is a fast update
3350 // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
3352 cmdlogname[cmdindex] = temp;
3353 SHOWNET("fast update");
3354 if (cls.signon == SIGNONS - 1)
3356 // first update is the final signon stage
3357 cls.signon = SIGNONS;
3360 EntityFrameQuake_ReadEntity (cmd&127);
3364 SHOWNET(svc_strings[cmd]);
3365 cmdlogname[cmdindex] = svc_strings[cmd];
3366 if (!cmdlogname[cmdindex])
3368 // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
3370 cmdlogname[cmdindex] = temp;
3378 char description[32*64], temp[64];
3380 strlcpy (description, "packet dump: ", sizeof(description));
3384 count = cmdcount - i;
3388 dpsnprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
3389 strlcat (description, temp, sizeof (description));
3394 description[strlen(description)-1] = '\n'; // replace the last space with a newline
3395 Con_Print(description);
3396 Host_Error ("CL_ParseServerMessage: Illegible server message");
3401 if (cls.signon < SIGNONS)
3402 Con_Print("<-- server to client keepalive\n");
3406 CL_NetworkTimeReceived(MSG_ReadFloat());
3409 case svc_clientdata:
3410 CL_ParseClientdata();
3414 i = MSG_ReadLong ();
3415 protocol = Protocol_EnumForNumber(i);
3416 if (protocol == PROTOCOL_UNKNOWN)
3417 Host_Error("CL_ParseServerMessage: Server is unrecognized protocol number (%i)", i);
3418 // hack for unmarked Nehahra movie demos which had a custom protocol
3419 if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
3420 protocol = PROTOCOL_NEHAHRAMOVIE;
3421 cls.protocol = protocol;
3424 case svc_disconnect:
3425 Con_Printf ("Server disconnected\n");
3426 if (cls.demonum != -1)
3433 temp = MSG_ReadString();
3434 if (CL_ExaminePrintString(temp)) // look for anything interesting like player IP addresses or ping reports
3435 CSQC_AddPrintText(temp); //[515]: csqc
3438 case svc_centerprint:
3439 CL_VM_Parse_CenterPrint(MSG_ReadString ()); //[515]: csqc
3443 CL_VM_Parse_StuffCmd(MSG_ReadString ()); //[515]: csqc
3450 case svc_serverinfo:
3451 CL_ParseServerInfo ();
3452 CL_VM_Init(); //[515]: init csqc
3456 for (i=0 ; i<3 ; i++)
3457 cl.viewangles[i] = MSG_ReadAngle (cls.protocol);
3458 if (!cls.demoplayback)
3460 cl.fixangle[0] = true;
3461 VectorCopy(cl.viewangles, cl.mviewangles[0]);
3462 // disable interpolation if this is new
3463 if (!cl.fixangle[1])
3464 VectorCopy(cl.viewangles, cl.mviewangles[1]);
3469 cl.viewentity = (unsigned short)MSG_ReadShort ();
3470 if (cl.viewentity >= MAX_EDICTS)
3471 Host_Error("svc_setview >= MAX_EDICTS");
3472 if (cl.viewentity >= cl.max_entities)
3473 CL_ExpandEntities(cl.viewentity);
3474 // LordHavoc: assume first setview recieved is the real player entity
3475 if (!cl.playerentity)
3476 cl.playerentity = cl.viewentity;
3479 case svc_lightstyle:
3480 i = MSG_ReadByte ();
3481 if (i >= cl.max_lightstyle)
3483 Con_Printf ("svc_lightstyle >= MAX_LIGHTSTYLES");
3486 strlcpy (cl.lightstyle[i].map, MSG_ReadString(), sizeof (cl.lightstyle[i].map));
3487 cl.lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
3488 cl.lightstyle[i].length = (int)strlen(cl.lightstyle[i].map);
3492 CL_ParseStartSoundPacket(false);
3496 if (cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3)
3498 // was svc_sound2 in protocols 1, 2, 3, removed in 4, 5, changed to svc_precache in 6
3499 CL_ParseStartSoundPacket(true);
3503 int i = (unsigned short)MSG_ReadShort();
3504 char *s = MSG_ReadString();
3507 if (i >= 1 && i < MAX_MODELS)
3509 model_t *model = Mod_ForName(s, false, false, i == 1);
3511 Con_DPrintf("svc_precache: Mod_ForName(\"%s\") failed\n", s);
3512 cl.model_precache[i] = model;
3515 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_MODELS);
3520 if (i >= 1 && i < MAX_SOUNDS)
3522 sfx_t *sfx = S_PrecacheSound (s, true, false);
3523 if (!sfx && snd_initialized.integer)
3524 Con_DPrintf("svc_precache: S_PrecacheSound(\"%s\") failed\n", s);
3525 cl.sound_precache[i] = sfx;
3528 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_SOUNDS);
3534 i = (unsigned short) MSG_ReadShort();
3535 S_StopSound(i>>3, i&7);
3538 case svc_updatename:
3539 i = MSG_ReadByte ();
3540 if (i >= cl.maxclients)
3541 Host_Error ("CL_ParseServerMessage: svc_updatename >= cl.maxclients");
3542 strlcpy (cl.scores[i].name, MSG_ReadString (), sizeof (cl.scores[i].name));
3545 case svc_updatefrags:
3546 i = MSG_ReadByte ();
3547 if (i >= cl.maxclients)
3548 Host_Error ("CL_ParseServerMessage: svc_updatefrags >= cl.maxclients");
3549 cl.scores[i].frags = (signed short) MSG_ReadShort ();
3552 case svc_updatecolors:
3553 i = MSG_ReadByte ();
3554 if (i >= cl.maxclients)
3555 Host_Error ("CL_ParseServerMessage: svc_updatecolors >= cl.maxclients");
3556 cl.scores[i].colors = MSG_ReadByte ();
3560 CL_ParseParticleEffect ();
3571 case svc_spawnbaseline:
3572 i = (unsigned short) MSG_ReadShort ();
3573 if (i < 0 || i >= MAX_EDICTS)
3574 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
3575 if (i >= cl.max_entities)
3576 CL_ExpandEntities(i);
3577 CL_ParseBaseline (cl.entities + i, false);
3579 case svc_spawnbaseline2:
3580 i = (unsigned short) MSG_ReadShort ();
3581 if (i < 0 || i >= MAX_EDICTS)
3582 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline2: invalid entity number %i", i);
3583 if (i >= cl.max_entities)
3584 CL_ExpandEntities(i);
3585 CL_ParseBaseline (cl.entities + i, true);
3587 case svc_spawnstatic:
3588 CL_ParseStatic (false);
3590 case svc_spawnstatic2:
3591 CL_ParseStatic (true);
3593 case svc_temp_entity:
3594 if(!CL_VM_Parse_TempEntity())
3595 CL_ParseTempEntity ();
3599 cl.paused = MSG_ReadByte ();
3604 S_PauseGameSounds (cl.paused);
3608 i = MSG_ReadByte ();
3609 // LordHavoc: it's rude to kick off the client if they missed the
3610 // reconnect somehow, so allow signon 1 even if at signon 1
3611 if (i <= cls.signon && i != 1)
3612 Host_Error ("Received signon %i when at %i", i, cls.signon);
3617 case svc_killedmonster:
3618 cl.stats[STAT_MONSTERS]++;
3621 case svc_foundsecret:
3622 cl.stats[STAT_SECRETS]++;
3625 case svc_updatestat:
3626 i = MSG_ReadByte ();
3627 if (i < 0 || i >= MAX_CL_STATS)
3628 Host_Error ("svc_updatestat: %i is invalid", i);
3629 cl.stats[i] = MSG_ReadLong ();
3632 case svc_updatestatubyte:
3633 i = MSG_ReadByte ();
3634 if (i < 0 || i >= MAX_CL_STATS)
3635 Host_Error ("svc_updatestat: %i is invalid", i);
3636 cl.stats[i] = MSG_ReadByte ();
3639 case svc_spawnstaticsound:
3640 CL_ParseStaticSound (false);
3643 case svc_spawnstaticsound2:
3644 CL_ParseStaticSound (true);
3648 cl.cdtrack = MSG_ReadByte ();
3649 cl.looptrack = MSG_ReadByte ();
3650 if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
3651 CDAudio_Play ((unsigned char)cls.forcetrack, true);
3653 CDAudio_Play ((unsigned char)cl.cdtrack, true);
3656 case svc_intermission:
3657 cl.intermission = 1;
3658 cl.completed_time = cl.time;
3662 cl.intermission = 2;
3663 cl.completed_time = cl.time;
3664 SCR_CenterPrint(MSG_ReadString ());
3668 cl.intermission = 3;
3669 cl.completed_time = cl.time;
3670 SCR_CenterPrint(MSG_ReadString ());
3673 case svc_sellscreen:
3674 Cmd_ExecuteString ("help", src_command);
3677 if (gamemode == GAME_TENEBRAE)
3679 // repeating particle effect
3680 MSG_ReadCoord(cls.protocol);
3681 MSG_ReadCoord(cls.protocol);
3682 MSG_ReadCoord(cls.protocol);
3683 MSG_ReadCoord(cls.protocol);
3684 MSG_ReadCoord(cls.protocol);
3685 MSG_ReadCoord(cls.protocol);
3692 SHOWLMP_decodehide();
3695 if (gamemode == GAME_TENEBRAE)
3698 MSG_ReadCoord(cls.protocol);
3699 MSG_ReadCoord(cls.protocol);
3700 MSG_ReadCoord(cls.protocol);
3705 SHOWLMP_decodeshow();
3708 R_SetSkyBox(MSG_ReadString());
3711 if (cls.signon == SIGNONS - 1)
3713 // first update is the final signon stage
3714 cls.signon = SIGNONS;
3717 if (cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3)
3718 EntityFrame_CL_ReadFrame();
3719 else if (cls.protocol == PROTOCOL_DARKPLACES4)
3720 EntityFrame4_CL_ReadFrame();
3722 EntityFrame5_CL_ReadFrame();
3724 case svc_csqcentities:
3725 CSQC_ReadEntities();
3727 case svc_downloaddata:
3730 case svc_trailparticles:
3731 CL_ParseTrailParticles();
3733 case svc_pointparticles:
3734 CL_ParsePointParticles();
3736 case svc_pointparticles1:
3737 CL_ParsePointParticles1();
3743 if (cls.signon == SIGNONS)
3744 CL_UpdateItemsAndWeapon();
3746 EntityFrameQuake_ISeeDeadEntities();
3748 CL_UpdateMoveVars();
3750 parsingerror = false;
3752 // LordHavoc: this was at the start of the function before cl_autodemo was
3754 if (cls.demorecording)
3755 CL_WriteDemoMessage (&net_message);
3758 void CL_Parse_DumpPacket(void)
3762 Con_Print("Packet dump:\n");
3763 SZ_HexDumpToConsole(&net_message);
3764 parsingerror = false;
3767 void CL_Parse_ErrorCleanUp(void)
3769 CL_StopDownload(0, 0);
3773 void CL_Parse_Init(void)
3775 // LordHavoc: added demo_nehahra cvar
3776 Cvar_RegisterVariable (&demo_nehahra);
3777 if (gamemode == GAME_NEHAHRA)
3778 Cvar_SetValue("demo_nehahra", 1);
3779 Cvar_RegisterVariable(&developer_networkentities);
3781 Cvar_RegisterVariable(&cl_sound_wizardhit);
3782 Cvar_RegisterVariable(&cl_sound_hknighthit);
3783 Cvar_RegisterVariable(&cl_sound_tink1);
3784 Cvar_RegisterVariable(&cl_sound_ric1);
3785 Cvar_RegisterVariable(&cl_sound_ric2);
3786 Cvar_RegisterVariable(&cl_sound_ric3);
3787 Cvar_RegisterVariable(&cl_sound_ric_gunshot);
3788 Cvar_RegisterVariable(&cl_sound_r_exp3);
3790 Cvar_RegisterVariable(&cl_joinbeforedownloadsfinish);
3792 // server extension cvars set by commands issued from the server during connect
3793 Cvar_RegisterVariable(&cl_serverextension_download);
3795 Cvar_RegisterVariable(&cl_nettimesyncfactor);
3796 Cvar_RegisterVariable(&cl_nettimesyncboundmode);
3797 Cvar_RegisterVariable(&cl_nettimesyncboundtolerance);
3798 Cvar_RegisterVariable(&cl_iplog_name);
3800 Cmd_AddCommand("nextul", QW_CL_NextUpload, "sends next fragment of current upload buffer (screenshot for example)");
3801 Cmd_AddCommand("stopul", QW_CL_StopUpload, "aborts current upload (screenshot for example)");
3802 Cmd_AddCommand("skins", QW_CL_Skins_f, "downloads missing qw skins from server");
3803 Cmd_AddCommand("changing", QW_CL_Changing_f, "sent by qw servers to tell client to wait for level change");
3804 Cmd_AddCommand("cl_begindownloads", CL_BeginDownloads_f, "used internally by darkplaces client while connecting (causes loading of models and sounds or triggers downloads for missing ones)");
3805 Cmd_AddCommand("cl_downloadbegin", CL_DownloadBegin_f, "(networking) informs client of download file information, client replies with sv_startsoundload to begin the transfer");
3806 Cmd_AddCommand("stopdownload", CL_StopDownload_f, "terminates a download");
3807 Cmd_AddCommand("cl_downloadfinished", CL_DownloadFinished_f, "signals that a download has finished and provides the client with file size and crc to check its integrity");
3808 Cmd_AddCommand("iplog_list", CL_IPLog_List_f, "lists names of players whose IP address begins with the supplied text (example: iplog_list 123.456.789)");
3811 void CL_Parse_Shutdown(void)