]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - cl_parse.c
rewrote protocol version system (including splitting PROTOCOL_QUAKE into PROTOCOL_QUA...
[xonotic/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_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\"\n", cl_name.string));
284
285                 MSG_WriteByte (&cls.message, clc_stringcmd);
286                 MSG_WriteString (&cls.message, va("color %i %i\n", 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\n", 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\n", 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\n", cl_playerskin.string));
302                 }
303
304                 MSG_WriteByte (&cls.message, clc_stringcmd);
305                 MSG_WriteString (&cls.message, va("rate %i\n", 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 = 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         Mod_PurgeUnused();
427
428         // do the same for sounds
429         S_ServerSounds (parse_sound_precache, numsounds);
430
431         // now we try to load everything that is new
432
433         // world model
434         CL_KeepaliveMessage ();
435         cl.model_precache[1] = Mod_ForName(parse_model_precache[1], false, false, true);
436         if (cl.model_precache[1] == NULL)
437                 Con_Printf("Map %s not found\n", parse_model_precache[1]);
438
439         // normal models
440         for (i=2 ; i<nummodels ; i++)
441         {
442                 CL_KeepaliveMessage();
443                 if ((cl.model_precache[i] = Mod_ForName(parse_model_precache[i], false, false, false)) == NULL)
444                         Con_Printf("Model %s not found\n", parse_model_precache[i]);
445         }
446
447         // sounds
448         for (i=1 ; i<numsounds ; i++)
449         {
450                 CL_KeepaliveMessage();
451
452                 // Don't lock the sfx here, S_ServerSounds already did that
453                 cl.sound_precache[i] = S_PrecacheSound (parse_sound_precache[i], true, false);
454         }
455
456         // local state
457         ent = &cl_entities[0];
458         // entire entity array was cleared, so just fill in a few fields
459         ent->state_current.active = true;
460         ent->render.model = cl.worldmodel = cl.model_precache[1];
461         ent->render.scale = 1; // some of the renderer still relies on scale
462         ent->render.alpha = 1;
463         ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
464         Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
465         Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
466         CL_BoundingBoxForEntity(&ent->render);
467
468         cl_num_entities = 1;
469
470         R_Modules_NewMap();
471         CL_CGVM_Start();
472
473         // noclip is turned off at start
474         noclip_anglehack = false;
475
476         // check memory integrity
477         Mem_CheckSentinelsGlobal();
478 }
479
480 void CL_ValidateState(entity_state_t *s)
481 {
482         model_t *model;
483
484         if (!s->active)
485                 return;
486
487         if (s->modelindex >= MAX_MODELS)
488                 Host_Error("CL_ValidateState: modelindex (%i) >= MAX_MODELS (%i)\n", s->modelindex, MAX_MODELS);
489
490         // colormap is client index + 1
491         if ((!s->flags & RENDER_COLORMAPPED) && s->colormap > cl.maxclients)
492         {
493                 Con_DPrintf("CL_ValidateState: colormap (%i) > cl.maxclients (%i)\n", s->colormap, cl.maxclients);
494                 s->colormap = 0;
495         }
496
497         model = cl.model_precache[s->modelindex];
498         Mod_CheckLoaded(model);
499         if (model && model->type && s->frame >= model->numframes)
500         {
501                 Con_DPrintf("CL_ValidateState: no such frame %i in \"%s\" (which has %i frames)\n", s->frame, model->name, model->numframes);
502                 s->frame = 0;
503         }
504         if (model && model->type && s->skin > 0 && s->skin >= model->numskins && !(s->lightpflags & PFLAGS_FULLDYNAMIC))
505         {
506                 Con_DPrintf("CL_ValidateState: no such skin %i in \"%s\" (which has %i skins)\n", s->skin, model->name, model->numskins);
507                 s->skin = 0;
508         }
509 }
510
511 void CL_MoveLerpEntityStates(entity_t *ent)
512 {
513         float odelta[3], adelta[3];
514         CL_ValidateState(&ent->state_current);
515         VectorSubtract(ent->state_current.origin, ent->persistent.neworigin, odelta);
516         VectorSubtract(ent->state_current.angles, ent->persistent.newangles, adelta);
517         if (!ent->state_previous.active || ent->state_previous.modelindex != ent->state_current.modelindex)
518         {
519                 // reset all persistent stuff if this is a new entity
520                 ent->persistent.lerpdeltatime = 0;
521                 ent->persistent.lerpstarttime = cl.mtime[1];
522                 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
523                 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
524                 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
525                 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
526                 // reset animation interpolation as well
527                 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
528                 ent->render.frame1time = ent->render.frame2time = cl.time;
529                 ent->render.framelerp = 1;
530                 // reset various persistent stuff
531                 ent->persistent.muzzleflash = 0;
532                 VectorCopy(ent->state_current.origin, ent->persistent.trail_origin);
533         }
534         else if (cls.timedemo || cl_nolerp.integer || DotProduct(odelta, odelta) > 1000*1000)
535         {
536                 // don't interpolate the move
537                 ent->persistent.lerpdeltatime = 0;
538                 ent->persistent.lerpstarttime = cl.mtime[1];
539                 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
540                 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
541                 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
542                 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
543         }
544         else if (ent->state_current.flags & RENDER_STEP)
545         {
546                 // monster interpolation
547                 if (DotProduct(odelta, odelta) + DotProduct(adelta, adelta) > 0.01)
548                 {
549                         ent->persistent.lerpdeltatime = bound(0, cl.mtime[1] - ent->persistent.lerpstarttime, 0.1);
550                         ent->persistent.lerpstarttime = cl.mtime[1];
551                         VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
552                         VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
553                         VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
554                         VectorCopy(ent->state_current.angles, ent->persistent.newangles);
555                 }
556         }
557         else
558         {
559                 // not a monster
560                 ent->persistent.lerpstarttime = ent->state_previous.time;
561                 // no lerp if it's singleplayer
562                 if (cl.islocalgame)
563                         ent->persistent.lerpdeltatime = 0;
564                 else
565                         ent->persistent.lerpdeltatime = bound(0, ent->state_current.time - ent->state_previous.time, 0.1);
566                 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
567                 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
568                 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
569                 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
570         }
571 }
572
573 /*
574 ==================
575 CL_ParseBaseline
576 ==================
577 */
578 void CL_ParseBaseline (entity_t *ent, int large)
579 {
580         int i;
581
582         ent->state_baseline = defaultstate;
583         // FIXME: set ent->state_baseline.number?
584         ent->state_baseline.active = true;
585         if (large)
586         {
587                 ent->state_baseline.modelindex = (unsigned short) MSG_ReadShort ();
588                 ent->state_baseline.frame = (unsigned short) MSG_ReadShort ();
589         }
590         else
591         {
592                 ent->state_baseline.modelindex = MSG_ReadByte ();
593                 ent->state_baseline.frame = MSG_ReadByte ();
594         }
595         ent->state_baseline.colormap = MSG_ReadByte();
596         ent->state_baseline.skin = MSG_ReadByte();
597         for (i = 0;i < 3;i++)
598         {
599                 ent->state_baseline.origin[i] = MSG_ReadCoord(cl.protocol);
600                 ent->state_baseline.angles[i] = MSG_ReadAngle(cl.protocol);
601         }
602         CL_ValidateState(&ent->state_baseline);
603         ent->state_previous = ent->state_current = ent->state_baseline;
604 }
605
606
607 /*
608 ==================
609 CL_ParseClientdata
610
611 Server information pertaining to this client only
612 ==================
613 */
614 void CL_ParseClientdata (void)
615 {
616         int i, j, bits;
617
618         VectorCopy (cl.mpunchangle[0], cl.mpunchangle[1]);
619         VectorCopy (cl.mpunchvector[0], cl.mpunchvector[1]);
620         VectorCopy (cl.mvelocity[0], cl.mvelocity[1]);
621         cl.mviewzoom[1] = cl.mviewzoom[0];
622
623         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)
624         {
625                 cl.stats[STAT_VIEWHEIGHT] = DEFAULT_VIEWHEIGHT;
626                 cl.stats[STAT_ITEMS] = 0;
627                 cl.stats[STAT_VIEWZOOM] = 255;
628         }
629         cl.idealpitch = 0;
630         cl.mpunchangle[0][0] = 0;
631         cl.mpunchangle[0][1] = 0;
632         cl.mpunchangle[0][2] = 0;
633         cl.mpunchvector[0][0] = 0;
634         cl.mpunchvector[0][1] = 0;
635         cl.mpunchvector[0][2] = 0;
636         cl.mvelocity[0][0] = 0;
637         cl.mvelocity[0][1] = 0;
638         cl.mvelocity[0][2] = 0;
639         cl.mviewzoom[0] = 1;
640
641         bits = (unsigned short) MSG_ReadShort ();
642         if (bits & SU_EXTEND1)
643                 bits |= (MSG_ReadByte() << 16);
644         if (bits & SU_EXTEND2)
645                 bits |= (MSG_ReadByte() << 24);
646
647         if (bits & SU_VIEWHEIGHT)
648                 cl.stats[STAT_VIEWHEIGHT] = MSG_ReadChar ();
649
650         if (bits & SU_IDEALPITCH)
651                 cl.idealpitch = MSG_ReadChar ();
652
653         for (i = 0;i < 3;i++)
654         {
655                 if (bits & (SU_PUNCH1<<i) )
656                 {
657                         if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE)
658                                 cl.mpunchangle[0][i] = MSG_ReadChar();
659                         else
660                                 cl.mpunchangle[0][i] = MSG_ReadAngle16i();
661                 }
662                 if (bits & (SU_PUNCHVEC1<<i))
663                 {
664                         if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
665                                 cl.mpunchvector[0][i] = MSG_ReadCoord16i();
666                         else
667                                 cl.mpunchvector[0][i] = MSG_ReadCoord32f();
668                 }
669                 if (bits & (SU_VELOCITY1<<i) )
670                 {
671                         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)
672                                 cl.mvelocity[0][i] = MSG_ReadChar()*16;
673                         else
674                                 cl.mvelocity[0][i] = MSG_ReadCoord32f();
675                 }
676         }
677
678         // LordHavoc: hipnotic demos don't have this bit set but should
679         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)
680                 cl.stats[STAT_ITEMS] = MSG_ReadLong ();
681
682         cl.onground = (bits & SU_ONGROUND) != 0;
683         cl.inwater = (bits & SU_INWATER) != 0;
684
685         if (cl.protocol == PROTOCOL_DARKPLACES5)
686         {
687                 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadShort() : 0;
688                 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadShort() : 0;
689                 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadShort() : 0;
690                 cl.stats[STAT_HEALTH] = MSG_ReadShort();
691                 cl.stats[STAT_AMMO] = MSG_ReadShort();
692                 cl.stats[STAT_SHELLS] = MSG_ReadShort();
693                 cl.stats[STAT_NAILS] = MSG_ReadShort();
694                 cl.stats[STAT_ROCKETS] = MSG_ReadShort();
695                 cl.stats[STAT_CELLS] = MSG_ReadShort();
696                 cl.stats[STAT_ACTIVEWEAPON] = (unsigned short) MSG_ReadShort ();
697         }
698         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)
699         {
700                 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
701                 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
702                 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
703                 cl.stats[STAT_HEALTH] = MSG_ReadShort();
704                 cl.stats[STAT_AMMO] = MSG_ReadByte();
705                 cl.stats[STAT_SHELLS] = MSG_ReadByte();
706                 cl.stats[STAT_NAILS] = MSG_ReadByte();
707                 cl.stats[STAT_ROCKETS] = MSG_ReadByte();
708                 cl.stats[STAT_CELLS] = MSG_ReadByte();
709                 if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_NEXUIZ)
710                         cl.stats[STAT_ACTIVEWEAPON] = (1<<MSG_ReadByte ());
711                 else
712                         cl.stats[STAT_ACTIVEWEAPON] = MSG_ReadByte ();
713         }
714
715         if (bits & SU_VIEWZOOM)
716         {
717                 if (cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
718                         cl.stats[STAT_VIEWZOOM] = MSG_ReadByte();
719                 else
720                         cl.stats[STAT_VIEWZOOM] = (unsigned short) MSG_ReadShort();
721         }
722
723         // check for important changes
724
725         // set flash times
726         if (cl.olditems != cl.stats[STAT_ITEMS])
727                 for (j = 0;j < 32;j++)
728                         if ((cl.stats[STAT_ITEMS] & (1<<j)) && !(cl.olditems & (1<<j)))
729                                 cl.item_gettime[j] = cl.time;
730         cl.olditems = cl.stats[STAT_ITEMS];
731
732         // GAME_NEXUIZ hud needs weapon change time
733         if (cl.activeweapon != cl.stats[STAT_ACTIVEWEAPON])
734                 cl.weapontime = cl.time;
735         cl.activeweapon = cl.stats[STAT_ACTIVEWEAPON];
736
737         // viewzoom interpolation
738         cl.mviewzoom[0] = (float) max(cl.stats[STAT_VIEWZOOM], 2) * (1.0f / 255.0f);
739 }
740
741 /*
742 =====================
743 CL_ParseStatic
744 =====================
745 */
746 void CL_ParseStatic (int large)
747 {
748         entity_t *ent;
749
750         if (cl_num_static_entities >= cl_max_static_entities)
751                 Host_Error ("Too many static entities");
752         ent = &cl_static_entities[cl_num_static_entities++];
753         CL_ParseBaseline (ent, large);
754
755 // copy it to the current state
756         ent->render.model = cl.model_precache[ent->state_baseline.modelindex];
757         ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_baseline.frame;
758         ent->render.framelerp = 0;
759         // make torchs play out of sync
760         ent->render.frame1time = ent->render.frame2time = lhrandom(-10, -1);
761         ent->render.colormap = -1; // no special coloring
762         ent->render.skinnum = ent->state_baseline.skin;
763         ent->render.effects = ent->state_baseline.effects;
764         ent->render.alpha = 1;
765         //ent->render.scale = 1;
766
767         //VectorCopy (ent->state_baseline.origin, ent->render.origin);
768         //VectorCopy (ent->state_baseline.angles, ent->render.angles);
769
770         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);
771         Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
772         CL_BoundingBoxForEntity(&ent->render);
773
774         // This is definitely cheating...
775         if (ent->render.model == NULL)
776                 cl_num_static_entities--;
777 }
778
779 /*
780 ===================
781 CL_ParseStaticSound
782 ===================
783 */
784 void CL_ParseStaticSound (int large)
785 {
786         vec3_t          org;
787         int                     sound_num, vol, atten;
788
789         MSG_ReadVector(org, cl.protocol);
790         if (large)
791                 sound_num = (unsigned short) MSG_ReadShort ();
792         else
793                 sound_num = MSG_ReadByte ();
794         vol = MSG_ReadByte ();
795         atten = MSG_ReadByte ();
796
797         S_StaticSound (cl.sound_precache[sound_num], org, vol/255.0f, atten);
798 }
799
800 void CL_ParseEffect (void)
801 {
802         vec3_t          org;
803         int                     modelindex, startframe, framecount, framerate;
804
805         MSG_ReadVector(org, cl.protocol);
806         modelindex = MSG_ReadByte ();
807         startframe = MSG_ReadByte ();
808         framecount = MSG_ReadByte ();
809         framerate = MSG_ReadByte ();
810
811         CL_Effect(org, modelindex, startframe, framecount, framerate);
812 }
813
814 void CL_ParseEffect2 (void)
815 {
816         vec3_t          org;
817         int                     modelindex, startframe, framecount, framerate;
818
819         MSG_ReadVector(org, cl.protocol);
820         modelindex = (unsigned short) MSG_ReadShort ();
821         startframe = (unsigned short) MSG_ReadShort ();
822         framecount = MSG_ReadByte ();
823         framerate = MSG_ReadByte ();
824
825         CL_Effect(org, modelindex, startframe, framecount, framerate);
826 }
827
828 model_t *cl_model_bolt = NULL;
829 model_t *cl_model_bolt2 = NULL;
830 model_t *cl_model_bolt3 = NULL;
831 model_t *cl_model_beam = NULL;
832
833 sfx_t *cl_sfx_wizhit;
834 sfx_t *cl_sfx_knighthit;
835 sfx_t *cl_sfx_tink1;
836 sfx_t *cl_sfx_ric1;
837 sfx_t *cl_sfx_ric2;
838 sfx_t *cl_sfx_ric3;
839 sfx_t *cl_sfx_r_exp3;
840
841 /*
842 =================
843 CL_ParseTEnt
844 =================
845 */
846 void CL_InitTEnts (void)
847 {
848         cl_sfx_wizhit = S_PrecacheSound ("sound/wizard/hit.wav", false, true);
849         cl_sfx_knighthit = S_PrecacheSound ("sound/hknight/hit.wav", false, true);
850         cl_sfx_tink1 = S_PrecacheSound ("sound/weapons/tink1.wav", false, true);
851         cl_sfx_ric1 = S_PrecacheSound ("sound/weapons/ric1.wav", false, true);
852         cl_sfx_ric2 = S_PrecacheSound ("sound/weapons/ric2.wav", false, true);
853         cl_sfx_ric3 = S_PrecacheSound ("sound/weapons/ric3.wav", false, true);
854         cl_sfx_r_exp3 = S_PrecacheSound ("sound/weapons/r_exp3.wav", false, true);
855 }
856
857 void CL_ParseBeam (model_t *m, int lightning)
858 {
859         int i, ent;
860         vec3_t start, end;
861         beam_t *b;
862
863         ent = (unsigned short) MSG_ReadShort ();
864         MSG_ReadVector(start, cl.protocol);
865         MSG_ReadVector(end, cl.protocol);
866
867         if (ent >= MAX_EDICTS)
868         {
869                 Con_Printf("CL_ParseBeam: invalid entity number %i\n", ent);
870                 ent = 0;
871         }
872
873         if (ent >= cl_max_entities)
874                 CL_ExpandEntities(ent);
875
876         // override any beam with the same entity
877         for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
878         {
879                 if (b->entity == ent)
880                 {
881                         //b->entity = ent;
882                         b->lightning = lightning;
883                         b->relativestartvalid = (ent && cl_entities[ent].state_current.active) ? 2 : 0;
884                         b->model = m;
885                         b->endtime = cl.time + 0.2;
886                         VectorCopy (start, b->start);
887                         VectorCopy (end, b->end);
888                         return;
889                 }
890         }
891
892         // find a free beam
893         for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
894         {
895                 if (!b->model || b->endtime < cl.time)
896                 {
897                         b->entity = ent;
898                         b->lightning = lightning;
899                         b->relativestartvalid = (ent && cl_entities[ent].state_current.active) ? 2 : 0;
900                         b->model = m;
901                         b->endtime = cl.time + 0.2;
902                         VectorCopy (start, b->start);
903                         VectorCopy (end, b->end);
904                         return;
905                 }
906         }
907         Con_Print("beam list overflow!\n");
908 }
909
910 void CL_ParseTempEntity(void)
911 {
912         int type;
913         vec3_t pos;
914         vec3_t dir;
915         vec3_t pos2;
916         vec3_t color;
917         int rnd;
918         int colorStart, colorLength, count;
919         float velspeed, radius;
920         qbyte *tempcolor;
921         matrix4x4_t tempmatrix;
922
923         type = MSG_ReadByte();
924         switch (type)
925         {
926         case TE_WIZSPIKE:
927                 // spike hitting wall
928                 MSG_ReadVector(pos, cl.protocol);
929                 CL_FindNonSolidLocation(pos, pos, 4);
930                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
931                 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);
932                 CL_RunParticleEffect(pos, vec3_origin, 20, 30);
933                 S_StartSound(-1, 0, cl_sfx_wizhit, pos, 1, 1);
934                 break;
935
936         case TE_KNIGHTSPIKE:
937                 // spike hitting wall
938                 MSG_ReadVector(pos, cl.protocol);
939                 CL_FindNonSolidLocation(pos, pos, 4);
940                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
941                 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);
942                 CL_RunParticleEffect(pos, vec3_origin, 226, 20);
943                 S_StartSound(-1, 0, cl_sfx_knighthit, pos, 1, 1);
944                 break;
945
946         case TE_SPIKE:
947                 // spike hitting wall
948                 MSG_ReadVector(pos, cl.protocol);
949                 CL_FindNonSolidLocation(pos, pos, 4);
950                 if (cl_particles_bulletimpacts.integer)
951                 {
952                         CL_SparkShower(pos, vec3_origin, 15, 1);
953                         CL_Smoke(pos, vec3_origin, 15);
954                         CL_BulletMark(pos);
955                 }
956                 if (rand() % 5)
957                         S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
958                 else
959                 {
960                         rnd = rand() & 3;
961                         if (rnd == 1)
962                                 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
963                         else if (rnd == 2)
964                                 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
965                         else
966                                 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
967                 }
968                 break;
969         case TE_SPIKEQUAD:
970                 // quad spike hitting wall
971                 MSG_ReadVector(pos, cl.protocol);
972                 CL_FindNonSolidLocation(pos, pos, 4);
973                 // LordHavoc: changed to spark shower
974                 if (cl_particles_bulletimpacts.integer)
975                 {
976                         CL_SparkShower(pos, vec3_origin, 15, 1);
977                         CL_Smoke(pos, vec3_origin, 15);
978                         CL_BulletMark(pos);
979                 }
980                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
981                 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);
982                 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
983                 if (rand() % 5)
984                         S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
985                 else
986                 {
987                         rnd = rand() & 3;
988                         if (rnd == 1)
989                                 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
990                         else if (rnd == 2)
991                                 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
992                         else
993                                 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
994                 }
995                 break;
996         case TE_SUPERSPIKE:
997                 // super spike hitting wall
998                 MSG_ReadVector(pos, cl.protocol);
999                 CL_FindNonSolidLocation(pos, pos, 4);
1000                 // LordHavoc: changed to dust shower
1001                 if (cl_particles_bulletimpacts.integer)
1002                 {
1003                         CL_SparkShower(pos, vec3_origin, 30, 1);
1004                         CL_Smoke(pos, vec3_origin, 30);
1005                         CL_BulletMark(pos);
1006                 }
1007                 if (rand() % 5)
1008                         S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
1009                 else
1010                 {
1011                         rnd = rand() & 3;
1012                         if (rnd == 1)
1013                                 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
1014                         else if (rnd == 2)
1015                                 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
1016                         else
1017                                 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
1018                 }
1019                 break;
1020         case TE_SUPERSPIKEQUAD:
1021                 // quad super spike hitting wall
1022                 MSG_ReadVector(pos, cl.protocol);
1023                 CL_FindNonSolidLocation(pos, pos, 4);
1024                 // LordHavoc: changed to dust shower
1025                 if (cl_particles_bulletimpacts.integer)
1026                 {
1027                         CL_SparkShower(pos, vec3_origin, 30, 1);
1028                         CL_Smoke(pos, vec3_origin, 30);
1029                         CL_BulletMark(pos);
1030                 }
1031                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1032                 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);
1033                 if (rand() % 5)
1034                         S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
1035                 else
1036                 {
1037                         rnd = rand() & 3;
1038                         if (rnd == 1)
1039                                 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
1040                         else if (rnd == 2)
1041                                 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
1042                         else
1043                                 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
1044                 }
1045                 break;
1046                 // LordHavoc: added for improved blood splatters
1047         case TE_BLOOD:
1048                 // blood puff
1049                 MSG_ReadVector(pos, cl.protocol);
1050                 CL_FindNonSolidLocation(pos, pos, 4);
1051                 dir[0] = MSG_ReadChar();
1052                 dir[1] = MSG_ReadChar();
1053                 dir[2] = MSG_ReadChar();
1054                 count = MSG_ReadByte();
1055                 CL_BloodPuff(pos, dir, count);
1056                 break;
1057         case TE_SPARK:
1058                 // spark shower
1059                 MSG_ReadVector(pos, cl.protocol);
1060                 CL_FindNonSolidLocation(pos, pos, 4);
1061                 dir[0] = MSG_ReadChar();
1062                 dir[1] = MSG_ReadChar();
1063                 dir[2] = MSG_ReadChar();
1064                 count = MSG_ReadByte();
1065                 CL_SparkShower(pos, dir, count, 1);
1066                 break;
1067         case TE_PLASMABURN:
1068                 MSG_ReadVector(pos, cl.protocol);
1069                 CL_FindNonSolidLocation(pos, pos, 4);
1070                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1071                 CL_AllocDlight(NULL, &tempmatrix, 200, 1, 1, 1, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1072                 CL_PlasmaBurn(pos);
1073                 break;
1074                 // LordHavoc: added for improved gore
1075         case TE_BLOODSHOWER:
1076                 // vaporized body
1077                 MSG_ReadVector(pos, cl.protocol); // mins
1078                 MSG_ReadVector(pos2, cl.protocol); // maxs
1079                 velspeed = MSG_ReadCoord(cl.protocol); // speed
1080                 count = (unsigned short) MSG_ReadShort(); // number of particles
1081                 CL_BloodShower(pos, pos2, velspeed, count);
1082                 break;
1083         case TE_PARTICLECUBE:
1084                 // general purpose particle effect
1085                 MSG_ReadVector(pos, cl.protocol); // mins
1086                 MSG_ReadVector(pos2, cl.protocol); // maxs
1087                 MSG_ReadVector(dir, cl.protocol); // dir
1088                 count = (unsigned short) MSG_ReadShort(); // number of particles
1089                 colorStart = MSG_ReadByte(); // color
1090                 colorLength = MSG_ReadByte(); // gravity (1 or 0)
1091                 velspeed = MSG_ReadCoord(cl.protocol); // randomvel
1092                 CL_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
1093                 break;
1094
1095         case TE_PARTICLERAIN:
1096                 // general purpose particle effect
1097                 MSG_ReadVector(pos, cl.protocol); // mins
1098                 MSG_ReadVector(pos2, cl.protocol); // maxs
1099                 MSG_ReadVector(dir, cl.protocol); // dir
1100                 count = (unsigned short) MSG_ReadShort(); // number of particles
1101                 colorStart = MSG_ReadByte(); // color
1102                 CL_ParticleRain(pos, pos2, dir, count, colorStart, 0);
1103                 break;
1104
1105         case TE_PARTICLESNOW:
1106                 // general purpose particle effect
1107                 MSG_ReadVector(pos, cl.protocol); // mins
1108                 MSG_ReadVector(pos2, cl.protocol); // maxs
1109                 MSG_ReadVector(dir, cl.protocol); // dir
1110                 count = (unsigned short) MSG_ReadShort(); // number of particles
1111                 colorStart = MSG_ReadByte(); // color
1112                 CL_ParticleRain(pos, pos2, dir, count, colorStart, 1);
1113                 break;
1114
1115         case TE_GUNSHOT:
1116                 // bullet hitting wall
1117                 MSG_ReadVector(pos, cl.protocol);
1118                 CL_FindNonSolidLocation(pos, pos, 4);
1119                 CL_SparkShower(pos, vec3_origin, 15, 1);
1120                 CL_Smoke(pos, vec3_origin, 15);
1121                 CL_BulletMark(pos);
1122                 break;
1123
1124         case TE_GUNSHOTQUAD:
1125                 // quad bullet hitting wall
1126                 MSG_ReadVector(pos, cl.protocol);
1127                 CL_FindNonSolidLocation(pos, pos, 4);
1128                 CL_SparkShower(pos, vec3_origin, 15, 1);
1129                 CL_Smoke(pos, vec3_origin, 15);
1130                 CL_BulletMark(pos);
1131                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1132                 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);
1133                 break;
1134
1135         case TE_EXPLOSION:
1136                 // rocket explosion
1137                 MSG_ReadVector(pos, cl.protocol);
1138                 CL_FindNonSolidLocation(pos, pos, 10);
1139                 CL_ParticleExplosion(pos);
1140                 // LordHavoc: boosted color from 1.0, 0.8, 0.4 to 1.25, 1.0, 0.5
1141                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1142                 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);
1143                 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1144                 break;
1145
1146         case TE_EXPLOSIONQUAD:
1147                 // quad rocket explosion
1148                 MSG_ReadVector(pos, cl.protocol);
1149                 CL_FindNonSolidLocation(pos, pos, 10);
1150                 CL_ParticleExplosion(pos);
1151                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1152                 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);
1153                 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1154                 break;
1155
1156         case TE_EXPLOSION3:
1157                 // Nehahra movie colored lighting explosion
1158                 MSG_ReadVector(pos, cl.protocol);
1159                 CL_FindNonSolidLocation(pos, pos, 10);
1160                 CL_ParticleExplosion(pos);
1161                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1162                 color[0] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1163                 color[1] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1164                 color[2] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1165                 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);
1166                 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1167                 break;
1168
1169         case TE_EXPLOSIONRGB:
1170                 // colored lighting explosion
1171                 MSG_ReadVector(pos, cl.protocol);
1172                 CL_FindNonSolidLocation(pos, pos, 10);
1173                 CL_ParticleExplosion(pos);
1174                 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1175                 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1176                 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1177                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1178                 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);
1179                 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1180                 break;
1181
1182         case TE_TAREXPLOSION:
1183                 // tarbaby explosion
1184                 MSG_ReadVector(pos, cl.protocol);
1185                 CL_FindNonSolidLocation(pos, pos, 10);
1186                 CL_BlobExplosion(pos);
1187
1188                 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1189                 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1190                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1191                 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);
1192                 break;
1193
1194         case TE_SMALLFLASH:
1195                 MSG_ReadVector(pos, cl.protocol);
1196                 CL_FindNonSolidLocation(pos, pos, 10);
1197                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1198                 CL_AllocDlight(NULL, &tempmatrix, 200, 2, 2, 2, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1199                 break;
1200
1201         case TE_CUSTOMFLASH:
1202                 MSG_ReadVector(pos, cl.protocol);
1203                 CL_FindNonSolidLocation(pos, pos, 4);
1204                 radius = (MSG_ReadByte() + 1) * 8;
1205                 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
1206                 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1207                 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1208                 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1209                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1210                 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);
1211                 break;
1212
1213         case TE_FLAMEJET:
1214                 MSG_ReadVector(pos, cl.protocol);
1215                 MSG_ReadVector(dir, cl.protocol);
1216                 count = MSG_ReadByte();
1217                 CL_Flames(pos, dir, count);
1218                 break;
1219
1220         case TE_LIGHTNING1:
1221                 // lightning bolts
1222                 if (!cl_model_bolt)
1223                         cl_model_bolt = Mod_ForName("progs/bolt.mdl", false, false, false);
1224                 CL_ParseBeam(cl_model_bolt, true);
1225                 break;
1226
1227         case TE_LIGHTNING2:
1228                 // lightning bolts
1229                 if (!cl_model_bolt2)
1230                         cl_model_bolt2 = Mod_ForName("progs/bolt2.mdl", false, false, false);
1231                 CL_ParseBeam(cl_model_bolt2, true);
1232                 break;
1233
1234         case TE_LIGHTNING3:
1235                 // lightning bolts
1236                 if (!cl_model_bolt3)
1237                         cl_model_bolt3 = Mod_ForName("progs/bolt3.mdl", true, false, false);
1238                 CL_ParseBeam(cl_model_bolt3, false);
1239                 break;
1240
1241 // PGM 01/21/97
1242         case TE_BEAM:
1243                 // grappling hook beam
1244                 if (!cl_model_beam)
1245                         cl_model_beam = Mod_ForName("progs/beam.mdl", true, false, false);
1246                 CL_ParseBeam(cl_model_beam, false);
1247                 break;
1248 // PGM 01/21/97
1249
1250 // LordHavoc: for compatibility with the Nehahra movie...
1251         case TE_LIGHTNING4NEH:
1252                 CL_ParseBeam(Mod_ForName(MSG_ReadString(), true, false, false), false);
1253                 break;
1254
1255         case TE_LAVASPLASH:
1256                 MSG_ReadVector(pos, cl.protocol);
1257                 CL_LavaSplash(pos);
1258                 break;
1259
1260         case TE_TELEPORT:
1261                 MSG_ReadVector(pos, cl.protocol);
1262                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1263                 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);
1264                 CL_TeleportSplash(pos);
1265                 break;
1266
1267         case TE_EXPLOSION2:
1268                 // color mapped explosion
1269                 MSG_ReadVector(pos, cl.protocol);
1270                 CL_FindNonSolidLocation(pos, pos, 10);
1271                 colorStart = MSG_ReadByte();
1272                 colorLength = MSG_ReadByte();
1273                 CL_ParticleExplosion2(pos, colorStart, colorLength);
1274                 tempcolor = (qbyte *)&palette_complete[(rand()%colorLength) + colorStart];
1275                 color[0] = tempcolor[0] * (2.0f / 255.0f);
1276                 color[1] = tempcolor[1] * (2.0f / 255.0f);
1277                 color[2] = tempcolor[2] * (2.0f / 255.0f);
1278                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1279                 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);
1280                 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1281                 break;
1282
1283         case TE_TEI_G3:
1284                 MSG_ReadVector(pos, cl.protocol);
1285                 MSG_ReadVector(pos2, cl.protocol);
1286                 MSG_ReadVector(dir, cl.protocol);
1287                 CL_BeamParticle(pos, pos2, 8, 1, 1, 1, 1, 1);
1288                 break;
1289
1290         case TE_TEI_SMOKE:
1291                 MSG_ReadVector(pos, cl.protocol);
1292                 MSG_ReadVector(dir, cl.protocol);
1293                 count = MSG_ReadByte();
1294                 CL_FindNonSolidLocation(pos, pos, 4);
1295                 CL_Tei_Smoke(pos, dir, count);
1296                 break;
1297
1298         case TE_TEI_BIGEXPLOSION:
1299                 MSG_ReadVector(pos, cl.protocol);
1300                 CL_FindNonSolidLocation(pos, pos, 10);
1301                 CL_ParticleExplosion(pos);
1302                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1303                 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);
1304                 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1305                 break;
1306
1307         case TE_TEI_PLASMAHIT:
1308                 MSG_ReadVector(pos, cl.protocol);
1309                 MSG_ReadVector(dir, cl.protocol);
1310                 count = MSG_ReadByte();
1311                 CL_FindNonSolidLocation(pos, pos, 5);
1312                 CL_Tei_PlasmaHit(pos, dir, count);
1313                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1314                 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);
1315                 break;
1316
1317         default:
1318                 Host_Error("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
1319         }
1320 }
1321
1322 #define SHOWNET(x) if(cl_shownet.integer==2)Con_Printf("%3i:%s\n", msg_readcount-1, x);
1323
1324 static qbyte cgamenetbuffer[65536];
1325
1326 /*
1327 =====================
1328 CL_ParseServerMessage
1329 =====================
1330 */
1331 int parsingerror = false;
1332 void CL_ParseServerMessage(void)
1333 {
1334         int                     cmd;
1335         int                     i;
1336         protocolversion_t protocol;
1337         qbyte           cmdlog[32];
1338         char            *cmdlogname[32], *temp;
1339         int                     cmdindex, cmdcount = 0;
1340         qboolean        sendmove = false;
1341
1342         if (cls.demorecording)
1343                 CL_WriteDemoMessage ();
1344
1345         cl.last_received_message = realtime;
1346
1347 //
1348 // if recording demos, copy the message out
1349 //
1350         if (cl_shownet.integer == 1)
1351                 Con_Printf("%f %i\n", realtime, net_message.cursize);
1352         else if (cl_shownet.integer == 2)
1353                 Con_Print("------------------\n");
1354
1355         cl.onground = false;    // unless the server says otherwise
1356 //
1357 // parse the message
1358 //
1359         //MSG_BeginReading ();
1360
1361         parsingerror = true;
1362
1363         while (1)
1364         {
1365                 if (msg_badread)
1366                         Host_Error ("CL_ParseServerMessage: Bad server message");
1367
1368                 cmd = MSG_ReadByte ();
1369
1370                 if (cmd == -1)
1371                 {
1372                         SHOWNET("END OF MESSAGE");
1373                         break;          // end of message
1374                 }
1375
1376                 cmdindex = cmdcount & 31;
1377                 cmdcount++;
1378                 cmdlog[cmdindex] = cmd;
1379
1380                 // if the high bit of the command byte is set, it is a fast update
1381                 if (cmd & 128)
1382                 {
1383                         // 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)
1384                         temp = "entity";
1385                         cmdlogname[cmdindex] = temp;
1386                         SHOWNET("fast update");
1387                         if (cls.signon == SIGNONS - 1)
1388                         {
1389                                 // first update is the final signon stage
1390                                 cls.signon = SIGNONS;
1391                                 CL_SignonReply ();
1392                         }
1393                         EntityFrameQuake_ReadEntity (cmd&127);
1394                         continue;
1395                 }
1396
1397                 SHOWNET(svc_strings[cmd]);
1398                 cmdlogname[cmdindex] = svc_strings[cmd];
1399                 if (!cmdlogname[cmdindex])
1400                 {
1401                         // 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)
1402                         temp = "<unknown>";
1403                         cmdlogname[cmdindex] = temp;
1404                 }
1405
1406                 // other commands
1407                 switch (cmd)
1408                 {
1409                 default:
1410                         {
1411                                 char description[32*64], temp[64];
1412                                 int count;
1413                                 strcpy (description, "packet dump: ");
1414                                 i = cmdcount - 32;
1415                                 if (i < 0)
1416                                         i = 0;
1417                                 count = cmdcount - i;
1418                                 i &= 31;
1419                                 while(count > 0)
1420                                 {
1421                                         dpsnprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
1422                                         strlcat (description, temp, sizeof (description));
1423                                         count--;
1424                                         i++;
1425                                         i &= 31;
1426                                 }
1427                                 description[strlen(description)-1] = '\n'; // replace the last space with a newline
1428                                 Con_Print(description);
1429                                 Host_Error ("CL_ParseServerMessage: Illegible server message\n");
1430                         }
1431                         break;
1432
1433                 case svc_nop:
1434                         if (cls.signon < SIGNONS)
1435                                 Con_Print("<-- server to client keepalive\n");
1436                         break;
1437
1438                 case svc_time:
1439                         cl.mtime[1] = cl.mtime[0];
1440                         cl.mtime[0] = MSG_ReadFloat ();
1441                         sendmove = true;
1442                         break;
1443
1444                 case svc_clientdata:
1445                         CL_ParseClientdata();
1446                         break;
1447
1448                 case svc_version:
1449                         i = MSG_ReadLong ();
1450                         protocol = Protocol_EnumForNumber(i);
1451                         if (protocol == PROTOCOL_UNKNOWN)
1452                                 Host_Error("CL_ParseServerMessage: Server is unrecognized protocol number (%i)\n", i);
1453                         // hack for unmarked Nehahra movie demos which had a custom protocol
1454                         if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
1455                                 protocol = PROTOCOL_NEHAHRAMOVIE;
1456                         cl.protocol = protocol;
1457                         break;
1458
1459                 case svc_disconnect:
1460                         Con_Printf ("Server disconnected\n");
1461                         if (cls.demonum != -1)
1462                                 CL_NextDemo ();
1463                         else
1464                                 CL_Disconnect ();
1465                         break;
1466
1467                 case svc_print:
1468                         Con_Print(MSG_ReadString());
1469                         break;
1470
1471                 case svc_centerprint:
1472                         SCR_CenterPrint(MSG_ReadString ());
1473                         break;
1474
1475                 case svc_stufftext:
1476                         Cbuf_AddText (MSG_ReadString ());
1477                         break;
1478
1479                 case svc_damage:
1480                         V_ParseDamage ();
1481                         break;
1482
1483                 case svc_serverinfo:
1484                         CL_ParseServerInfo ();
1485                         break;
1486
1487                 case svc_setangle:
1488                         for (i=0 ; i<3 ; i++)
1489                                 cl.viewangles[i] = MSG_ReadAngle (cl.protocol);
1490                         break;
1491
1492                 case svc_setview:
1493                         cl.viewentity = (unsigned short)MSG_ReadShort ();
1494                         if (cl.viewentity >= MAX_EDICTS)
1495                                 Host_Error("svc_setview >= MAX_EDICTS\n");
1496                         if (cl.viewentity >= cl_max_entities)
1497                                 CL_ExpandEntities(cl.viewentity);
1498                         // LordHavoc: assume first setview recieved is the real player entity
1499                         if (!cl.playerentity)
1500                                 cl.playerentity = cl.viewentity;
1501                         break;
1502
1503                 case svc_lightstyle:
1504                         i = MSG_ReadByte ();
1505                         if (i >= MAX_LIGHTSTYLES)
1506                                 Host_Error ("svc_lightstyle >= MAX_LIGHTSTYLES");
1507                         strlcpy (cl_lightstyle[i].map,  MSG_ReadString(), sizeof (cl_lightstyle[i].map));
1508                         cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
1509                         cl_lightstyle[i].length = strlen(cl_lightstyle[i].map);
1510                         break;
1511
1512                 case svc_sound:
1513                         CL_ParseStartSoundPacket(false);
1514                         break;
1515
1516                 case svc_precache:
1517                         if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1518                         {
1519                                 // was svc_sound2 in protocols 1, 2, 3, removed in 4, 5, changed to svc_precache in 6
1520                                 CL_ParseStartSoundPacket(true);
1521                         }
1522                         else
1523                         {
1524                                 int i = (unsigned short)MSG_ReadShort();
1525                                 char *s = MSG_ReadString();
1526                                 if (i < 32768)
1527                                 {
1528                                         if (i >= 1 && i < MAX_MODELS)
1529                                         {
1530                                                 model_t *model = Mod_ForName(s, false, false, i == 1);
1531                                                 if (!model)
1532                                                         Con_Printf("svc_precache: Mod_ForName(\"%s\") failed\n", s);
1533                                                 cl.model_precache[i] = model;
1534                                         }
1535                                         else
1536                                                 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_MODELS);
1537                                 }
1538                                 else
1539                                 {
1540                                         i -= 32768;
1541                                         if (i >= 1 && i < MAX_SOUNDS)
1542                                         {
1543                                                 sfx_t *sfx = S_PrecacheSound (s, true, false);
1544                                                 if (!sfx && snd_initialized.integer)
1545                                                         Con_Printf("svc_precache: S_PrecacheSound(\"%s\") failed\n", s);
1546                                                 cl.sound_precache[i] = sfx;
1547                                         }
1548                                         else
1549                                                 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_SOUNDS);
1550                                 }
1551                         }
1552                         break;
1553
1554                 case svc_stopsound:
1555                         i = (unsigned short) MSG_ReadShort();
1556                         S_StopSound(i>>3, i&7);
1557                         break;
1558
1559                 case svc_updatename:
1560                         i = MSG_ReadByte ();
1561                         if (i >= cl.maxclients)
1562                                 Host_Error ("CL_ParseServerMessage: svc_updatename >= cl.maxclients");
1563                         strlcpy (cl.scores[i].name, MSG_ReadString (), sizeof (cl.scores[i].name));
1564                         break;
1565
1566                 case svc_updatefrags:
1567                         i = MSG_ReadByte ();
1568                         if (i >= cl.maxclients)
1569                                 Host_Error ("CL_ParseServerMessage: svc_updatefrags >= cl.maxclients");
1570                         cl.scores[i].frags = (signed short) MSG_ReadShort ();
1571                         break;
1572
1573                 case svc_updatecolors:
1574                         i = MSG_ReadByte ();
1575                         if (i >= cl.maxclients)
1576                                 Host_Error ("CL_ParseServerMessage: svc_updatecolors >= cl.maxclients");
1577                         cl.scores[i].colors = MSG_ReadByte ();
1578                         break;
1579
1580                 case svc_particle:
1581                         CL_ParseParticleEffect ();
1582                         break;
1583
1584                 case svc_effect:
1585                         CL_ParseEffect ();
1586                         break;
1587
1588                 case svc_effect2:
1589                         CL_ParseEffect2 ();
1590                         break;
1591
1592                 case svc_spawnbaseline:
1593                         i = (unsigned short) MSG_ReadShort ();
1594                         if (i < 0 || i >= MAX_EDICTS)
1595                                 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
1596                         if (i >= cl_max_entities)
1597                                 CL_ExpandEntities(i);
1598                         CL_ParseBaseline (cl_entities + i, false);
1599                         break;
1600                 case svc_spawnbaseline2:
1601                         i = (unsigned short) MSG_ReadShort ();
1602                         if (i < 0 || i >= MAX_EDICTS)
1603                                 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline2: invalid entity number %i", i);
1604                         if (i >= cl_max_entities)
1605                                 CL_ExpandEntities(i);
1606                         CL_ParseBaseline (cl_entities + i, true);
1607                         break;
1608                 case svc_spawnstatic:
1609                         CL_ParseStatic (false);
1610                         break;
1611                 case svc_spawnstatic2:
1612                         CL_ParseStatic (true);
1613                         break;
1614                 case svc_temp_entity:
1615                         CL_ParseTempEntity ();
1616                         break;
1617
1618                 case svc_setpause:
1619                         cl.paused = MSG_ReadByte ();
1620                         if (cl.paused)
1621                                 CDAudio_Pause ();
1622                         else
1623                                 CDAudio_Resume ();
1624                         S_PauseGameSounds (cl.paused);
1625                         break;
1626
1627                 case svc_signonnum:
1628                         i = MSG_ReadByte ();
1629                         // LordHavoc: it's rude to kick off the client if they missed the
1630                         // reconnect somehow, so allow signon 1 even if at signon 1
1631                         if (i <= cls.signon && i != 1)
1632                                 Host_Error ("Received signon %i when at %i", i, cls.signon);
1633                         cls.signon = i;
1634                         CL_SignonReply ();
1635                         break;
1636
1637                 case svc_killedmonster:
1638                         cl.stats[STAT_MONSTERS]++;
1639                         break;
1640
1641                 case svc_foundsecret:
1642                         cl.stats[STAT_SECRETS]++;
1643                         break;
1644
1645                 case svc_updatestat:
1646                         i = MSG_ReadByte ();
1647                         if (i < 0 || i >= MAX_CL_STATS)
1648                                 Host_Error ("svc_updatestat: %i is invalid", i);
1649                         cl.stats[i] = MSG_ReadLong ();
1650                         break;
1651
1652                 case svc_updatestatubyte:
1653                         i = MSG_ReadByte ();
1654                         if (i < 0 || i >= MAX_CL_STATS)
1655                                 Host_Error ("svc_updatestat: %i is invalid", i);
1656                         cl.stats[i] = MSG_ReadByte ();
1657                         break;
1658
1659                 case svc_spawnstaticsound:
1660                         CL_ParseStaticSound (false);
1661                         break;
1662
1663                 case svc_spawnstaticsound2:
1664                         CL_ParseStaticSound (true);
1665                         break;
1666
1667                 case svc_cdtrack:
1668                         cl.cdtrack = MSG_ReadByte ();
1669                         cl.looptrack = MSG_ReadByte ();
1670                         if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
1671                                 CDAudio_Play ((qbyte)cls.forcetrack, true);
1672                         else
1673                                 CDAudio_Play ((qbyte)cl.cdtrack, true);
1674                         break;
1675
1676                 case svc_intermission:
1677                         cl.intermission = 1;
1678                         cl.completed_time = cl.time;
1679                         break;
1680
1681                 case svc_finale:
1682                         cl.intermission = 2;
1683                         cl.completed_time = cl.time;
1684                         SCR_CenterPrint(MSG_ReadString ());
1685                         break;
1686
1687                 case svc_cutscene:
1688                         cl.intermission = 3;
1689                         cl.completed_time = cl.time;
1690                         SCR_CenterPrint(MSG_ReadString ());
1691                         break;
1692
1693                 case svc_sellscreen:
1694                         Cmd_ExecuteString ("help", src_command);
1695                         break;
1696                 case svc_hidelmp:
1697                         if (gamemode == GAME_TENEBRAE)
1698                         {
1699                                 // repeating particle effect
1700                                 MSG_ReadCoord(cl.protocol);
1701                                 MSG_ReadCoord(cl.protocol);
1702                                 MSG_ReadCoord(cl.protocol);
1703                                 MSG_ReadCoord(cl.protocol);
1704                                 MSG_ReadCoord(cl.protocol);
1705                                 MSG_ReadCoord(cl.protocol);
1706                                 MSG_ReadByte();
1707                                 MSG_ReadLong();
1708                                 MSG_ReadLong();
1709                                 MSG_ReadString();
1710                         }
1711                         else
1712                                 SHOWLMP_decodehide();
1713                         break;
1714                 case svc_showlmp:
1715                         if (gamemode == GAME_TENEBRAE)
1716                         {
1717                                 // particle effect
1718                                 MSG_ReadCoord(cl.protocol);
1719                                 MSG_ReadCoord(cl.protocol);
1720                                 MSG_ReadCoord(cl.protocol);
1721                                 MSG_ReadByte();
1722                                 MSG_ReadString();
1723                         }
1724                         else
1725                                 SHOWLMP_decodeshow();
1726                         break;
1727                 case svc_skybox:
1728                         R_SetSkyBox(MSG_ReadString());
1729                         break;
1730                 case svc_cgame:
1731                         {
1732                                 int length;
1733                                 length = (int) ((unsigned short) MSG_ReadShort());
1734                                 for (i = 0;i < length;i++)
1735                                         cgamenetbuffer[i] = MSG_ReadByte();
1736                                 if (!msg_badread)
1737                                         CL_CGVM_ParseNetwork(cgamenetbuffer, length);
1738                         }
1739                         break;
1740                 case svc_entities:
1741                         if (cls.signon == SIGNONS - 1)
1742                         {
1743                                 // first update is the final signon stage
1744                                 cls.signon = SIGNONS;
1745                                 CL_SignonReply ();
1746                         }
1747                         if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1748                                 EntityFrame_CL_ReadFrame();
1749                         else if (cl.protocol == PROTOCOL_DARKPLACES4)
1750                                 EntityFrame4_CL_ReadFrame();
1751                         else
1752                                 EntityFrame5_CL_ReadFrame();
1753                         break;
1754                 }
1755         }
1756
1757         EntityFrameQuake_ISeeDeadEntities();
1758
1759         if (sendmove)
1760         {
1761                 // send one move per server frame
1762                 CL_SendMove();
1763         }
1764
1765         parsingerror = false;
1766 }
1767
1768 void CL_Parse_DumpPacket(void)
1769 {
1770         if (!parsingerror)
1771                 return;
1772         Con_Print("Packet dump:\n");
1773         SZ_HexDumpToConsole(&net_message);
1774         parsingerror = false;
1775 }
1776
1777 void CL_Parse_Init(void)
1778 {
1779         // LordHavoc: added demo_nehahra cvar
1780         Cvar_RegisterVariable (&demo_nehahra);
1781         if (gamemode == GAME_NEHAHRA)
1782                 Cvar_SetValue("demo_nehahra", 1);
1783         Cvar_RegisterVariable(&developer_networkentities);
1784 }
1785
1786 void CL_Parse_Shutdown(void)
1787 {
1788 }