]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - common.c
Update extension description to prefer "ent" as the parameter name over "e"
[xonotic/darkplaces.git] / common.c
index 47edc4c9c06211253896925212c7358a01772670..090f097088e0a471390597b82cff9befd0bd3b6c 100644 (file)
--- a/common.c
+++ b/common.c
@@ -28,8 +28,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "quakedef.h"
 #include "utf8lib.h"
 
-cvar_t registered = {0, "registered","0", "indicates if this is running registered quake (whether gfx/pop.lmp was found)"};
-cvar_t cmdline = {0, "cmdline","0", "contains commandline the engine was launched with"};
+cvar_t registered = {CVAR_CLIENT | CVAR_SERVER, "registered","0", "indicates if this is running registered quake (whether gfx/pop.lmp was found)"};
+cvar_t cmdline = {CVAR_CLIENT | CVAR_SERVER, "cmdline","0", "contains commandline the engine was launched with"};
 
 char com_token[MAX_INPUTLINE];
 int com_argc;
@@ -372,7 +372,7 @@ void MSG_WriteVector (sizebuf_t *sb, const vec3_t v, protocolversion_t protocol)
        MSG_WriteCoord (sb, v[2], protocol);
 }
 
-// LordHavoc: round to nearest value, rather than rounding toward zero, fixes crosshair problem
+// LadyHavoc: round to nearest value, rather than rounding toward zero, fixes crosshair problem
 void MSG_WriteAngle8i (sizebuf_t *sb, float f)
 {
        if (f >= 0)
@@ -552,7 +552,7 @@ void MSG_ReadVector (sizebuf_t *sb, vec3_t v, protocolversion_t protocol)
        v[2] = MSG_ReadCoord(sb, protocol);
 }
 
-// LordHavoc: round to nearest value, rather than rounding toward zero, fixes crosshair problem
+// LadyHavoc: round to nearest value, rather than rounding toward zero, fixes crosshair problem
 float MSG_ReadAngle8i (sizebuf_t *sb)
 {
        return (signed char) MSG_ReadByte (sb) * (360.0/256.0);
@@ -612,7 +612,7 @@ void SZ_Write (sizebuf_t *buf, const unsigned char *data, int length)
        memcpy (SZ_GetSpace(buf,length),data,length);
 }
 
-// LordHavoc: thanks to Fuh for bringing the pure evil of SZ_Print to my
+// LadyHavoc: thanks to Fuh for bringing the pure evil of SZ_Print to my
 // attention, it has been eradicated from here, its only (former) use in
 // all of darkplaces.
 
@@ -1475,6 +1475,7 @@ static const gamemode_info_t gamemode_info [GAME_COUNT] =
 { GAME_STEELSTORM,                             GAME_STEELSTORM,                        "steelstorm",                   "-steelstorm",                          "Steel-Storm",                          "Steel-Storm",                          "gamedata",     NULL,                   "ss",                           "steelstorm"                    }, // COMMANDLINEOPTION: Game: -steelstorm runs the game Steel Storm
 { GAME_STEELSTORM2,                            GAME_STEELSTORM2,                       "steelstorm2",                  "-steelstorm2",                         "Steel Storm 2",                        "Steel_Storm_2",                        "gamedata",     NULL,                   "ss2",                          "steelstorm2"                   }, // COMMANDLINEOPTION: Game: -steelstorm2 runs the game Steel Storm 2
 { GAME_SSAMMO,                                 GAME_SSAMMO,                            "steelstorm-ammo",              "-steelstormammo",                      "Steel Storm A.M.M.O.",         "Steel_Storm_A.M.M.O.",         "gamedata", NULL,                       "ssammo",                       "steelstorm-ammo"               }, // COMMANDLINEOPTION: Game: -steelstormammo runs the game Steel Storm A.M.M.O.
+{ GAME_STEELSTORMREVENANTS,            GAME_STEELSTORMREVENANTS,       "steelstorm-revenants", "-steelstormrev",                       "Steel Storm: Revenants",       "Steel_Storm_Revenants",        "base", NULL,                           "ssrev",                        "steelstorm-revenants"  }, // COMMANDLINEOPTION: Game: -steelstormrev runs the game Steel Storm: Revenants
 { GAME_TOMESOFMEPHISTOPHELES,  GAME_TOMESOFMEPHISTOPHELES,     "tomesofmephistopheles","-tomesofmephistopheles",       "Tomes of Mephistopheles",      "Tomes_of_Mephistopheles",      "gamedata",     NULL,                   "tom",                          "tomesofmephistopheles" }, // COMMANDLINEOPTION: Game: -tomesofmephistopheles runs the game Tomes of Mephistopheles
 { GAME_STRAPBOMB,                              GAME_STRAPBOMB,                         "strapbomb",                    "-strapbomb",                           "Strap-on-bomb Car",            "Strap-on-bomb_Car",            "id1",          NULL,                   "strap",                        "strapbomb"                             }, // COMMANDLINEOPTION: Game: -strapbomb runs the game Strap-on-bomb Car
 { GAME_MOONHELM,                               GAME_MOONHELM,                          "moonhelm",                             "-moonhelm",                            "MoonHelm",                                     "MoonHelm",                                     "data",         NULL,                   "mh",                           "moonhelm"                              }, // COMMANDLINEOPTION: Game: -moonhelm runs the game MoonHelm
@@ -1619,13 +1620,22 @@ void COM_Init_Commands (void)
                if (strstr(com_argv[j], " "))
                {
                        // arg contains whitespace, store quotes around it
+                       // This condition checks whether we can allow to put
+                       // in two quote characters.
+                       if (n >= ((int)sizeof(com_cmdline) - 2))
+                               break;
                        com_cmdline[n++] = '\"';
-                       while ((n < ((int)sizeof(com_cmdline) - 1)) && com_argv[j][i])
+                       // This condition checks whether we can allow one
+                       // more character and a quote character.
+                       while ((n < ((int)sizeof(com_cmdline) - 2)) && com_argv[j][i])
+                               // FIXME: Doesn't quote special characters.
                                com_cmdline[n++] = com_argv[j][i++];
                        com_cmdline[n++] = '\"';
                }
                else
                {
+                       // This condition checks whether we can allow one
+                       // more character.
                        while ((n < ((int)sizeof(com_cmdline) - 1)) && com_argv[j][i])
                                com_cmdline[n++] = com_argv[j][i++];
                }
@@ -1635,7 +1645,7 @@ void COM_Init_Commands (void)
                        break;
        }
        com_cmdline[n] = 0;
-       Cvar_Set ("cmdline", com_cmdline);
+       Cvar_SetQuick(&cmdline, com_cmdline);
 }
 
 /*
@@ -1869,7 +1879,7 @@ COM_StringLengthNoColors(const char *s, size_t size_s, qboolean *valid)
                {
                        case 0:
                                if(valid)
-                                       *valid = TRUE;
+                                       *valid = true;
                                return len;
                        case STRING_COLOR_TAG:
                                ++s;
@@ -1889,7 +1899,7 @@ COM_StringLengthNoColors(const char *s, size_t size_s, qboolean *valid)
                                        case 0: // ends with unfinished color code!
                                                ++len;
                                                if(valid)
-                                                       *valid = FALSE;
+                                                       *valid = false;
                                                return len;
                                        case STRING_COLOR_TAG: // escaped ^
                                                ++len;
@@ -1935,17 +1945,17 @@ all characters until the zero terminator.
 qboolean
 COM_StringDecolorize(const char *in, size_t size_in, char *out, size_t size_out, qboolean escape_carets)
 {
-#define APPEND(ch) do { if(--size_out) { *out++ = (ch); } else { *out++ = 0; return FALSE; } } while(0)
+#define APPEND(ch) do { if(--size_out) { *out++ = (ch); } else { *out++ = 0; return false; } } while(0)
        const char *end = size_in ? (in + size_in) : NULL;
        if(size_out < 1)
-               return FALSE;
+               return false;
        for(;;)
        {
                switch((in == end) ? 0 : *in)
                {
                        case 0:
                                *out++ = 0;
-                               return TRUE;
+                               return true;
                        case STRING_COLOR_TAG:
                                ++in;
                                switch((in == end) ? 0 : *in)
@@ -1969,7 +1979,7 @@ COM_StringDecolorize(const char *in, size_t size_in, char *out, size_t size_out,
                                                if(escape_carets)
                                                        APPEND(STRING_COLOR_TAG);
                                                *out++ = 0;
-                                               return TRUE;
+                                               return true;
                                        case STRING_COLOR_TAG: // escaped ^
                                                APPEND(STRING_COLOR_TAG);
                                                // append a ^ twice when escaping
@@ -2025,16 +2035,20 @@ char *InfoString_GetValue(const char *buffer, const char *key, char *value, size
        }
        while (buffer[pos] == '\\')
        {
-               if (!memcmp(buffer + pos+1, key, keylength))
+               if (!memcmp(buffer + pos+1, key, keylength) &&
+                               (buffer[pos+1 + keylength] == 0 ||
+                                buffer[pos+1 + keylength] == '\\'))
                {
-                       for (pos++;buffer[pos] && buffer[pos] != '\\';pos++);
-                       pos++;
+                       pos += 1 + (int)keylength;           // Skip \key
+                       if (buffer[pos] == '\\') pos++; // Skip \ before value.
                        for (j = 0;buffer[pos+j] && buffer[pos+j] != '\\' && j < (int)valuelength - 1;j++)
                                value[j] = buffer[pos+j];
                        value[j] = 0;
                        return value;
                }
+               if (buffer[pos] == '\\') pos++; // Skip \ before value.
                for (pos++;buffer[pos] && buffer[pos] != '\\';pos++);
+               if (buffer[pos] == '\\') pos++; // Skip \ before value.
                for (pos++;buffer[pos] && buffer[pos] != '\\';pos++);
        }
        // if we reach this point the key was not found
@@ -2067,24 +2081,29 @@ void InfoString_SetValue(char *buffer, size_t bufferlength, const char *key, con
        }
        while (buffer[pos] == '\\')
        {
-               if (!memcmp(buffer + pos+1, key, keylength))
+               if (!memcmp(buffer + pos+1, key, keylength) &&
+                               (buffer[pos+1 + keylength] == 0 ||
+                                buffer[pos+1 + keylength] == '\\'))
                        break;
-               for (pos++;buffer[pos] && buffer[pos] != '\\';pos++);
-               for (pos++;buffer[pos] && buffer[pos] != '\\';pos++);
+               if (buffer[pos] == '\\') pos++; // Skip \ before value.
+               for (;buffer[pos] && buffer[pos] != '\\';pos++);
+               if (buffer[pos] == '\\') pos++; // Skip \ before value.
+               for (;buffer[pos] && buffer[pos] != '\\';pos++);
        }
        // if we found the key, find the end of it because we will be replacing it
        pos2 = pos;
        if (buffer[pos] == '\\')
        {
-               for (pos2++;buffer[pos2] && buffer[pos2] != '\\';pos2++);
-               for (pos2++;buffer[pos2] && buffer[pos2] != '\\';pos2++);
+               pos2 += 1 + (int)keylength;  // Skip \key
+               if (buffer[pos2] == '\\') pos2++; // Skip \ before value.
+               for (;buffer[pos2] && buffer[pos2] != '\\';pos2++);
        }
        if (bufferlength <= pos + 1 + strlen(key) + 1 + strlen(value) + strlen(buffer + pos2))
        {
                Con_Printf("InfoString_SetValue: no room for \"%s\" \"%s\" in infostring\n", key, value);
                return;
        }
-       if (value && value[0])
+       if (value[0])
        {
                // set the key/value and append the remaining text
                char tempbuffer[MAX_INPUTLINE];
@@ -2287,7 +2306,7 @@ size_t base64_encode(unsigned char *buf, size_t buflen, size_t outbuflen)
        for(i = blocks; i > 0; )
        {
                --i;
-               base64_3to4(buf + 3*i, buf + 4*i, buflen - 3*i);
+               base64_3to4(buf + 3*i, buf + 4*i, (int)(buflen - 3*i));
        }
        return blocks * 4;
 }