+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;
+}
+