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