X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=netconn.c;h=659e2be62a9f172f5164c137c6337edab3f0152c;hb=d4c8d7d1f126232f3ed69a97da905d9425a291c2;hp=f584b86c7006a34f3eb028885158024bfc1f68d4;hpb=72125a0f1092db1722c65be750fac8db7c303d4b;p=xonotic%2Fdarkplaces.git diff --git a/netconn.c b/netconn.c index f584b86c..659e2be6 100755 --- a/netconn.c +++ b/netconn.c @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MASTER_PORT 27950 -cvar_t sv_public = {0, "sv_public", "0"}; +cvar_t sv_public = {0, "sv_public", "1"}; static cvar_t sv_heartbeatperiod = {CVAR_SAVE, "sv_heartbeatperiod", "180"}; // FIXME: resolve DNS on masters whenever their value changes and cache it (to avoid major delays in active servers when they heartbeat) @@ -37,6 +37,7 @@ static cvar_t sv_masters [] = {CVAR_SAVE, "sv_master4", ""}, {0, "sv_masterextra1", "69.59.212.88"}, // ghdigital.com {0, "sv_masterextra2", "66.169.205.13"}, // dpmaster.deathmask.net + {0, "sv_masterextra3", "12.166.196.192"}, // blaze.mindphukd.org {0, NULL, NULL} }; @@ -125,7 +126,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; // > 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; @@ -145,7 +146,7 @@ static qboolean _HostCache_SortTest( hostcache_t *A, hostcache_t *B ) result = strcmp( B->info.mod, A->info.mod ); else if( hostcache_sortbyfield == HCIF_NAME ) result = strcmp( B->info.name, A->info.name ); - + if( hostcache_sortdescending ) return result > 0; return result < 0; @@ -180,7 +181,7 @@ static qboolean _hc_teststr( const char *A, hostcache_maskop_t op, const char *B else if( op == HCMO_EQUAL ) return strcmp( A, B ) == 0; else if( op == HCMO_GREATER ) - return strcmp( A, B ) > 0; + return strcmp( A, B ) > 0; else if( op == HCMO_NOTEQUAL ) return strcmp( A, B ) != 0; else // HCMO_GREATEREQUAL @@ -221,7 +222,7 @@ static void _HostCache_Insert( hostcache_t *entry ) if( hostcache_viewcount == HOSTCACHE_VIEWCACHESIZE ) return; // now check whether it passes through the masks mask - for( start = 0 ; hostcache_andmasks[start].active && start < HOSTCACHE_ANDMASKCOUNT ; start++ ) + for( start = 0 ; hostcache_andmasks[start].active && start < HOSTCACHE_ANDMASKCOUNT ; start++ ) if( !_HostCache_TestMask( &hostcache_andmasks[start], &entry->info ) ) return; @@ -256,7 +257,7 @@ static void _HostCache_Insert( hostcache_t *entry ) if( _HostCache_SortTest( entry, hostcache_viewset[mid] ) ) // the item has to be in the upper half end = mid; - else + else // the item has to be in the lower half start = mid; } @@ -279,7 +280,7 @@ static void _HostCache_Remove( hostcache_t *entry ) void HostCache_RebuildViewSet(void) { int i; - + hostcache_viewcount = 0; for( i = 0 ; i < hostcache_cachecount ; i++ ) if( hostcache_cache[i].finished ) @@ -292,14 +293,14 @@ void HostCache_ResetMasks(void) memset( &hostcache_ormasks, 0, sizeof( hostcache_ormasks ) ); } -#if 1 +#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; - snprintf( hostcache_cache[hostcache_cachecount].info.name, 128, "Black's HostCache Test %i", i ); + 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] ); @@ -319,8 +320,8 @@ void HostCache_QueryList(void) hostcache_viewcount = 0; hostcache_consoleoutput = false; NetConn_QueryMasters(); - - _HostCache_Test(); + + //_HostCache_Test(); } // rest @@ -911,7 +912,7 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length, hostcache_info_t *info; int i, n; double pingtime; - + string += 13; // hostcache only uses text addresses LHNETADDRESS_ToString(peeraddress, cname, sizeof(cname), true); @@ -942,8 +943,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) { @@ -959,12 +960,12 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length, if (hostcache_cache[n].line1[i] != ' ') hostcache_cache[n].line1[i] -= 30; } - // if not in the slist menu we should print the server to console - if( hostcache_consoleoutput ) - Con_Printf("%s\n%s\n", hostcache_cache[n].line1, hostcache_cache[n].line2); // and finally, update the view set if( hostcache_cache[n].finished ) _HostCache_Remove( &hostcache_cache[n] ); + // else if not in the slist menu we should print the server to console (if wanted) + else if( hostcache_consoleoutput ) + Con_Printf("%s\n%s\n", hostcache_cache[n].line1, hostcache_cache[n].line2); _HostCache_Insert( &hostcache_cache[n] ); hostcache_cache[n].finished = true; @@ -980,14 +981,22 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length, Con_Print("received server list...\n"); while (length >= 7 && data[0] == '\\' && (data[1] != 0xFF || data[2] != 0xFF || data[3] != 0xFF || data[4] != 0xFF) && data[5] * 256 + data[6] != 0) { + int n; + 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); + Con_Printf("Requesting info from server %s\n", ipstring); // ignore the rest of the message if the hostcache is full if( hostcache_cachecount == HOSTCACHE_TOTALSIZE ) break; + // also ignore it if we have already queried it (other master server response) + for( n = 0 ; n < hostcache_cachecount ; n++ ) + if( !strcmp( ipstring, hostcache_cache[ n ].info.cname ) ) + break; + if( n < hostcache_cachecount ) + break; LHNETADDRESS_FromString(&svaddress, ipstring, 0); NetConn_WriteString(mysocket, "\377\377\377\377getinfo", &svaddress); @@ -1318,13 +1327,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); @@ -1586,20 +1595,22 @@ void NetConn_QueryMasters(void) int i; int masternum; lhnetaddress_t masteraddress; + lhnetaddress_t broadcastaddress; char request[256]; if (hostcache_cachecount >= HOSTCACHE_TOTALSIZE) return; + // 26000 is the default quake server port, servers on other ports will not + // be found + // 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 (cl_sockets[i]) { -#if 0 - // search LAN -#if 1 - UDP_Broadcast(UDP_controlSock, "\377\377\377\377getinfo", 11); -#else + // search LAN for Quake servers SZ_Clear(&net_message); // save space for the header, filled in later MSG_WriteLong(&net_message, 0); @@ -1607,13 +1618,14 @@ void NetConn_QueryMasters(void) 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)); - UDP_Broadcast(UDP_controlSock, net_message.data, net_message.cursize); + NetConn_Write(cl_sockets[i], net_message.data, net_message.cursize, &broadcastaddress); SZ_Clear(&net_message); -#endif -#endif - // build the getservers - snprintf(request, sizeof(request), "\377\377\377\377getservers %s %u empty full\x0A", gamename, NET_PROTOCOL_VERSION); + // search LAN for DarkPlaces servers + NetConn_WriteString(cl_sockets[i], "\377\377\377\377getinfo", &broadcastaddress); + + // build the getservers message to send to the 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++)