Use server global variables for client loops

Use server global variables for determining the num clients to loop over. This is cheaper and better than always looping over MAX_PLAYERS.
This commit is contained in:
Kawe Mazidjatari 2023-04-30 01:50:38 +02:00
parent 6b23570beb
commit f319fc0846
4 changed files with 5 additions and 5 deletions

View File

@ -83,7 +83,7 @@ int CServer::GetNumClients(void) const
// Purpose: Initializes a CSVClient for a new net connection. This will only be called
// once for a player each game, not once for each level change.
// Input : *pServer -
// *pInpacket -
// *pChallenge -
// Output : pointer to client instance on success, nullptr on failure
//---------------------------------------------------------------------------------
CClient* CServer::ConnectClient(CServer* pServer, user_creds_s* pChallenge)

View File

@ -76,7 +76,7 @@ void SV_CheckForBan(const BannedVec_t* pBannedVec /*= nullptr*/)
Assert(ThreadInMainThread());
BannedVec_t bannedVec;
for (int c = 0; c < MAX_PLAYERS; c++) // Loop through all possible client instances.
for (int c = 0; c < g_ServerGlobalVariables->m_nMaxClients; c++) // Loop through all possible client instances.
{
CClient* pClient = g_pClient->GetClient(c);
if (!pClient)

View File

@ -19,7 +19,7 @@ void Physics_RunBotSimulation(bool bSimulating)
if (!sv_simulateBots->GetBool())
return;
for (int i = 0; i < MAX_PLAYERS; i++)
for (int i = 0; i < g_ServerGlobalVariables->m_nMaxClients; i++)
{
CClient* pClient = g_pClient->GetClient(i);
if (!pClient)

View File

@ -294,7 +294,7 @@ void CBanSystem::AuthorPlayerByName(const char* playerName, const bool shouldBan
if (!reason)
reason = shouldBan ? "Banned from server" : "Kicked from server";
for (int i = 0; i < MAX_PLAYERS; i++)
for (int i = 0; i < g_ServerGlobalVariables->m_nMaxClients; i++)
{
CClient* pClient = g_pClient->GetClient(i);
if (!pClient)
@ -347,7 +347,7 @@ void CBanSystem::AuthorPlayerById(const char* playerHandle, const bool shouldBan
if (!reason)
reason = shouldBan ? "Banned from server" : "Kicked from server";
for (int i = 0; i < MAX_PLAYERS; i++)
for (int i = 0; i < g_ServerGlobalVariables->m_nMaxClients; i++)
{
CClient* pClient = g_pClient->GetClient(i);
if (!pClient)