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