]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_parse.c
added a new hack to make MSVC work which will definitely not break any other compilers
[xonotic/darkplaces.git] / cl_parse.c
index 7810cb5e42794207d5e46b866fd144d46d72347d..44525d8ffc2c6cf47a5ab9531520fa6ffd2b1add 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",
@@ -81,7 +81,7 @@ char *svc_strings[] =
        "?", // 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_fog", // [byte] enable <optional past this point, only included if enable is true> [short] density*4096 [byte] red [byte] green [byte] blue
        "svc_playerposition" // [float] x [float] y [float] z
 };
 
@@ -331,9 +331,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;
@@ -384,6 +384,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);
        }
@@ -400,6 +402,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);
        }
@@ -761,6 +765,9 @@ 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
@@ -789,21 +796,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:
@@ -915,14 +956,11 @@ void CL_ParseServerMessage (void)
                        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: