Thread: limiting humans
View Single Post
limiting humans
Old
  (#1)
Austin
Moderator
 
Austin's Avatar
 
Status: Offline
Posts: 403
Join Date: Nov 2003
Default limiting humans - 04-01-2004

I am using this code to count the number of players + bots on the server
// -----------------------------------------------------------------------
for (client_index = 1; client_index <= gpGlobals->maxClients; client_index++)
{
pPlayer = INDEXENT(client_index);

// skip invalid players
if( FNullEnt(pPlayer) || pPlayer->free || !(pPlayer->v.flags & (FL_CLIENT | FL_FAKECLIENT)))
continue;

if(pPlayer->v.flags & FL_FAKECLIENT)
nbots++;
else
nhumans++;
}


I am using this code to limit the number of humans on the server
// -----------------------------------------------------------------------
BOOL ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128])
{
// is max humans are on
if(nhumans >= (int)CVAR_GET_FLOAT("maxhumans"))
{
// don't allow this human to connect
sprintf (szRejectReason, MESSAGE_REFUSE_CLIENTCONNECT);
RETURN_META_VALUE (MRES_SUPERCEDE, false);
}

RETURN_META_VALUE(MRES_IGNORED, true);
}

Everything works fine except when more then 1 human tries to connect to the server a the same time. This method allows more then maxhumans on since it doesn't take into account players who are in the process of connecting, and not yet flagged as a valid player.

So for example, if maxhumans is set to 5 and there are 4 humans on the server and nhumans is 4 and 2 humans try to connect within a few seconds of each other BOTH will be allowed on.

Does anyone have a clean solution for this?

P.S.
How do I post code examples without it removing my tabs/spaces in front of every line?
Tx

Last edited by Austin; 04-01-2004 at 21:48..
  
Reply With Quote