From 2e11c41508ae51b8a84bab8bfdcb09dac6a33fe0 Mon Sep 17 00:00:00 2001 From: havoc Date: Wed, 18 Apr 2007 08:08:31 +0000 Subject: [PATCH] added numbots and numhumans in server info parsing, serverlist filtering can also mask by these, and the 'player empty' check for the engine's own server listings now uses numhumans rather than numplayers git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7125 d7cf8633-e32d-0410-b094-e92efae38249 --- mvm_cmds.c | 16 ++++++++++++++++ netconn.c | 39 ++++++++++++++++++++++++++++++--------- netconn.h | 8 +++++++- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/mvm_cmds.c b/mvm_cmds.c index 1a9a84f3..f690ea28 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -407,6 +407,12 @@ void VM_M_setserverlistmasknumber( void ) case SLIF_NUMPLAYERS: mask->info.numplayers = number; break; + case SLIF_NUMBOTS: + mask->info.numbots = number; + break; + case SLIF_NUMHUMANS: + mask->info.numhumans = number; + break; case SLIF_PING: mask->info.ping = number; break; @@ -519,6 +525,12 @@ void VM_M_getserverlistnumber(void) case SLIF_NUMPLAYERS: PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numplayers; break; + case SLIF_NUMBOTS: + PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numbots; + break; + case SLIF_NUMHUMANS: + PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numhumans; + break; case SLIF_PING: PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping; break; @@ -589,6 +601,10 @@ void VM_M_getserverlistindexforkey( void ) PRVM_G_FLOAT( OFS_RETURN ) = SLIF_MAXPLAYERS; else if( !strcmp( key, "numplayers" ) ) PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMPLAYERS; + else if( !strcmp( key, "numbotss" ) ) + PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMBOTS; + else if( !strcmp( key, "numhumans" ) ) + PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMHUMANS; else if( !strcmp( key, "protocol" ) ) PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL; else diff --git a/netconn.c b/netconn.c index 0860c7ce..778046ac 100755 --- a/netconn.c +++ b/netconn.c @@ -184,6 +184,12 @@ static qboolean _ServerList_Entry_Compare( serverlist_entry_t *A, serverlist_ent case SLIF_NUMPLAYERS: result = A->info.numplayers - B->info.numplayers; break; + case SLIF_NUMBOTS: + result = A->info.numbots - B->info.numbots; + break; + case SLIF_NUMHUMANS: + result = A->info.numhumans - B->info.numhumans; + break; case SLIF_PROTOCOL: result = A->info.protocol - B->info.protocol; break; @@ -285,6 +291,10 @@ static qboolean _ServerList_Entry_Mask( serverlist_mask_t *mask, serverlist_info return false; if( !_ServerList_CompareInt( info->numplayers, mask->tests[SLIF_NUMPLAYERS], mask->info.numplayers ) ) return false; + if( !_ServerList_CompareInt( info->numplayers, mask->tests[SLIF_NUMBOTS], mask->info.numbots ) ) + return false; + if( !_ServerList_CompareInt( info->numplayers, mask->tests[SLIF_NUMHUMANS], mask->info.numhumans ) ) + return false; if( !_ServerList_CompareInt( info->protocol, mask->tests[SLIF_PROTOCOL], mask->info.protocol )) return false; if( *mask->info.cname @@ -1217,7 +1227,7 @@ 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].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->numhumans > 0 && info->numhumans < info->maxplayers) ? (info->numhumans >= 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]); @@ -1303,14 +1313,25 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat return true; 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; - 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; - if ((s = SearchInfostring(string, "gameversion" )) != NULL) info->gameversion = atoi(s);else info->gameversion = 0; + info->game[0] = 0; + info->mod[0] = 0; + info->map[0] = 0; + info->name[0] = 0; + info->protocol = -1; + info->numplayers = 0; + info->numbots = 0; + info->maxplayers = 0; + info->gameversion = 0; + if ((s = SearchInfostring(string, "gamename" )) != NULL) strlcpy(info->game, s, sizeof (info->game)); + if ((s = SearchInfostring(string, "modname" )) != NULL) strlcpy(info->mod , s, sizeof (info->mod )); + if ((s = SearchInfostring(string, "mapname" )) != NULL) strlcpy(info->map , s, sizeof (info->map )); + if ((s = SearchInfostring(string, "hostname" )) != NULL) strlcpy(info->name, s, sizeof (info->name)); + if ((s = SearchInfostring(string, "protocol" )) != NULL) info->protocol = atoi(s); + if ((s = SearchInfostring(string, "clients" )) != NULL) info->numplayers = atoi(s); + if ((s = SearchInfostring(string, "bots" )) != NULL) info->numbots = atoi(s); + if ((s = SearchInfostring(string, "sv_maxclients")) != NULL) info->maxplayers = atoi(s); + if ((s = SearchInfostring(string, "gameversion" )) != NULL) info->gameversion = atoi(s); + info->numhumans = info->numplayers - info->numbots; NetConn_ClientParsePacket_ServerList_UpdateCache(n); diff --git a/netconn.h b/netconn.h index 603d987b..6b5252a3 100755 --- a/netconn.h +++ b/netconn.h @@ -246,8 +246,12 @@ typedef struct serverlist_info_s char name[128]; // max client number int maxplayers; - // number of currently connected players + // number of currently connected players (including bots) int numplayers; + // number of currently connected players that are bots + int numbots; + // number of currently connected players that are not bots + int numhumans; // protocol version int protocol; // game data version @@ -267,6 +271,8 @@ typedef enum SLIF_MAXPLAYERS, SLIF_NUMPLAYERS, SLIF_PROTOCOL, + SLIF_NUMBOTS, + SLIF_NUMHUMANS, SLIF_COUNT } serverlist_infofield_t; -- 2.39.2