]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - netconn.c
split up net_slist into net_slist and net_slistqw, and modified menu accordingly...
[xonotic/darkplaces.git] / netconn.c
index 883c43dd1901147119efaf27fd7469554021581a..4a6ea050cf48a564f778dd11a794b6bc651224d2 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -86,6 +86,8 @@ static cvar_t net_slist_queriesperframe = {0, "net_slist_queriesperframe", "4",
 static cvar_t net_slist_timeout = {0, "net_slist_timeout", "4", "how long to listen for a server information response before giving up"};
 static cvar_t net_slist_maxtries = {0, "net_slist_maxtries", "3", "how many times to ask the same server for information (more times gives better ping reports but takes longer)"};
 
 static cvar_t net_slist_timeout = {0, "net_slist_timeout", "4", "how long to listen for a server information response before giving up"};
 static cvar_t net_slist_maxtries = {0, "net_slist_maxtries", "3", "how many times to ask the same server for information (more times gives better ping reports but takes longer)"};
 
+static cvar_t gameversion = {0, "gameversion", "0", "version of game data (mod-specific), when client and server gameversion mismatch in the server browser the server is shown as incompatible"};
+
 /* statistic counters */
 static int packetsSent = 0;
 static int packetsReSent = 0;
 /* statistic counters */
 static int packetsSent = 0;
 static int packetsReSent = 0;
@@ -105,7 +107,11 @@ int serverquerycount = 0;
 int serverreplycount = 0;
 
 // this is only false if there are still servers left to query
 int serverreplycount = 0;
 
 // this is only false if there are still servers left to query
-int serverlist_querysleep = true;
+static qboolean serverlist_querysleep = true;
+// this is pushed a second or two ahead of realtime whenever a master server
+// reply is received, to avoid issuing queries while master replies are still
+// flooding in (which would make a mess of the ping times)
+static double serverlist_querywaittime = 0;
 
 static unsigned char sendbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
 static unsigned char readbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
 
 static unsigned char sendbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
 static unsigned char readbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
@@ -298,6 +304,10 @@ static void ServerList_ViewList_Insert( serverlist_entry_t *entry )
 {
        int start, end, mid;
 
 {
        int start, end, mid;
 
+       // reject incompatible servers
+       if (entry->info.gameversion != gameversion.integer)
+               return;
+
        // FIXME: change this to be more readable (...)
        // now check whether it passes through the masks
        for( start = 0 ; serverlist_andmasks[start].active && start < SERVERLIST_ANDMASKCOUNT ; start++ )
        // FIXME: change this to be more readable (...)
        // now check whether it passes through the masks
        for( start = 0 ; serverlist_andmasks[start].active && start < SERVERLIST_ANDMASKCOUNT ; start++ )
@@ -387,9 +397,10 @@ static void _ServerList_Test(void)
 }
 #endif
 
 }
 #endif
 
-void ServerList_QueryList(void)
+void ServerList_QueryList(qboolean querydp, qboolean queryqw)
 {
 {
-       masterquerytime = realtime;
+       //masterquerytime = realtime;
+       masterquerytime = Sys_DoubleTime();
        masterquerycount = 0;
        masterreplycount = 0;
        serverquerycount = 0;
        masterquerycount = 0;
        masterreplycount = 0;
        serverquerycount = 0;
@@ -400,7 +411,7 @@ void ServerList_QueryList(void)
 
        //_ServerList_Test();
 
 
        //_ServerList_Test();
 
-       NetConn_QueryMasters();
+       NetConn_QueryMasters(querydp, queryqw);
 }
 
 // rest
 }
 
 // rest
@@ -1085,7 +1096,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
 
                LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
 
 
                LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
 
-               if (developer.integer)
+               if (developer_networking.integer)
                {
                        Con_Printf("NetConn_ClientParsePacket: %s sent us a command:\n", addressstring2);
                        Com_HexDumpToConsole(data, length);
                {
                        Con_Printf("NetConn_ClientParsePacket: %s sent us a command:\n", addressstring2);
                        Com_HexDumpToConsole(data, length);
@@ -1160,7 +1171,8 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                                // 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;
                                // 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 = 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);
                                // if not in the slist menu we should print the server to console
                                if (serverlist_consoleoutput) {
                                        Con_Printf("querying %s\n", ipstring);
@@ -1177,11 +1189,12 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        if ((s = SearchInfostring(string, "protocol"     )) != NULL) info->protocol = atoi(s);else info->protocol = -1;
                        if ((s = SearchInfostring(string, "clients"      )) != NULL) info->numplayers = atoi(s);else info->numplayers = 0;
                        if ((s = SearchInfostring(string, "sv_maxclients")) != NULL) info->maxplayers = atoi(s);else info->maxplayers  = 0;
                        if ((s = SearchInfostring(string, "protocol"     )) != NULL) info->protocol = atoi(s);else info->protocol = -1;
                        if ((s = SearchInfostring(string, "clients"      )) != NULL) info->numplayers = atoi(s);else info->numplayers = 0;
                        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++;
 
 
                        if (info->ping == 100000)
                                        serverreplycount++;
 
-                       pingtime = (int)((realtime - serverlist_cache[n].querytime) * 1000.0);
+                       pingtime = (int)((Sys_DoubleTime() - serverlist_cache[n].querytime) * 1000.0 + 0.5);
                        pingtime = bound(0, pingtime, 9999);
                        // update the ping
                        info->ping = pingtime;
                        pingtime = bound(0, pingtime, 9999);
                        // update the ping
                        info->ping = pingtime;
@@ -1189,8 +1202,8 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        // legacy/old stuff move it to the menu ASAP
 
                        // build description strings for the things users care about
                        // 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%c%5d%c%c%c%3u/%3u %-65.65s", STRING_COLOR_TAG, pingtime >= 300 ? '1' : (pingtime >= 200 ? '3' : '7'), (int)pingtime, STRING_COLOR_TAG, STRING_COLOR_DEFAULT + '0', info->protocol != NET_PROTOCOL_VERSION ? '*' : ' ', info->numplayers, info->maxplayers, info->name);
-                       dpsnprintf(serverlist_cache[n].line2, sizeof(serverlist_cache[n].line2), "%-21.21s %-19.19s %-17.17s %-20.20s", info->cname, info->game, info->mod, info->map);
+                       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( serverlist_cache[n].query == SQS_QUERIED ) {
                                ServerList_ViewList_Remove( &serverlist_cache[n] );
                        }
@@ -1216,7 +1229,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                                int n;
 
                                dpsnprintf (ipstring, sizeof (ipstring), "%u.%u.%u.%u:%u", data[1], data[2], data[3], data[4], data[5] * 256 + data[6]);
                                int n;
 
                                dpsnprintf (ipstring, sizeof (ipstring), "%u.%u.%u.%u:%u", data[1], data[2], data[3], data[4], data[5] * 256 + data[6]);
-                               if (developer.integer)
+                               if (serverlist_consoleoutput && developer_networking.integer)
                                        Con_Printf("Requesting info from DarkPlaces server %s\n", ipstring);
                                // ignore the rest of the message if the serverlist is full
                                if( serverlist_cachecount == SERVERLIST_TOTALSIZE )
                                        Con_Printf("Requesting info from DarkPlaces server %s\n", ipstring);
                                // ignore the rest of the message if the serverlist is full
                                if( serverlist_cachecount == SERVERLIST_TOTALSIZE )
@@ -1245,6 +1258,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        }
                        // begin or resume serverlist queries
                        serverlist_querysleep = false;
                        }
                        // begin or resume serverlist queries
                        serverlist_querysleep = false;
+                       serverlist_querywaittime = realtime + 3;
                        return true;
                }
                if (!memcmp(string, "d\n", 2) && serverlist_cachecount < SERVERLIST_TOTALSIZE)
                        return true;
                }
                if (!memcmp(string, "d\n", 2) && serverlist_cachecount < SERVERLIST_TOTALSIZE)
@@ -1260,7 +1274,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                                int n;
 
                                dpsnprintf (ipstring, sizeof (ipstring), "%u.%u.%u.%u:%u", data[0], data[1], data[2], data[3], data[4] * 256 + data[5]);
                                int n;
 
                                dpsnprintf (ipstring, sizeof (ipstring), "%u.%u.%u.%u:%u", data[0], data[1], data[2], data[3], data[4] * 256 + data[5]);
-                               if (developer.integer)
+                               if (serverlist_consoleoutput && developer_networking.integer)
                                        Con_Printf("Requesting info from QuakeWorld server %s\n", ipstring);
                                // ignore the rest of the message if the serverlist is full
                                if( serverlist_cachecount == SERVERLIST_TOTALSIZE )
                                        Con_Printf("Requesting info from QuakeWorld server %s\n", ipstring);
                                // ignore the rest of the message if the serverlist is full
                                if( serverlist_cachecount == SERVERLIST_TOTALSIZE )
@@ -1289,6 +1303,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        }
                        // begin or resume serverlist queries
                        serverlist_querysleep = false;
                        }
                        // begin or resume serverlist queries
                        serverlist_querysleep = false;
+                       serverlist_querywaittime = realtime + 3;
                        return true;
                }
                /*
                        return true;
                }
                /*
@@ -1334,7 +1349,8 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        double pingtime;
 
                        // qw server status
                        double pingtime;
 
                        // qw server status
-                       Con_Printf("QW server status from server at %s:\n%s\n", addressstring2, string + 1);
+                       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
 
                        string += 1;
                        // serverlist only uses text addresses
@@ -1355,7 +1371,8 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                                // 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;
                                // 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 = 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);
                                // if not in the slist menu we should print the server to console
                                if (serverlist_consoleoutput) {
                                        Con_Printf("querying %s\n", ipstring);
@@ -1365,18 +1382,36 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        }
 
                        info = &serverlist_cache[n].info;
                        }
 
                        info = &serverlist_cache[n].info;
-                       if ((s = SearchInfostring(string, "gamename"     )) != NULL) strlcpy(info->game, s, sizeof (info->game));else info->game[0] = 0;
-                       if ((s = SearchInfostring(string, "modname"      )) != NULL) strlcpy(info->mod , s, sizeof (info->mod ));else info->mod[0]  = 0;
-                       if ((s = SearchInfostring(string, "mapname"      )) != NULL) strlcpy(info->map , s, sizeof (info->map ));else info->map[0]  = 0;
+                       strlcpy(info->game, "QuakeWorld", sizeof(info->game));;
+                       if ((s = SearchInfostring(string, "*gamedir"     )) != NULL) strlcpy(info->mod , s, sizeof (info->mod ));else info->mod[0]  = 0;
+                       if ((s = SearchInfostring(string, "map"          )) != NULL) strlcpy(info->map , s, sizeof (info->map ));else info->map[0]  = 0;
                        if ((s = SearchInfostring(string, "hostname"     )) != NULL) strlcpy(info->name, s, sizeof (info->name));else info->name[0] = 0;
                        if ((s = SearchInfostring(string, "hostname"     )) != NULL) strlcpy(info->name, s, sizeof (info->name));else info->name[0] = 0;
-                       if ((s = SearchInfostring(string, "protocol"     )) != NULL) info->protocol = atoi(s);else info->protocol = -1;
-                       if ((s = SearchInfostring(string, "clients"      )) != NULL) info->numplayers = atoi(s);else info->numplayers = 0;
-                       if ((s = SearchInfostring(string, "sv_maxclients")) != NULL) info->maxplayers = atoi(s);else info->maxplayers  = 0;
+                       info->protocol = 0;
+                       info->numplayers = 0; // updated below
+                       if ((s = SearchInfostring(string, "maxclients"   )) != NULL) info->maxplayers = atoi(s);else info->maxplayers  = 0;
+                       if ((s = SearchInfostring(string, "gameversion"  )) != NULL) info->gameversion = atoi(s);else info->gameversion = 0;
+
+                       // count active players on server
+                       // (we could gather more info, but we're just after the number)
+                       s = strchr(string, '\n');
+                       if (s)
+                       {
+                               s++;
+                               while (s < string + length)
+                               {
+                                       for (;s < string + length && *s != '\n';s++)
+                                               ;
+                                       if (s >= string + length)
+                                               break;
+                                       info->numplayers++;
+                                       s++;
+                               }
+                       }
 
                        if (info->ping == 100000)
                                        serverreplycount++;
 
 
                        if (info->ping == 100000)
                                        serverreplycount++;
 
-                       pingtime = (int)((realtime - serverlist_cache[n].querytime) * 1000.0);
+                       pingtime = (int)((Sys_DoubleTime() - serverlist_cache[n].querytime) * 1000.0 + 0.5);
                        pingtime = bound(0, pingtime, 9999);
                        // update the ping
                        info->ping = pingtime;
                        pingtime = bound(0, pingtime, 9999);
                        // update the ping
                        info->ping = pingtime;
@@ -1384,8 +1419,8 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        // legacy/old stuff move it to the menu ASAP
 
                        // build description strings for the things users care about
                        // 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%c%5d%c%c%c%3u/%3u %-65.65s", STRING_COLOR_TAG, pingtime >= 300 ? '1' : (pingtime >= 200 ? '3' : '7'), (int)pingtime, STRING_COLOR_TAG, STRING_COLOR_DEFAULT + '0', info->protocol != NET_PROTOCOL_VERSION ? '*' : ' ', info->numplayers, info->maxplayers, info->name);
-                       dpsnprintf(serverlist_cache[n].line2, sizeof(serverlist_cache[n].line2), "%-21.21s %-19.19s %-17.17s %-20.20s", info->cname, info->game, info->mod, info->map);
+                       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( serverlist_cache[n].query == SQS_QUERIED ) {
                                ServerList_ViewList_Remove( &serverlist_cache[n] );
                        }
@@ -1517,6 +1552,11 @@ void NetConn_QueryQueueFrame(void)
        if (serverlist_querysleep)
                return;
 
        if (serverlist_querysleep)
                return;
 
+       // apply a cool down time after master server replies,
+       // to avoid messing up the ping times on the servers
+       if (serverlist_querywaittime > realtime)
+               return;
+
        // each time querycounter reaches 1.0 issue a query
        querycounter += host_realframetime * net_slist_queriespersecond.value;
        maxqueries = (int)querycounter;
        // each time querycounter reaches 1.0 issue a query
        querycounter += host_realframetime * net_slist_queriespersecond.value;
        maxqueries = (int)querycounter;
@@ -1562,7 +1602,8 @@ void NetConn_QueryQueueFrame(void)
                                        NetConn_WriteString(cl_sockets[socket], "\377\377\377\377getinfo", &address);
                        }
 
                                        NetConn_WriteString(cl_sockets[socket], "\377\377\377\377getinfo", &address);
                        }
 
-                       entry->querytime = realtime;
+                       //entry->querytime = realtime;
+                       entry->querytime = Sys_DoubleTime();
                        entry->querycounter++;
 
                        // if not in the slist menu we should print the server to console
                        entry->querycounter++;
 
                        // if not in the slist menu we should print the server to console
@@ -1657,12 +1698,12 @@ static qboolean NetConn_BuildStatusResponse(const char* challenge, char* out_msg
        // TODO: we should add more information for the full status string
        length = dpsnprintf(out_msg, out_size,
                                                "\377\377\377\377%s\x0A"
        // TODO: we should add more information for the full status string
        length = dpsnprintf(out_msg, out_size,
                                                "\377\377\377\377%s\x0A"
-                                               "\\gamename\\%s\\modname\\%s\\sv_maxclients\\%d"
-                                               "\\clients\\%d\\mapname\\%s\\hostname\\%s""\\protocol\\%d"
+                                               "\\gamename\\%s\\modname\\%s\\gameversion\\%d\\sv_maxclients\\%d"
+                                               "\\clients\\%d\\mapname\\%s\\hostname\\%s\\protocol\\%d"
                                                "%s%s"
                                                "%s",
                                                fullstatus ? "statusResponse" : "infoResponse",
                                                "%s%s"
                                                "%s",
                                                fullstatus ? "statusResponse" : "infoResponse",
-                                               gamename, com_modname, svs.maxclients,
+                                               gamename, com_modname, gameversion.integer, svs.maxclients,
                                                nb_clients, sv.name, hostname.string, NET_PROTOCOL_VERSION,
                                                challenge ? "\\challenge\\" : "", challenge ? challenge : "",
                                                fullstatus ? "\n" : "");
                                                nb_clients, sv.name, hostname.string, NET_PROTOCOL_VERSION,
                                                challenge ? "\\challenge\\" : "", challenge ? challenge : "",
                                                fullstatus ? "\n" : "");
@@ -2179,12 +2220,14 @@ void NetConn_ServerFrame(void)
                if (host_client->netconnection && realtime > host_client->netconnection->timeout && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP)
                {
                        Con_Printf("Client \"%s\" connection timed out\n", host_client->name);
                if (host_client->netconnection && realtime > host_client->netconnection->timeout && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP)
                {
                        Con_Printf("Client \"%s\" connection timed out\n", host_client->name);
+                       SV_VM_Begin();
                        SV_DropClient(false);
                        SV_DropClient(false);
+                       SV_VM_End();
                }
        }
 }
 
                }
        }
 }
 
-void NetConn_QueryMasters(void)
+void NetConn_QueryMasters(qboolean querydp, qboolean queryqw)
 {
        int i;
        int masternum;
 {
        int i;
        int masternum;
@@ -2200,48 +2243,61 @@ void NetConn_QueryMasters(void)
        // note this is IPv4-only, I doubt there are IPv6-only LANs out there
        LHNETADDRESS_FromString(&broadcastaddress, "255.255.255.255", 26000);
 
        // note this is IPv4-only, I doubt there are IPv6-only LANs out there
        LHNETADDRESS_FromString(&broadcastaddress, "255.255.255.255", 26000);
 
-       for (i = 0;i < cl_numsockets;i++)
+       if (querydp)
        {
        {
-               if (cl_sockets[i])
+               for (i = 0;i < cl_numsockets;i++)
                {
                {
-                       // search LAN for Quake servers
-                       SZ_Clear(&net_message);
-                       // save space for the header, filled in later
-                       MSG_WriteLong(&net_message, 0);
-                       MSG_WriteByte(&net_message, CCREQ_SERVER_INFO);
-                       MSG_WriteString(&net_message, "QUAKE");
-                       MSG_WriteByte(&net_message, NET_PROTOCOL_VERSION);
-                       *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
-                       NetConn_Write(cl_sockets[i], net_message.data, net_message.cursize, &broadcastaddress);
-                       SZ_Clear(&net_message);
-
-                       // search LAN for DarkPlaces servers
-                       NetConn_WriteString(cl_sockets[i], "\377\377\377\377getinfo", &broadcastaddress);
-
-                       // build the getservers message to send to the dpmaster master servers
-                       dpsnprintf(request, sizeof(request), "\377\377\377\377getservers %s %u empty full\x0A", gamename, NET_PROTOCOL_VERSION);
-
-                       // search internet
-                       for (masternum = 0;sv_masters[masternum].name;masternum++)
+                       if (cl_sockets[i])
                        {
                        {
-                               if (sv_masters[masternum].string && LHNETADDRESS_FromString(&masteraddress, sv_masters[masternum].string, DPMASTER_PORT) && LHNETADDRESS_GetAddressType(&masteraddress) == LHNETADDRESS_GetAddressType(LHNET_AddressFromSocket(cl_sockets[i])))
+                               // search LAN for Quake servers
+                               SZ_Clear(&net_message);
+                               // save space for the header, filled in later
+                               MSG_WriteLong(&net_message, 0);
+                               MSG_WriteByte(&net_message, CCREQ_SERVER_INFO);
+                               MSG_WriteString(&net_message, "QUAKE");
+                               MSG_WriteByte(&net_message, NET_PROTOCOL_VERSION);
+                               *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
+                               NetConn_Write(cl_sockets[i], net_message.data, net_message.cursize, &broadcastaddress);
+                               SZ_Clear(&net_message);
+
+                               // search LAN for DarkPlaces servers
+                               NetConn_WriteString(cl_sockets[i], "\377\377\377\377getinfo", &broadcastaddress);
+
+                               // build the getservers message to send to the dpmaster master servers
+                               dpsnprintf(request, sizeof(request), "\377\377\377\377getservers %s %u empty full\x0A", gamename, NET_PROTOCOL_VERSION);
+
+                               // search internet
+                               for (masternum = 0;sv_masters[masternum].name;masternum++)
                                {
                                {
-                                       masterquerycount++;
-                                       NetConn_WriteString(cl_sockets[i], request, &masteraddress);
+                                       if (sv_masters[masternum].string && 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);
+                                       }
                                }
                        }
                                }
                        }
+               }
+       }
 
 
-                       // 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");
-
-                       // search internet
-                       for (masternum = 0;sv_qwmasters[masternum].name;masternum++)
+       // only query QuakeWorld servers when the user wants to
+       if (queryqw)
+       {
+               for (i = 0;i < cl_numsockets;i++)
+               {
+                       if (cl_sockets[i])
                        {
                        {
-                               if (sv_qwmasters[masternum].string && LHNETADDRESS_FromString(&masteraddress, sv_qwmasters[masternum].string, QWMASTER_PORT) && LHNETADDRESS_GetAddressType(&masteraddress) == LHNETADDRESS_GetAddressType(LHNET_AddressFromSocket(cl_sockets[i])))
+                               // 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");
+
+                               // search internet
+                               for (masternum = 0;sv_qwmasters[masternum].name;masternum++)
                                {
                                {
-                                       masterquerycount++;
-                                       NetConn_Write(cl_sockets[i], request, 7, &masteraddress);
+                                       if (sv_qwmasters[masternum].string && LHNETADDRESS_FromString(&masteraddress, sv_qwmasters[masternum].string, QWMASTER_PORT) && LHNETADDRESS_GetAddressType(&masteraddress) == LHNETADDRESS_GetAddressType(LHNET_AddressFromSocket(cl_sockets[i])))
+                                       {
+                                               masterquerycount++;
+                                               NetConn_Write(cl_sockets[i], request, 7, &masteraddress);
+                                       }
                                }
                        }
                }
                                }
                        }
                }
@@ -2324,11 +2380,25 @@ void Net_Slist_f(void)
        serverlist_sortdescending = false;
     if (m_state != m_slist) {
                Con_Print("Sending requests to master servers\n");
        serverlist_sortdescending = false;
     if (m_state != m_slist) {
                Con_Print("Sending requests to master servers\n");
-               ServerList_QueryList();
+               ServerList_QueryList(true, false);
+               serverlist_consoleoutput = true;
+               Con_Print("Listening for replies...\n");
+       } else
+               ServerList_QueryList(true, false);
+}
+
+void Net_SlistQW_f(void)
+{
+       ServerList_ResetMasks();
+       serverlist_sortbyfield = SLIF_PING;
+       serverlist_sortdescending = false;
+    if (m_state != m_slist) {
+               Con_Print("Sending requests to master servers\n");
+               ServerList_QueryList(false, true);
                serverlist_consoleoutput = true;
                Con_Print("Listening for replies...\n");
        } else
                serverlist_consoleoutput = true;
                Con_Print("Listening for replies...\n");
        } else
-               ServerList_QueryList();
+               ServerList_QueryList(false, true);
 }
 
 void NetConn_Init(void)
 }
 
 void NetConn_Init(void)
@@ -2337,7 +2407,8 @@ void NetConn_Init(void)
        lhnetaddress_t tempaddress;
        netconn_mempool = Mem_AllocPool("network connections", 0, NULL);
        Cmd_AddCommand("net_stats", Net_Stats_f, "print network statistics");
        lhnetaddress_t tempaddress;
        netconn_mempool = Mem_AllocPool("network connections", 0, NULL);
        Cmd_AddCommand("net_stats", Net_Stats_f, "print network statistics");
-       Cmd_AddCommand("net_slist", Net_Slist_f, "query master series and print all server information");
+       Cmd_AddCommand("net_slist", Net_Slist_f, "query dp master servers and print all server information");
+       Cmd_AddCommand("net_slistqw", Net_SlistQW_f, "query qw master servers and print all server information");
        Cmd_AddCommand("heartbeat", Net_Heartbeat_f, "send a heartbeat to the master server (updates your server information)");
        Cvar_RegisterVariable(&net_slist_queriespersecond);
        Cvar_RegisterVariable(&net_slist_queriesperframe);
        Cmd_AddCommand("heartbeat", Net_Heartbeat_f, "send a heartbeat to the master server (updates your server information)");
        Cvar_RegisterVariable(&net_slist_queriespersecond);
        Cvar_RegisterVariable(&net_slist_queriesperframe);
@@ -2358,6 +2429,7 @@ void NetConn_Init(void)
        Cvar_RegisterVariable(&sv_heartbeatperiod);
        for (i = 0;sv_masters[i].name;i++)
                Cvar_RegisterVariable(&sv_masters[i]);
        Cvar_RegisterVariable(&sv_heartbeatperiod);
        for (i = 0;sv_masters[i].name;i++)
                Cvar_RegisterVariable(&sv_masters[i]);
+       Cvar_RegisterVariable(&gameversion);
 // COMMANDLINEOPTION: Server: -ip <ipaddress> sets the ip address of this machine for purposes of networking (default 0.0.0.0 also known as INADDR_ANY), use only if you have multiple network adapters and need to choose one specifically.
        if ((i = COM_CheckParm("-ip")) && i + 1 < com_argc)
        {
 // COMMANDLINEOPTION: Server: -ip <ipaddress> sets the ip address of this machine for purposes of networking (default 0.0.0.0 also known as INADDR_ANY), use only if you have multiple network adapters and need to choose one specifically.
        if ((i = COM_CheckParm("-ip")) && i + 1 < com_argc)
        {