]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - netconn.c
added r_shadow_glsl_geforcefxlowquality cvar (automatically on if running a GeForce...
[xonotic/darkplaces.git] / netconn.c
index cf380f8936f470dd71ad4cd4ca938035d8944419..0b7e0eb1148f07c879afa344c4edce42fad2f385 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -54,7 +54,10 @@ cvar_t developer_networking = {0, "developer_networking", "0"};
 
 cvar_t cl_netlocalping = {0, "cl_netlocalping","0"};
 static cvar_t cl_netpacketloss = {0, "cl_netpacketloss","0"};
-
+static cvar_t net_slist_queriespersecond = {0, "net_slist_queriespersecond", "20"};
+static cvar_t net_slist_queriesperframe = {0, "net_slist_queriesperframe", "4"};
+static cvar_t net_slist_timeout = {0, "net_slist_timeout", "4"};
+static cvar_t net_slist_maxtries = {0, "net_slist_maxtries", "3"};
 
 /* statistic counters */
 static int packetsSent = 0;
@@ -74,6 +77,9 @@ int masterreplycount = 0;
 int serverquerycount = 0;
 int serverreplycount = 0;
 
+// this is only false if there are still servers left to query
+int serverlist_querysleep = true;
+
 static qbyte sendbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
 static qbyte readbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
 
@@ -271,7 +277,7 @@ static void ServerList_ViewList_Insert( serverlist_entry_t *entry )
        if( !serverlist_viewcount ) {
                _ServerList_ViewList_Helper_InsertBefore( 0, entry );
                return;
-       } 
+       }
        // ok, insert it, we just need to find out where exactly:
 
        // two special cases
@@ -319,7 +325,7 @@ void ServerList_RebuildViewList(void)
 
        serverlist_viewcount = 0;
        for( i = 0 ; i < serverlist_cachecount ; i++ )
-               if( serverlist_cache[i].finished )
+               if( serverlist_cache[i].query == SQS_QUERIED )
                        ServerList_ViewList_Insert( &serverlist_cache[i] );
 }
 
@@ -355,9 +361,9 @@ void ServerList_QueryList(void)
        serverlist_cachecount = 0;
        serverlist_viewcount = 0;
        serverlist_consoleoutput = false;
-       
+
        //_ServerList_Test();
-       
+
        NetConn_QueryMasters();
 }
 
@@ -884,6 +890,10 @@ void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_t *peer
        M_Update_Return_Reason("");
        // the connection request succeeded, stop current connection and set up a new connection
        CL_Disconnect();
+       // if we're connecting to a remote server, shut down any local server
+       if (LHNETADDRESS_GetAddressType(peeraddress) != LHNETADDRESSTYPE_LOOP && sv.active)
+               Host_ShutdownServer (false);
+       // allocate a net connection to keep track of things
        cls.netcon = NetConn_Open(mysocket, peeraddress);
        Con_Printf("Connection accepted to %s\n", cls.netcon->address);
        key_dest = key_game;
@@ -903,7 +913,6 @@ int NetConn_IsLocalGame(void)
 int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length, lhnetaddress_t *peeraddress)
 {
        int ret, c, control;
-       lhnetaddress_t svaddress;
        const char *s;
        char *string, addressstring2[128], cname[128], ipstring[32];
        char stringbuf[16384];
@@ -973,7 +982,6 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
                                // find a slot
                                if( serverlist_cachecount == SERVERLIST_TOTALSIZE )
                                        return true;
-                               serverquerycount++;
 
                                memset(&serverlist_cache[serverlist_cachecount], 0, sizeof(serverlist_cache[serverlist_cachecount]));
                                // store the data the engine cares about (address and ping)
@@ -986,8 +994,8 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
                                }
 
                                ++serverlist_cachecount;
-
                        }
+
                        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;
@@ -1025,14 +1033,15 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
                                        if (serverlist_cache[n].line1[i] != ' ')
                                                serverlist_cache[n].line1[i] -= 30;
                        }
-                       // and finally, update the view set
-                       if( serverlist_cache[n].finished )
-                ServerList_ViewList_Remove( &serverlist_cache[n] );
-                       // else if not in the slist menu we should print the server to console (if wanted)
+                       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].finished = true;
+                       serverlist_cache[n].query = SQS_QUERIED;
 
                        return true;
                }
@@ -1062,17 +1071,11 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
                                {
                                        serverquerycount++;
 
-                                       LHNETADDRESS_FromString(&svaddress, ipstring, 0);
-                                       NetConn_WriteString(mysocket, "\377\377\377\377getinfo", &svaddress);
-
                                        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, ipstring, sizeof (serverlist_cache[serverlist_cachecount].info.cname));
                                        serverlist_cache[serverlist_cachecount].info.ping = 100000;
-                                       serverlist_cache[serverlist_cachecount].querytime = realtime;
-                                       // if not in the slist menu we should print the server to console
-                                       if (serverlist_consoleoutput)
-                                               Con_Printf("querying %s\n", ipstring);
+                                       serverlist_cache[serverlist_cachecount].query = SQS_QUERYING;
 
                                        ++serverlist_cachecount;
                                }
@@ -1081,6 +1084,8 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
                                data += 7;
                                length -= 7;
                        }
+                       // begin or resume serverlist queries
+                       serverlist_querysleep = false;
                        return true;
                }
                /*
@@ -1190,6 +1195,71 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
        return ret;
 }
 
+void NetConn_QueryQueueFrame(void)
+{
+       int index;
+       int queries;
+       int maxqueries;
+       double timeouttime;
+       static double querycounter = 0;
+
+       if (serverlist_querysleep)
+               return;
+
+       // each time querycounter reaches 1.0 issue a query
+       querycounter += host_realframetime * net_slist_queriespersecond.value;
+       maxqueries = (int)querycounter;
+       maxqueries = bound(0, maxqueries, net_slist_queriesperframe.integer);
+       querycounter -= maxqueries;
+
+       if( maxqueries == 0 ) {
+               return;
+       }
+
+       // scan serverlist and issue queries as needed
+    serverlist_querysleep = true;
+
+       timeouttime = realtime - net_slist_timeout.value;
+       for( index = 0, queries = 0 ; index < serverlist_cachecount && queries < maxqueries ; index++ )
+       {
+               serverlist_entry_t *entry = &serverlist_cache[ index ];
+               if( entry->query != SQS_QUERYING ) 
+               {
+                       continue;
+               }
+
+        serverlist_querysleep = false;
+               if( entry->querycounter != 0 && entry->querytime > timeouttime )
+               {
+                       continue;
+               }
+
+               if( entry->querycounter != (unsigned) net_slist_maxtries.integer ) 
+               {
+                       lhnetaddress_t address;
+                       int socket;
+
+                       LHNETADDRESS_FromString(&address, entry->info.cname, 0);
+                       for (socket = 0; socket < cl_numsockets ; socket++) {
+                               NetConn_WriteString(cl_sockets[socket], "\377\377\377\377getinfo", &address);
+                       }
+
+                       entry->querytime = realtime;
+                       entry->querycounter++;
+
+                       // if not in the slist menu we should print the server to console
+                       if (serverlist_consoleoutput)
+                               Con_Printf("querying %25s (%i. try)\n", entry->info.cname, entry->querycounter);
+
+                       queries++;
+               } 
+               else 
+               {
+                       entry->query = SQS_TIMEDOUT;
+               }
+       }
+}
+
 void NetConn_ClientFrame(void)
 {
        int i, length;
@@ -1221,9 +1291,12 @@ void NetConn_ClientFrame(void)
                NetConn_Write(cls.connect_mysocket, net_message.data, net_message.cursize, &cls.connect_address);
                SZ_Clear(&net_message);
        }
-       for (i = 0;i < cl_numsockets;i++)
-               while (cl_sockets[i] && (length = NetConn_Read(cl_sockets[i], readbuffer, sizeof(readbuffer), &peeraddress)) > 0)
+       for (i = 0;i < cl_numsockets;i++) {
+               while (cl_sockets[i] && (length = NetConn_Read(cl_sockets[i], readbuffer, sizeof(readbuffer), &peeraddress)) > 0) {
                        NetConn_ClientParsePacket(cl_sockets[i], readbuffer, length, &peeraddress);
+               }
+       }
+       NetConn_QueryQueueFrame();
        if (cls.netcon && realtime > cls.netcon->timeout)
        {
                Con_Print("Connection timed out\n");
@@ -1840,6 +1913,10 @@ void NetConn_Init(void)
        Cmd_AddCommand("net_stats", Net_Stats_f);
        Cmd_AddCommand("net_slist", Net_Slist_f);
        Cmd_AddCommand("heartbeat", Net_Heartbeat_f);
+       Cvar_RegisterVariable(&net_slist_queriespersecond);
+       Cvar_RegisterVariable(&net_slist_queriesperframe);
+       Cvar_RegisterVariable(&net_slist_timeout);
+       Cvar_RegisterVariable(&net_slist_maxtries);
        Cvar_RegisterVariable(&net_messagetimeout);
        Cvar_RegisterVariable(&net_messagerejointimeout);
        Cvar_RegisterVariable(&net_connecttimeout);