Use CServer's 'GetClient'

Use the CServer's 'GetClient' method for obtaining clients by index.
This commit is contained in:
Amos 2023-07-12 08:56:17 +02:00
parent 126091d3bc
commit ccdfed1c19
7 changed files with 15 additions and 18 deletions

View File

@ -14,15 +14,6 @@
#include "engine/server/server.h"
#include "engine/client/client.h"
//---------------------------------------------------------------------------------
// Purpose: gets the client from buffer by index
//---------------------------------------------------------------------------------
CClient* CClient::GetClient(int nIndex) const
{
return reinterpret_cast<CClient*>(
(reinterpret_cast<uintptr_t>(g_pClient) + (nIndex * sizeof(CClient))));
}
//---------------------------------------------------------------------------------
// Purpose: gets the client's team number
//---------------------------------------------------------------------------------

View File

@ -63,7 +63,6 @@ class CClient : IClientMessageHandler, INetChannelHandler
{
friend class ServerDataBlockSender;
public:
CClient* GetClient(int nIndex) const;
int64_t GetTeamNum() const;
edict_t GetHandle(void) const;
int GetUserID(void) const;

View File

@ -29,7 +29,7 @@ int CServer::GetNumHumanPlayers(void) const
int nHumans = 0;
for (int i = 0; i < g_ServerGlobalVariables->m_nMaxClients; i++)
{
CClient* pClient = g_pClient->GetClient(i);
CClient* pClient = g_pServer->GetClient(i);
if (!pClient)
continue;
@ -49,7 +49,7 @@ int CServer::GetNumFakeClients(void) const
int nBots = 0;
for (int i = 0; i < g_ServerGlobalVariables->m_nMaxClients; i++)
{
CClient* pClient = g_pClient->GetClient(i);
CClient* pClient = g_pServer->GetClient(i);
if (!pClient)
continue;
@ -69,7 +69,7 @@ int CServer::GetNumClients(void) const
int nClients = 0;
for (int i = 0; i < g_ServerGlobalVariables->m_nMaxClients; i++)
{
CClient* pClient = g_pClient->GetClient(i);
CClient* pClient = g_pServer->GetClient(i);
if (!pClient)
continue;

View File

@ -37,9 +37,14 @@ public:
inline const char* GetMapName(void) const { return m_szMapname; }
inline const char* GetMapGroupName(void) const { return m_szMapGroupName; }
inline int GetNumClasses(void) const { return m_nServerClasses; }
inline int GetClassBits(void) const { return m_nServerClassBits; }
inline CClient* GetClient(int nIndex) { Assert(nIndex < MAX_PLAYERS); return &m_Clients[nIndex]; }
inline float GetCPUUsage(void) const { return m_fCPUPercent; }
inline bool IsActive(void) const { return m_State >= server_state_t::ss_active; }
inline bool IsLoading(void) const { return m_State == server_state_t::ss_loading; }
inline bool IsDedicated(void) const { return m_bIsDedicated; }

View File

@ -78,7 +78,7 @@ void SV_CheckForBan(const BannedVec_t* pBannedVec /*= nullptr*/)
for (int c = 0; c < g_ServerGlobalVariables->m_nMaxClients; c++) // Loop through all possible client instances.
{
CClient* pClient = g_pClient->GetClient(c);
CClient* pClient = g_pServer->GetClient(c);
if (!pClient)
continue;
@ -162,7 +162,7 @@ void SV_BroadcastVoiceData(CClient* cl, int nBytes, char* data)
for (int i = 0; i < g_ServerGlobalVariables->m_nMaxClients; i++)
{
CClient* pClient = g_pClient->GetClient(i);
CClient* pClient = g_pServer->GetClient(i);
if (!pClient)
continue;

View File

@ -8,6 +8,7 @@
#include "tier1/cvar.h"
#include "player.h"
#include "physics_main.h"
#include "engine/server/server.h"
#include "engine/client/client.h"
#include "game/shared/util_shared.h"
@ -21,7 +22,7 @@ void Physics_RunBotSimulation(bool bSimulating)
for (int i = 0; i < g_ServerGlobalVariables->m_nMaxClients; i++)
{
CClient* pClient = g_pClient->GetClient(i);
CClient* pClient = g_pServer->GetClient(i);
if (!pClient)
continue;

View File

@ -7,6 +7,7 @@
#include "core/stdafx.h"
#include "engine/net.h"
#include "engine/server/server.h"
#include "engine/client/client.h"
#include "filesystem/filesystem.h"
#include "networksystem/bansystem.h"
@ -294,7 +295,7 @@ void CBanSystem::AuthorPlayerByName(const char* playerName, const bool shouldBan
for (int i = 0; i < g_ServerGlobalVariables->m_nMaxClients; i++)
{
CClient* pClient = g_pClient->GetClient(i);
CClient* pClient = g_pServer->GetClient(i);
if (!pClient)
continue;
@ -347,7 +348,7 @@ void CBanSystem::AuthorPlayerById(const char* playerHandle, const bool shouldBan
for (int i = 0; i < g_ServerGlobalVariables->m_nMaxClients; i++)
{
CClient* pClient = g_pClient->GetClient(i);
CClient* pClient = g_pServer->GetClient(i);
if (!pClient)
continue;