]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Refactor InfoString_GetValue() calling
authorbones_was_here <bones_was_here@xonotic.au>
Sun, 21 Jan 2024 10:30:23 +0000 (20:30 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Sun, 21 Jan 2024 13:27:43 +0000 (23:27 +1000)
Returning the number of bytes written is more useful.

Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
com_infostring.c
com_infostring.h
crypto.c
netconn.c

index 778bf82d6df4c93415ea2a99cf5adecd5a720090..9af6e357edac8c92c273b9e30b329f2e4fa13719 100644 (file)
@@ -20,33 +20,34 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "darkplaces.h"
 
-char *InfoString_GetValue(const char *buffer, const char *key, char *value, size_t valuelength)
+size_t InfoString_GetValue(const char *buffer, const char *key, char *value, size_t valuesize)
 {
-       int pos = 0, j;
+       unsigned pos = 0, j;
        size_t keylength;
+
        if (!key)
                key = "";
        keylength = strlen(key);
-       if (valuelength < 1 || !value)
+       if (valuesize < 1 || !value)
        {
                Con_Printf("InfoString_GetValue: no room in value\n");
-               return NULL;
+               return 0;
        }
-       value[0] = 0;
+       value[0] = '\0';
        if (strchr(key, '\\'))
        {
                Con_Printf("InfoString_GetValue: key name \"%s\" contains \\ which is not possible in an infostring\n", key);
-               return NULL;
+               return 0;
        }
        if (strchr(key, '\"'))
        {
                Con_Printf("InfoString_SetValue: key name \"%s\" contains \" which is not allowed in an infostring\n", key);
-               return NULL;
+               return 0;
        }
        if (!key[0])
        {
                Con_Printf("InfoString_GetValue: can not look up a key with no name\n");
-               return NULL;
+               return 0;
        }
        while (buffer[pos] == '\\')
        {
@@ -54,12 +55,12 @@ char *InfoString_GetValue(const char *buffer, const char *key, char *value, size
                                (buffer[pos+1 + keylength] == 0 ||
                                 buffer[pos+1 + keylength] == '\\'))
                {
-                       pos += 1 + (int)keylength;           // Skip \key
+                       pos += 1 + keylength;           // Skip \key
                        if (buffer[pos] == '\\') pos++; // Skip \ before value.
-                       for (j = 0;buffer[pos+j] && buffer[pos+j] != '\\' && j < (int)valuelength - 1;j++)
+                       for (j = 0;buffer[pos+j] && buffer[pos+j] != '\\' && j < valuesize - 1;j++)
                                value[j] = buffer[pos+j];
-                       value[j] = 0;
-                       return value;
+                       value[j] = '\0';
+                       return j;
                }
                if (buffer[pos] == '\\') pos++; // Skip \ before value.
                for (pos++;buffer[pos] && buffer[pos] != '\\';pos++);
@@ -67,7 +68,7 @@ char *InfoString_GetValue(const char *buffer, const char *key, char *value, size
                for (pos++;buffer[pos] && buffer[pos] != '\\';pos++);
        }
        // if we reach this point the key was not found
-       return NULL;
+       return 0;
 }
 
 void InfoString_SetValue(char *buffer, size_t bufferlength, const char *key, const char *value)
index 538c1ba2543cb2db890a6f4d4fb04693fd3d8d86..ae274bb7f3c4f31ef467dd2da35bb3c8cefd836a 100644 (file)
@@ -24,7 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "qtypes.h"
 #include <stdlib.h>
 
-char *InfoString_GetValue(const char *buffer, const char *key, char *value, size_t valuelength);
+/// Returns the number of bytes written to *value excluding the \0 terminator.
+size_t InfoString_GetValue(const char *buffer, const char *key, char *value, size_t valuesize);
 void InfoString_SetValue(char *buffer, size_t bufferlength, const char *key, const char *value);
 void InfoString_Print(char *buffer);
 
index e6a09ea0b318a39f15e2912e28d0b315b68b8f40..501bef0be7d15400b602c17f86308db4ec1e41c9 100644 (file)
--- a/crypto.c
+++ b/crypto.c
@@ -1741,16 +1741,15 @@ static int Crypto_ServerParsePacket_Internal(const char *data_in, size_t len_in,
 
        if (len_in > 8 && !memcmp(string, "connect\\", 8) && d0_rijndael_dll && crypto_aeslevel.integer >= 3)
        {
-               const char *s;
                int i;
                // sorry, we have to verify the challenge here to not reflect network spam
 
-               if (!(s = InfoString_GetValue(string + 4, "challenge", infostringvalue, sizeof(infostringvalue))))
+               if (!InfoString_GetValue(string + 4, "challenge", infostringvalue, sizeof(infostringvalue)))
                        return CRYPTO_NOMATCH; // will be later accepted if encryption was set up
                // validate the challenge
                for (i = 0;i < MAX_CHALLENGES;i++)
                        if(challenges[i].time > 0)
-                               if (!LHNETADDRESS_Compare(peeraddress, &challenges[i].address) && !strcmp(challenges[i].string, s))
+                               if (!LHNETADDRESS_Compare(peeraddress, &challenges[i].address) && !strcmp(challenges[i].string, infostringvalue))
                                        break;
                // if the challenge is not recognized, drop the packet
                if (i == MAX_CHALLENGES) // challenge mismatch is silent
@@ -1762,12 +1761,11 @@ static int Crypto_ServerParsePacket_Internal(const char *data_in, size_t len_in,
        }
        else if(len_in > 5 && !memcmp(string, "d0pk\\", 5) && ((LHNETADDRESS_GetAddressType(peeraddress) == LHNETADDRESSTYPE_LOOP) || sv_public.integer > -3))
        {
-               const char *cnt, *s, *p;
+               const char *cnt, *p;
                int id;
                int clientid = -1, serverid = -1;
-               cnt = InfoString_GetValue(string + 4, "id", infostringvalue, sizeof(infostringvalue));
-               id = (cnt ? atoi(cnt) : -1);
-               cnt = InfoString_GetValue(string + 4, "cnt", infostringvalue, sizeof(infostringvalue));
+               id = (InfoString_GetValue(string + 4, "id", infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : -1);
+               cnt = (InfoString_GetValue(string + 4, "cnt", infostringvalue, sizeof(infostringvalue)) ? infostringvalue : NULL);
                if(!cnt)
                        return Crypto_SoftServerError(data_out, len_out, "missing cnt in d0pk");
                GetUntilNul(&data_in, &len_in);
@@ -1776,21 +1774,21 @@ static int Crypto_ServerParsePacket_Internal(const char *data_in, size_t len_in,
                if(!strcmp(cnt, "0"))
                {
                        int i;
-                       if (!(s = InfoString_GetValue(string + 4, "challenge", infostringvalue, sizeof(infostringvalue))))
+                       if (!InfoString_GetValue(string + 4, "challenge", infostringvalue, sizeof(infostringvalue)))
                                return Crypto_SoftServerError(data_out, len_out, "missing challenge in d0pk\\0");
                        // validate the challenge
                        for (i = 0;i < MAX_CHALLENGES;i++)
                                if(challenges[i].time > 0)
-                                       if (!LHNETADDRESS_Compare(peeraddress, &challenges[i].address) && !strcmp(challenges[i].string, s))
+                                       if (!LHNETADDRESS_Compare(peeraddress, &challenges[i].address) && !strcmp(challenges[i].string, infostringvalue))
                                                break;
                        // if the challenge is not recognized, drop the packet
                        if (i == MAX_CHALLENGES)
                                return Crypto_SoftServerError(data_out, len_out, "invalid challenge in d0pk\\0");
 
-                       if (!(s = InfoString_GetValue(string + 4, "aeslevel", infostringvalue, sizeof(infostringvalue))))
+                       if (!InfoString_GetValue(string + 4, "aeslevel", infostringvalue, sizeof(infostringvalue)))
                                aeslevel = 0; // not supported
                        else
-                               aeslevel = bound(0, atoi(s), 3);
+                               aeslevel = bound(0, atoi(infostringvalue), 3);
                        switch(bound(0, d0_rijndael_dll ? crypto_aeslevel.integer : 0, 3))
                        {
                                default: // dummy, never happens, but to make gcc happy...
@@ -2048,7 +2046,7 @@ int Crypto_ServerParsePacket(const char *data_in, size_t len_in, char *data_out,
                if(len_in > 5 && !memcmp(data_in, "d0pk\\", 5))
                {
                        do_time = true;
-                       cnt = InfoString_GetValue(data_in + 4, "cnt", infostringvalue, sizeof(infostringvalue));
+                       cnt = (InfoString_GetValue(data_in + 4, "cnt", infostringvalue, sizeof(infostringvalue)) ? infostringvalue : NULL);
                        if(cnt)
                                if(!strcmp(cnt, "0"))
                                        do_reject = true;
@@ -2110,7 +2108,6 @@ int Crypto_ClientParsePacket(const char *data_in, size_t len_in, char *data_out,
 {
        crypto_t *crypto = &cls.crypto;
        const char *string = data_in;
-       const char *s;
        D0_BOOL aes;
        char *data_out_p = data_out;
        D0_BOOL status;
@@ -2173,9 +2170,8 @@ int Crypto_ClientParsePacket(const char *data_in, size_t len_in, char *data_out,
        }
        else if (len_in >= 13 && !memcmp(string, "infoResponse\x0A", 13))
        {
-               s = InfoString_GetValue(string + 13, "d0_blind_id", infostringvalue, sizeof(infostringvalue));
-               if(s)
-                       Crypto_StoreHostKey(peeraddress, s, true);
+               if(InfoString_GetValue(string + 13, "d0_blind_id", infostringvalue, sizeof(infostringvalue)))
+                       Crypto_StoreHostKey(peeraddress, infostringvalue, true);
                return CRYPTO_NOMATCH;
        }
        else if (len_in >= 15 && !memcmp(string, "statusResponse\x0A", 15))
@@ -2188,9 +2184,8 @@ int Crypto_ClientParsePacket(const char *data_in, size_t len_in, char *data_out,
                        save = *p;
                        * (char *) p = 0; // cut off the string there
                }
-               s = InfoString_GetValue(string + 15, "d0_blind_id", infostringvalue, sizeof(infostringvalue));
-               if(s)
-                       Crypto_StoreHostKey(peeraddress, s, true);
+               if(InfoString_GetValue(string + 15, "d0_blind_id", infostringvalue, sizeof(infostringvalue)))
+                       Crypto_StoreHostKey(peeraddress, infostringvalue, true);
                if(p)
                {
                        * (char *) p = save;
@@ -2434,9 +2429,8 @@ int Crypto_ClientParsePacket(const char *data_in, size_t len_in, char *data_out,
                        return Crypto_SoftClientError(data_out, len_out, warn_msg);
                }
 
-               cnt = InfoString_GetValue(string + 4, "id", infostringvalue, sizeof(infostringvalue));
-               id = (cnt ? atoi(cnt) : -1);
-               cnt = InfoString_GetValue(string + 4, "cnt", infostringvalue, sizeof(infostringvalue));
+               id = (InfoString_GetValue(string + 4, "id", infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : -1);
+               cnt = (InfoString_GetValue(string + 4, "cnt", infostringvalue, sizeof(infostringvalue)) ? infostringvalue : NULL);
                if(!cnt)
                        return Crypto_ClientError(data_out, len_out, "d0pk\\ message without cnt");
                GetUntilNul(&data_in, &len_in);
@@ -2453,8 +2447,8 @@ int Crypto_ClientParsePacket(const char *data_in, size_t len_in, char *data_out,
 
                        cls.connect_nextsendtime = max(cls.connect_nextsendtime, host.realtime + 1); // prevent "hammering"
 
-                       if((s = InfoString_GetValue(string + 4, "aes", infostringvalue, sizeof(infostringvalue))))
-                               aes = atoi(s);
+                       if(InfoString_GetValue(string + 4, "aes", infostringvalue, sizeof(infostringvalue)))
+                               aes = atoi(infostringvalue);
                        else
                                aes = false;
                        // we CANNOT toggle the AES status any more!
@@ -2586,8 +2580,8 @@ int Crypto_ClientParsePacket(const char *data_in, size_t len_in, char *data_out,
 
                        if(CDATA->s < 0) // only if server didn't auth
                        {
-                               if((s = InfoString_GetValue(string + 4, "aes", infostringvalue, sizeof(infostringvalue))))
-                                       aes = atoi(s);
+                               if(InfoString_GetValue(string + 4, "aes", infostringvalue, sizeof(infostringvalue)))
+                                       aes = atoi(infostringvalue);
                                else
                                        aes = false;
                                if(CDATA->wantserver_idfp[0]) // if we know a host key, honor its encryption setting
index 0a5a9b9a7cb451fa5b42dc155e6f944736dabbc5..6a78bd7e8b2ebb4befaae2d7e42416792d5d4e41 100644 (file)
--- a/netconn.c
+++ b/netconn.c
@@ -2009,7 +2009,6 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
        size_t sendlength;
 #ifdef CONFIG_MENU
        char infostringvalue[MAX_INPUTLINE];
-       const char *s;
 #endif
 
        // quakeworld ingame packet
@@ -2169,44 +2168,34 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                                string += 15;
                                // search the cache for this server and update it
                                // the challenge is (ab)used to return the query time
-                               s = InfoString_GetValue(string, "challenge", infostringvalue, sizeof(infostringvalue));
-                               n = NetConn_ClientParsePacket_ServerList_ProcessReply(addressstring2, s);
+                               InfoString_GetValue(string, "challenge", infostringvalue, sizeof(infostringvalue));
+                               n = NetConn_ClientParsePacket_ServerList_ProcessReply(addressstring2, infostringvalue);
                                if (n < 0)
                                        return true;
 
                                info = &serverlist_cache[n].info;
-                               info->game[0]     = '\0'; info->game_len = 0;
-                               info->mod[0]      = '\0'; info->mod_len = 0;
-                               info->map[0]      = '\0'; info->map_len = 0;
-                               info->name[0]     = '\0'; info->name_len = 0;
-                               info->qcstatus[0] = '\0'; info->qcstatus_len = 0;
-                               info->players[0]  = '\0'; info->players_len = 0;
-                               info->protocol    = -1;
-                               info->numplayers  = 0;
-                               info->numbots     = -1;
-                               info->maxplayers  = 0;
-                               info->gameversion = 0;
-
                                p = strchr(string, '\n');
                                if(p)
                                {
                                        *p = 0; // cut off the string there
                                        ++p;
+                                       info->players_len = dp_strlcpy(info->players, p, sizeof(info->players));
                                }
                                else
+                               {
                                        Con_Printf("statusResponse without players block?\n");
-
-                               if ((s = InfoString_GetValue(string, "gamename"     , infostringvalue, sizeof(infostringvalue))) != NULL) info->game_len = dp_strlcpy(info->game, s, sizeof(info->game));
-                               if ((s = InfoString_GetValue(string, "modname"      , infostringvalue, sizeof(infostringvalue))) != NULL) info->mod_len = dp_strlcpy(info->mod, s, sizeof(info->mod));
-                               if ((s = InfoString_GetValue(string, "mapname"      , infostringvalue, sizeof(infostringvalue))) != NULL) info->map_len = dp_strlcpy(info->map, s, sizeof(info->map));
-                               if ((s = InfoString_GetValue(string, "hostname"     , infostringvalue, sizeof(infostringvalue))) != NULL) info->name_len = dp_strlcpy(info->name, s, sizeof(info->name));
-                               if ((s = InfoString_GetValue(string, "protocol"     , infostringvalue, sizeof(infostringvalue))) != NULL) info->protocol = atoi(s);
-                               if ((s = InfoString_GetValue(string, "clients"      , infostringvalue, sizeof(infostringvalue))) != NULL) info->numplayers = atoi(s);
-                               if ((s = InfoString_GetValue(string, "bots"         , infostringvalue, sizeof(infostringvalue))) != NULL) info->numbots = atoi(s);
-                               if ((s = InfoString_GetValue(string, "sv_maxclients", infostringvalue, sizeof(infostringvalue))) != NULL) info->maxplayers = atoi(s);
-                               if ((s = InfoString_GetValue(string, "gameversion"  , infostringvalue, sizeof(infostringvalue))) != NULL) info->gameversion = atoi(s);
-                               if ((s = InfoString_GetValue(string, "qcstatus"     , infostringvalue, sizeof(infostringvalue))) != NULL) info->qcstatus_len = dp_strlcpy(info->qcstatus, s, sizeof(info->qcstatus));
-                               if (p                                                                                            != NULL) info->players_len = dp_strlcpy(info->players, p, sizeof(info->players));
+                                       info->players_len = info->players[0] = 0;
+                               }
+                               info->game_len     = InfoString_GetValue(string, "gamename", info->game,     sizeof(info->game));
+                               info->mod_len      = InfoString_GetValue(string, "modname",  info->mod,      sizeof(info->mod));
+                               info->map_len      = InfoString_GetValue(string, "mapname",  info->map,      sizeof(info->map));
+                               info->name_len     = InfoString_GetValue(string, "hostname", info->name,     sizeof(info->name));
+                               info->qcstatus_len = InfoString_GetValue(string, "qcstatus", info->qcstatus, sizeof(info->qcstatus));
+                               info->protocol    = InfoString_GetValue(string, "protocol"     , infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : -1;
+                               info->numplayers  = InfoString_GetValue(string, "clients"      , infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : 0;
+                               info->numbots     = InfoString_GetValue(string, "bots"         , infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : -1;
+                               info->maxplayers  = InfoString_GetValue(string, "sv_maxclients", infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : 0;
+                               info->gameversion = InfoString_GetValue(string, "gameversion"  , infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : 0;
                                info->numhumans = info->numplayers - max(0, info->numbots);
                                info->freeslots = info->maxplayers - info->numplayers;
 
@@ -2222,34 +2211,23 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                                string += 13;
                                // search the cache for this server and update it
                                // the challenge is (ab)used to return the query time
-                               s = InfoString_GetValue(string, "challenge", infostringvalue, sizeof(infostringvalue));
-                               n = NetConn_ClientParsePacket_ServerList_ProcessReply(addressstring2, s);
+                               InfoString_GetValue(string, "challenge", infostringvalue, sizeof(infostringvalue));
+                               n = NetConn_ClientParsePacket_ServerList_ProcessReply(addressstring2, infostringvalue);
                                if (n < 0)
                                        return true;
 
                                info = &serverlist_cache[n].info;
-                               info->game[0]     = '\0'; info->game_len = 0;
-                               info->mod[0]      = '\0'; info->mod_len = 0;
-                               info->map[0]      = '\0'; info->map_len = 0;
-                               info->name[0]     = '\0'; info->name_len = 0;
-                               info->qcstatus[0] = '\0'; info->qcstatus_len = 0;
-                               info->players[0]  = '\0'; info->players_len = 0;
-                               info->protocol    = -1;
-                               info->numplayers  = 0;
-                               info->numbots     = -1;
-                               info->maxplayers  = 0;
-                               info->gameversion = 0;
-
-                               if ((s = InfoString_GetValue(string, "gamename"     , infostringvalue, sizeof(infostringvalue))) != NULL) info->game_len = dp_strlcpy(info->game, s, sizeof(info->game));
-                               if ((s = InfoString_GetValue(string, "modname"      , infostringvalue, sizeof(infostringvalue))) != NULL) info->mod_len = dp_strlcpy(info->mod, s, sizeof(info->mod));
-                               if ((s = InfoString_GetValue(string, "mapname"      , infostringvalue, sizeof(infostringvalue))) != NULL) info->map_len = dp_strlcpy(info->map, s, sizeof(info->map));
-                               if ((s = InfoString_GetValue(string, "hostname"     , infostringvalue, sizeof(infostringvalue))) != NULL) info->name_len = dp_strlcpy(info->name, s, sizeof(info->name));
-                               if ((s = InfoString_GetValue(string, "protocol"     , infostringvalue, sizeof(infostringvalue))) != NULL) info->protocol = atoi(s);
-                               if ((s = InfoString_GetValue(string, "clients"      , infostringvalue, sizeof(infostringvalue))) != NULL) info->numplayers = atoi(s);
-                               if ((s = InfoString_GetValue(string, "bots"         , infostringvalue, sizeof(infostringvalue))) != NULL) info->numbots = atoi(s);
-                               if ((s = InfoString_GetValue(string, "sv_maxclients", infostringvalue, sizeof(infostringvalue))) != NULL) info->maxplayers = atoi(s);
-                               if ((s = InfoString_GetValue(string, "gameversion"  , infostringvalue, sizeof(infostringvalue))) != NULL) info->gameversion = atoi(s);
-                               if ((s = InfoString_GetValue(string, "qcstatus"     , infostringvalue, sizeof(infostringvalue))) != NULL) info->qcstatus_len = dp_strlcpy(info->qcstatus, s, sizeof(info->qcstatus));
+                               info->players_len = info->players[0] = 0;
+                               info->game_len     = InfoString_GetValue(string, "gamename", info->game,     sizeof(info->game));
+                               info->mod_len      = InfoString_GetValue(string, "modname",  info->mod,      sizeof(info->mod));
+                               info->map_len      = InfoString_GetValue(string, "mapname",  info->map,      sizeof(info->map));
+                               info->name_len     = InfoString_GetValue(string, "hostname", info->name,     sizeof(info->name));
+                               info->qcstatus_len = InfoString_GetValue(string, "qcstatus", info->qcstatus, sizeof(info->qcstatus));
+                               info->protocol    = InfoString_GetValue(string, "protocol"     , infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : -1;
+                               info->numplayers  = InfoString_GetValue(string, "clients"      , infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : 0;
+                               info->numbots     = InfoString_GetValue(string, "bots"         , infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : -1;
+                               info->maxplayers  = InfoString_GetValue(string, "sv_maxclients", infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : 0;
+                               info->gameversion = InfoString_GetValue(string, "gameversion"  , infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : 0;
                                info->numhumans = info->numplayers - max(0, info->numbots);
                                info->freeslots = info->maxplayers - info->numplayers;
 
@@ -2335,6 +2313,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
 #ifdef CONFIG_MENU
                        serverlist_info_t *info;
                        int n;
+                       const char *s;
 
                        // qw server status
                        if (serverlist_consoleoutput && developer_networking.integer >= 2)
@@ -2348,17 +2327,14 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
 
                        info = &serverlist_cache[n].info;
                        dp_strlcpy(info->game, "QuakeWorld", sizeof(info->game));
-                       if ((s = InfoString_GetValue(string, "*gamedir"     , infostringvalue, sizeof(infostringvalue))) != NULL) info->mod_len = dp_strlcpy(info->mod, s, sizeof(info->mod));
-                       else { info->mod[0] = '\0'; info->mod_len = 0; }
-                       if ((s = InfoString_GetValue(string, "map"          , infostringvalue, sizeof(infostringvalue))) != NULL) info->map_len = dp_strlcpy(info->map, s, sizeof(info->map));
-                       else { info->map[0] = '\0'; info->map_len = 0; }
-                       if ((s = InfoString_GetValue(string, "hostname"     , infostringvalue, sizeof(infostringvalue))) != NULL) info->name_len = dp_strlcpy(info->name, s, sizeof(info->name));
-                       else { info->name[0] = '\0'; info->name_len = 0; }
+                       info->mod_len  = InfoString_GetValue(string, "*gamedir", info->mod, sizeof(info->mod));
+                       info->map_len  = InfoString_GetValue(string, "map"     , info->map, sizeof(info->map));
+                       info->name_len = InfoString_GetValue(string, "hostname", info->name, sizeof(info->name));
                        info->protocol = 0;
                        info->numplayers = 0; // updated below
                        info->numhumans = 0; // updated below
-                       if ((s = InfoString_GetValue(string, "maxclients"   , infostringvalue, sizeof(infostringvalue))) != NULL) info->maxplayers = atoi(s);else info->maxplayers  = 0;
-                       if ((s = InfoString_GetValue(string, "gameversion"  , infostringvalue, sizeof(infostringvalue))) != NULL) info->gameversion = atoi(s);else info->gameversion = 0;
+                       info->maxplayers  = InfoString_GetValue(string, "maxclients" , infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : 0;
+                       info->gameversion = InfoString_GetValue(string, "gameversion", infostringvalue, sizeof(infostringvalue)) ? atoi(infostringvalue) : 0;
 
                        // count active players on server
                        // (we could gather more info, but we're just after the number)
@@ -3268,7 +3244,6 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                }
                if (length > 8 && !memcmp(string, "connect\\", 8))
                {
-                       char *s;
                        client_t *client;
                        crypto_t *crypto = Crypto_ServerGetInstance(peeraddress);
                        string += 7;
@@ -3293,12 +3268,12 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        }
                        else
                        {
-                               if ((s = InfoString_GetValue(string, "challenge", infostringvalue, sizeof(infostringvalue))))
+                               if (InfoString_GetValue(string, "challenge", infostringvalue, sizeof(infostringvalue)))
                                {
                                        // validate the challenge
                                        for (i = 0;i < MAX_CHALLENGES;i++)
                                                if(challenges[i].time > 0)
-                                                       if (!LHNETADDRESS_Compare(peeraddress, &challenges[i].address) && !strcmp(challenges[i].string, s))
+                                                       if (!LHNETADDRESS_Compare(peeraddress, &challenges[i].address) && !strcmp(challenges[i].string, infostringvalue))
                                                                break;
                                        // if the challenge is not recognized, drop the packet
                                        if (i == MAX_CHALLENGES)
@@ -3306,8 +3281,8 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                                }
                        }
 
-                       if((s = InfoString_GetValue(string, "message", infostringvalue, sizeof(infostringvalue))))
-                               Con_DPrintf("Connecting client %s sent us the message: %s\n", addressstring2, s);
+                       if(InfoString_GetValue(string, "message", infostringvalue, sizeof(infostringvalue)))
+                               Con_DPrintf("Connecting client %s sent us the message: %s\n", addressstring2, infostringvalue);
 
                        if(!(islocal || sv_public.integer > -2))
                        {
@@ -3320,7 +3295,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        }
 
                        // check engine protocol
-                       if(!(s = InfoString_GetValue(string, "protocol", infostringvalue, sizeof(infostringvalue))) || strcmp(s, "darkplaces 3"))
+                       if(!InfoString_GetValue(string, "protocol", infostringvalue, sizeof(infostringvalue)) || strcmp(infostringvalue, "darkplaces 3"))
                        {
                                if (developer_extra.integer)
                                        Con_Printf("Datagram_ParseConnectionless: sending \"reject Wrong game protocol.\" to %s.\n", addressstring2);