]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - netconn.c
added ping and packet loss display to scoreboard, and pings/pingplreport commands...
[xonotic/darkplaces.git] / netconn.c
index 4a6ea050cf48a564f778dd11a794b6bc651224d2..79448a9c4f4c9a79da4b0e0e68975853ece45749 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -49,22 +49,19 @@ static cvar_t sv_qwmasters [] =
        {CVAR_SAVE, "sv_qwmaster2", "", "user-chosen qwmaster server 2"},
        {CVAR_SAVE, "sv_qwmaster3", "", "user-chosen qwmaster server 3"},
        {CVAR_SAVE, "sv_qwmaster4", "", "user-chosen qwmaster server 4"},
-       {0, "sv_qwmasterextra1", "satan.idsoftware.com", "default qwmaster server 1 (admin: idSoftware)"},
-       {0, "sv_qwmasterextra2", "192.246.40.37:27000", "id Limbo (admin: id Software)"},
-       {0, "sv_qwmasterextra3", "192.246.40.37:27002", "id CTF (admin: id Software)"},
-       {0, "sv_qwmasterextra4", "192.246.40.37:27003", "id TeamFortress (admin: id Software)"},
-       {0, "sv_qwmasterextra5", "192.246.40.37:27004", "id Miscilaneous (admin: id Software)"},
-       {0, "sv_qwmasterextra6", "192.246.40.37:27006", "id Deathmatch Only (admin: id Software)"},
-       {0, "sv_qwmasterextra7", "150.254.66.120:27000", "Poland's master server. (admin: unknown)"},
-       {0, "sv_qwmasterextra8", "62.112.145.129:27000", "Ocrana master server. (admin: unknown)"},
-       {0, "sv_qwmasterextra9", "master.edome.net", "edome master server. (admin: unknown)"},
-       {0, "sv_qwmasterextra10", "qwmaster.barrysworld.com", "barrysworld master server. (admin: unknown)"},
-       {0, "sv_qwmasterextra11", "qwmaster.ocrana.de:27000", "Ocrana2 master server. (admin: unknown)"},
-       {0, "sv_qwmasterextra12", "213.221.174.165:27000", "unknown1 master server. (admin: unknown)"},
-       {0, "sv_qwmasterextra13", "195.74.0.8", "unknown2 master server. (admin: unknown)"},
-       {0, "sv_qwmasterextra14", "192.246.40.37", "unknown3 master server. (admin: unknown)"},
-       {0, "sv_qwmasterextra15", "192.246.40.37:27006", "unknown4 master server. (admin: unknown)"},
-       {0, "sv_qwmasterextra16", "204.182.161.2", "unknown5 master server. (admin: unknown)"},
+       {0, "sv_qwmasterextra1", "192.246.40.37:27000", "id Limbo (admin: id Software)"},
+       {0, "sv_qwmasterextra2", "192.246.40.37:27002", "id CTF (admin: id Software)"},
+       {0, "sv_qwmasterextra3", "192.246.40.37:27003", "id TeamFortress (admin: id Software)"},
+       {0, "sv_qwmasterextra4", "192.246.40.37:27004", "id Miscilaneous (admin: id Software)"},
+       {0, "sv_qwmasterextra5", "192.246.40.37:27006", "id Deathmatch Only (admin: id Software)"},
+       {0, "sv_qwmasterextra6", "150.254.66.120:27000", "Poland's master server. (admin: unknown)"},
+       {0, "sv_qwmasterextra7", "62.112.145.129:27000", "Ocrana master server. (admin: unknown)"},
+       {0, "sv_qwmasterextra8", "master.edome.net", "edome master server. (admin: unknown)"},
+       {0, "sv_qwmasterextra9", "qwmaster.barrysworld.com", "barrysworld master server. (admin: unknown)"},
+       {0, "sv_qwmasterextra10", "qwmaster.ocrana.de:27000", "Ocrana2 master server. (admin: unknown)"},
+       {0, "sv_qwmasterextra11", "213.221.174.165:27000", "unknown1 master server. (admin: unknown)"},
+       {0, "sv_qwmasterextra12", "195.74.0.8", "unknown2 master server. (admin: unknown)"},
+       {0, "sv_qwmasterextra13", "204.182.161.2", "unknown3 master server. (admin: unknown)"},
        {0, NULL, NULL, NULL}
 };
 
@@ -116,10 +113,10 @@ static double serverlist_querywaittime = 0;
 static unsigned char sendbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
 static unsigned char readbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
 
-int cl_numsockets;
-lhnetsocket_t *cl_sockets[16];
-int sv_numsockets;
-lhnetsocket_t *sv_sockets[16];
+static int cl_numsockets;
+static lhnetsocket_t *cl_sockets[16];
+static int sv_numsockets;
+static lhnetsocket_t *sv_sockets[16];
 
 netconn_t *netconn_list = NULL;
 mempool_t *netconn_mempool = NULL;
@@ -209,7 +206,12 @@ static qboolean _ServerList_Entry_Compare( serverlist_entry_t *A, serverlist_ent
 
        if( serverlist_sortdescending )
                return result > 0;
-       return result < 0;
+       if (result != 0)
+               return result < 0;
+       // if the chosen sort key is identical, sort by index
+       // (makes this a stable sort, so that later replies from servers won't
+       //  shuffle the servers around when they have the same ping)
+       return A < B;
 }
 
 static qboolean _ServerList_CompareInt( int A, serverlist_maskop_t op, int B )
@@ -502,6 +504,8 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers
                {
                        *((short *)(sendbuffer + 8)) = LittleShort(cls.qw_qport);
                        packetLen += 2;
+                       // also update cls.qw_outgoing_sequence
+                       cls.qw_outgoing_sequence = conn->qw.outgoing_sequence;
                }
                if (packetLen + (sendreliable ? conn->sendMessageLength : 0) > 1400)
                {
@@ -842,6 +846,8 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len
        if (length < 8)
                return 0;
 
+       // TODO: add netgraph stuff rather than just packetloss counting...
+
        if (protocol == PROTOCOL_QUAKEWORLD)
        {
                int sequence, sequence_ack;
@@ -872,15 +878,22 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len
                sequence_ack &= ~(1<<31);
                if (sequence <= conn->qw.incoming_sequence)
                {
-                       Con_DPrint("Got a stale datagram\n");
+                       //Con_DPrint("Got a stale datagram\n");
                        return 0;
                }
                count = sequence - (conn->qw.incoming_sequence + 1);
                if (count > 0)
                {
                        droppedDatagrams += count;
-                       Con_DPrintf("Dropped %u datagram(s)\n", count);
+                       //Con_DPrintf("Dropped %u datagram(s)\n", count);
+                       while (count--)
+                       {
+                               conn->packetlost[conn->packetlostcounter] = true;
+                               conn->packetlostcounter = (conn->packetlostcounter + 1) % 100;
+                       }
                }
+               conn->packetlost[conn->packetlostcounter] = false;
+               conn->packetlostcounter = (conn->packetlostcounter + 1) % 100;
                if (reliable_ack == conn->qw.reliable_sequence)
                {
                        // received, now we will be able to send another reliable message
@@ -888,6 +901,8 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len
                        reliableMessagesReceived++;
                }
                conn->qw.incoming_sequence = sequence;
+               if (conn == cls.netcon)
+                       cls.qw_incoming_sequence = conn->qw.incoming_sequence;
                conn->qw.incoming_acknowledged = sequence_ack;
                conn->qw.incoming_reliable_acknowledged = reliable_ack;
                if (reliable_message)
@@ -925,8 +940,15 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len
                                        {
                                                count = sequence - conn->nq.unreliableReceiveSequence;
                                                droppedDatagrams += count;
-                                               Con_DPrintf("Dropped %u datagram(s)\n", count);
+                                               //Con_DPrintf("Dropped %u datagram(s)\n", count);
+                                               while (count--)
+                                               {
+                                                       conn->packetlost[conn->packetlostcounter] = true;
+                                                       conn->packetlostcounter = (conn->packetlostcounter + 1) % 100;
+                                               }
                                        }
+                                       conn->packetlost[conn->packetlostcounter] = false;
+                                       conn->packetlostcounter = (conn->packetlostcounter + 1) % 100;
                                        conn->nq.unreliableReceiveSequence = sequence + 1;
                                        conn->lastMessageTime = realtime;
                                        conn->timeout = realtime + net_messagetimeout.value;
@@ -939,8 +961,8 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len
                                                return 2;
                                        }
                                }
-                               else
-                                       Con_DPrint("Got a stale datagram\n");
+                               //else
+                               //      Con_DPrint("Got a stale datagram\n");
                                return 1;
                        }
                        else if (flags & NETFLAG_ACK)
@@ -993,11 +1015,11 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len
                                                else
                                                        conn->sendMessageLength = 0;
                                        }
-                                       else
-                                               Con_DPrint("Duplicate ACK received\n");
+                                       //else
+                                       //      Con_DPrint("Duplicate ACK received\n");
                                }
-                               else
-                                       Con_DPrint("Stale ACK received\n");
+                               //else
+                               //      Con_DPrint("Stale ACK received\n");
                                return 1;
                        }
                        else if (flags & NETFLAG_DATA)
@@ -1072,17 +1094,75 @@ int NetConn_IsLocalGame(void)
        return false;
 }
 
+static int NetConn_ClientParsePacket_ServerList_ProcessReply(const char *addressstring)
+{
+       int n;
+       int pingtime;
+       // search the cache for this server and update it
+       for (n = 0;n < serverlist_cachecount;n++)
+               if (!strcmp(addressstring, serverlist_cache[n].info.cname))
+                       break;
+       if (n == serverlist_cachecount)
+       {
+               // LAN search doesnt require an answer from the master server so we wont
+               // know the ping nor will it be initialized already...
+
+               // find a slot
+               if (serverlist_cachecount == SERVERLIST_TOTALSIZE)
+                       return -1;
+
+               memset(&serverlist_cache[serverlist_cachecount], 0, sizeof(serverlist_cache[serverlist_cachecount]));
+               // store the data the engine cares about (address and ping)
+               strlcpy(serverlist_cache[serverlist_cachecount].info.cname, addressstring, sizeof(serverlist_cache[serverlist_cachecount].info.cname));
+               serverlist_cache[serverlist_cachecount].info.ping = 100000;
+               //serverlist_cache[serverlist_cachecount].querytime = realtime;
+               serverlist_cache[serverlist_cachecount].querytime = Sys_DoubleTime();
+               // if not in the slist menu we should print the server to console
+               if (serverlist_consoleoutput)
+                       Con_Printf("querying %s\n", addressstring);
+               ++serverlist_cachecount;
+       }
+       // if this is the first reply from this server, count it as having replied
+       if (serverlist_cache[n].info.ping == 100000)
+               serverreplycount++;
+       pingtime = (int)((Sys_DoubleTime() - serverlist_cache[n].querytime) * 1000.0 + 0.5);
+       pingtime = bound(0, pingtime, 9999);
+       // update the ping
+       serverlist_cache[n].info.ping = min(serverlist_cache[n].info.ping, pingtime);
+       // other server info is updated by the caller
+       return n;
+}
+
+static void NetConn_ClientParsePacket_ServerList_UpdateCache(int n)
+{
+       serverlist_info_t *info = &serverlist_cache[n].info;
+       // update description strings for engine menu and console output
+       dpsnprintf(serverlist_cache[n].line1, sizeof(serverlist_cache[n].line1), "^%c%5d^7 ^%c%3u^7/%3u %-65.65s", info->ping >= 300 ? '1' : (info->ping >= 200 ? '3' : '7'), (int)info->ping, ((info->numplayers > 0 && info->numplayers < info->maxplayers) ? (info->numplayers >= 4 ? '7' : '3') : '1'), info->numplayers, info->maxplayers, info->name);
+       dpsnprintf(serverlist_cache[n].line2, sizeof(serverlist_cache[n].line2), "^4%-21.21s %-19.19s ^%c%-17.17s^4 %-20.20s", info->cname, info->game, (info->gameversion != gameversion.integer) ? '1' : '4', info->mod, info->map);
+       if (serverlist_cache[n].query == SQS_QUERIED)
+               ServerList_ViewList_Remove(&serverlist_cache[n]);
+       // if not in the slist menu we should print the server to console (if wanted)
+       else if( serverlist_consoleoutput )
+               Con_Printf("%s\n%s\n", serverlist_cache[n].line1, serverlist_cache[n].line2);
+       // and finally, update the view set
+       ServerList_ViewList_Insert( &serverlist_cache[n] );
+       serverlist_cache[n].query = SQS_QUERIED;
+}
+
 static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *data, int length, lhnetaddress_t *peeraddress)
 {
        qboolean fromserver;
        int ret, c, control;
        const char *s;
-       char *string, addressstring2[128], cname[128], ipstring[32];
+       char *string, addressstring2[128], ipstring[32];
        char stringbuf[16384];
 
        // quakeworld ingame packet
        fromserver = cls.netcon && mysocket == cls.netcon->mysocket && !LHNETADDRESS_Compare(&cls.netcon->peeraddress, peeraddress);
 
+       // convert the address to a string incase we need it
+       LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
+
        if (length >= 5 && data[0] == 255 && data[1] == 255 && data[2] == 255 && data[3] == 255)
        {
                // received a command string - strip off the packaging and put it
@@ -1094,8 +1174,6 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                stringbuf[length] = 0;
                string = stringbuf;
 
-               LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
-
                if (developer_networking.integer)
                {
                        Con_Printf("NetConn_ClientParsePacket: %s sent us a command:\n", addressstring2);
@@ -1109,18 +1187,12 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        Protocol_Names(protocolnames, sizeof(protocolnames));
                        Con_Printf("\"%s\" received, sending connect request back to %s\n", string, addressstring2);
                        M_Update_Return_Reason("Got challenge response");
+                       // update the server IP in the userinfo (QW servers expect this, and it is used by the reconnect command)
+                       InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "*ip", addressstring2);
+                       // TODO: add userinfo stuff here instead of using NQ commands?
                        NetConn_WriteString(mysocket, va("\377\377\377\377connect\\protocol\\darkplaces 3\\protocols\\%s\\challenge\\%s", protocolnames, string + 10), peeraddress);
                        return true;
                }
-               if (length > 1 && string[0] == 'c' && (string[1] == '-' || (string[1] >= '0' && string[1] <= '9')))
-               {
-                       // quakeworld
-                       LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
-                       Con_Printf("\"%s\" received, sending QuakeWorld connect request back to %s\n", string, addressstring2);
-                       M_Update_Return_Reason("Got QuakeWorld challenge response");
-                       cls.qw_qport = qport.integer;
-                       NetConn_WriteString(mysocket, va("\377\377\377\377connect 28 %i %i \"%s\"\n", cls.qw_qport, atoi(string + 1), cls.userinfo), peeraddress);
-               }
                if (length == 6 && !memcmp(string, "accept", 6) && cls.connect_trying)
                {
                        // darkplaces or quake3
@@ -1128,13 +1200,6 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        NetConn_ConnectionEstablished(mysocket, peeraddress, PROTOCOL_DARKPLACES3);
                        return true;
                }
-               if (length > 1 && string[0] == 'j' && cls.connect_trying)
-               {
-                       // quakeworld
-                       M_Update_Return_Reason("QuakeWorld Accepted");
-                       NetConn_ConnectionEstablished(mysocket, peeraddress, PROTOCOL_QUAKEWORLD);
-                       return true;
-               }
                if (length > 7 && !memcmp(string, "reject ", 7) && cls.connect_trying)
                {
                        char rejectreason[32];
@@ -1150,36 +1215,12 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                {
                        serverlist_info_t *info;
                        int n;
-                       double pingtime;
 
                        string += 13;
-                       // serverlist only uses text addresses
-                       LHNETADDRESS_ToString(peeraddress, cname, sizeof(cname), true);
                        // search the cache for this server and update it
-                       for( n = 0; n < serverlist_cachecount; n++ )
-                               if( !strcmp( cname, serverlist_cache[n].info.cname ) )
-                                       break;
-                       if( n == serverlist_cachecount ) {
-                               // LAN search doesnt require an answer from the master server so we wont
-                               // know the ping nor will it be initialized already...
-
-                               // find a slot
-                               if( serverlist_cachecount == SERVERLIST_TOTALSIZE )
-                                       return true;
-
-                               memset(&serverlist_cache[serverlist_cachecount], 0, sizeof(serverlist_cache[serverlist_cachecount]));
-                               // store the data the engine cares about (address and ping)
-                               strlcpy (serverlist_cache[serverlist_cachecount].info.cname, cname, sizeof (serverlist_cache[serverlist_cachecount].info.cname));
-                               serverlist_cache[serverlist_cachecount].info.ping = 100000;
-                               //serverlist_cache[serverlist_cachecount].querytime = realtime;
-                               serverlist_cache[serverlist_cachecount].querytime = Sys_DoubleTime();
-                               // if not in the slist menu we should print the server to console
-                               if (serverlist_consoleoutput) {
-                                       Con_Printf("querying %s\n", ipstring);
-                               }
-
-                               ++serverlist_cachecount;
-                       }
+                       n = NetConn_ClientParsePacket_ServerList_ProcessReply(addressstring2);
+                       if (n < 0)
+                               return true;
 
                        info = &serverlist_cache[n].info;
                        if ((s = SearchInfostring(string, "gamename"     )) != NULL) strlcpy(info->game, s, sizeof (info->game));else info->game[0] = 0;
@@ -1191,28 +1232,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        if ((s = SearchInfostring(string, "sv_maxclients")) != NULL) info->maxplayers = atoi(s);else info->maxplayers  = 0;
                        if ((s = SearchInfostring(string, "gameversion"  )) != NULL) info->gameversion = atoi(s);else info->gameversion = 0;
 
-                       if (info->ping == 100000)
-                                       serverreplycount++;
-
-                       pingtime = (int)((Sys_DoubleTime() - serverlist_cache[n].querytime) * 1000.0 + 0.5);
-                       pingtime = bound(0, pingtime, 9999);
-                       // update the ping
-                       info->ping = pingtime;
-
-                       // legacy/old stuff move it to the menu ASAP
-
-                       // build description strings for the things users care about
-                       dpsnprintf(serverlist_cache[n].line1, sizeof(serverlist_cache[n].line1), "^%c%5d^7 ^%c%3u^7/%3u %-65.65s", pingtime >= 300 ? '1' : (pingtime >= 200 ? '3' : '7'), (int)pingtime, ((info->numplayers > 0 && info->numplayers < info->maxplayers) ? (info->numplayers >= 4 ? '7' : '3') : '1'), info->numplayers, info->maxplayers, info->name);
-                       dpsnprintf(serverlist_cache[n].line2, sizeof(serverlist_cache[n].line2), "^5%-21.21s %-19.19s ^%c%-17.17s^5 %-20.20s", info->cname, info->game, (info->gameversion != gameversion.integer) ? '1' : '5', info->mod, info->map);
-                       if( serverlist_cache[n].query == SQS_QUERIED ) {
-                               ServerList_ViewList_Remove( &serverlist_cache[n] );
-                       }
-                       // if not in the slist menu we should print the server to console (if wanted)
-                       else if( serverlist_consoleoutput )
-                               Con_Printf("%s\n%s\n", serverlist_cache[n].line1, serverlist_cache[n].line2);
-                       // and finally, update the view set
-                       ServerList_ViewList_Insert( &serverlist_cache[n] );
-                       serverlist_cache[n].query = SQS_QUERIED;
+                       NetConn_ClientParsePacket_ServerList_UpdateCache(n);
 
                        return true;
                }
@@ -1268,7 +1288,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        length -= 2;
                        masterreplycount++;
                        if (serverlist_consoleoutput)
-                               Con_Print("received QuakeWorld server list...\n");
+                               Con_Printf("received QuakeWorld server list from %s...\n", addressstring2);
                        while (length >= 6 && (data[0] != 0xFF || data[1] != 0xFF || data[2] != 0xFF || data[3] != 0xFF) && data[4] * 256 + data[5] != 0)
                        {
                                int n;
@@ -1306,80 +1326,48 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        serverlist_querywaittime = realtime + 3;
                        return true;
                }
-               /*
                if (!strncmp(string, "ping", 4))
                {
-                       if (developer.integer)
-                               Con_Printf("Received ping from %s, sending ack\n", UDP_AddrToString(readaddr));
+                       if (developer.integer >= 10)
+                               Con_Printf("Received ping from %s, sending ack\n", addressstring2);
                        NetConn_WriteString(mysocket, "\377\377\377\377ack", peeraddress);
                        return true;
                }
                if (!strncmp(string, "ack", 3))
                        return true;
-               */
                // QuakeWorld compatibility
-               if (length >= 1 && string[0] == 'j' && cls.connect_trying)
-               {
-                       // accept message
-                       M_Update_Return_Reason("Accepted");
-                       NetConn_ConnectionEstablished(mysocket, peeraddress, PROTOCOL_QUAKEWORLD);
-                       return true;
-               }
-               if (length > 1 && string[0] == 'c' && string[1] >= '0' && string[1] <= '9' && cls.connect_trying)
+               if (length > 1 && string[0] == 'c' && (string[1] == '-' || (string[1] >= '0' && string[1] <= '9')) && cls.connect_trying)
                {
                        // challenge message
-                       LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
-                       Con_Printf("challenge %s received, sending connect request back to %s\n", string + 1, addressstring2);
-                       M_Update_Return_Reason("Got challenge response");
+                       Con_Printf("challenge %s received, sending QuakeWorld connect request back to %s\n", string + 1, addressstring2);
+                       M_Update_Return_Reason("Got QuakeWorld challenge response");
                        cls.qw_qport = qport.integer;
+                       // update the server IP in the userinfo (QW servers expect this, and it is used by the reconnect command)
                        InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "*ip", addressstring2);
-                       InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "name", cl_name.string);
-                       InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "topcolor", va("%i", (cl_color.integer >> 4) & 15));
-                       InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "bottomcolor", va("%i", (cl_color.integer) & 15));
-                       InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "rate", va("%i", cl_rate.integer));
-                       InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "msg", "1");
-                       InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "*ver", engineversion);
                        NetConn_WriteString(mysocket, va("\377\377\377\377connect %i %i %i \"%s\"\n", 28, cls.qw_qport, atoi(string + 1), cls.userinfo), peeraddress);
                        return true;
                }
+               if (length >= 1 && string[0] == 'j' && cls.connect_trying)
+               {
+                       // accept message
+                       M_Update_Return_Reason("QuakeWorld Accepted");
+                       NetConn_ConnectionEstablished(mysocket, peeraddress, PROTOCOL_QUAKEWORLD);
+                       return true;
+               }
                if (length > 2 && !memcmp(string, "n\\", 2))
                {
                        serverlist_info_t *info;
                        int n;
-                       double pingtime;
 
                        // qw server status
                        if (serverlist_consoleoutput && developer_networking.integer >= 2)
                                Con_Printf("QW server status from server at %s:\n%s\n", addressstring2, string + 1);
 
                        string += 1;
-                       // serverlist only uses text addresses
-                       LHNETADDRESS_ToString(peeraddress, cname, sizeof(cname), true);
                        // search the cache for this server and update it
-                       for( n = 0; n < serverlist_cachecount; n++ )
-                               if( !strcmp( cname, serverlist_cache[n].info.cname ) )
-                                       break;
-                       if( n == serverlist_cachecount ) {
-                               // LAN search doesnt require an answer from the master server so we wont
-                               // know the ping nor will it be initialized already...
-
-                               // find a slot
-                               if( serverlist_cachecount == SERVERLIST_TOTALSIZE )
-                                       return true;
-
-                               memset(&serverlist_cache[serverlist_cachecount], 0, sizeof(serverlist_cache[serverlist_cachecount]));
-                               // store the data the engine cares about (address and ping)
-                               strlcpy (serverlist_cache[serverlist_cachecount].info.cname, cname, sizeof (serverlist_cache[serverlist_cachecount].info.cname));
-                               serverlist_cache[serverlist_cachecount].info.ping = 100000;
-                               //serverlist_cache[serverlist_cachecount].querytime = realtime;
-                               serverlist_cache[serverlist_cachecount].querytime = Sys_DoubleTime();
-                               // if not in the slist menu we should print the server to console
-                               if (serverlist_consoleoutput) {
-                                       Con_Printf("querying %s\n", ipstring);
-                               }
-
-                               ++serverlist_cachecount;
-                       }
+                       n = NetConn_ClientParsePacket_ServerList_ProcessReply(addressstring2);
+                       if (n < 0)
+                               return true;
 
                        info = &serverlist_cache[n].info;
                        strlcpy(info->game, "QuakeWorld", sizeof(info->game));;
@@ -1408,28 +1396,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                                }
                        }
 
-                       if (info->ping == 100000)
-                                       serverreplycount++;
-
-                       pingtime = (int)((Sys_DoubleTime() - serverlist_cache[n].querytime) * 1000.0 + 0.5);
-                       pingtime = bound(0, pingtime, 9999);
-                       // update the ping
-                       info->ping = pingtime;
-
-                       // legacy/old stuff move it to the menu ASAP
-
-                       // build description strings for the things users care about
-                       dpsnprintf(serverlist_cache[n].line1, sizeof(serverlist_cache[n].line1), "^%c%5d^7 ^%c%3u^7/%3u %-65.65s", pingtime >= 300 ? '1' : (pingtime >= 200 ? '3' : '7'), (int)pingtime, ((info->numplayers > 0 && info->numplayers < info->maxplayers) ? (info->numplayers >= 4 ? '7' : '3') : '1'), info->numplayers, info->maxplayers, info->name);
-                       dpsnprintf(serverlist_cache[n].line2, sizeof(serverlist_cache[n].line2), "^4%-21.21s %-19.19s ^%c%-17.17s^4 %-20.20s", info->cname, info->game, (info->gameversion != gameversion.integer) ? '1' : '4', info->mod, info->map);
-                       if( serverlist_cache[n].query == SQS_QUERIED ) {
-                               ServerList_ViewList_Remove( &serverlist_cache[n] );
-                       }
-                       // if not in the slist menu we should print the server to console (if wanted)
-                       else if( serverlist_consoleoutput )
-                               Con_Printf("%s\n%s\n", serverlist_cache[n].line1, serverlist_cache[n].line2);
-                       // and finally, update the view set
-                       ServerList_ViewList_Insert( &serverlist_cache[n] );
-                       serverlist_cache[n].query = SQS_QUERIED;
+                       NetConn_ClientParsePacket_ServerList_UpdateCache(n);
 
                        return true;
                }
@@ -1452,14 +1419,16 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
        // netquake control packets, supported for compatibility only
        if (length >= 5 && (control = BigLong(*((int *)data))) && (control & (~NETFLAG_LENGTH_MASK)) == (int)NETFLAG_CTL && (control & NETFLAG_LENGTH_MASK) == length)
        {
+               int n;
+               serverlist_info_t *info;
+
                c = data[4];
                data += 5;
                length -= 5;
-               LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
                switch (c)
                {
                case CCREP_ACCEPT:
-                       if (developer.integer)
+                       if (developer.integer >= 10)
                                Con_Printf("Datagram_ParseConnectionless: received CCREP_ACCEPT from %s.\n", addressstring2);
                        if (cls.connect_trying)
                        {
@@ -1473,61 +1442,51 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                                        LHNETADDRESS_SetPort(&clientportaddress, port);
                                }
                                M_Update_Return_Reason("Accepted");
+                               // update the server IP in the userinfo (QW servers expect this, and it is used by the reconnect command)
+                               InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "*ip", addressstring2);
                                NetConn_ConnectionEstablished(mysocket, &clientportaddress, PROTOCOL_QUAKE);
                        }
                        break;
                case CCREP_REJECT:
-                       if (developer.integer)
+                       if (developer.integer >= 10)
                                Con_Printf("Datagram_ParseConnectionless: received CCREP_REJECT from %s.\n", addressstring2);
                        cls.connect_trying = false;
                        M_Update_Return_Reason((char *)data);
                        break;
-#if 0
+               // TODO: fix this code so that lan searches for quake servers will work
                case CCREP_SERVER_INFO:
-                       if (developer.integer)
+                       if (developer.integer >= 10)
                                Con_Printf("Datagram_ParseConnectionless: received CCREP_SERVER_INFO from %s.\n", addressstring2);
-                       if (cls.state != ca_dedicated)
-                       {
-                               // LordHavoc: because the UDP driver reports 0.0.0.0:26000 as the address
-                               // string we just ignore it and keep the real address
-                               MSG_ReadString();
-                               // serverlist only uses text addresses
-                               cname = UDP_AddrToString(readaddr);
-                               // search the cache for this server
-                               for (n = 0; n < hostCacheCount; n++)
-                                       if (!strcmp(cname, serverlist[n].cname))
-                                               break;
-                               // add it
-                               if (n == hostCacheCount && hostCacheCount < SERVERLISTSIZE)
-                               {
-                                       hostCacheCount++;
-                                       memset(&serverlist[n], 0, sizeof(serverlist[n]));
-                                       strlcpy (serverlist[n].name, MSG_ReadString(), sizeof (serverlist[n].name));
-                                       strlcpy (serverlist[n].map, MSG_ReadString(), sizeof (serverlist[n].map));
-                                       serverlist[n].users = MSG_ReadByte();
-                                       serverlist[n].maxusers = MSG_ReadByte();
-                                       c = MSG_ReadByte();
-                                       if (c != NET_PROTOCOL_VERSION)
-                                       {
-                                               strlcpy (serverlist[n].cname, serverlist[n].name, sizeof (serverlist[n].cname));
-                                               strcpy(serverlist[n].name, "*");
-                                               strlcat (serverlist[n].name, serverlist[n].cname, sizeof(serverlist[n].name));
-                                       }
-                                       strlcpy (serverlist[n].cname, cname, sizeof (serverlist[n].cname));
-                               }
-                       }
+                       // LordHavoc: because the quake server may report weird addresses
+                       // we just ignore it and keep the real address
+                       MSG_ReadString();
+                       // search the cache for this server and update it
+                       n = NetConn_ClientParsePacket_ServerList_ProcessReply(addressstring2);
+                       if (n < 0)
+                               break;
+
+                       info = &serverlist_cache[n].info;
+                       strlcpy(info->game, "Quake", sizeof(info->game));
+                       strlcpy(info->mod , "", sizeof(info->mod)); // mod name is not specified
+                       strlcpy(info->name, MSG_ReadString(), sizeof(info->name));
+                       strlcpy(info->map , MSG_ReadString(), sizeof(info->map));
+                       info->numplayers = MSG_ReadByte();
+                       info->maxplayers = MSG_ReadByte();
+                       info->protocol = MSG_ReadByte();
+
+                       NetConn_ClientParsePacket_ServerList_UpdateCache(n);
+
                        break;
                case CCREP_PLAYER_INFO:
                        // we got a CCREP_PLAYER_INFO??
-                       //if (developer.integer)
+                       //if (developer.integer >= 10)
                                Con_Printf("Datagram_ParseConnectionless: received CCREP_PLAYER_INFO from %s.\n", addressstring2);
                        break;
                case CCREP_RULE_INFO:
                        // we got a CCREP_RULE_INFO??
-                       //if (developer.integer)
+                       //if (developer.integer >= 10)
                                Con_Printf("Datagram_ParseConnectionless: received CCREP_RULE_INFO from %s.\n", addressstring2);
                        break;
-#endif
                default:
                        break;
                }
@@ -1558,7 +1517,7 @@ void NetConn_QueryQueueFrame(void)
                return;
 
        // each time querycounter reaches 1.0 issue a query
-       querycounter += host_realframetime * net_slist_queriespersecond.value;
+       querycounter += cl.realframetime * net_slist_queriespersecond.value;
        maxqueries = (int)querycounter;
        maxqueries = bound(0, maxqueries, net_slist_queriesperframe.integer);
        querycounter -= maxqueries;
@@ -1767,6 +1726,12 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
        netconn_t *conn;
        char *s, *string, response[1400], addressstring2[128], stringbuf[16384];
 
+       if (!sv.active)
+               return false;
+
+       // convert the address to a string incase we need it
+       LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
+
        // see if we can identify the sender as a local player
        // (this is necessary for rcon to send a reliable reply if the client is
        //  actually on the server, not sending remotely)
@@ -1776,431 +1741,423 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
        if (i == svs.maxclients)
                host_client = NULL;
 
-       if (sv.active)
+       if (length >= 5 && data[0] == 255 && data[1] == 255 && data[2] == 255 && data[3] == 255)
        {
-               if (length >= 5 && data[0] == 255 && data[1] == 255 && data[2] == 255 && data[3] == 255)
+               // received a command string - strip off the packaging and put it
+               // into our string buffer with NULL termination
+               data += 4;
+               length -= 4;
+               length = min(length, (int)sizeof(stringbuf) - 1);
+               memcpy(stringbuf, data, length);
+               stringbuf[length] = 0;
+               string = stringbuf;
+
+               if (developer.integer >= 10)
+               {
+                       Con_Printf("NetConn_ServerParsePacket: %s sent us a command:\n", addressstring2);
+                       Com_HexDumpToConsole(data, length);
+               }
+
+               if (length >= 12 && !memcmp(string, "getchallenge", 12))
                {
-                       // received a command string - strip off the packaging and put it
-                       // into our string buffer with NULL termination
-                       data += 4;
-                       length -= 4;
-                       length = min(length, (int)sizeof(stringbuf) - 1);
-                       memcpy(stringbuf, data, length);
-                       stringbuf[length] = 0;
-                       string = stringbuf;
-
-                       if (developer.integer)
+                       for (i = 0, best = 0, besttime = realtime;i < MAX_CHALLENGES;i++)
                        {
-                               LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
-                               Con_Printf("NetConn_ServerParsePacket: %s sent us a command:\n", addressstring2);
-                               Com_HexDumpToConsole(data, length);
+                               if (!LHNETADDRESS_Compare(peeraddress, &challenge[i].address))
+                                       break;
+                               if (besttime > challenge[i].time)
+                                       besttime = challenge[best = i].time;
                        }
-
-                       if (length >= 12 && !memcmp(string, "getchallenge", 12))
+                       // if we did not find an exact match, choose the oldest and
+                       // update address and string
+                       if (i == MAX_CHALLENGES)
                        {
-                               for (i = 0, best = 0, besttime = realtime;i < MAX_CHALLENGES;i++)
-                               {
-                                       if (!LHNETADDRESS_Compare(peeraddress, &challenge[i].address))
-                                               break;
-                                       if (besttime > challenge[i].time)
-                                               besttime = challenge[best = i].time;
-                               }
-                               // if we did not find an exact match, choose the oldest and
-                               // update address and string
-                               if (i == MAX_CHALLENGES)
-                               {
-                                       i = best;
-                                       challenge[i].address = *peeraddress;
-                                       NetConn_BuildChallengeString(challenge[i].string, sizeof(challenge[i].string));
-                               }
-                               challenge[i].time = realtime;
-                               // send the challenge
-                               NetConn_WriteString(mysocket, va("\377\377\377\377challenge %s", challenge[i].string), peeraddress);
-                               return true;
+                               i = best;
+                               challenge[i].address = *peeraddress;
+                               NetConn_BuildChallengeString(challenge[i].string, sizeof(challenge[i].string));
                        }
-                       if (length > 8 && !memcmp(string, "connect\\", 8))
+                       challenge[i].time = realtime;
+                       // send the challenge
+                       NetConn_WriteString(mysocket, va("\377\377\377\377challenge %s", challenge[i].string), peeraddress);
+                       return true;
+               }
+               if (length > 8 && !memcmp(string, "connect\\", 8))
+               {
+                       string += 7;
+                       length -= 7;
+                       if ((s = SearchInfostring(string, "challenge")))
                        {
-                               string += 7;
-                               length -= 7;
-                               if ((s = SearchInfostring(string, "challenge")))
+                               // validate the challenge
+                               for (i = 0;i < MAX_CHALLENGES;i++)
+                                       if (!LHNETADDRESS_Compare(peeraddress, &challenge[i].address) && !strcmp(challenge[i].string, s))
+                                               break;
+                               if (i < MAX_CHALLENGES)
                                {
-                                       // validate the challenge
-                                       for (i = 0;i < MAX_CHALLENGES;i++)
-                                               if (!LHNETADDRESS_Compare(peeraddress, &challenge[i].address) && !strcmp(challenge[i].string, s))
-                                                       break;
-                                       if (i < MAX_CHALLENGES)
+                                       // check engine protocol
+                                       if (strcmp(SearchInfostring(string, "protocol"), "darkplaces 3"))
                                        {
-                                               // check engine protocol
-                                               if (strcmp(SearchInfostring(string, "protocol"), "darkplaces 3"))
+                                               if (developer.integer >= 10)
+                                                       Con_Printf("Datagram_ParseConnectionless: sending \"reject Wrong game protocol.\" to %s.\n", addressstring2);
+                                               NetConn_WriteString(mysocket, "\377\377\377\377reject Wrong game protocol.", peeraddress);
+                                       }
+                                       else
+                                       {
+                                               // see if this is a duplicate connection request
+                                               for (clientnum = 0, client = svs.clients;clientnum < svs.maxclients;clientnum++, client++)
+                                                       if (client->netconnection && LHNETADDRESS_Compare(peeraddress, &client->netconnection->peeraddress) == 0)
+                                                               break;
+                                               if (clientnum < svs.maxclients && realtime - client->connecttime < net_messagerejointimeout.value)
                                                {
-                                                       if (developer.integer)
-                                                               Con_Printf("Datagram_ParseConnectionless: sending \"reject Wrong game protocol.\" to %s.\n", addressstring2);
-                                                       NetConn_WriteString(mysocket, "\377\377\377\377reject Wrong game protocol.", peeraddress);
+                                                       // client is still trying to connect,
+                                                       // so we send a duplicate reply
+                                                       if (developer.integer >= 10)
+                                                               Con_Printf("Datagram_ParseConnectionless: sending duplicate accept to %s.\n", addressstring2);
+                                                       NetConn_WriteString(mysocket, "\377\377\377\377accept", peeraddress);
+                                               }
+#if 0
+                                               else if (clientnum < svs.maxclients)
+                                               {
+                                                       if (realtime - client->netconnection->lastMessageTime >= net_messagerejointimeout.value)
+                                                       {
+                                                               // client crashed and is coming back, keep their stuff intact
+                                                               SV_SendServerinfo(client);
+                                                               //host_client = client;
+                                                               //SV_DropClient (true);
+                                                       }
+                                                       // else ignore them
                                                }
+#endif
                                                else
                                                {
-                                                       // see if this is a duplicate connection request
+                                                       // this is a new client, find a slot
                                                        for (clientnum = 0, client = svs.clients;clientnum < svs.maxclients;clientnum++, client++)
-                                                               if (client->netconnection && LHNETADDRESS_Compare(peeraddress, &client->netconnection->peeraddress) == 0)
+                                                               if (!client->active)
                                                                        break;
-                                                       if (clientnum < svs.maxclients && realtime - client->connecttime < net_messagerejointimeout.value)
-                                                       {
-                                                               // client is still trying to connect,
-                                                               // so we send a duplicate reply
-                                                               if (developer.integer)
-                                                                       Con_Printf("Datagram_ParseConnectionless: sending duplicate accept to %s.\n", addressstring2);
-                                                               NetConn_WriteString(mysocket, "\377\377\377\377accept", peeraddress);
-                                                       }
-#if 0
-                                                       else if (clientnum < svs.maxclients)
+                                                       if (clientnum < svs.maxclients)
                                                        {
-                                                               if (realtime - client->netconnection->lastMessageTime >= net_messagerejointimeout.value)
+                                                               // prepare the client struct
+                                                               if ((conn = NetConn_Open(mysocket, peeraddress)))
                                                                {
-                                                                       // client crashed and is coming back, keep their stuff intact
-                                                                       SV_SendServerinfo(client);
-                                                                       //host_client = client;
-                                                                       //SV_DropClient (true);
+                                                                       // allocated connection
+                                                                       if (developer.integer >= 10)
+                                                                               Con_Printf("Datagram_ParseConnectionless: sending \"accept\" to %s.\n", conn->address);
+                                                                       NetConn_WriteString(mysocket, "\377\377\377\377accept", peeraddress);
+                                                                       // now set up the client
+                                                                       SV_VM_Begin();
+                                                                       SV_ConnectClient(clientnum, conn);
+                                                                       SV_VM_End();
+                                                                       NetConn_Heartbeat(1);
                                                                }
-                                                               // else ignore them
                                                        }
-#endif
                                                        else
                                                        {
-                                                               // this is a new client, find a slot
-                                                               for (clientnum = 0, client = svs.clients;clientnum < svs.maxclients;clientnum++, client++)
-                                                                       if (!client->active)
-                                                                               break;
-                                                               if (clientnum < svs.maxclients)
-                                                               {
-                                                                       // prepare the client struct
-                                                                       if ((conn = NetConn_Open(mysocket, peeraddress)))
-                                                                       {
-                                                                               // allocated connection
-                                                                               LHNETADDRESS_ToString(peeraddress, conn->address, sizeof(conn->address), true);
-                                                                               if (developer.integer)
-                                                                                       Con_Printf("Datagram_ParseConnectionless: sending \"accept\" to %s.\n", conn->address);
-                                                                               NetConn_WriteString(mysocket, "\377\377\377\377accept", peeraddress);
-                                                                               // now set up the client
-                                                                               SV_VM_Begin();
-                                                                               SV_ConnectClient(clientnum, conn);
-                                                                               SV_VM_End();
-                                                                               NetConn_Heartbeat(1);
-                                                                       }
-                                                               }
-                                                               else
-                                                               {
-                                                                       // server is full
-                                                                       if (developer.integer)
-                                                                               Con_Printf("Datagram_ParseConnectionless: sending \"reject Server is full.\" to %s.\n", addressstring2);
-                                                                       NetConn_WriteString(mysocket, "\377\377\377\377reject Server is full.", peeraddress);
-                                                               }
+                                                               // server is full
+                                                               if (developer.integer >= 10)
+                                                                       Con_Printf("Datagram_ParseConnectionless: sending \"reject Server is full.\" to %s.\n", addressstring2);
+                                                               NetConn_WriteString(mysocket, "\377\377\377\377reject Server is full.", peeraddress);
                                                        }
                                                }
                                        }
                                }
-                               return true;
                        }
-                       if (length >= 7 && !memcmp(string, "getinfo", 7))
-                       {
-                               const char *challenge = NULL;
+                       return true;
+               }
+               if (length >= 7 && !memcmp(string, "getinfo", 7))
+               {
+                       const char *challenge = NULL;
 
-                               // If there was a challenge in the getinfo message
-                               if (length > 8 && string[7] == ' ')
-                                       challenge = string + 8;
+                       // If there was a challenge in the getinfo message
+                       if (length > 8 && string[7] == ' ')
+                               challenge = string + 8;
 
-                               if (NetConn_BuildStatusResponse(challenge, response, sizeof(response), false))
-                               {
-                                       if (developer.integer)
-                                               Con_Printf("Sending reply to master %s - %s\n", addressstring2, response);
-                                       NetConn_WriteString(mysocket, response, peeraddress);
-                               }
-                               return true;
-                       }
-                       if (length >= 9 && !memcmp(string, "getstatus", 9))
+                       if (NetConn_BuildStatusResponse(challenge, response, sizeof(response), false))
                        {
-                               const char *challenge = NULL;
+                               if (developer.integer >= 10)
+                                       Con_Printf("Sending reply to master %s - %s\n", addressstring2, response);
+                               NetConn_WriteString(mysocket, response, peeraddress);
+                       }
+                       return true;
+               }
+               if (length >= 9 && !memcmp(string, "getstatus", 9))
+               {
+                       const char *challenge = NULL;
 
-                               // If there was a challenge in the getinfo message
-                               if (length > 10 && string[9] == ' ')
-                                       challenge = string + 10;
+                       // If there was a challenge in the getinfo message
+                       if (length > 10 && string[9] == ' ')
+                               challenge = string + 10;
 
-                               if (NetConn_BuildStatusResponse(challenge, response, sizeof(response), true))
-                               {
-                                       if (developer.integer)
-                                               Con_Printf("Sending reply to client %s - %s\n", addressstring2, response);
-                                       NetConn_WriteString(mysocket, response, peeraddress);
-                               }
-                               return true;
+                       if (NetConn_BuildStatusResponse(challenge, response, sizeof(response), true))
+                       {
+                               if (developer.integer >= 10)
+                                       Con_Printf("Sending reply to client %s - %s\n", addressstring2, response);
+                               NetConn_WriteString(mysocket, response, peeraddress);
                        }
-                       if (length >= 5 && !memcmp(string, "rcon ", 5))
+                       return true;
+               }
+               if (length >= 5 && !memcmp(string, "rcon ", 5))
+               {
+                       int i;
+                       char *s = string + 5;
+                       char password[64];
+                       for (i = 0;*s > ' ';s++)
+                               if (i < (int)sizeof(password) - 1)
+                                       password[i++] = *s;
+                       password[i] = 0;
+                       if (password[0] > ' ' && !strcmp(rcon_password.string, password))
                        {
-                               int i;
-                               char *s = string + 5;
-                               char password[64];
-                               for (i = 0;*s > ' ';s++)
-                                       if (i < (int)sizeof(password) - 1)
-                                               password[i++] = *s;
-                               password[i] = 0;
-                               if (password[0] > ' ' && !strcmp(rcon_password.string, password))
+                               // looks like a legitimate rcon command with the correct password
+                               Con_Printf("server received rcon command from %s:\n%s\n", host_client ? host_client->name : addressstring2, s);
+                               rcon_redirect = true;
+                               rcon_redirect_bufferpos = 0;
+                               Cmd_ExecuteString(s, src_command);
+                               rcon_redirect_buffer[rcon_redirect_bufferpos] = 0;
+                               rcon_redirect = false;
+                               // print resulting text to client
+                               // if client is playing, send a reliable reply instead of
+                               // a command packet
+                               if (host_client)
                                {
-                                       // looks like a legitimate rcon command with the correct password
-                                       Con_Printf("server received rcon command from %s:\n%s\n", host_client ? host_client->name : addressstring2, s);
-                                       rcon_redirect = true;
-                                       rcon_redirect_bufferpos = 0;
-                                       Cmd_ExecuteString(s, src_command);
-                                       rcon_redirect_buffer[rcon_redirect_bufferpos] = 0;
-                                       rcon_redirect = false;
-                                       // print resulting text to client
-                                       // if client is playing, send a reliable reply instead of
-                                       // a command packet
-                                       if (host_client)
-                                       {
-                                               // if the netconnection is loop, then this is the
-                                               // local player on a listen mode server, and it would
-                                               // result in duplicate printing to the console
-                                               // (not that the local player should be using rcon
-                                               //  when they have the console)
-                                               if (host_client->netconnection && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP)
-                                                       SV_ClientPrintf("%s", rcon_redirect_buffer);
-                                       }
-                                       else
-                                       {
-                                               // qw print command
-                                               dpsnprintf(response, sizeof(response), "\377\377\377\377n%s", rcon_redirect_buffer);
-                                               NetConn_WriteString(mysocket, response, peeraddress);
-                                       }
+                                       // if the netconnection is loop, then this is the
+                                       // local player on a listen mode server, and it would
+                                       // result in duplicate printing to the console
+                                       // (not that the local player should be using rcon
+                                       //  when they have the console)
+                                       if (host_client->netconnection && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP)
+                                               SV_ClientPrintf("%s", rcon_redirect_buffer);
+                               }
+                               else
+                               {
+                                       // qw print command
+                                       dpsnprintf(response, sizeof(response), "\377\377\377\377n%s", rcon_redirect_buffer);
+                                       NetConn_WriteString(mysocket, response, peeraddress);
                                }
-                               return true;
-                       }
-                       /*
-                       if (!strncmp(string, "ping", 4))
-                       {
-                               if (developer.integer)
-                                       Con_Printf("Received ping from %s, sending ack\n", UDP_AddrToString(readaddr));
-                               NetConn_WriteString(mysocket, "\377\377\377\377ack", peeraddress);
-                               return true;
                        }
-                       if (!strncmp(string, "ack", 3))
-                               return true;
-                       */
-                       // we may not have liked the packet, but it was a command packet, so
-                       // we're done processing this packet now
                        return true;
                }
-               // LordHavoc: disabled netquake control packet support in server
+               if (!strncmp(string, "ping", 4))
+               {
+                       if (developer.integer >= 10)
+                               Con_Printf("Received ping from %s, sending ack\n", addressstring2);
+                       NetConn_WriteString(mysocket, "\377\377\377\377ack", peeraddress);
+                       return true;
+               }
+               if (!strncmp(string, "ack", 3))
+                       return true;
+               // we may not have liked the packet, but it was a command packet, so
+               // we're done processing this packet now
+               return true;
+       }
+       // LordHavoc: disabled netquake control packet support in server
 #if 0
+       {
+               int c, control;
+               // netquake control packets, supported for compatibility only
+               if (length >= 5 && (control = BigLong(*((int *)data))) && (control & (~NETFLAG_LENGTH_MASK)) == (int)NETFLAG_CTL && (control & NETFLAG_LENGTH_MASK) == length)
                {
-                       int c, control;
-                       // netquake control packets, supported for compatibility only
-                       if (length >= 5 && (control = BigLong(*((int *)data))) && (control & (~NETFLAG_LENGTH_MASK)) == (int)NETFLAG_CTL && (control & NETFLAG_LENGTH_MASK) == length)
+                       c = data[4];
+                       data += 5;
+                       length -= 5;
+                       switch (c)
                        {
-                               c = data[4];
-                               data += 5;
-                               length -= 5;
-                               LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
-                               switch (c)
+                       case CCREQ_CONNECT:
+                               if (developer.integer >= 10)
+                                       Con_Printf("Datagram_ParseConnectionless: received CCREQ_CONNECT from %s.\n", addressstring2);
+                               if (length >= (int)strlen("QUAKE") + 1 + 1)
                                {
-                               case CCREQ_CONNECT:
-                                       //if (developer.integer)
-                                               Con_Printf("Datagram_ParseConnectionless: received CCREQ_CONNECT from %s.\n", addressstring2);
-                                       if (length >= (int)strlen("QUAKE") + 1 + 1)
+                                       if (memcmp(data, "QUAKE", strlen("QUAKE") + 1) != 0 || (int)data[strlen("QUAKE") + 1] != NET_PROTOCOL_VERSION)
                                        {
-                                               if (memcmp(data, "QUAKE", strlen("QUAKE") + 1) != 0 || (int)data[strlen("QUAKE") + 1] != NET_PROTOCOL_VERSION)
+                                               if (developer.integer >= 10)
+                                                       Con_Printf("Datagram_ParseConnectionless: sending CCREP_REJECT \"Incompatible version.\" to %s.\n", addressstring2);
+                                               SZ_Clear(&net_message);
+                                               // save space for the header, filled in later
+                                               MSG_WriteLong(&net_message, 0);
+                                               MSG_WriteByte(&net_message, CCREP_REJECT);
+                                               MSG_WriteString(&net_message, "Incompatible version.\n");
+                                               *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
+                                               NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
+                                               SZ_Clear(&net_message);
+                                       }
+                                       else
+                                       {
+                                               // see if this is a duplicate connection request
+                                               for (clientnum = 0, client = svs.clients;clientnum < svs.maxclients;clientnum++, client++)
+                                                       if (client->netconnection && LHNETADDRESS_Compare(peeraddress, &client->netconnection->peeraddress) == 0)
+                                                               break;
+                                               if (clientnum < svs.maxclients)
                                                {
-                                                       if (developer.integer)
-                                                               Con_Printf("Datagram_ParseConnectionless: sending CCREP_REJECT \"Incompatible version.\" to %s.\n", addressstring2);
-                                                       SZ_Clear(&net_message);
-                                                       // save space for the header, filled in later
-                                                       MSG_WriteLong(&net_message, 0);
-                                                       MSG_WriteByte(&net_message, CCREP_REJECT);
-                                                       MSG_WriteString(&net_message, "Incompatible version.\n");
-                                                       *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
-                                                       NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
-                                                       SZ_Clear(&net_message);
+                                                       // duplicate connection request
+                                                       if (realtime - client->connecttime < 2.0)
+                                                       {
+                                                               // client is still trying to connect,
+                                                               // so we send a duplicate reply
+                                                               if (developer.integer >= 10)
+                                                                       Con_Printf("Datagram_ParseConnectionless: sending duplicate CCREP_ACCEPT to %s.\n", addressstring2);
+                                                               SZ_Clear(&net_message);
+                                                               // save space for the header, filled in later
+                                                               MSG_WriteLong(&net_message, 0);
+                                                               MSG_WriteByte(&net_message, CCREP_ACCEPT);
+                                                               MSG_WriteLong(&net_message, LHNETADDRESS_GetPort(LHNET_AddressFromSocket(client->netconnection->mysocket)));
+                                                               *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
+                                                               NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
+                                                               SZ_Clear(&net_message);
+                                                       }
+#if 0
+                                                       else if (realtime - client->netconnection->lastMessageTime >= net_messagerejointimeout.value)
+                                                       {
+                                                               SV_SendServerinfo(client);
+                                                               // the old client hasn't sent us anything
+                                                               // in quite a while, so kick off and let
+                                                               // the retry take care of it...
+                                                               //host_client = client;
+                                                               //SV_DropClient (true);
+                                                       }
+#endif
                                                }
                                                else
                                                {
-                                                       // see if this is a duplicate connection request
+                                                       // this is a new client, find a slot
                                                        for (clientnum = 0, client = svs.clients;clientnum < svs.maxclients;clientnum++, client++)
-                                                               if (client->netconnection && LHNETADDRESS_Compare(peeraddress, &client->netconnection->peeraddress) == 0)
+                                                               if (!client->active)
                                                                        break;
-                                                       if (clientnum < svs.maxclients)
+                                                       if (clientnum < svs.maxclients && (client->netconnection = conn = NetConn_Open(mysocket, peeraddress)) != NULL)
                                                        {
-                                                               // duplicate connection request
-                                                               if (realtime - client->connecttime < 2.0)
-                                                               {
-                                                                       // client is still trying to connect,
-                                                                       // so we send a duplicate reply
-                                                                       if (developer.integer)
-                                                                               Con_Printf("Datagram_ParseConnectionless: sending duplicate CCREP_ACCEPT to %s.\n", addressstring2);
-                                                                       SZ_Clear(&net_message);
-                                                                       // save space for the header, filled in later
-                                                                       MSG_WriteLong(&net_message, 0);
-                                                                       MSG_WriteByte(&net_message, CCREP_ACCEPT);
-                                                                       MSG_WriteLong(&net_message, LHNETADDRESS_GetPort(LHNET_AddressFromSocket(client->netconnection->mysocket)));
-                                                                       *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
-                                                                       NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
-                                                                       SZ_Clear(&net_message);
-                                                               }
-#if 0
-                                                               else if (realtime - client->netconnection->lastMessageTime >= net_messagerejointimeout.value)
-                                                               {
-                                                                       SV_SendServerinfo(client);
-                                                                       // the old client hasn't sent us anything
-                                                                       // in quite a while, so kick off and let
-                                                                       // the retry take care of it...
-                                                                       //host_client = client;
-                                                                       //SV_DropClient (true);
-                                                               }
-#endif
+                                                               // connect to the client
+                                                               // everything is allocated, just fill in the details
+                                                               strlcpy (conn->address, addressstring2, sizeof (conn->address));
+                                                               if (developer.integer >= 10)
+                                                                       Con_Printf("Datagram_ParseConnectionless: sending CCREP_ACCEPT to %s.\n", addressstring2);
+                                                               // send back the info about the server connection
+                                                               SZ_Clear(&net_message);
+                                                               // save space for the header, filled in later
+                                                               MSG_WriteLong(&net_message, 0);
+                                                               MSG_WriteByte(&net_message, CCREP_ACCEPT);
+                                                               MSG_WriteLong(&net_message, LHNETADDRESS_GetPort(LHNET_AddressFromSocket(conn->mysocket)));
+                                                               *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
+                                                               NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
+                                                               SZ_Clear(&net_message);
+                                                               // now set up the client struct
+                                                               SV_VM_Begin();
+                                                               SV_ConnectClient(clientnum, conn);
+                                                               SV_VM_End();
+                                                               NetConn_Heartbeat(1);
                                                        }
                                                        else
                                                        {
-                                                               // this is a new client, find a slot
-                                                               for (clientnum = 0, client = svs.clients;clientnum < svs.maxclients;clientnum++, client++)
-                                                                       if (!client->active)
-                                                                               break;
-                                                               if (clientnum < svs.maxclients && (client->netconnection = conn = NetConn_Open(mysocket, peeraddress)) != NULL)
-                                                               {
-                                                                       // connect to the client
-                                                                       // everything is allocated, just fill in the details
-                                                                       strlcpy (conn->address, addressstring2, sizeof (conn->address));
-                                                                       if (developer.integer)
-                                                                               Con_Printf("Datagram_ParseConnectionless: sending CCREP_ACCEPT to %s.\n", addressstring2);
-                                                                       // send back the info about the server connection
-                                                                       SZ_Clear(&net_message);
-                                                                       // save space for the header, filled in later
-                                                                       MSG_WriteLong(&net_message, 0);
-                                                                       MSG_WriteByte(&net_message, CCREP_ACCEPT);
-                                                                       MSG_WriteLong(&net_message, LHNETADDRESS_GetPort(LHNET_AddressFromSocket(conn->mysocket)));
-                                                                       *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
-                                                                       NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
-                                                                       SZ_Clear(&net_message);
-                                                                       // now set up the client struct
-                                                                       SV_VM_Begin();
-                                                                       SV_ConnectClient(clientnum, conn);
-                                                                       SV_VM_End();
-                                                                       NetConn_Heartbeat(1);
-                                                               }
-                                                               else
-                                                               {
-                                                                       //if (developer.integer)
-                                                                               Con_Printf("Datagram_ParseConnectionless: sending CCREP_REJECT \"Server is full.\" to %s.\n", addressstring2);
-                                                                       // no room; try to let player know
-                                                                       SZ_Clear(&net_message);
-                                                                       // save space for the header, filled in later
-                                                                       MSG_WriteLong(&net_message, 0);
-                                                                       MSG_WriteByte(&net_message, CCREP_REJECT);
-                                                                       MSG_WriteString(&net_message, "Server is full.\n");
-                                                                       *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
-                                                                       NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
-                                                                       SZ_Clear(&net_message);
-                                                               }
+                                                               if (developer.integer >= 10)
+                                                                       Con_Printf("Datagram_ParseConnectionless: sending CCREP_REJECT \"Server is full.\" to %s.\n", addressstring2);
+                                                               // no room; try to let player know
+                                                               SZ_Clear(&net_message);
+                                                               // save space for the header, filled in later
+                                                               MSG_WriteLong(&net_message, 0);
+                                                               MSG_WriteByte(&net_message, CCREP_REJECT);
+                                                               MSG_WriteString(&net_message, "Server is full.\n");
+                                                               *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
+                                                               NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
+                                                               SZ_Clear(&net_message);
                                                        }
                                                }
                                        }
-                                       break;
+                               }
+                               break;
 #if 0
-                               case CCREQ_SERVER_INFO:
-                                       if (developer.integer)
-                                               Con_Printf("Datagram_ParseConnectionless: received CCREQ_SERVER_INFO from %s.\n", addressstring2);
-                                       if (sv.active && !strcmp(MSG_ReadString(), "QUAKE"))
+                       case CCREQ_SERVER_INFO:
+                               if (developer.integer >= 10)
+                                       Con_Printf("Datagram_ParseConnectionless: received CCREQ_SERVER_INFO from %s.\n", addressstring2);
+                               if (sv.active && !strcmp(MSG_ReadString(), "QUAKE"))
+                               {
+                                       if (developer.integer >= 10)
+                                               Con_Printf("Datagram_ParseConnectionless: sending CCREP_SERVER_INFO to %s.\n", addressstring2);
+                                       SZ_Clear(&net_message);
+                                       // save space for the header, filled in later
+                                       MSG_WriteLong(&net_message, 0);
+                                       MSG_WriteByte(&net_message, CCREP_SERVER_INFO);
+                                       UDP_GetSocketAddr(UDP_acceptSock, &newaddr);
+                                       MSG_WriteString(&net_message, UDP_AddrToString(&newaddr));
+                                       MSG_WriteString(&net_message, hostname.string);
+                                       MSG_WriteString(&net_message, sv.name);
+                                       MSG_WriteByte(&net_message, net_activeconnections);
+                                       MSG_WriteByte(&net_message, svs.maxclients);
+                                       MSG_WriteByte(&net_message, NET_PROTOCOL_VERSION);
+                                       *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
+                                       NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
+                                       SZ_Clear(&net_message);
+                               }
+                               break;
+                       case CCREQ_PLAYER_INFO:
+                               if (developer.integer >= 10)
+                                       Con_Printf("Datagram_ParseConnectionless: received CCREQ_PLAYER_INFO from %s.\n", addressstring2);
+                               if (sv.active)
+                               {
+                                       int playerNumber, activeNumber, clientNumber;
+                                       client_t *client;
+
+                                       playerNumber = MSG_ReadByte();
+                                       activeNumber = -1;
+                                       for (clientNumber = 0, client = svs.clients; clientNumber < svs.maxclients; clientNumber++, client++)
+                                               if (client->active && ++activeNumber == playerNumber)
+                                                       break;
+                                       if (clientNumber != svs.maxclients)
                                        {
-                                               if (developer.integer)
-                                                       Con_Printf("Datagram_ParseConnectionless: sending CCREP_SERVER_INFO to %s.\n", addressstring2);
                                                SZ_Clear(&net_message);
                                                // save space for the header, filled in later
                                                MSG_WriteLong(&net_message, 0);
-                                               MSG_WriteByte(&net_message, CCREP_SERVER_INFO);
-                                               UDP_GetSocketAddr(UDP_acceptSock, &newaddr);
-                                               MSG_WriteString(&net_message, UDP_AddrToString(&newaddr));
-                                               MSG_WriteString(&net_message, hostname.string);
-                                               MSG_WriteString(&net_message, sv.name);
-                                               MSG_WriteByte(&net_message, net_activeconnections);
-                                               MSG_WriteByte(&net_message, svs.maxclients);
-                                               MSG_WriteByte(&net_message, NET_PROTOCOL_VERSION);
+                                               MSG_WriteByte(&net_message, CCREP_PLAYER_INFO);
+                                               MSG_WriteByte(&net_message, playerNumber);
+                                               MSG_WriteString(&net_message, client->name);
+                                               MSG_WriteLong(&net_message, client->colors);
+                                               MSG_WriteLong(&net_message, (int)client->edict->fields.server->frags);
+                                               MSG_WriteLong(&net_message, (int)(realtime - client->connecttime));
+                                               MSG_WriteString(&net_message, client->netconnection ? client->netconnection->address : "botclient");
                                                *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
                                                NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
                                                SZ_Clear(&net_message);
                                        }
-                                       break;
-                               case CCREQ_PLAYER_INFO:
-                                       if (developer.integer)
-                                               Con_Printf("Datagram_ParseConnectionless: received CCREQ_PLAYER_INFO from %s.\n", addressstring2);
-                                       if (sv.active)
-                                       {
-                                               int playerNumber, activeNumber, clientNumber;
-                                               client_t *client;
-
-                                               playerNumber = MSG_ReadByte();
-                                               activeNumber = -1;
-                                               for (clientNumber = 0, client = svs.clients; clientNumber < svs.maxclients; clientNumber++, client++)
-                                                       if (client->active && ++activeNumber == playerNumber)
-                                                               break;
-                                               if (clientNumber != svs.maxclients)
-                                               {
-                                                       SZ_Clear(&net_message);
-                                                       // save space for the header, filled in later
-                                                       MSG_WriteLong(&net_message, 0);
-                                                       MSG_WriteByte(&net_message, CCREP_PLAYER_INFO);
-                                                       MSG_WriteByte(&net_message, playerNumber);
-                                                       MSG_WriteString(&net_message, client->name);
-                                                       MSG_WriteLong(&net_message, client->colors);
-                                                       MSG_WriteLong(&net_message, (int)client->edict->fields.server->frags);
-                                                       MSG_WriteLong(&net_message, (int)(realtime - client->connecttime));
-                                                       MSG_WriteString(&net_message, client->netconnection ? client->netconnection->address : "botclient");
-                                                       *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
-                                                       NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
-                                                       SZ_Clear(&net_message);
-                                               }
-                                       }
-                                       break;
-                               case CCREQ_RULE_INFO:
-                                       if (developer.integer)
-                                               Con_Printf("Datagram_ParseConnectionless: received CCREQ_RULE_INFO from %s.\n", addressstring2);
-                                       if (sv.active)
+                               }
+                               break;
+                       case CCREQ_RULE_INFO:
+                               if (developer.integer >= 10)
+                                       Con_Printf("Datagram_ParseConnectionless: received CCREQ_RULE_INFO from %s.\n", addressstring2);
+                               if (sv.active)
+                               {
+                                       char *prevCvarName;
+                                       cvar_t *var;
+
+                                       // find the search start location
+                                       prevCvarName = MSG_ReadString();
+                                       var = Cvar_FindVarAfter(prevCvarName, CVAR_NOTIFY);
+
+                                       // send the response
+                                       SZ_Clear(&net_message);
+                                       // save space for the header, filled in later
+                                       MSG_WriteLong(&net_message, 0);
+                                       MSG_WriteByte(&net_message, CCREP_RULE_INFO);
+                                       if (var)
                                        {
-                                               char *prevCvarName;
-                                               cvar_t *var;
-
-                                               // find the search start location
-                                               prevCvarName = MSG_ReadString();
-                                               var = Cvar_FindVarAfter(prevCvarName, CVAR_NOTIFY);
-
-                                               // send the response
-                                               SZ_Clear(&net_message);
-                                               // save space for the header, filled in later
-                                               MSG_WriteLong(&net_message, 0);
-                                               MSG_WriteByte(&net_message, CCREP_RULE_INFO);
-                                               if (var)
-                                               {
-                                                       MSG_WriteString(&net_message, var->name);
-                                                       MSG_WriteString(&net_message, var->string);
-                                               }
-                                               *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
-                                               NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
-                                               SZ_Clear(&net_message);
+                                               MSG_WriteString(&net_message, var->name);
+                                               MSG_WriteString(&net_message, var->string);
                                        }
-                                       break;
-#endif
-                               default:
-                                       break;
+                                       *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
+                                       NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
+                                       SZ_Clear(&net_message);
                                }
-                               // we may not have liked the packet, but it was a valid control
-                               // packet, so we're done processing this packet now
-                               return true;
+                               break;
+#endif
+                       default:
+                               break;
                        }
+                       // we may not have liked the packet, but it was a valid control
+                       // packet, so we're done processing this packet now
+                       return true;
                }
+       }
 #endif
-               if (host_client)
+       if (host_client)
+       {
+               if ((ret = NetConn_ReceivedMessage(host_client->netconnection, data, length, sv.protocol)) == 2)
                {
-                       if ((ret = NetConn_ReceivedMessage(host_client->netconnection, data, length, sv.protocol)) == 2)
-                       {
-                               SV_VM_Begin();
-                               SV_ReadClientMessage();
-                               SV_VM_End();
-                               return ret;
-                       }
+                       SV_VM_Begin();
+                       SV_ReadClientMessage();
+                       SV_VM_End();
+                       return ret;
                }
        }
        return 0;
@@ -2210,7 +2167,6 @@ void NetConn_ServerFrame(void)
 {
        int i, length;
        lhnetaddress_t peeraddress;
-       NetConn_UpdateSockets();
        for (i = 0;i < sv_numsockets;i++)
                while (sv_sockets[i] && (length = NetConn_Read(sv_sockets[i], readbuffer, sizeof(readbuffer), &peeraddress)) > 0)
                        NetConn_ServerParsePacket(sv_sockets[i], readbuffer, length, &peeraddress);
@@ -2269,7 +2225,7 @@ void NetConn_QueryMasters(qboolean querydp, qboolean queryqw)
                                // search internet
                                for (masternum = 0;sv_masters[masternum].name;masternum++)
                                {
-                                       if (sv_masters[masternum].string && LHNETADDRESS_FromString(&masteraddress, sv_masters[masternum].string, DPMASTER_PORT) && LHNETADDRESS_GetAddressType(&masteraddress) == LHNETADDRESS_GetAddressType(LHNET_AddressFromSocket(cl_sockets[i])))
+                                       if (sv_masters[masternum].string && sv_masters[masternum].string[0] && LHNETADDRESS_FromString(&masteraddress, sv_masters[masternum].string, DPMASTER_PORT) && LHNETADDRESS_GetAddressType(&masteraddress) == LHNETADDRESS_GetAddressType(LHNET_AddressFromSocket(cl_sockets[i])))
                                        {
                                                masterquerycount++;
                                                NetConn_WriteString(cl_sockets[i], request, &masteraddress);
@@ -2286,6 +2242,9 @@ void NetConn_QueryMasters(qboolean querydp, qboolean queryqw)
                {
                        if (cl_sockets[i])
                        {
+                               // search LAN for QuakeWorld servers
+                               NetConn_WriteString(cl_sockets[i], "\377\377\377\377status\n", &broadcastaddress);
+
                                // build the getservers message to send to the qwmaster master servers
                                // note this has no -1 prefix, and the trailing nul byte is sent
                                dpsnprintf(request, sizeof(request), "c\n");
@@ -2295,8 +2254,14 @@ void NetConn_QueryMasters(qboolean querydp, qboolean queryqw)
                                {
                                        if (sv_qwmasters[masternum].string && LHNETADDRESS_FromString(&masteraddress, sv_qwmasters[masternum].string, QWMASTER_PORT) && LHNETADDRESS_GetAddressType(&masteraddress) == LHNETADDRESS_GetAddressType(LHNET_AddressFromSocket(cl_sockets[i])))
                                        {
+                                               if (m_state != m_slist)
+                                               {
+                                                       char lookupstring[128];
+                                                       LHNETADDRESS_ToString(&masteraddress, lookupstring, sizeof(lookupstring), true);
+                                                       Con_Printf("Querying master %s (resolved from %s)\n", lookupstring, sv_qwmasters[masternum].string);
+                                               }
                                                masterquerycount++;
-                                               NetConn_Write(cl_sockets[i], request, 7, &masteraddress);
+                                               NetConn_Write(cl_sockets[i], request, (int)strlen(request) + 1, &masteraddress);
                                        }
                                }
                        }
@@ -2335,7 +2300,7 @@ void NetConn_Heartbeat(int priority)
        {
                nextheartbeattime = realtime + sv_heartbeatperiod.value;
                for (masternum = 0;sv_masters[masternum].name;masternum++)
-                       if (sv_masters[masternum].string && LHNETADDRESS_FromString(&masteraddress, sv_masters[masternum].string, DPMASTER_PORT) && (mysocket = NetConn_ChooseServerSocketForAddress(&masteraddress)))
+                       if (sv_masters[masternum].string && sv_masters[masternum].string[0] && LHNETADDRESS_FromString(&masteraddress, sv_masters[masternum].string, DPMASTER_PORT) && (mysocket = NetConn_ChooseServerSocketForAddress(&masteraddress)))
                                NetConn_WriteString(mysocket, "\377\377\377\377heartbeat DarkPlaces\x0A", &masteraddress);
        }
 }