]> icculus.org git repositories - divverent/darkplaces.git/blob - cl_parse.c
fix a float->enum conversion error with g++ 4
[divverent/darkplaces.git] / cl_parse.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
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.
8
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.
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20 // cl_parse.c  -- parse a message received from the server
21
22 #include "quakedef.h"
23 #include "cdaudio.h"
24 #include "cl_collision.h"
25
26 char *svc_strings[128] =
27 {
28         "svc_bad",
29         "svc_nop",
30         "svc_disconnect",
31         "svc_updatestat",
32         "svc_version",          // [int] server version
33         "svc_setview",          // [short] entity number
34         "svc_sound",                    // <see code>
35         "svc_time",                     // [float] server time
36         "svc_print",                    // [string] null terminated string
37         "svc_stufftext",                // [string] stuffed into client's console buffer
38                                                 // the string should be \n terminated
39         "svc_setangle",         // [vec3] set the view angle to this absolute value
40
41         "svc_serverinfo",               // [int] version
42                                                 // [string] signon string
43                                                 // [string]..[0]model cache [string]...[0]sounds cache
44                                                 // [string]..[0]item cache
45         "svc_lightstyle",               // [byte] [string]
46         "svc_updatename",               // [byte] [string]
47         "svc_updatefrags",      // [byte] [short]
48         "svc_clientdata",               // <shortbits + data>
49         "svc_stopsound",                // <see code>
50         "svc_updatecolors",     // [byte] [byte]
51         "svc_particle",         // [vec3] <variable>
52         "svc_damage",                   // [byte] impact [byte] blood [vec3] from
53
54         "svc_spawnstatic",
55         "OBSOLETE svc_spawnbinary",
56         "svc_spawnbaseline",
57
58         "svc_temp_entity",              // <variable>
59         "svc_setpause",
60         "svc_signonnum",
61         "svc_centerprint",
62         "svc_killedmonster",
63         "svc_foundsecret",
64         "svc_spawnstaticsound",
65         "svc_intermission",
66         "svc_finale",                   // [string] music [string] text
67         "svc_cdtrack",                  // [byte] track [byte] looptrack
68         "svc_sellscreen",
69         "svc_cutscene",
70         "svc_showlmp",  // [string] iconlabel [string] lmpfile [short] x [short] y
71         "svc_hidelmp",  // [string] iconlabel
72         "svc_skybox", // [string] skyname
73         "", // 38
74         "", // 39
75         "", // 40
76         "", // 41
77         "", // 42
78         "", // 43
79         "", // 44
80         "", // 45
81         "", // 46
82         "", // 47
83         "", // 48
84         "", // 49
85         "svc_cgame", //                         50              // [short] length [bytes] data
86         "svc_updatestatubyte", //                       51              // [byte] stat [byte] value
87         "svc_effect", //                        52              // [vector] org [byte] modelindex [byte] startframe [byte] framecount [byte] framerate
88         "svc_effect2", //                       53              // [vector] org [short] modelindex [short] startframe [byte] framecount [byte] framerate
89         "svc_sound2", //                        54              // short soundindex instead of byte
90         "svc_spawnbaseline2", //        55              // short modelindex instead of byte
91         "svc_spawnstatic2", //          56              // short modelindex instead of byte
92         "svc_entities", //                      57              // [int] deltaframe [int] thisframe [float vector] eye [variable length] entitydata
93         "svc_unusedlh3", //                     58
94         "svc_spawnstaticsound2", //     59              // [coord3] [short] samp [byte] vol [byte] aten
95 };
96
97 //=============================================================================
98
99 cvar_t demo_nehahra = {0, "demo_nehahra", "0"};
100 cvar_t developer_networkentities = {0, "developer_networkentities", "0"};
101
102 /*
103 ==================
104 CL_ParseStartSoundPacket
105 ==================
106 */
107 void CL_ParseStartSoundPacket(int largesoundindex)
108 {
109         vec3_t  pos;
110         int     channel, ent;
111         int     sound_num;
112         int     volume;
113         int     field_mask;
114         float   attenuation;
115
116         field_mask = MSG_ReadByte();
117
118         if (field_mask & SND_VOLUME)
119                 volume = MSG_ReadByte ();
120         else
121                 volume = DEFAULT_SOUND_PACKET_VOLUME;
122
123         if (field_mask & SND_ATTENUATION)
124                 attenuation = MSG_ReadByte () / 64.0;
125         else
126                 attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
127
128         if (field_mask & SND_LARGEENTITY)
129         {
130                 ent = (unsigned short) MSG_ReadShort ();
131                 channel = MSG_ReadByte ();
132         }
133         else
134         {
135                 channel = (unsigned short) MSG_ReadShort ();
136                 ent = channel >> 3;
137                 channel &= 7;
138         }
139
140         if (largesoundindex || field_mask & SND_LARGESOUND)
141                 sound_num = (unsigned short) MSG_ReadShort ();
142         else
143                 sound_num = MSG_ReadByte ();
144
145         MSG_ReadVector(pos, cl.protocol);
146
147         if (sound_num >= MAX_SOUNDS)
148         {
149                 Con_Printf("CL_ParseStartSoundPacket: sound_num (%i) >= MAX_SOUNDS (%i)\n", sound_num, MAX_SOUNDS);
150                 return;
151         }
152
153         if (ent >= MAX_EDICTS)
154         {
155                 Con_Printf("CL_ParseStartSoundPacket: ent = %i", ent);
156                 return;
157         }
158
159         S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0f, attenuation);
160 }
161
162 /*
163 ==================
164 CL_KeepaliveMessage
165
166 When the client is taking a long time to load stuff, send keepalive messages
167 so the server doesn't disconnect.
168 ==================
169 */
170
171 static qbyte olddata[NET_MAXMESSAGE];
172 void CL_KeepaliveMessage (void)
173 {
174         float time;
175         static float lastmsg;
176         int oldreadcount;
177         qboolean oldbadread;
178         sizebuf_t old;
179
180         // no need if server is local and definitely not if this is a demo
181         if (sv.active || cls.demoplayback)
182                 return;
183
184 // read messages from server, should just be nops
185         oldreadcount = msg_readcount;
186         oldbadread = msg_badread;
187         old = net_message;
188         memcpy(olddata, net_message.data, net_message.cursize);
189
190         NetConn_ClientFrame();
191
192         msg_readcount = oldreadcount;
193         msg_badread = oldbadread;
194         net_message = old;
195         memcpy(net_message.data, olddata, net_message.cursize);
196
197         if (cls.netcon && NetConn_CanSendMessage(cls.netcon) && (time = Sys_DoubleTime()) - lastmsg >= 5)
198         {
199                 sizebuf_t       msg;
200                 qbyte           buf[4];
201                 lastmsg = time;
202                 // write out a nop
203                 // LordHavoc: must use unreliable because reliable could kill the sigon message!
204                 Con_Print("--> client to server keepalive\n");
205                 msg.data = buf;
206                 msg.maxsize = sizeof(buf);
207                 msg.cursize = 0;
208                 MSG_WriteChar(&msg, svc_nop);
209                 NetConn_SendUnreliableMessage(cls.netcon, &msg);
210         }
211 }
212
213 void CL_ParseEntityLump(char *entdata)
214 {
215         const char *data;
216         char key[128], value[4096];
217         FOG_clear(); // LordHavoc: no fog until set
218         // LordHavoc: default to the map's sky (q3 shader parsing sets this)
219         R_SetSkyBox(cl.worldmodel->brush.skybox);
220         data = entdata;
221         if (!data)
222                 return;
223         if (!COM_ParseToken(&data, false))
224                 return; // error
225         if (com_token[0] != '{')
226                 return; // error
227         while (1)
228         {
229                 if (!COM_ParseToken(&data, false))
230                         return; // error
231                 if (com_token[0] == '}')
232                         break; // end of worldspawn
233                 if (com_token[0] == '_')
234                         strlcpy (key, com_token + 1, sizeof (key));
235                 else
236                         strlcpy (key, com_token, sizeof (key));
237                 while (key[strlen(key)-1] == ' ') // remove trailing spaces
238                         key[strlen(key)-1] = 0;
239                 if (!COM_ParseToken(&data, false))
240                         return; // error
241                 strlcpy (value, com_token, sizeof (value));
242                 if (!strcmp("sky", key))
243                         R_SetSkyBox(value);
244                 else if (!strcmp("skyname", key)) // non-standard, introduced by QuakeForge... sigh.
245                         R_SetSkyBox(value);
246                 else if (!strcmp("qlsky", key)) // non-standard, introduced by QuakeLives (EEK)
247                         R_SetSkyBox(value);
248                 else if (!strcmp("fog", key))
249                         sscanf(value, "%f %f %f %f", &fog_density, &fog_red, &fog_green, &fog_blue);
250                 else if (!strcmp("fog_density", key))
251                         fog_density = atof(value);
252                 else if (!strcmp("fog_red", key))
253                         fog_red = atof(value);
254                 else if (!strcmp("fog_green", key))
255                         fog_green = atof(value);
256                 else if (!strcmp("fog_blue", key))
257                         fog_blue = atof(value);
258         }
259 }
260
261 /*
262 =====================
263 CL_SignonReply
264
265 An svc_signonnum has been received, perform a client side setup
266 =====================
267 */
268 static void CL_SignonReply (void)
269 {
270         //char  str[8192];
271
272 Con_DPrintf("CL_SignonReply: %i\n", cls.signon);
273
274         switch (cls.signon)
275         {
276         case 1:
277                 MSG_WriteByte (&cls.message, clc_stringcmd);
278                 MSG_WriteString (&cls.message, "prespawn");
279                 break;
280
281         case 2:
282                 MSG_WriteByte (&cls.message, clc_stringcmd);
283                 MSG_WriteString (&cls.message, va("name \"%s\"", cl_name.string));
284
285                 MSG_WriteByte (&cls.message, clc_stringcmd);
286                 MSG_WriteString (&cls.message, va("color %i %i", cl_color.integer >> 4, cl_color.integer & 15));
287
288                 if (cl_pmodel.integer)
289                 {
290                         MSG_WriteByte (&cls.message, clc_stringcmd);
291                         MSG_WriteString (&cls.message, va("pmodel %i", cl_pmodel.integer));
292                 }
293                 if (*cl_playermodel.string)
294                 {
295                         MSG_WriteByte (&cls.message, clc_stringcmd);
296                         MSG_WriteString (&cls.message, va("playermodel %s", cl_playermodel.string));
297                 }
298                 if (*cl_playerskin.string)
299                 {
300                         MSG_WriteByte (&cls.message, clc_stringcmd);
301                         MSG_WriteString (&cls.message, va("playerskin %s", cl_playerskin.string));
302                 }
303
304                 MSG_WriteByte (&cls.message, clc_stringcmd);
305                 MSG_WriteString (&cls.message, va("rate %i", cl_rate.integer));
306
307                 MSG_WriteByte (&cls.message, clc_stringcmd);
308                 MSG_WriteString (&cls.message, "spawn");
309                 break;
310
311         case 3:
312                 MSG_WriteByte (&cls.message, clc_stringcmd);
313                 MSG_WriteString (&cls.message, "begin");
314                 break;
315
316         case 4:
317                 Con_ClearNotify();
318                 break;
319         }
320 }
321
322 /*
323 ==================
324 CL_ParseServerInfo
325 ==================
326 */
327 // FIXME: this is a lot of memory to be keeping around, this needs to be dynamically allocated and freed
328 static char parse_model_precache[MAX_MODELS][MAX_QPATH];
329 static char parse_sound_precache[MAX_SOUNDS][MAX_QPATH];
330 void CL_ParseServerInfo (void)
331 {
332         char *str;
333         int i;
334         protocolversion_t protocol;
335         int nummodels, numsounds;
336         entity_t *ent;
337
338         Con_DPrint("Serverinfo packet received.\n");
339
340         // check memory integrity
341         Mem_CheckSentinelsGlobal();
342
343 //
344 // wipe the client_state_t struct
345 //
346         CL_ClearState ();
347
348 // parse protocol version number
349         i = MSG_ReadLong ();
350         protocol = Protocol_EnumForNumber(i);
351         if (protocol == PROTOCOL_UNKNOWN)
352         {
353                 Host_Error("CL_ParseServerInfo: Server is unrecognized protocol number (%i)\n", i);
354                 return;
355         }
356         // hack for unmarked Nehahra movie demos which had a custom protocol
357         if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
358                 protocol = PROTOCOL_NEHAHRAMOVIE;
359         cl.protocol = protocol;
360         Con_DPrintf("Server protocol is %s\n", Protocol_NameForEnum(cl.protocol));
361
362 // parse maxclients
363         cl.maxclients = MSG_ReadByte ();
364         if (cl.maxclients < 1 || cl.maxclients > MAX_SCOREBOARD)
365         {
366                 Host_Error("Bad maxclients (%u) from server\n", cl.maxclients);
367                 return;
368         }
369         cl.scores = (scoreboard_t *)Mem_Alloc(cl_mempool, cl.maxclients*sizeof(*cl.scores));
370
371 // parse gametype
372         cl.gametype = MSG_ReadByte ();
373
374 // parse signon message
375         str = MSG_ReadString ();
376         strlcpy (cl.levelname, str, sizeof(cl.levelname));
377
378 // seperate the printfs so the server message can have a color
379         if (cl.protocol != PROTOCOL_NEHAHRAMOVIE) // no messages when playing the Nehahra movie
380                 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);
381
382         // check memory integrity
383         Mem_CheckSentinelsGlobal();
384
385         S_StopAllSounds();
386         // if server is active, we already began a loading plaque
387         if (!sv.active)
388                 SCR_BeginLoadingPlaque();
389
390         // disable until we get textures for it
391         R_ResetSkyBox();
392
393         memset(cl.model_precache, 0, sizeof(cl.model_precache));
394         memset(cl.sound_precache, 0, sizeof(cl.sound_precache));
395
396         // parse model precache list
397         for (nummodels=1 ; ; nummodels++)
398         {
399                 str = MSG_ReadString();
400                 if (!str[0])
401                         break;
402                 if (nummodels==MAX_MODELS)
403                         Host_Error ("Server sent too many model precaches\n");
404                 if (strlen(str) >= MAX_QPATH)
405                         Host_Error ("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
406                 strlcpy (parse_model_precache[nummodels], str, sizeof (parse_model_precache[nummodels]));
407         }
408         // parse sound precache list
409         for (numsounds=1 ; ; numsounds++)
410         {
411                 str = MSG_ReadString();
412                 if (!str[0])
413                         break;
414                 if (numsounds==MAX_SOUNDS)
415                         Host_Error("Server sent too many sound precaches\n");
416                 if (strlen(str) >= MAX_QPATH)
417                         Host_Error("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
418                 strlcpy (parse_sound_precache[numsounds], str, sizeof (parse_sound_precache[numsounds]));
419         }
420
421         // touch all of the precached models that are still loaded so we can free
422         // anything that isn't needed
423         Mod_ClearUsed();
424         for (i = 1;i < nummodels;i++)
425                 Mod_FindName(parse_model_precache[i]);
426         // precache any models used by the client (this also marks them used)
427         cl.model_bolt = Mod_ForName("progs/bolt.mdl", false, false, false);
428         cl.model_bolt2 = Mod_ForName("progs/bolt2.mdl", false, false, false);
429         cl.model_bolt3 = Mod_ForName("progs/bolt3.mdl", false, false, false);
430         cl.model_beam = Mod_ForName("progs/beam.mdl", false, false, false);
431         Mod_PurgeUnused();
432
433         // do the same for sounds
434         // FIXME: S_ServerSounds does not know about cl.sfx_ sounds
435         S_ServerSounds (parse_sound_precache, numsounds);
436
437         // precache any sounds used by the client
438         cl.sfx_wizhit = S_PrecacheSound("sound/wizard/hit.wav", false, true);
439         cl.sfx_knighthit = S_PrecacheSound("sound/hknight/hit.wav", false, true);
440         cl.sfx_tink1 = S_PrecacheSound("sound/weapons/tink1.wav", false, true);
441         cl.sfx_ric1 = S_PrecacheSound("sound/weapons/ric1.wav", false, true);
442         cl.sfx_ric2 = S_PrecacheSound("sound/weapons/ric2.wav", false, true);
443         cl.sfx_ric3 = S_PrecacheSound("sound/weapons/ric3.wav", false, true);
444         cl.sfx_r_exp3 = S_PrecacheSound("sound/weapons/r_exp3.wav", false, true);
445
446         // now we try to load everything that is new
447
448         // world model
449         CL_KeepaliveMessage ();
450         cl.model_precache[1] = Mod_ForName(parse_model_precache[1], false, false, true);
451         if (cl.model_precache[1] == NULL)
452                 Con_Printf("Map %s not found\n", parse_model_precache[1]);
453
454         // normal models
455         for (i=2 ; i<nummodels ; i++)
456         {
457                 CL_KeepaliveMessage();
458                 if ((cl.model_precache[i] = Mod_ForName(parse_model_precache[i], false, false, false)) == NULL)
459                         Con_Printf("Model %s not found\n", parse_model_precache[i]);
460         }
461
462         // sounds
463         for (i=1 ; i<numsounds ; i++)
464         {
465                 CL_KeepaliveMessage();
466
467                 // Don't lock the sfx here, S_ServerSounds already did that
468                 cl.sound_precache[i] = S_PrecacheSound (parse_sound_precache[i], true, false);
469         }
470
471         // local state
472         ent = &cl_entities[0];
473         // entire entity array was cleared, so just fill in a few fields
474         ent->state_current.active = true;
475         ent->render.model = cl.worldmodel = cl.model_precache[1];
476         ent->render.scale = 1; // some of the renderer still relies on scale
477         ent->render.alpha = 1;
478         ent->render.colormap = -1; // no special coloring
479         ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
480         Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
481         Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
482         CL_BoundingBoxForEntity(&ent->render);
483
484         cl_num_entities = 1;
485
486         R_Modules_NewMap();
487         CL_CGVM_Start();
488
489         // noclip is turned off at start
490         noclip_anglehack = false;
491
492         // check memory integrity
493         Mem_CheckSentinelsGlobal();
494 }
495
496 void CL_ValidateState(entity_state_t *s)
497 {
498         model_t *model;
499
500         if (!s->active)
501                 return;
502
503         if (s->modelindex >= MAX_MODELS)
504                 Host_Error("CL_ValidateState: modelindex (%i) >= MAX_MODELS (%i)\n", s->modelindex, MAX_MODELS);
505
506         // colormap is client index + 1
507         if ((!s->flags & RENDER_COLORMAPPED) && s->colormap > cl.maxclients)
508         {
509                 Con_DPrintf("CL_ValidateState: colormap (%i) > cl.maxclients (%i)\n", s->colormap, cl.maxclients);
510                 s->colormap = 0;
511         }
512
513         model = cl.model_precache[s->modelindex];
514         Mod_CheckLoaded(model);
515         if (model && model->type && s->frame >= model->numframes)
516         {
517                 Con_DPrintf("CL_ValidateState: no such frame %i in \"%s\" (which has %i frames)\n", s->frame, model->name, model->numframes);
518                 s->frame = 0;
519         }
520         if (model && model->type && s->skin > 0 && s->skin >= model->numskins && !(s->lightpflags & PFLAGS_FULLDYNAMIC))
521         {
522                 Con_DPrintf("CL_ValidateState: no such skin %i in \"%s\" (which has %i skins)\n", s->skin, model->name, model->numskins);
523                 s->skin = 0;
524         }
525 }
526
527 void CL_MoveLerpEntityStates(entity_t *ent)
528 {
529         float odelta[3], adelta[3];
530         CL_ValidateState(&ent->state_current);
531         VectorSubtract(ent->state_current.origin, ent->persistent.neworigin, odelta);
532         VectorSubtract(ent->state_current.angles, ent->persistent.newangles, adelta);
533         if (!ent->state_previous.active || ent->state_previous.modelindex != ent->state_current.modelindex)
534         {
535                 // reset all persistent stuff if this is a new entity
536                 ent->persistent.lerpdeltatime = 0;
537                 ent->persistent.lerpstarttime = cl.mtime[1];
538                 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
539                 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
540                 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
541                 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
542                 // reset animation interpolation as well
543                 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
544                 ent->render.frame1time = ent->render.frame2time = cl.time;
545                 ent->render.framelerp = 1;
546                 // reset various persistent stuff
547                 ent->persistent.muzzleflash = 0;
548                 VectorCopy(ent->state_current.origin, ent->persistent.trail_origin);
549         }
550         else if (cls.timedemo || cl_nolerp.integer || DotProduct(odelta, odelta) > 1000*1000)
551         {
552                 // don't interpolate the move
553                 ent->persistent.lerpdeltatime = 0;
554                 ent->persistent.lerpstarttime = cl.mtime[1];
555                 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
556                 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
557                 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
558                 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
559         }
560         else if (ent->state_current.flags & RENDER_STEP)
561         {
562                 // monster interpolation
563                 if (DotProduct(odelta, odelta) + DotProduct(adelta, adelta) > 0.01)
564                 {
565                         ent->persistent.lerpdeltatime = bound(0, cl.mtime[1] - ent->persistent.lerpstarttime, 0.1);
566                         ent->persistent.lerpstarttime = cl.mtime[1];
567                         VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
568                         VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
569                         VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
570                         VectorCopy(ent->state_current.angles, ent->persistent.newangles);
571                 }
572         }
573         else
574         {
575                 // not a monster
576                 ent->persistent.lerpstarttime = ent->state_previous.time;
577                 // no lerp if it's singleplayer
578                 if (cl.islocalgame)
579                         ent->persistent.lerpdeltatime = 0;
580                 else
581                         ent->persistent.lerpdeltatime = bound(0, ent->state_current.time - ent->state_previous.time, 0.1);
582                 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
583                 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
584                 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
585                 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
586         }
587 }
588
589 /*
590 ==================
591 CL_ParseBaseline
592 ==================
593 */
594 void CL_ParseBaseline (entity_t *ent, int large)
595 {
596         int i;
597
598         ent->state_baseline = defaultstate;
599         // FIXME: set ent->state_baseline.number?
600         ent->state_baseline.active = true;
601         if (large)
602         {
603                 ent->state_baseline.modelindex = (unsigned short) MSG_ReadShort ();
604                 ent->state_baseline.frame = (unsigned short) MSG_ReadShort ();
605         }
606         else
607         {
608                 ent->state_baseline.modelindex = MSG_ReadByte ();
609                 ent->state_baseline.frame = MSG_ReadByte ();
610         }
611         ent->state_baseline.colormap = MSG_ReadByte();
612         ent->state_baseline.skin = MSG_ReadByte();
613         for (i = 0;i < 3;i++)
614         {
615                 ent->state_baseline.origin[i] = MSG_ReadCoord(cl.protocol);
616                 ent->state_baseline.angles[i] = MSG_ReadAngle(cl.protocol);
617         }
618         CL_ValidateState(&ent->state_baseline);
619         ent->state_previous = ent->state_current = ent->state_baseline;
620 }
621
622
623 /*
624 ==================
625 CL_ParseClientdata
626
627 Server information pertaining to this client only
628 ==================
629 */
630 void CL_ParseClientdata (void)
631 {
632         int i, j, bits;
633
634         VectorCopy (cl.mpunchangle[0], cl.mpunchangle[1]);
635         VectorCopy (cl.mpunchvector[0], cl.mpunchvector[1]);
636         VectorCopy (cl.mvelocity[0], cl.mvelocity[1]);
637         cl.mviewzoom[1] = cl.mviewzoom[0];
638
639         if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4 || cl.protocol == PROTOCOL_DARKPLACES5)
640         {
641                 cl.stats[STAT_VIEWHEIGHT] = DEFAULT_VIEWHEIGHT;
642                 cl.stats[STAT_ITEMS] = 0;
643                 cl.stats[STAT_VIEWZOOM] = 255;
644         }
645         cl.idealpitch = 0;
646         cl.mpunchangle[0][0] = 0;
647         cl.mpunchangle[0][1] = 0;
648         cl.mpunchangle[0][2] = 0;
649         cl.mpunchvector[0][0] = 0;
650         cl.mpunchvector[0][1] = 0;
651         cl.mpunchvector[0][2] = 0;
652         cl.mvelocity[0][0] = 0;
653         cl.mvelocity[0][1] = 0;
654         cl.mvelocity[0][2] = 0;
655         cl.mviewzoom[0] = 1;
656
657         bits = (unsigned short) MSG_ReadShort ();
658         if (bits & SU_EXTEND1)
659                 bits |= (MSG_ReadByte() << 16);
660         if (bits & SU_EXTEND2)
661                 bits |= (MSG_ReadByte() << 24);
662
663         if (bits & SU_VIEWHEIGHT)
664                 cl.stats[STAT_VIEWHEIGHT] = MSG_ReadChar ();
665
666         if (bits & SU_IDEALPITCH)
667                 cl.idealpitch = MSG_ReadChar ();
668
669         for (i = 0;i < 3;i++)
670         {
671                 if (bits & (SU_PUNCH1<<i) )
672                 {
673                         if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE)
674                                 cl.mpunchangle[0][i] = MSG_ReadChar();
675                         else
676                                 cl.mpunchangle[0][i] = MSG_ReadAngle16i();
677                 }
678                 if (bits & (SU_PUNCHVEC1<<i))
679                 {
680                         if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
681                                 cl.mpunchvector[0][i] = MSG_ReadCoord16i();
682                         else
683                                 cl.mpunchvector[0][i] = MSG_ReadCoord32f();
684                 }
685                 if (bits & (SU_VELOCITY1<<i) )
686                 {
687                         if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
688                                 cl.mvelocity[0][i] = MSG_ReadChar()*16;
689                         else
690                                 cl.mvelocity[0][i] = MSG_ReadCoord32f();
691                 }
692         }
693
694         // LordHavoc: hipnotic demos don't have this bit set but should
695         if (bits & SU_ITEMS || cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4 || cl.protocol == PROTOCOL_DARKPLACES5)
696                 cl.stats[STAT_ITEMS] = MSG_ReadLong ();
697
698         cl.onground = (bits & SU_ONGROUND) != 0;
699         cl.inwater = (bits & SU_INWATER) != 0;
700
701         if (cl.protocol == PROTOCOL_DARKPLACES5)
702         {
703                 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadShort() : 0;
704                 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadShort() : 0;
705                 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadShort() : 0;
706                 cl.stats[STAT_HEALTH] = MSG_ReadShort();
707                 cl.stats[STAT_AMMO] = MSG_ReadShort();
708                 cl.stats[STAT_SHELLS] = MSG_ReadShort();
709                 cl.stats[STAT_NAILS] = MSG_ReadShort();
710                 cl.stats[STAT_ROCKETS] = MSG_ReadShort();
711                 cl.stats[STAT_CELLS] = MSG_ReadShort();
712                 cl.stats[STAT_ACTIVEWEAPON] = (unsigned short) MSG_ReadShort ();
713         }
714         else if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
715         {
716                 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
717                 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
718                 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
719                 cl.stats[STAT_HEALTH] = MSG_ReadShort();
720                 cl.stats[STAT_AMMO] = MSG_ReadByte();
721                 cl.stats[STAT_SHELLS] = MSG_ReadByte();
722                 cl.stats[STAT_NAILS] = MSG_ReadByte();
723                 cl.stats[STAT_ROCKETS] = MSG_ReadByte();
724                 cl.stats[STAT_CELLS] = MSG_ReadByte();
725                 if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_NEXUIZ)
726                         cl.stats[STAT_ACTIVEWEAPON] = (1<<MSG_ReadByte ());
727                 else
728                         cl.stats[STAT_ACTIVEWEAPON] = MSG_ReadByte ();
729         }
730
731         if (bits & SU_VIEWZOOM)
732         {
733                 if (cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
734                         cl.stats[STAT_VIEWZOOM] = MSG_ReadByte();
735                 else
736                         cl.stats[STAT_VIEWZOOM] = (unsigned short) MSG_ReadShort();
737         }
738
739         // check for important changes
740
741         // set flash times
742         if (cl.olditems != cl.stats[STAT_ITEMS])
743                 for (j = 0;j < 32;j++)
744                         if ((cl.stats[STAT_ITEMS] & (1<<j)) && !(cl.olditems & (1<<j)))
745                                 cl.item_gettime[j] = cl.time;
746         cl.olditems = cl.stats[STAT_ITEMS];
747
748         // GAME_NEXUIZ hud needs weapon change time
749         if (cl.activeweapon != cl.stats[STAT_ACTIVEWEAPON])
750                 cl.weapontime = cl.time;
751         cl.activeweapon = cl.stats[STAT_ACTIVEWEAPON];
752
753         // viewzoom interpolation
754         cl.mviewzoom[0] = (float) max(cl.stats[STAT_VIEWZOOM], 2) * (1.0f / 255.0f);
755 }
756
757 /*
758 =====================
759 CL_ParseStatic
760 =====================
761 */
762 void CL_ParseStatic (int large)
763 {
764         entity_t *ent;
765
766         if (cl_num_static_entities >= cl_max_static_entities)
767                 Host_Error ("Too many static entities");
768         ent = &cl_static_entities[cl_num_static_entities++];
769         CL_ParseBaseline (ent, large);
770
771 // copy it to the current state
772         ent->render.model = cl.model_precache[ent->state_baseline.modelindex];
773         ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_baseline.frame;
774         ent->render.framelerp = 0;
775         // make torchs play out of sync
776         ent->render.frame1time = ent->render.frame2time = lhrandom(-10, -1);
777         ent->render.colormap = -1; // no special coloring
778         ent->render.skinnum = ent->state_baseline.skin;
779         ent->render.effects = ent->state_baseline.effects;
780         ent->render.alpha = 1;
781         //ent->render.scale = 1;
782
783         //VectorCopy (ent->state_baseline.origin, ent->render.origin);
784         //VectorCopy (ent->state_baseline.angles, ent->render.angles);
785
786         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);
787         Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
788         CL_BoundingBoxForEntity(&ent->render);
789
790         // This is definitely cheating...
791         if (ent->render.model == NULL)
792                 cl_num_static_entities--;
793 }
794
795 /*
796 ===================
797 CL_ParseStaticSound
798 ===================
799 */
800 void CL_ParseStaticSound (int large)
801 {
802         vec3_t          org;
803         int                     sound_num, vol, atten;
804
805         MSG_ReadVector(org, cl.protocol);
806         if (large)
807                 sound_num = (unsigned short) MSG_ReadShort ();
808         else
809                 sound_num = MSG_ReadByte ();
810         vol = MSG_ReadByte ();
811         atten = MSG_ReadByte ();
812
813         S_StaticSound (cl.sound_precache[sound_num], org, vol/255.0f, atten);
814 }
815
816 void CL_ParseEffect (void)
817 {
818         vec3_t          org;
819         int                     modelindex, startframe, framecount, framerate;
820
821         MSG_ReadVector(org, cl.protocol);
822         modelindex = MSG_ReadByte ();
823         startframe = MSG_ReadByte ();
824         framecount = MSG_ReadByte ();
825         framerate = MSG_ReadByte ();
826
827         CL_Effect(org, modelindex, startframe, framecount, framerate);
828 }
829
830 void CL_ParseEffect2 (void)
831 {
832         vec3_t          org;
833         int                     modelindex, startframe, framecount, framerate;
834
835         MSG_ReadVector(org, cl.protocol);
836         modelindex = (unsigned short) MSG_ReadShort ();
837         startframe = (unsigned short) MSG_ReadShort ();
838         framecount = MSG_ReadByte ();
839         framerate = MSG_ReadByte ();
840
841         CL_Effect(org, modelindex, startframe, framecount, framerate);
842 }
843
844 void CL_ParseBeam (model_t *m, int lightning)
845 {
846         int i, ent;
847         vec3_t start, end;
848         beam_t *b;
849
850         ent = (unsigned short) MSG_ReadShort ();
851         MSG_ReadVector(start, cl.protocol);
852         MSG_ReadVector(end, cl.protocol);
853
854         if (ent >= MAX_EDICTS)
855         {
856                 Con_Printf("CL_ParseBeam: invalid entity number %i\n", ent);
857                 ent = 0;
858         }
859
860         if (ent >= cl_max_entities)
861                 CL_ExpandEntities(ent);
862
863         // override any beam with the same entity
864         for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
865         {
866                 if (b->entity == ent && ent)
867                 {
868                         //b->entity = ent;
869                         b->lightning = lightning;
870                         b->relativestartvalid = (ent && cl_entities[ent].state_current.active) ? 2 : 0;
871                         b->model = m;
872                         b->endtime = cl.time + 0.2;
873                         VectorCopy (start, b->start);
874                         VectorCopy (end, b->end);
875                         return;
876                 }
877         }
878
879         // find a free beam
880         for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
881         {
882                 if (!b->model || b->endtime < cl.time)
883                 {
884                         b->entity = ent;
885                         b->lightning = lightning;
886                         b->relativestartvalid = (ent && cl_entities[ent].state_current.active) ? 2 : 0;
887                         b->model = m;
888                         b->endtime = cl.time + 0.2;
889                         VectorCopy (start, b->start);
890                         VectorCopy (end, b->end);
891                         return;
892                 }
893         }
894         Con_Print("beam list overflow!\n");
895 }
896
897 void CL_ParseTempEntity(void)
898 {
899         int type;
900         vec3_t pos;
901         vec3_t dir;
902         vec3_t pos2;
903         vec3_t color;
904         int rnd;
905         int colorStart, colorLength, count;
906         float velspeed, radius;
907         qbyte *tempcolor;
908         matrix4x4_t tempmatrix;
909
910         type = MSG_ReadByte();
911         switch (type)
912         {
913         case TE_WIZSPIKE:
914                 // spike hitting wall
915                 MSG_ReadVector(pos, cl.protocol);
916                 CL_FindNonSolidLocation(pos, pos, 4);
917                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
918                 CL_AllocDlight(NULL, &tempmatrix, 100, 0.12f, 0.50f, 0.12f, 500, 0.2, 0, -1, false, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
919                 CL_RunParticleEffect(pos, vec3_origin, 20, 30);
920                 S_StartSound(-1, 0, cl.sfx_wizhit, pos, 1, 1);
921                 break;
922
923         case TE_KNIGHTSPIKE:
924                 // spike hitting wall
925                 MSG_ReadVector(pos, cl.protocol);
926                 CL_FindNonSolidLocation(pos, pos, 4);
927                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
928                 CL_AllocDlight(NULL, &tempmatrix, 100, 0.50f, 0.30f, 0.10f, 500, 0.2, 0, -1, false, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
929                 CL_RunParticleEffect(pos, vec3_origin, 226, 20);
930                 S_StartSound(-1, 0, cl.sfx_knighthit, pos, 1, 1);
931                 break;
932
933         case TE_SPIKE:
934                 // spike hitting wall
935                 MSG_ReadVector(pos, cl.protocol);
936                 CL_FindNonSolidLocation(pos, pos, 4);
937                 if (cl_particles_bulletimpacts.integer)
938                 {
939                         CL_SparkShower(pos, vec3_origin, 15, 1);
940                         CL_Smoke(pos, vec3_origin, 15);
941                         CL_BulletMark(pos);
942                 }
943                 if (rand() % 5)
944                         S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
945                 else
946                 {
947                         rnd = rand() & 3;
948                         if (rnd == 1)
949                                 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
950                         else if (rnd == 2)
951                                 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
952                         else
953                                 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
954                 }
955                 break;
956         case TE_SPIKEQUAD:
957                 // quad spike hitting wall
958                 MSG_ReadVector(pos, cl.protocol);
959                 CL_FindNonSolidLocation(pos, pos, 4);
960                 // LordHavoc: changed to spark shower
961                 if (cl_particles_bulletimpacts.integer)
962                 {
963                         CL_SparkShower(pos, vec3_origin, 15, 1);
964                         CL_Smoke(pos, vec3_origin, 15);
965                         CL_BulletMark(pos);
966                 }
967                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
968                 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
969                 if (rand() % 5)
970                         S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
971                 else
972                 {
973                         rnd = rand() & 3;
974                         if (rnd == 1)
975                                 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
976                         else if (rnd == 2)
977                                 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
978                         else
979                                 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
980                 }
981                 break;
982         case TE_SUPERSPIKE:
983                 // super spike hitting wall
984                 MSG_ReadVector(pos, cl.protocol);
985                 CL_FindNonSolidLocation(pos, pos, 4);
986                 // LordHavoc: changed to dust shower
987                 if (cl_particles_bulletimpacts.integer)
988                 {
989                         CL_SparkShower(pos, vec3_origin, 30, 1);
990                         CL_Smoke(pos, vec3_origin, 30);
991                         CL_BulletMark(pos);
992                 }
993                 if (rand() % 5)
994                         S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
995                 else
996                 {
997                         rnd = rand() & 3;
998                         if (rnd == 1)
999                                 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
1000                         else if (rnd == 2)
1001                                 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
1002                         else
1003                                 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
1004                 }
1005                 break;
1006         case TE_SUPERSPIKEQUAD:
1007                 // quad super spike hitting wall
1008                 MSG_ReadVector(pos, cl.protocol);
1009                 CL_FindNonSolidLocation(pos, pos, 4);
1010                 // LordHavoc: changed to dust shower
1011                 if (cl_particles_bulletimpacts.integer)
1012                 {
1013                         CL_SparkShower(pos, vec3_origin, 30, 1);
1014                         CL_Smoke(pos, vec3_origin, 30);
1015                         CL_BulletMark(pos);
1016                 }
1017                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1018                 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1019                 if (rand() % 5)
1020                         S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
1021                 else
1022                 {
1023                         rnd = rand() & 3;
1024                         if (rnd == 1)
1025                                 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
1026                         else if (rnd == 2)
1027                                 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
1028                         else
1029                                 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
1030                 }
1031                 break;
1032                 // LordHavoc: added for improved blood splatters
1033         case TE_BLOOD:
1034                 // blood puff
1035                 MSG_ReadVector(pos, cl.protocol);
1036                 CL_FindNonSolidLocation(pos, pos, 4);
1037                 dir[0] = MSG_ReadChar();
1038                 dir[1] = MSG_ReadChar();
1039                 dir[2] = MSG_ReadChar();
1040                 count = MSG_ReadByte();
1041                 CL_BloodPuff(pos, dir, count);
1042                 break;
1043         case TE_SPARK:
1044                 // spark shower
1045                 MSG_ReadVector(pos, cl.protocol);
1046                 CL_FindNonSolidLocation(pos, pos, 4);
1047                 dir[0] = MSG_ReadChar();
1048                 dir[1] = MSG_ReadChar();
1049                 dir[2] = MSG_ReadChar();
1050                 count = MSG_ReadByte();
1051                 CL_SparkShower(pos, dir, count, 1);
1052                 break;
1053         case TE_PLASMABURN:
1054                 MSG_ReadVector(pos, cl.protocol);
1055                 CL_FindNonSolidLocation(pos, pos, 4);
1056                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1057                 CL_AllocDlight(NULL, &tempmatrix, 200, 1, 1, 1, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1058                 CL_PlasmaBurn(pos);
1059                 break;
1060                 // LordHavoc: added for improved gore
1061         case TE_BLOODSHOWER:
1062                 // vaporized body
1063                 MSG_ReadVector(pos, cl.protocol); // mins
1064                 MSG_ReadVector(pos2, cl.protocol); // maxs
1065                 velspeed = MSG_ReadCoord(cl.protocol); // speed
1066                 count = (unsigned short) MSG_ReadShort(); // number of particles
1067                 CL_BloodShower(pos, pos2, velspeed, count);
1068                 break;
1069         case TE_PARTICLECUBE:
1070                 // general purpose particle effect
1071                 MSG_ReadVector(pos, cl.protocol); // mins
1072                 MSG_ReadVector(pos2, cl.protocol); // maxs
1073                 MSG_ReadVector(dir, cl.protocol); // dir
1074                 count = (unsigned short) MSG_ReadShort(); // number of particles
1075                 colorStart = MSG_ReadByte(); // color
1076                 colorLength = MSG_ReadByte(); // gravity (1 or 0)
1077                 velspeed = MSG_ReadCoord(cl.protocol); // randomvel
1078                 CL_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
1079                 break;
1080
1081         case TE_PARTICLERAIN:
1082                 // general purpose particle effect
1083                 MSG_ReadVector(pos, cl.protocol); // mins
1084                 MSG_ReadVector(pos2, cl.protocol); // maxs
1085                 MSG_ReadVector(dir, cl.protocol); // dir
1086                 count = (unsigned short) MSG_ReadShort(); // number of particles
1087                 colorStart = MSG_ReadByte(); // color
1088                 CL_ParticleRain(pos, pos2, dir, count, colorStart, 0);
1089                 break;
1090
1091         case TE_PARTICLESNOW:
1092                 // general purpose particle effect
1093                 MSG_ReadVector(pos, cl.protocol); // mins
1094                 MSG_ReadVector(pos2, cl.protocol); // maxs
1095                 MSG_ReadVector(dir, cl.protocol); // dir
1096                 count = (unsigned short) MSG_ReadShort(); // number of particles
1097                 colorStart = MSG_ReadByte(); // color
1098                 CL_ParticleRain(pos, pos2, dir, count, colorStart, 1);
1099                 break;
1100
1101         case TE_GUNSHOT:
1102                 // bullet hitting wall
1103                 MSG_ReadVector(pos, cl.protocol);
1104                 CL_FindNonSolidLocation(pos, pos, 4);
1105                 CL_SparkShower(pos, vec3_origin, 15, 1);
1106                 CL_Smoke(pos, vec3_origin, 15);
1107                 CL_BulletMark(pos);
1108                 break;
1109
1110         case TE_GUNSHOTQUAD:
1111                 // quad bullet hitting wall
1112                 MSG_ReadVector(pos, cl.protocol);
1113                 CL_FindNonSolidLocation(pos, pos, 4);
1114                 CL_SparkShower(pos, vec3_origin, 15, 1);
1115                 CL_Smoke(pos, vec3_origin, 15);
1116                 CL_BulletMark(pos);
1117                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1118                 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1119                 break;
1120
1121         case TE_EXPLOSION:
1122                 // rocket explosion
1123                 MSG_ReadVector(pos, cl.protocol);
1124                 CL_FindNonSolidLocation(pos, pos, 10);
1125                 CL_ParticleExplosion(pos);
1126                 // LordHavoc: boosted color from 1.0, 0.8, 0.4 to 1.25, 1.0, 0.5
1127                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1128                 CL_AllocDlight(NULL, &tempmatrix, 350, 4.0f, 2.0f, 0.50f, 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1129                 if (gamemode != GAME_NEXUIZ)
1130                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1131                 break;
1132
1133         case TE_EXPLOSIONQUAD:
1134                 // quad rocket explosion
1135                 MSG_ReadVector(pos, cl.protocol);
1136                 CL_FindNonSolidLocation(pos, pos, 10);
1137                 CL_ParticleExplosion(pos);
1138                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1139                 CL_AllocDlight(NULL, &tempmatrix, 350, 2.5f, 2.0f, 4.0f, 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1140                 if (gamemode != GAME_NEXUIZ)
1141                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1142                 break;
1143
1144         case TE_EXPLOSION3:
1145                 // Nehahra movie colored lighting explosion
1146                 MSG_ReadVector(pos, cl.protocol);
1147                 CL_FindNonSolidLocation(pos, pos, 10);
1148                 CL_ParticleExplosion(pos);
1149                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1150                 color[0] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1151                 color[1] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1152                 color[2] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1153                 CL_AllocDlight(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);
1154                 if (gamemode != GAME_NEXUIZ)
1155                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1156                 break;
1157
1158         case TE_EXPLOSIONRGB:
1159                 // colored lighting explosion
1160                 MSG_ReadVector(pos, cl.protocol);
1161                 CL_FindNonSolidLocation(pos, pos, 10);
1162                 CL_ParticleExplosion(pos);
1163                 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1164                 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1165                 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1166                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1167                 CL_AllocDlight(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);
1168                 if (gamemode != GAME_NEXUIZ)
1169                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1170                 break;
1171
1172         case TE_TAREXPLOSION:
1173                 // tarbaby explosion
1174                 MSG_ReadVector(pos, cl.protocol);
1175                 CL_FindNonSolidLocation(pos, pos, 10);
1176                 CL_BlobExplosion(pos);
1177
1178                 if (gamemode != GAME_NEXUIZ)
1179                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1180                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1181                 CL_AllocDlight(NULL, &tempmatrix, 600, 1.6f, 0.8f, 2.0f, 1200, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1182                 break;
1183
1184         case TE_SMALLFLASH:
1185                 MSG_ReadVector(pos, cl.protocol);
1186                 CL_FindNonSolidLocation(pos, pos, 10);
1187                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1188                 CL_AllocDlight(NULL, &tempmatrix, 200, 2, 2, 2, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1189                 break;
1190
1191         case TE_CUSTOMFLASH:
1192                 MSG_ReadVector(pos, cl.protocol);
1193                 CL_FindNonSolidLocation(pos, pos, 4);
1194                 radius = (MSG_ReadByte() + 1) * 8;
1195                 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
1196                 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1197                 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1198                 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1199                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1200                 CL_AllocDlight(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);
1201                 break;
1202
1203         case TE_FLAMEJET:
1204                 MSG_ReadVector(pos, cl.protocol);
1205                 MSG_ReadVector(dir, cl.protocol);
1206                 count = MSG_ReadByte();
1207                 CL_Flames(pos, dir, count);
1208                 break;
1209
1210         case TE_LIGHTNING1:
1211                 // lightning bolts
1212                 CL_ParseBeam(cl.model_bolt, true);
1213                 break;
1214
1215         case TE_LIGHTNING2:
1216                 // lightning bolts
1217                 CL_ParseBeam(cl.model_bolt2, true);
1218                 break;
1219
1220         case TE_LIGHTNING3:
1221                 // lightning bolts
1222                 CL_ParseBeam(cl.model_bolt3, false);
1223                 break;
1224
1225 // PGM 01/21/97
1226         case TE_BEAM:
1227                 // grappling hook beam
1228                 CL_ParseBeam(cl.model_beam, false);
1229                 break;
1230 // PGM 01/21/97
1231
1232 // LordHavoc: for compatibility with the Nehahra movie...
1233         case TE_LIGHTNING4NEH:
1234                 CL_ParseBeam(Mod_ForName(MSG_ReadString(), true, false, false), false);
1235                 break;
1236
1237         case TE_LAVASPLASH:
1238                 MSG_ReadVector(pos, cl.protocol);
1239                 CL_LavaSplash(pos);
1240                 break;
1241
1242         case TE_TELEPORT:
1243                 MSG_ReadVector(pos, cl.protocol);
1244                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1245                 CL_AllocDlight(NULL, &tempmatrix, 200, 1.0f, 1.0f, 1.0f, 600, 99.0f, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1246                 CL_TeleportSplash(pos);
1247                 break;
1248
1249         case TE_EXPLOSION2:
1250                 // color mapped explosion
1251                 MSG_ReadVector(pos, cl.protocol);
1252                 CL_FindNonSolidLocation(pos, pos, 10);
1253                 colorStart = MSG_ReadByte();
1254                 colorLength = MSG_ReadByte();
1255                 CL_ParticleExplosion2(pos, colorStart, colorLength);
1256                 tempcolor = (qbyte *)&palette_complete[(rand()%colorLength) + colorStart];
1257                 color[0] = tempcolor[0] * (2.0f / 255.0f);
1258                 color[1] = tempcolor[1] * (2.0f / 255.0f);
1259                 color[2] = tempcolor[2] * (2.0f / 255.0f);
1260                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1261                 CL_AllocDlight(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);
1262                 if (gamemode != GAME_NEXUIZ)
1263                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1264                 break;
1265
1266         case TE_TEI_G3:
1267                 MSG_ReadVector(pos, cl.protocol);
1268                 MSG_ReadVector(pos2, cl.protocol);
1269                 MSG_ReadVector(dir, cl.protocol);
1270                 CL_BeamParticle(pos, pos2, 8, 1, 1, 1, 1, 1);
1271                 break;
1272
1273         case TE_TEI_SMOKE:
1274                 MSG_ReadVector(pos, cl.protocol);
1275                 MSG_ReadVector(dir, cl.protocol);
1276                 count = MSG_ReadByte();
1277                 CL_FindNonSolidLocation(pos, pos, 4);
1278                 CL_Tei_Smoke(pos, dir, count);
1279                 break;
1280
1281         case TE_TEI_BIGEXPLOSION:
1282                 MSG_ReadVector(pos, cl.protocol);
1283                 CL_FindNonSolidLocation(pos, pos, 10);
1284                 CL_ParticleExplosion(pos);
1285                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1286                 CL_AllocDlight(NULL, &tempmatrix, 500, 2.5f, 2.0f, 1.0f, 500, 9999, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1287                 if (gamemode != GAME_NEXUIZ)
1288                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1289                 break;
1290
1291         case TE_TEI_PLASMAHIT:
1292                 MSG_ReadVector(pos, cl.protocol);
1293                 MSG_ReadVector(dir, cl.protocol);
1294                 count = MSG_ReadByte();
1295                 CL_FindNonSolidLocation(pos, pos, 5);
1296                 CL_Tei_PlasmaHit(pos, dir, count);
1297                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1298                 CL_AllocDlight(NULL, &tempmatrix, 500, 0.6, 1.2, 2.0f, 2000, 9999, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1299                 break;
1300
1301         default:
1302                 Host_Error("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
1303         }
1304 }
1305
1306 #define SHOWNET(x) if(cl_shownet.integer==2)Con_Printf("%3i:%s\n", msg_readcount-1, x);
1307
1308 static qbyte cgamenetbuffer[65536];
1309
1310 /*
1311 =====================
1312 CL_ParseServerMessage
1313 =====================
1314 */
1315 int parsingerror = false;
1316 void CL_ParseServerMessage(void)
1317 {
1318         int                     cmd;
1319         int                     i;
1320         protocolversion_t protocol;
1321         qbyte           cmdlog[32];
1322         char            *cmdlogname[32], *temp;
1323         int                     cmdindex, cmdcount = 0;
1324         qboolean        sendmove = false;
1325
1326         if (cls.demorecording)
1327                 CL_WriteDemoMessage ();
1328
1329         cl.last_received_message = realtime;
1330
1331 //
1332 // if recording demos, copy the message out
1333 //
1334         if (cl_shownet.integer == 1)
1335                 Con_Printf("%f %i\n", realtime, net_message.cursize);
1336         else if (cl_shownet.integer == 2)
1337                 Con_Print("------------------\n");
1338
1339         cl.onground = false;    // unless the server says otherwise
1340 //
1341 // parse the message
1342 //
1343         //MSG_BeginReading ();
1344
1345         parsingerror = true;
1346
1347         while (1)
1348         {
1349                 if (msg_badread)
1350                         Host_Error ("CL_ParseServerMessage: Bad server message");
1351
1352                 cmd = MSG_ReadByte ();
1353
1354                 if (cmd == -1)
1355                 {
1356                         SHOWNET("END OF MESSAGE");
1357                         break;          // end of message
1358                 }
1359
1360                 cmdindex = cmdcount & 31;
1361                 cmdcount++;
1362                 cmdlog[cmdindex] = cmd;
1363
1364                 // if the high bit of the command byte is set, it is a fast update
1365                 if (cmd & 128)
1366                 {
1367                         // 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)
1368                         temp = "entity";
1369                         cmdlogname[cmdindex] = temp;
1370                         SHOWNET("fast update");
1371                         if (cls.signon == SIGNONS - 1)
1372                         {
1373                                 // first update is the final signon stage
1374                                 cls.signon = SIGNONS;
1375                                 CL_SignonReply ();
1376                         }
1377                         EntityFrameQuake_ReadEntity (cmd&127);
1378                         continue;
1379                 }
1380
1381                 SHOWNET(svc_strings[cmd]);
1382                 cmdlogname[cmdindex] = svc_strings[cmd];
1383                 if (!cmdlogname[cmdindex])
1384                 {
1385                         // 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)
1386                         temp = "<unknown>";
1387                         cmdlogname[cmdindex] = temp;
1388                 }
1389
1390                 // other commands
1391                 switch (cmd)
1392                 {
1393                 default:
1394                         {
1395                                 char description[32*64], temp[64];
1396                                 int count;
1397                                 strcpy (description, "packet dump: ");
1398                                 i = cmdcount - 32;
1399                                 if (i < 0)
1400                                         i = 0;
1401                                 count = cmdcount - i;
1402                                 i &= 31;
1403                                 while(count > 0)
1404                                 {
1405                                         dpsnprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
1406                                         strlcat (description, temp, sizeof (description));
1407                                         count--;
1408                                         i++;
1409                                         i &= 31;
1410                                 }
1411                                 description[strlen(description)-1] = '\n'; // replace the last space with a newline
1412                                 Con_Print(description);
1413                                 Host_Error ("CL_ParseServerMessage: Illegible server message\n");
1414                         }
1415                         break;
1416
1417                 case svc_nop:
1418                         if (cls.signon < SIGNONS)
1419                                 Con_Print("<-- server to client keepalive\n");
1420                         break;
1421
1422                 case svc_time:
1423                         cl.mtime[1] = cl.mtime[0];
1424                         cl.mtime[0] = MSG_ReadFloat ();
1425                         sendmove = true;
1426                         break;
1427
1428                 case svc_clientdata:
1429                         CL_ParseClientdata();
1430                         break;
1431
1432                 case svc_version:
1433                         i = MSG_ReadLong ();
1434                         protocol = Protocol_EnumForNumber(i);
1435                         if (protocol == PROTOCOL_UNKNOWN)
1436                                 Host_Error("CL_ParseServerMessage: Server is unrecognized protocol number (%i)\n", i);
1437                         // hack for unmarked Nehahra movie demos which had a custom protocol
1438                         if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
1439                                 protocol = PROTOCOL_NEHAHRAMOVIE;
1440                         cl.protocol = protocol;
1441                         break;
1442
1443                 case svc_disconnect:
1444                         Con_Printf ("Server disconnected\n");
1445                         if (cls.demonum != -1)
1446                                 CL_NextDemo ();
1447                         else
1448                                 CL_Disconnect ();
1449                         break;
1450
1451                 case svc_print:
1452                         Con_Print(MSG_ReadString());
1453                         break;
1454
1455                 case svc_centerprint:
1456                         SCR_CenterPrint(MSG_ReadString ());
1457                         break;
1458
1459                 case svc_stufftext:
1460                         Cbuf_AddText (MSG_ReadString ());
1461                         break;
1462
1463                 case svc_damage:
1464                         V_ParseDamage ();
1465                         break;
1466
1467                 case svc_serverinfo:
1468                         CL_ParseServerInfo ();
1469                         break;
1470
1471                 case svc_setangle:
1472                         for (i=0 ; i<3 ; i++)
1473                                 cl.viewangles[i] = MSG_ReadAngle (cl.protocol);
1474                         break;
1475
1476                 case svc_setview:
1477                         cl.viewentity = (unsigned short)MSG_ReadShort ();
1478                         if (cl.viewentity >= MAX_EDICTS)
1479                                 Host_Error("svc_setview >= MAX_EDICTS\n");
1480                         if (cl.viewentity >= cl_max_entities)
1481                                 CL_ExpandEntities(cl.viewentity);
1482                         // LordHavoc: assume first setview recieved is the real player entity
1483                         if (!cl.playerentity)
1484                                 cl.playerentity = cl.viewentity;
1485                         break;
1486
1487                 case svc_lightstyle:
1488                         i = MSG_ReadByte ();
1489                         if (i >= MAX_LIGHTSTYLES)
1490                                 Host_Error ("svc_lightstyle >= MAX_LIGHTSTYLES");
1491                         strlcpy (cl_lightstyle[i].map,  MSG_ReadString(), sizeof (cl_lightstyle[i].map));
1492                         cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
1493                         cl_lightstyle[i].length = (int)strlen(cl_lightstyle[i].map);
1494                         break;
1495
1496                 case svc_sound:
1497                         CL_ParseStartSoundPacket(false);
1498                         break;
1499
1500                 case svc_precache:
1501                         if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1502                         {
1503                                 // was svc_sound2 in protocols 1, 2, 3, removed in 4, 5, changed to svc_precache in 6
1504                                 CL_ParseStartSoundPacket(true);
1505                         }
1506                         else
1507                         {
1508                                 int i = (unsigned short)MSG_ReadShort();
1509                                 char *s = MSG_ReadString();
1510                                 if (i < 32768)
1511                                 {
1512                                         if (i >= 1 && i < MAX_MODELS)
1513                                         {
1514                                                 model_t *model = Mod_ForName(s, false, false, i == 1);
1515                                                 if (!model)
1516                                                         Con_Printf("svc_precache: Mod_ForName(\"%s\") failed\n", s);
1517                                                 cl.model_precache[i] = model;
1518                                         }
1519                                         else
1520                                                 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_MODELS);
1521                                 }
1522                                 else
1523                                 {
1524                                         i -= 32768;
1525                                         if (i >= 1 && i < MAX_SOUNDS)
1526                                         {
1527                                                 sfx_t *sfx = S_PrecacheSound (s, true, false);
1528                                                 if (!sfx && snd_initialized.integer)
1529                                                         Con_Printf("svc_precache: S_PrecacheSound(\"%s\") failed\n", s);
1530                                                 cl.sound_precache[i] = sfx;
1531                                         }
1532                                         else
1533                                                 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_SOUNDS);
1534                                 }
1535                         }
1536                         break;
1537
1538                 case svc_stopsound:
1539                         i = (unsigned short) MSG_ReadShort();
1540                         S_StopSound(i>>3, i&7);
1541                         break;
1542
1543                 case svc_updatename:
1544                         i = MSG_ReadByte ();
1545                         if (i >= cl.maxclients)
1546                                 Host_Error ("CL_ParseServerMessage: svc_updatename >= cl.maxclients");
1547                         strlcpy (cl.scores[i].name, MSG_ReadString (), sizeof (cl.scores[i].name));
1548                         break;
1549
1550                 case svc_updatefrags:
1551                         i = MSG_ReadByte ();
1552                         if (i >= cl.maxclients)
1553                                 Host_Error ("CL_ParseServerMessage: svc_updatefrags >= cl.maxclients");
1554                         cl.scores[i].frags = (signed short) MSG_ReadShort ();
1555                         break;
1556
1557                 case svc_updatecolors:
1558                         i = MSG_ReadByte ();
1559                         if (i >= cl.maxclients)
1560                                 Host_Error ("CL_ParseServerMessage: svc_updatecolors >= cl.maxclients");
1561                         cl.scores[i].colors = MSG_ReadByte ();
1562                         break;
1563
1564                 case svc_particle:
1565                         CL_ParseParticleEffect ();
1566                         break;
1567
1568                 case svc_effect:
1569                         CL_ParseEffect ();
1570                         break;
1571
1572                 case svc_effect2:
1573                         CL_ParseEffect2 ();
1574                         break;
1575
1576                 case svc_spawnbaseline:
1577                         i = (unsigned short) MSG_ReadShort ();
1578                         if (i < 0 || i >= MAX_EDICTS)
1579                                 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
1580                         if (i >= cl_max_entities)
1581                                 CL_ExpandEntities(i);
1582                         CL_ParseBaseline (cl_entities + i, false);
1583                         break;
1584                 case svc_spawnbaseline2:
1585                         i = (unsigned short) MSG_ReadShort ();
1586                         if (i < 0 || i >= MAX_EDICTS)
1587                                 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline2: invalid entity number %i", i);
1588                         if (i >= cl_max_entities)
1589                                 CL_ExpandEntities(i);
1590                         CL_ParseBaseline (cl_entities + i, true);
1591                         break;
1592                 case svc_spawnstatic:
1593                         CL_ParseStatic (false);
1594                         break;
1595                 case svc_spawnstatic2:
1596                         CL_ParseStatic (true);
1597                         break;
1598                 case svc_temp_entity:
1599                         CL_ParseTempEntity ();
1600                         break;
1601
1602                 case svc_setpause:
1603                         cl.paused = MSG_ReadByte ();
1604                         if (cl.paused)
1605                                 CDAudio_Pause ();
1606                         else
1607                                 CDAudio_Resume ();
1608                         S_PauseGameSounds (cl.paused);
1609                         break;
1610
1611                 case svc_signonnum:
1612                         i = MSG_ReadByte ();
1613                         // LordHavoc: it's rude to kick off the client if they missed the
1614                         // reconnect somehow, so allow signon 1 even if at signon 1
1615                         if (i <= cls.signon && i != 1)
1616                                 Host_Error ("Received signon %i when at %i", i, cls.signon);
1617                         cls.signon = i;
1618                         CL_SignonReply ();
1619                         break;
1620
1621                 case svc_killedmonster:
1622                         cl.stats[STAT_MONSTERS]++;
1623                         break;
1624
1625                 case svc_foundsecret:
1626                         cl.stats[STAT_SECRETS]++;
1627                         break;
1628
1629                 case svc_updatestat:
1630                         i = MSG_ReadByte ();
1631                         if (i < 0 || i >= MAX_CL_STATS)
1632                                 Host_Error ("svc_updatestat: %i is invalid", i);
1633                         cl.stats[i] = MSG_ReadLong ();
1634                         break;
1635
1636                 case svc_updatestatubyte:
1637                         i = MSG_ReadByte ();
1638                         if (i < 0 || i >= MAX_CL_STATS)
1639                                 Host_Error ("svc_updatestat: %i is invalid", i);
1640                         cl.stats[i] = MSG_ReadByte ();
1641                         break;
1642
1643                 case svc_spawnstaticsound:
1644                         CL_ParseStaticSound (false);
1645                         break;
1646
1647                 case svc_spawnstaticsound2:
1648                         CL_ParseStaticSound (true);
1649                         break;
1650
1651                 case svc_cdtrack:
1652                         cl.cdtrack = MSG_ReadByte ();
1653                         cl.looptrack = MSG_ReadByte ();
1654                         if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
1655                                 CDAudio_Play ((qbyte)cls.forcetrack, true);
1656                         else
1657                                 CDAudio_Play ((qbyte)cl.cdtrack, true);
1658                         break;
1659
1660                 case svc_intermission:
1661                         cl.intermission = 1;
1662                         cl.completed_time = cl.time;
1663                         break;
1664
1665                 case svc_finale:
1666                         cl.intermission = 2;
1667                         cl.completed_time = cl.time;
1668                         SCR_CenterPrint(MSG_ReadString ());
1669                         break;
1670
1671                 case svc_cutscene:
1672                         cl.intermission = 3;
1673                         cl.completed_time = cl.time;
1674                         SCR_CenterPrint(MSG_ReadString ());
1675                         break;
1676
1677                 case svc_sellscreen:
1678                         Cmd_ExecuteString ("help", src_command);
1679                         break;
1680                 case svc_hidelmp:
1681                         if (gamemode == GAME_TENEBRAE)
1682                         {
1683                                 // repeating particle effect
1684                                 MSG_ReadCoord(cl.protocol);
1685                                 MSG_ReadCoord(cl.protocol);
1686                                 MSG_ReadCoord(cl.protocol);
1687                                 MSG_ReadCoord(cl.protocol);
1688                                 MSG_ReadCoord(cl.protocol);
1689                                 MSG_ReadCoord(cl.protocol);
1690                                 MSG_ReadByte();
1691                                 MSG_ReadLong();
1692                                 MSG_ReadLong();
1693                                 MSG_ReadString();
1694                         }
1695                         else
1696                                 SHOWLMP_decodehide();
1697                         break;
1698                 case svc_showlmp:
1699                         if (gamemode == GAME_TENEBRAE)
1700                         {
1701                                 // particle effect
1702                                 MSG_ReadCoord(cl.protocol);
1703                                 MSG_ReadCoord(cl.protocol);
1704                                 MSG_ReadCoord(cl.protocol);
1705                                 MSG_ReadByte();
1706                                 MSG_ReadString();
1707                         }
1708                         else
1709                                 SHOWLMP_decodeshow();
1710                         break;
1711                 case svc_skybox:
1712                         R_SetSkyBox(MSG_ReadString());
1713                         break;
1714                 case svc_cgame:
1715                         {
1716                                 int length;
1717                                 length = (int) ((unsigned short) MSG_ReadShort());
1718                                 for (i = 0;i < length;i++)
1719                                         cgamenetbuffer[i] = MSG_ReadByte();
1720                                 if (!msg_badread)
1721                                         CL_CGVM_ParseNetwork(cgamenetbuffer, length);
1722                         }
1723                         break;
1724                 case svc_entities:
1725                         if (cls.signon == SIGNONS - 1)
1726                         {
1727                                 // first update is the final signon stage
1728                                 cls.signon = SIGNONS;
1729                                 CL_SignonReply ();
1730                         }
1731                         if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1732                                 EntityFrame_CL_ReadFrame();
1733                         else if (cl.protocol == PROTOCOL_DARKPLACES4)
1734                                 EntityFrame4_CL_ReadFrame();
1735                         else
1736                                 EntityFrame5_CL_ReadFrame();
1737                         break;
1738                 }
1739         }
1740
1741         EntityFrameQuake_ISeeDeadEntities();
1742
1743         if (sendmove)
1744         {
1745                 // send one move per server frame
1746                 CL_SendMove();
1747         }
1748
1749         parsingerror = false;
1750 }
1751
1752 void CL_Parse_DumpPacket(void)
1753 {
1754         if (!parsingerror)
1755                 return;
1756         Con_Print("Packet dump:\n");
1757         SZ_HexDumpToConsole(&net_message);
1758         parsingerror = false;
1759 }
1760
1761 void CL_Parse_Init(void)
1762 {
1763         // LordHavoc: added demo_nehahra cvar
1764         Cvar_RegisterVariable (&demo_nehahra);
1765         if (gamemode == GAME_NEHAHRA)
1766                 Cvar_SetValue("demo_nehahra", 1);
1767         Cvar_RegisterVariable(&developer_networkentities);
1768 }
1769
1770 void CL_Parse_Shutdown(void)
1771 {
1772 }