]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_parse.c
added newmap function to render modules (so explosions and other things are reset...
[xonotic/darkplaces.git] / cl_parse.c
index 028dda200500bbcde5659ca024179f697ebab831..d856ce119268b9fbeb21e7262595e7b80583aea6 100644 (file)
@@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "quakedef.h"
 
-char *svc_strings[] =
+char *svc_strings[128] =
 {
        "svc_bad",
        "svc_nop",
@@ -65,24 +65,25 @@ char *svc_strings[] =
        "svc_cdtrack",                  // [byte] track [byte] looptrack
        "svc_sellscreen",
        "svc_cutscene",
-       "svc_showlmp",  // [string] iconlabel [string] lmpfile [byte] x [byte] y
+       "svc_showlmp",  // [string] iconlabel [string] lmpfile [short] x [short] y
        "svc_hidelmp",  // [string] iconlabel
-       "svc_skybox", // [string] skyname
-       "?", // 38
-       "?", // 39
-       "?", // 40
-       "?", // 41
-       "?", // 42
-       "?", // 43
-       "?", // 44
-       "?", // 45
-       "?", // 46
-       "?", // 47
-       "?", // 48
-       "?", // 49
-       "svc_farclip", // [coord] size
-       "svc_fog", // [byte] enable <optional past this point, only included if enable is true> [short * 4096] density [byte] red [byte] green [byte] blue
-       "svc_playerposition" // [float] x [float] y [float] z
+       "", // 37
+       "", // 38
+       "", // 39
+       "", // 40
+       "", // 41
+       "", // 42
+       "", // 43
+       "", // 44
+       "", // 45
+       "", // 46
+       "", // 47
+       "", // 48
+       "", // 49
+       "", // 50
+       "svc_fog", // 51
+       "svc_effect", // [vector] org [byte] modelindex [byte] startframe [byte] framecount [byte] framerate
+       "svc_effect2", // [vector] org [short] modelindex [byte] startframe [byte] framecount [byte] framerate
 };
 
 //=============================================================================
@@ -119,14 +120,14 @@ entity_t  *CL_EntityNum (int num)
 CL_ParseStartSoundPacket
 ==================
 */
-void CL_ParseStartSoundPacket(void)
+void CL_ParseStartSoundPacket(int largesoundindex)
 {
     vec3_t  pos;
     int        channel, ent;
     int        sound_num;
     int        volume;
     int        field_mask;
-    float      attenuation;  
+    float      attenuation;
        int             i;
                   
     field_mask = MSG_ReadByte(); 
@@ -142,7 +143,13 @@ void CL_ParseStartSoundPacket(void)
                attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
        
        channel = MSG_ReadShort ();
-       sound_num = MSG_ReadByte ();
+       if (largesoundindex)
+               sound_num = (unsigned short) MSG_ReadShort ();
+       else
+               sound_num = MSG_ReadByte ();
+
+       if (sound_num >= MAX_SOUNDS)
+               Host_Error("CL_ParseStartSoundPacket: sound_num (%i) >= MAX_SOUNDS (%i)\n", sound_num, MAX_SOUNDS);
 
        ent = channel >> 3;
        channel &= 7;
@@ -219,10 +226,6 @@ void CL_KeepaliveMessage (void)
 
 extern qboolean isworldmodel;
 extern char skyname[];
-extern float fog_density;
-extern float fog_red;
-extern float fog_green;
-extern float fog_blue;
 extern void R_SetSkyBox (char *sky);
 extern void FOG_clear();
 extern cvar_t r_farclip;
@@ -230,7 +233,7 @@ extern cvar_t r_farclip;
 void CL_ParseEntityLump(char *entdata)
 {
        char *data;
-       char key[128], value[1024];
+       char key[128], value[4096];
        char wadname[128];
        int i, j, k;
        FOG_clear(); // LordHavoc: no fog until set
@@ -286,12 +289,12 @@ void CL_ParseEntityLump(char *entdata)
                else if (!strcmp("wad", key)) // for HalfLife maps
                {
                        j = 0;
-                       for (i = 0;i < 128;i++)
+                       for (i = 0;i < 4096;i++)
                                if (value[i] != ';' && value[i] != '\\' && value[i] != '/' && value[i] != ':')
                                        break;
                        if (value[i])
                        {
-                               for (;i < 128;i++)
+                               for (;i < 4096;i++)
                                {
                                        // ignore path - the \\ check is for HalfLife... stupid windoze 'programmers'...
                                        if (value[i] == '\\' || value[i] == '/' || value[i] == ':')
@@ -302,7 +305,7 @@ void CL_ParseEntityLump(char *entdata)
                                                value[i] = 0;
                                                strcpy(wadname, "textures/");
                                                strcat(wadname, &value[j]);
-                                               W_LoadTextureWadFile (wadname, FALSE);
+                                               W_LoadTextureWadFile (wadname, false);
                                                j = i+1;
                                                if (!k)
                                                        break;
@@ -335,9 +338,9 @@ void CL_ParseServerInfo (void)
 
 // parse protocol version number
        i = MSG_ReadLong ();
-       if (i != PROTOCOL_VERSION && i != 250)
+       if (i != PROTOCOL_VERSION && i != DPPROTOCOL_VERSION && i != 250)
        {
-               Con_Printf ("Server returned version %i, not %i", i, PROTOCOL_VERSION);
+               Con_Printf ("Server returned version %i, not %i or %i", i, DPPROTOCOL_VERSION, PROTOCOL_VERSION);
                return;
        }
        Nehahrademcompatibility = false;
@@ -388,6 +391,8 @@ void CL_ParseServerInfo (void)
                        Con_Printf ("Server sent too many model precaches\n");
                        return;
                }
+               if (strlen(str) >= MAX_QPATH)
+                       Host_Error ("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
                strcpy (model_precache[nummodels], str);
                Mod_TouchModel (str);
        }
@@ -404,6 +409,8 @@ void CL_ParseServerInfo (void)
                        Con_Printf ("Server sent too many sound precaches\n");
                        return;
                }
+               if (strlen(str) >= MAX_QPATH)
+                       Host_Error ("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
                strcpy (sound_precache[numsounds], str);
                S_TouchSound (str);
        }
@@ -453,11 +460,9 @@ If an entities model or origin changes from frame to frame, it must be
 relinked.  Other attributes can change without relinking.
 ==================
 */
-//int  bitcounts[16];
-
 void CL_ParseUpdate (int bits)
 {
-       int                     i, modnum, num, skin, alpha, scale, glowsize, glowcolor, colormod;
+       int                     i, modnum, num, alpha, scale, glowsize, glowcolor, colormod, frame;
        model_t         *model;
        qboolean        forcelink;
        entity_t        *ent;
@@ -470,10 +475,7 @@ void CL_ParseUpdate (int bits)
        }
 
        if (bits & U_MOREBITS)
-       {
-               i = MSG_ReadByte ();
-               bits |= (i<<8);
-       }
+               bits |= (MSG_ReadByte()<<8);
        if (bits & U_EXTEND1 && !Nehahrademcompatibility)
        {
                bits |= MSG_ReadByte() << 16;
@@ -488,10 +490,6 @@ void CL_ParseUpdate (int bits)
 
        ent = CL_EntityNum (num);
 
-//for (i=0 ; i<16 ; i++)
-//if (bits&(1<<i))
-//     bitcounts[i]++;
-
        forcelink = ent->msgtime != cl.mtime[1]; // no previous frame to lerp from
 
        ent->msgtime = cl.mtime[0];
@@ -501,24 +499,27 @@ void CL_ParseUpdate (int bits)
        if (bits & U_DELTA)
                baseline = &ent->deltabaseline;
 
+       if (forcelink)
+       {
+               ent->deltabaseline.origin[0] = ent->deltabaseline.origin[1] = ent->deltabaseline.origin[2] = 0;
+               ent->deltabaseline.angles[0] = ent->deltabaseline.angles[1] = ent->deltabaseline.angles[2] = 0;
+               ent->deltabaseline.effects = 0;
+               ent->deltabaseline.modelindex = 0;
+               ent->deltabaseline.frame = 0;
+               ent->deltabaseline.colormap = 0;
+               ent->deltabaseline.skin = 0;
+               ent->deltabaseline.alpha = 255;
+               ent->deltabaseline.scale = 16;
+               ent->deltabaseline.glowsize = 0;
+               ent->deltabaseline.glowcolor = 254;
+               ent->deltabaseline.colormod = 255;
+       }
+
        modnum = bits & U_MODEL ? MSG_ReadByte() : baseline->modelindex;
        if (modnum >= MAX_MODELS)
                Host_Error ("CL_ParseModel: bad modnum");
-       ent->deltabaseline.modelindex = modnum;
-               
-       model = cl.model_precache[modnum];
-       if (model != ent->model)
-       {
-               ent->model = model;
-       // automatic animation (torches, etc) can be either all together
-       // or randomized
-               if (model)
-                       ent->syncbase = model->synctype == ST_RAND ? (float)(rand()&0x7fff) / 0x7fff : 0.0;
-               else
-                       forcelink = true;       // hack to make null model players work
-       }
 
-       ent->frame = ((bits & U_FRAME) ? MSG_ReadByte() : (baseline->frame & 0xFF));
+       frame = ((bits & U_FRAME) ? MSG_ReadByte() : (baseline->frame & 0xFF));
 
        i = bits & U_COLORMAP ? MSG_ReadByte() : baseline->colormap;
        ent->deltabaseline.colormap = i;
@@ -531,12 +532,7 @@ void CL_ParseUpdate (int bits)
                ent->colormap = cl.scores[i-1].colors; // color it
        }
 
-       skin = bits & U_SKIN ? MSG_ReadByte() : baseline->skin;
-       if (skin != ent->skinnum)
-       {
-               ent->skinnum = skin;
-       }
-       ent->deltabaseline.skin = skin;
+       ent->deltabaseline.skin = ent->skinnum = bits & U_SKIN ? MSG_ReadByte() : baseline->skin;
 
        ent->effects = ((bits & U_EFFECTS) ? MSG_ReadByte() : (baseline->effects & 0xFF));
 
@@ -562,14 +558,36 @@ void CL_ParseUpdate (int bits)
        glowsize = bits & U_GLOWSIZE ? MSG_ReadByte() : baseline->glowsize;
        glowcolor = bits & U_GLOWCOLOR ? MSG_ReadByte() : baseline->glowcolor;
        colormod = bits & U_COLORMOD ? MSG_ReadByte() : baseline->colormod;
-       ent->frame |= ((bits & U_FRAME2) ? (MSG_ReadByte() << 8) : (baseline->frame & 0xFF00));
+       modnum |= ((bits & U_MODEL2) ? (MSG_ReadByte() << 8) : (baseline->modelindex & 0xFF00));
+       frame |= ((bits & U_FRAME2) ? (MSG_ReadByte() << 8) : (baseline->frame & 0xFF00));
+
+       if (modnum >= MAX_MODELS)
+               Host_Error("modnum (%i) >= MAX_MODELS (%i)\n", modnum, MAX_MODELS);
+
+       model = cl.model_precache[modnum];
+       if (model != ent->model)
+       {
+               ent->model = model;
+       // automatic animation (torches, etc) can be either all together
+       // or randomized
+               if (model)
+                       ent->syncbase = model->synctype == ST_RAND ? (float)(rand()&0x7fff) / 0x7fff : 0.0;
+               else
+                       forcelink = true;       // hack to make null model players work
+       }
+
+       ent->frame = frame;
+       if (model && (unsigned) frame >= model->numframes)
+               Con_DPrintf("CL_ParseUpdate: no such frame %i in \"%s\"\n", frame, model->name);
+
        ent->deltabaseline.alpha = alpha;
        ent->deltabaseline.scale = scale;
        ent->deltabaseline.effects = ent->effects;
        ent->deltabaseline.glowsize = glowsize;
        ent->deltabaseline.glowcolor = glowcolor;
        ent->deltabaseline.colormod = colormod;
-       ent->deltabaseline.frame = ent->frame;
+       ent->deltabaseline.modelindex = modnum;
+       ent->deltabaseline.frame = frame;
        ent->alpha = (float) alpha * (1.0 / 255.0);
        ent->scale = (float) scale * (1.0 / 16.0);
        ent->glowsize = glowsize * 4.0;
@@ -577,7 +595,7 @@ void CL_ParseUpdate (int bits)
        ent->colormod[0] = (float) ((colormod >> 5) & 7) * (1.0 / 7.0);
        ent->colormod[1] = (float) ((colormod >> 2) & 7) * (1.0 / 7.0);
        ent->colormod[2] = (float) (colormod & 3) * (1.0 / 3.0);
-       if (bits & U_EXTEND1 && Nehahrademcompatibility) // LordHavoc: to allow playback of the early Nehahra movie segments
+       if (bits & U_EXTEND1 && Nehahrademcompatibility) // LordHavoc: to allow playback of the Nehahra movie
        {
                i = MSG_ReadFloat();
                ent->alpha = MSG_ReadFloat();
@@ -606,11 +624,14 @@ void CL_ParseUpdate (int bits)
 CL_ParseBaseline
 ==================
 */
-void CL_ParseBaseline (entity_t *ent)
+void CL_ParseBaseline (entity_t *ent, int largemodelindex)
 {
        int                     i;
-       
-       ent->baseline.modelindex = MSG_ReadByte ();
+
+       if (largemodelindex)
+               ent->baseline.modelindex = (unsigned short) MSG_ReadShort ();
+       else
+               ent->baseline.modelindex = MSG_ReadByte ();
        ent->baseline.frame = MSG_ReadByte ();
        ent->baseline.colormap = MSG_ReadByte();
        ent->baseline.skin = MSG_ReadByte();
@@ -624,6 +645,9 @@ void CL_ParseBaseline (entity_t *ent)
        ent->baseline.glowsize = 0;
        ent->baseline.glowcolor = 254;
        ent->baseline.colormod = 255;
+       
+       if (ent->baseline.modelindex >= MAX_MODELS)
+               Host_Error("CL_ParseBaseline: modelindex (%i) >= MAX_MODELS (%i)\n", ent->baseline.modelindex, MAX_MODELS);
 }
 
 
@@ -637,7 +661,13 @@ Server information pertaining to this client only
 void CL_ParseClientdata (int bits)
 {
        int             i, j;
-       
+
+       bits &= 0xFFFF;
+       if (bits & SU_EXTEND1)
+               bits |= (MSG_ReadByte() << 16);
+       if (bits & SU_EXTEND2)
+               bits |= (MSG_ReadByte() << 24);
+
        if (bits & SU_VIEWHEIGHT)
                cl.viewheight = MSG_ReadChar ();
        else
@@ -652,21 +682,27 @@ void CL_ParseClientdata (int bits)
        for (i=0 ; i<3 ; i++)
        {
                if (bits & (SU_PUNCH1<<i) )
-                       cl.punchangle[i] = MSG_ReadChar();
+               {
+                       if (dpprotocol)
+                               cl.punchangle[i] = MSG_ReadPreciseAngle();
+                       else
+                               cl.punchangle[i] = MSG_ReadChar();
+               }
                else
                        cl.punchangle[i] = 0;
+               if (bits & (SU_PUNCHVEC1<<i))
+                       cl.punchvector[i] = MSG_ReadFloatCoord();
+               else
+                       cl.punchvector[i] = 0;
                if (bits & (SU_VELOCITY1<<i) )
                        cl.mvelocity[0][i] = MSG_ReadChar()*16;
                else
                        cl.mvelocity[0][i] = 0;
        }
 
-// [always sent]       if (bits & SU_ITEMS)
-               i = MSG_ReadLong ();
-
+       i = MSG_ReadLong ();
        if (cl.items != i)
        {       // set flash times
-//             Sbar_Changed ();
                for (j=0 ; j<32 ; j++)
                        if ( (i & (1<<j)) && !(cl.items & (1<<j)))
                                cl.item_gettime[j] = cl.time;
@@ -676,73 +712,23 @@ void CL_ParseClientdata (int bits)
        cl.onground = (bits & SU_ONGROUND) != 0;
        cl.inwater = (bits & SU_INWATER) != 0;
 
-       if (bits & SU_WEAPONFRAME)
-               cl.stats[STAT_WEAPONFRAME] = MSG_ReadByte ();
-       else
-               cl.stats[STAT_WEAPONFRAME] = 0;
+       cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
+       cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
+       cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
+       cl.stats[STAT_HEALTH] = MSG_ReadShort();
+       cl.stats[STAT_AMMO] = MSG_ReadByte();
 
-       if (bits & SU_ARMOR)
-               i = MSG_ReadByte ();
-       else
-               i = 0;
-       if (cl.stats[STAT_ARMOR] != i)
-       {
-               cl.stats[STAT_ARMOR] = i;
-//             Sbar_Changed ();
-       }
-
-       if (bits & SU_WEAPON)
-               i = MSG_ReadByte ();
-       else
-               i = 0;
-       if (cl.stats[STAT_WEAPON] != i)
-       {
-               cl.stats[STAT_WEAPON] = i;
-//             Sbar_Changed ();
-       }
-       
-       i = MSG_ReadShort ();
-       if (cl.stats[STAT_HEALTH] != i)
-       {
-               cl.stats[STAT_HEALTH] = i;
-//             Sbar_Changed ();
-       }
-
-       i = MSG_ReadByte ();
-       if (cl.stats[STAT_AMMO] != i)
-       {
-               cl.stats[STAT_AMMO] = i;
-//             Sbar_Changed ();
-       }
-
-       for (i=0 ; i<4 ; i++)
-       {
-               j = MSG_ReadByte ();
-               if (cl.stats[STAT_SHELLS+i] != j)
-               {
-                       cl.stats[STAT_SHELLS+i] = j;
-//                     Sbar_Changed ();
-               }
-       }
+       cl.stats[STAT_SHELLS] = MSG_ReadByte();
+       cl.stats[STAT_NAILS] = MSG_ReadByte();
+       cl.stats[STAT_ROCKETS] = MSG_ReadByte();
+       cl.stats[STAT_CELLS] = MSG_ReadByte();
 
        i = MSG_ReadByte ();
 
        if (standard_quake)
-       {
-               if (cl.stats[STAT_ACTIVEWEAPON] != i)
-               {
-                       cl.stats[STAT_ACTIVEWEAPON] = i;
-//                     Sbar_Changed ();
-               }
-       }
+               cl.stats[STAT_ACTIVEWEAPON] = i;
        else
-       {
-               if (cl.stats[STAT_ACTIVEWEAPON] != (1<<i))
-               {
-                       cl.stats[STAT_ACTIVEWEAPON] = (1<<i);
-//                     Sbar_Changed ();
-               }
-       }
+               cl.stats[STAT_ACTIVEWEAPON] = (1<<i);
 }
 
 /*
@@ -750,7 +736,7 @@ void CL_ParseClientdata (int bits)
 CL_ParseStatic
 =====================
 */
-void CL_ParseStatic (void)
+void CL_ParseStatic (int largemodelindex)
 {
        entity_t *ent;
        int             i;
@@ -760,11 +746,15 @@ void CL_ParseStatic (void)
                Host_Error ("Too many static entities");
        ent = &cl_static_entities[i];
        cl.num_statics++;
-       CL_ParseBaseline (ent);
+       CL_ParseBaseline (ent, largemodelindex);
 
 // copy it to the current state
        ent->model = cl.model_precache[ent->baseline.modelindex];
-       ent->frame = ent->baseline.frame;
+       ent->frame = ent->frame1 = ent->frame2 = ent->baseline.frame;
+       ent->framelerp = 0;
+       ent->lerp_starttime = -1;
+       // make torchs play out of sync
+       ent->frame1start = ent->frame2start = -(rand() & 32767);
        ent->colormap = -1; // no special coloring
        ent->skinnum = ent->baseline.skin;
        ent->effects = ent->baseline.effects;
@@ -789,10 +779,8 @@ void CL_ParseStaticSound (void)
 {
        vec3_t          org;
        int                     sound_num, vol, atten;
-       int                     i;
-       
-       for (i=0 ; i<3 ; i++)
-               org[i] = MSG_ReadCoord ();
+
+       MSG_ReadVector(org);
        sound_num = MSG_ReadByte ();
        vol = MSG_ReadByte ();
        atten = MSG_ReadByte ();
@@ -800,17 +788,41 @@ void CL_ParseStaticSound (void)
        S_StaticSound (cl.sound_precache[sound_num], org, vol, atten);
 }
 
+void CL_ParseEffect (void)
+{
+       vec3_t          org;
+       int                     modelindex, startframe, framecount, framerate;
+
+       MSG_ReadVector(org);
+       modelindex = MSG_ReadByte ();
+       startframe = MSG_ReadByte ();
+       framecount = MSG_ReadByte ();
+       framerate = MSG_ReadByte ();
+
+       CL_Effect(org, modelindex, startframe, framecount, framerate);
+}
+
+void CL_ParseEffect2 (void)
+{
+       vec3_t          org;
+       int                     modelindex, startframe, framecount, framerate;
+
+       MSG_ReadVector(org);
+       modelindex = MSG_ReadShort ();
+       startframe = MSG_ReadByte ();
+       framecount = MSG_ReadByte ();
+       framerate = MSG_ReadByte ();
+
+       CL_Effect(org, modelindex, startframe, framecount, framerate);
+}
+
 
 #define SHOWNET(x) if(cl_shownet.value==2)Con_Printf ("%3i:%s\n", msg_readcount-1, x);
 
 extern void SHOWLMP_decodehide();
 extern void SHOWLMP_decodeshow();
 extern void R_SetSkyBox(char* sky);
-
-extern float fog_density;
-extern float fog_red;
-extern float fog_green;
-extern float fog_blue;
+extern int netshown;
 
 /*
 =====================
@@ -821,14 +833,23 @@ void CL_ParseServerMessage (void)
 {
        int                     cmd;
        int                     i;
+       byte            cmdlog[32];
+       char            *cmdlogname[32], *temp;
+       int                     cmdindex, cmdcount = 0;
        
 //
 // if recording demos, copy the message out
 //
        if (cl_shownet.value == 1)
+       {
                Con_Printf ("%i ",net_message.cursize);
+               netshown = true;
+       }
        else if (cl_shownet.value == 2)
+       {
                Con_Printf ("------------------\n");
+               netshown = true;
+       }
        
        cl.onground = false;    // unless the server says otherwise     
 //
@@ -849,21 +870,55 @@ void CL_ParseServerMessage (void)
                        return;         // end of message
                }
 
-       // if the high bit of the command byte is set, it is a fast update
+               cmdindex = cmdcount & 31;
+               cmdcount++;
+               cmdlog[cmdindex] = cmd;
+
+               // if the high bit of the command byte is set, it is a fast update
                if (cmd & 128)
                {
+                       // 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)
+                       temp = "svc_entity";
+                       cmdlogname[cmdindex] = temp;
                        SHOWNET("fast update");
                        CL_ParseUpdate (cmd&127);
                        continue;
                }
 
                SHOWNET(svc_strings[cmd]);
+               cmdlogname[cmdindex] = svc_strings[cmd];
+               if (!cmdlogname[cmdindex])
+               {
+                       // 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)
+                       temp = "<unknown>";
+                       cmdlogname[cmdindex] = temp;
+               }
        
-       // other commands
+               // other commands
                switch (cmd)
                {
                default:
-                       Host_Error ("CL_ParseServerMessage: Illegible server message\n");
+                       {
+                               char description[32*64], temp[64];
+                               int count;
+                               strcpy(description, "packet dump: ");
+                               i = cmdcount - 32;
+                               if (i < 0)
+                                       i = 0;
+                               count = cmdcount - i;
+                               i &= 31;
+                               while(count > 0)
+                               {
+                                       sprintf(temp, "%3i:%s ", cmdlog[i], cmdlogname[i]);
+                                       strcat(description, temp);
+                                       count--;
+                                       i++;
+                                       i &= 31;
+                               }
+                               description[strlen(description)-1] = '\n'; // replace the last space with a newline
+                               Con_Printf(description);
+                               Host_Error ("CL_ParseServerMessage: Illegible server message\n");
+                       }
                        break;
                        
                case svc_nop:
@@ -882,9 +937,17 @@ void CL_ParseServerMessage (void)
                
                case svc_version:
                        i = MSG_ReadLong ();
-                       if (i != PROTOCOL_VERSION && i != 250)
-                               Host_Error ("CL_ParseServerMessage: Server is protocol %i instead of %i\n", i, PROTOCOL_VERSION);
-                       Nehahrademcompatibility = i == 250;
+                       if (i != PROTOCOL_VERSION && i != DPPROTOCOL_VERSION && i != 250)
+                       {
+                               Host_Error ("CL_ParseServerMessage: Server is protocol %i, not %i or %i", i, DPPROTOCOL_VERSION, PROTOCOL_VERSION);
+                               return;
+                       }
+                       Nehahrademcompatibility = false;
+                       if (i == 250)
+                               Nehahrademcompatibility = true;
+                       if (cls.demoplayback && demo_nehahra.value)
+                               Nehahrademcompatibility = true;
+                       dpprotocol = i == DPPROTOCOL_VERSION;
                        break;
                        
                case svc_disconnect:
@@ -924,40 +987,42 @@ void CL_ParseServerMessage (void)
                        i = MSG_ReadByte ();
                        if (i >= MAX_LIGHTSTYLES)
                                Host_Error ("svc_lightstyle > MAX_LIGHTSTYLES");
-                       strcpy (cl_lightstyle[i].map,  MSG_ReadString());
+                       strncpy (cl_lightstyle[i].map,  MSG_ReadString(), MAX_STYLESTRING - 1);
+                       cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
                        cl_lightstyle[i].length = strlen(cl_lightstyle[i].map);
                        break;
                        
                case svc_sound:
-                       CL_ParseStartSoundPacket();
+                       CL_ParseStartSoundPacket(false);
                        break;
-                       
+
+               case svc_sound2:
+                       CL_ParseStartSoundPacket(true);
+                       break;
+
                case svc_stopsound:
                        i = MSG_ReadShort();
                        S_StopSound(i>>3, i&7);
                        break;
                
                case svc_updatename:
-//                     Sbar_Changed ();
                        i = MSG_ReadByte ();
                        if (i >= cl.maxclients)
-                               Host_Error ("CL_ParseServerMessage: svc_updatename > MAX_SCOREBOARD");
+                               Host_Error ("CL_ParseServerMessage: svc_updatename >= MAX_SCOREBOARD");
                        strcpy (cl.scores[i].name, MSG_ReadString ());
                        break;
                        
                case svc_updatefrags:
-//                     Sbar_Changed ();
                        i = MSG_ReadByte ();
                        if (i >= cl.maxclients)
-                               Host_Error ("CL_ParseServerMessage: svc_updatefrags > MAX_SCOREBOARD");
+                               Host_Error ("CL_ParseServerMessage: svc_updatefrags >= MAX_SCOREBOARD");
                        cl.scores[i].frags = MSG_ReadShort ();
                        break;                  
 
                case svc_updatecolors:
-//                     Sbar_Changed ();
                        i = MSG_ReadByte ();
                        if (i >= cl.maxclients)
-                               Host_Error ("CL_ParseServerMessage: svc_updatecolors > MAX_SCOREBOARD");
+                               Host_Error ("CL_ParseServerMessage: svc_updatecolors >= MAX_SCOREBOARD");
                        cl.scores[i].colors = MSG_ReadByte ();
                        break;
                        
@@ -965,27 +1030,40 @@ void CL_ParseServerMessage (void)
                        R_ParseParticleEffect ();
                        break;
 
+               case svc_effect:
+                       CL_ParseEffect ();
+                       break;
+
+               case svc_effect2:
+                       CL_ParseEffect2 ();
+                       break;
+
                case svc_spawnbaseline:
                        i = MSG_ReadShort ();
                        // must use CL_EntityNum() to force cl.num_entities up
-                       CL_ParseBaseline (CL_EntityNum(i));
+                       CL_ParseBaseline (CL_EntityNum(i), false);
+                       break;
+               case svc_spawnbaseline2:
+                       i = MSG_ReadShort ();
+                       // must use CL_EntityNum() to force cl.num_entities up
+                       CL_ParseBaseline (CL_EntityNum(i), false);
                        break;
                case svc_spawnstatic:
-                       CL_ParseStatic ();
-                       break;                  
+                       CL_ParseStatic (false);
+                       break;
+               case svc_spawnstatic2:
+                       CL_ParseStatic (true);
+                       break;
                case svc_temp_entity:
                        CL_ParseTEnt ();
                        break;
 
                case svc_setpause:
-                       {
-                               cl.paused = MSG_ReadByte ();
-
-                               if (cl.paused)
-                                       CDAudio_Pause ();
-                               else
-                                       CDAudio_Resume ();
-                       }
+                       cl.paused = MSG_ReadByte ();
+                       if (cl.paused)
+                               CDAudio_Pause ();
+                       else
+                               CDAudio_Resume ();
                        break;
                        
                case svc_signonnum:
@@ -1008,7 +1086,7 @@ void CL_ParseServerMessage (void)
                        i = MSG_ReadByte ();
                        if (i < 0 || i >= MAX_CL_STATS)
                                Host_Error ("svc_updatestat: %i is invalid", i);
-                       cl.stats[i] = MSG_ReadLong ();;
+                       cl.stats[i] = MSG_ReadLong ();
                        break;
                        
                case svc_spawnstaticsound:
@@ -1053,24 +1131,6 @@ void CL_ParseServerMessage (void)
                case svc_showlmp:
                        SHOWLMP_decodeshow();
                        break;
-       // LordHavoc: extra worldspawn fields (fog, sky, farclip)
-               case svc_skybox:
-                       R_SetSkyBox(MSG_ReadString());
-                       break;
-               case svc_farclip:
-                       r_farclip.value = MSG_ReadCoord();
-                       break;
-               case svc_fog:
-                       if (MSG_ReadByte())
-                       {
-                               fog_density = MSG_ReadShort() * (1.0f / 4096.0f);
-                               fog_red = MSG_ReadByte() * (1.0 / 255.0);
-                               fog_green = MSG_ReadByte() * (1.0 / 255.0);
-                               fog_blue = MSG_ReadByte() * (1.0 / 255.0);
-                       }
-                       else
-                               fog_density = 0.0f;
-                       break;
                }
        }
 }