]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - netconn.c
Replaced snprintf and vnsprintf calls by dpsnprintf and dpvsnprintf calls, to ensure...
[xonotic/darkplaces.git] / netconn.c
index e2d34910f8026cec73edfff270c9214ddcc66ac2..53446bac14f234c359e6c250c90030eccdcad07d 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -125,7 +125,7 @@ static void _HostCache_ViewSet_Remove( int index )
 // returns true if A should be inserted before B
 static qboolean _HostCache_SortTest( hostcache_t *A, hostcache_t *B )
 {
-       int result; // > 0 if for numbers A > B and for text if A < B 
+       int result = 0; // > 0 if for numbers A > B and for text if A < B 
 
        if( hostcache_sortbyfield == HCIF_PING )
                result = A->info.ping - B->info.ping;
@@ -170,9 +170,9 @@ static qboolean _hc_testint( int A, hostcache_maskop_t op, int B )
 static qboolean _hc_teststr( const char *A, hostcache_maskop_t op, const char *B )
 {
        if( op == HCMO_CONTAINS ) // A info B mask
-               return *A && !!strstr( B, A ); // we want a real bool
+               return *B && !!strstr( A, B ); // we want a real bool
        else if( op == HCMO_NOTCONTAIN )
-               return !*A || !strstr( B, A );
+               return !*B || !strstr( A, B );
        else if( op == HCMO_LESS )
                return strcmp( A, B ) < 0;
        else if( op == HCMO_LESSEQUAL )
@@ -292,6 +292,21 @@ void HostCache_ResetMasks(void)
        memset( &hostcache_ormasks, 0, sizeof( hostcache_ormasks ) );
 }
 
+#if 0
+static void _HostCache_Test(void)
+{
+       int i;
+       for( i = 0 ; i < 1024 ; i++ ) {
+               memset( &hostcache_cache[hostcache_cachecount], 0, sizeof( hostcache_t ) );
+               hostcache_cache[hostcache_cachecount].info.ping = rand() % 450 + 250;
+               dpsnprintf( hostcache_cache[hostcache_cachecount].info.name, 128, "Black's HostCache Test %i", i );
+               hostcache_cache[hostcache_cachecount].finished = true;
+               sprintf( hostcache_cache[hostcache_cachecount].line1, "%i %s", hostcache_cache[hostcache_cachecount].info.ping, hostcache_cache[hostcache_cachecount].info.name );
+               _HostCache_Insert( &hostcache_cache[hostcache_cachecount] );
+               hostcache_cachecount++;
+       }
+}
+#endif
 
 void HostCache_QueryList(void)
 {
@@ -305,23 +320,8 @@ void HostCache_QueryList(void)
        hostcache_consoleoutput = false;
        NetConn_QueryMasters();
        
-       //_HostCache_PingTest(); 
-}
-
-#if 0
-static void _HostCache_PingTest(void)
-{
-       int i;
-       for( i = 0 ; i < 50 ; i++ ) {
-               memset( &hostcache_cache[hostcache_cachecount], 0, sizeof( hostcache_t ) );
-               hostcache_cache[hostcache_cachecount].info.ping = rand() % 450;
-               hostcache_cache[hostcache_cachecount].finished = true;
-               sprintf( hostcache_cache[hostcache_cachecount].line1, "%i", hostcache_cache[hostcache_cachecount].info.ping );
-               _HostCache_Insert( &hostcache_cache[hostcache_cachecount] );
-               hostcache_cachecount++;
-       }
+       //_HostCache_Test(); 
 }
-#endif
 
 // rest
 
@@ -329,11 +329,13 @@ int NetConn_Read(lhnetsocket_t *mysocket, void *data, int maxlength, lhnetaddres
 {
        int length = LHNET_Read(mysocket, data, maxlength, peeraddress);
        int i;
+       if (length == 0)
+               return 0;
        if (cl_netpacketloss.integer)
                for (i = 0;i < cl_numsockets;i++)
                        if (cl_sockets[i] == mysocket && (rand() % 100) < cl_netpacketloss.integer)
                                return 0;
-       if (developer_networking.integer && length != 0)
+       if (developer_networking.integer)
        {
                char addressstring[128], addressstring2[128];
                LHNETADDRESS_ToString(LHNET_AddressFromSocket(mysocket), addressstring, sizeof(addressstring), true);
@@ -844,7 +846,6 @@ void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_t *peer
        cls.state = ca_connected;
        cls.signon = 0;                         // need all the signon messages before playing
        CL_ClearState();
-       SCR_BeginLoadingPlaque();
 }
 
 int NetConn_IsLocalGame(void)
@@ -941,8 +942,8 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
                        // legacy/old stuff move it to the menu ASAP
 
                        // build description strings for the things users care about
-                       snprintf(hostcache_cache[n].line1, sizeof(hostcache_cache[n].line1), "%5d%c%3u/%3u %-65.65s", (int)pingtime, info->protocol != NET_PROTOCOL_VERSION ? '*' : ' ', info->numplayers, info->maxplayers, info->name);
-                       snprintf(hostcache_cache[n].line2, sizeof(hostcache_cache[n].line2), "%-21.21s %-19.19s %-17.17s %-20.20s", info->cname, info->game, info->mod, info->map);
+                       dpsnprintf(hostcache_cache[n].line1, sizeof(hostcache_cache[n].line1), "%5d%c%3u/%3u %-65.65s", (int)pingtime, info->protocol != NET_PROTOCOL_VERSION ? '*' : ' ', info->numplayers, info->maxplayers, info->name);
+                       dpsnprintf(hostcache_cache[n].line2, sizeof(hostcache_cache[n].line2), "%-21.21s %-19.19s %-17.17s %-20.20s", info->cname, info->game, info->mod, info->map);
                        // if ping is especially high, display it as such
                        if (pingtime >= 300)
                        {
@@ -981,7 +982,7 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
                        {
                                serverquerycount++;
        
-                               snprintf (ipstring, sizeof (ipstring), "%u.%u.%u.%u:%u", data[1], data[2], data[3], data[4], (data[5] << 8) | data[6]);
+                               dpsnprintf (ipstring, sizeof (ipstring), "%u.%u.%u.%u:%u", data[1], data[2], data[3], data[4], (data[5] << 8) | data[6]);
                                if (developer.integer)
                                        Con_Printf("Requesting info from server %s\n", ipstring);                               
                                // ignore the rest of the message if the hostcache is full
@@ -1317,13 +1318,13 @@ int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length,
                                for (i = 0, n = 0;i < svs.maxclients;i++)
                                        if (svs.clients[i].active)
                                                n++;
-                               responselength = snprintf(response, sizeof(response), "\377\377\377\377infoResponse\x0A"
+                               responselength = dpsnprintf(response, sizeof(response), "\377\377\377\377infoResponse\x0A"
                                                        "\\gamename\\%s\\modname\\%s\\sv_maxclients\\%d"
                                                        "\\clients\\%d\\mapname\\%s\\hostname\\%s\\protocol\\%d%s%s",
                                                        gamename, com_modname, svs.maxclients, n,
                                                        sv.name, hostname.string, NET_PROTOCOL_VERSION, challenge ? "\\challenge\\" : "", challenge ? challenge : "");
                                // does it fit in the buffer?
-                               if (responselength < (int)sizeof(response))
+                               if (responselength >= 0)
                                {
                                        if (developer.integer)
                                                Con_Printf("Sending reply to master %s - %s\n", addressstring2, response);
@@ -1612,7 +1613,7 @@ void NetConn_QueryMasters(void)
 #endif
 
                        // build the getservers
-                       snprintf(request, sizeof(request), "\377\377\377\377getservers %s %u empty full\x0A", gamename, NET_PROTOCOL_VERSION);
+                       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++)