add a "freeslots" field to the host cache
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 5 Nov 2007 13:39:06 +0000 (13:39 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 5 Nov 2007 13:39:06 +0000 (13:39 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7661 d7cf8633-e32d-0410-b094-e92efae38249

mvm_cmds.c
netconn.c
netconn.h

index 0c68542..594fded 100644 (file)
@@ -421,6 +421,9 @@ void VM_M_setserverlistmasknumber( void )
                case SLIF_PROTOCOL:
                        mask->info.protocol = number;
                        break;
+               case SLIF_FREESLOTS:
+                       mask->info.freeslots = number;
+                       break;
                default:
                        VM_Warning( "VM_M_setserverlistmasknumber: Bad field number %i passed!\n", field );
                        return;
@@ -533,6 +536,9 @@ void VM_M_getserverlistnumber(void)
                case SLIF_NUMHUMANS:
                        PRVM_G_FLOAT( OFS_RETURN ) = cache->info.numhumans;
                        break;
+               case SLIF_FREESLOTS:
+                       PRVM_G_FLOAT( OFS_RETURN ) = cache->info.freeslots;
+                       break;
                case SLIF_PING:
                        PRVM_G_FLOAT( OFS_RETURN ) = cache->info.ping;
                        break;
@@ -607,6 +613,8 @@ void VM_M_getserverlistindexforkey( void )
                PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMBOTS;
        else if( !strcmp( key, "numhumans" ) )
                PRVM_G_FLOAT( OFS_RETURN ) = SLIF_NUMHUMANS;
+       else if( !strcmp( key, "freeslots" ) )
+               PRVM_G_FLOAT( OFS_RETURN ) = SLIF_FREESLOTS;
        else if( !strcmp( key, "protocol" ) )
                PRVM_G_FLOAT( OFS_RETURN ) = SLIF_PROTOCOL;
        else
index 6c420e5..8513eaf 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -191,6 +191,9 @@ static qboolean _ServerList_Entry_Compare( serverlist_entry_t *A, serverlist_ent
                case SLIF_NUMHUMANS:
                        result = A->info.numhumans - B->info.numhumans;
                        break;
+               case SLIF_FREESLOTS:
+                       result = A->info.freeslots - B->info.freeslots;
+                       break;
                case SLIF_PROTOCOL:
                        result = A->info.protocol - B->info.protocol;
                        break;
@@ -296,6 +299,8 @@ static qboolean _ServerList_Entry_Mask( serverlist_mask_t *mask, serverlist_info
                return false;
        if( !_ServerList_CompareInt( info->numhumans, mask->tests[SLIF_NUMHUMANS], mask->info.numhumans ) )
                return false;
+       if( !_ServerList_CompareInt( info->freeslots, mask->tests[SLIF_FREESLOTS], mask->info.freeslots ) )
+               return false;
        if( !_ServerList_CompareInt( info->protocol, mask->tests[SLIF_PROTOCOL], mask->info.protocol ))
                return false;
        if( *mask->info.cname
@@ -1347,6 +1352,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        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 - max(0, info->numbots);
+                       info->freeslots = info->maxplayers - info->numplayers;
 
                        NetConn_ClientParsePacket_ServerList_UpdateCache(n);
 
index 63df664..e04bdb5 100755 (executable)
--- a/netconn.h
+++ b/netconn.h
@@ -252,6 +252,8 @@ typedef struct serverlist_info_s
        int numbots;
        // number of currently connected players that are not bots
        int numhumans;
+       // number of free slots
+       int freeslots;
        // protocol version
        int protocol;
        // game data version
@@ -273,7 +275,8 @@ typedef enum
        SLIF_PROTOCOL,
        SLIF_NUMBOTS,
        SLIF_NUMHUMANS,
-       SLIF_COUNT
+       SLIF_COUNT,
+       SLIF_FREESLOTS
 } serverlist_infofield_t;
 
 typedef enum