mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Server: rename 'ServerPlayer_t' to 'CClientExtended'
A more correct name + comments as to why this structure exists.
This commit is contained in:
parent
caba6a7aba
commit
89320b48ad
@ -27,7 +27,7 @@
|
|||||||
void CClient::Clear(void)
|
void CClient::Clear(void)
|
||||||
{
|
{
|
||||||
#ifndef CLIENT_DLL
|
#ifndef CLIENT_DLL
|
||||||
g_ServerPlayer[GetUserID()].Reset(); // Reset ServerPlayer slot.
|
GetClientExtended()->Reset(); // Reset extended data.
|
||||||
#endif // !CLIENT_DLL
|
#endif // !CLIENT_DLL
|
||||||
v_CClient_Clear(this);
|
v_CClient_Clear(this);
|
||||||
}
|
}
|
||||||
@ -41,6 +41,16 @@ void CClient::VClear(CClient* pClient)
|
|||||||
pClient->Clear();
|
pClient->Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
// Purpose: gets the extended client data
|
||||||
|
// Output : CClientExtended* -
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
CClientExtended* CClient::GetClientExtended(void) const
|
||||||
|
{
|
||||||
|
return m_pServer->GetClientExtended(m_nUserID);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char JWT_PUBLIC_KEY[] =
|
static const char JWT_PUBLIC_KEY[] =
|
||||||
"-----BEGIN PUBLIC KEY-----\n"
|
"-----BEGIN PUBLIC KEY-----\n"
|
||||||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2/335exIZ6LE8pYi6e50\n"
|
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2/335exIZ6LE8pYi6e50\n"
|
||||||
@ -186,7 +196,7 @@ bool CClient::Connect(const char* szName, CNetChan* pNetChan, bool bFakePlayer,
|
|||||||
CUtlVector<NET_SetConVar::cvar_t>* conVars, char* szMessage, int nMessageSize)
|
CUtlVector<NET_SetConVar::cvar_t>* conVars, char* szMessage, int nMessageSize)
|
||||||
{
|
{
|
||||||
#ifndef CLIENT_DLL
|
#ifndef CLIENT_DLL
|
||||||
g_ServerPlayer[GetUserID()].Reset(); // Reset ServerPlayer slot.
|
GetClientExtended()->Reset(); // Reset extended data.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!v_CClient_Connect(this, szName, pNetChan, bFakePlayer, conVars, szMessage, nMessageSize))
|
if (!v_CClient_Connect(this, szName, pNetChan, bFakePlayer, conVars, szMessage, nMessageSize))
|
||||||
@ -362,8 +372,7 @@ bool CClient::VProcessStringCmd(CClient* pClient, NET_StringCmd* pMsg)
|
|||||||
if (!pClient_Adj->IsActive())
|
if (!pClient_Adj->IsActive())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
const int nUserID = pClient_Adj->GetUserID();
|
CClientExtended* const pSlot = pClient_Adj->GetClientExtended();
|
||||||
ServerPlayer_t* const pSlot = &g_ServerPlayer[nUserID];
|
|
||||||
|
|
||||||
const double flStartTime = Plat_FloatTime();
|
const double flStartTime = Plat_FloatTime();
|
||||||
const int nCmdQuotaLimit = sv_quota_stringCmdsPerSecond->GetInt();
|
const int nCmdQuotaLimit = sv_quota_stringCmdsPerSecond->GetInt();
|
||||||
@ -427,7 +436,7 @@ bool CClient::VProcessSetConVar(CClient* pClient, NET_SetConVar* pMsg)
|
|||||||
{
|
{
|
||||||
#ifndef CLIENT_DLL
|
#ifndef CLIENT_DLL
|
||||||
CClient* const pAdj = AdjustShiftedThisPointer(pClient);
|
CClient* const pAdj = AdjustShiftedThisPointer(pClient);
|
||||||
ServerPlayer_t* const pSlot = &g_ServerPlayer[pAdj->GetUserID()];
|
CClientExtended* const pSlot = pAdj->GetClientExtended();
|
||||||
|
|
||||||
// This loop never exceeds 255 iterations, NET_SetConVar::ReadFromBuffer(...)
|
// This loop never exceeds 255 iterations, NET_SetConVar::ReadFromBuffer(...)
|
||||||
// reads and inserts up to 255 entries in the vector (reads a byte for size).
|
// reads and inserts up to 255 entries in the vector (reads a byte for size).
|
||||||
|
@ -21,6 +21,7 @@ enum Reputation_t
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
class CServer;
|
class CServer;
|
||||||
class CClient;
|
class CClient;
|
||||||
|
class CClientExtended;
|
||||||
|
|
||||||
struct Spike_t
|
struct Spike_t
|
||||||
{
|
{
|
||||||
@ -73,6 +74,8 @@ public:
|
|||||||
inline CNetChan* GetNetChan(void) const { return m_NetChannel; }
|
inline CNetChan* GetNetChan(void) const { return m_NetChannel; }
|
||||||
inline CServer* GetServer(void) const { return m_pServer; }
|
inline CServer* GetServer(void) const { return m_pServer; }
|
||||||
|
|
||||||
|
CClientExtended* GetClientExtended(void) const;
|
||||||
|
|
||||||
inline int GetCommandTick(void) const { return m_nCommandTick; }
|
inline int GetCommandTick(void) const { return m_nCommandTick; }
|
||||||
inline const char* GetServerName(void) const { return m_szServerName; }
|
inline const char* GetServerName(void) const { return m_szServerName; }
|
||||||
inline const char* GetClientName(void) const { return m_szClientName; }
|
inline const char* GetClientName(void) const { return m_szClientName; }
|
||||||
@ -208,6 +211,41 @@ static_assert(sizeof(CClient) == 0x4A440);
|
|||||||
static_assert(sizeof(CClient) == 0x4A4C0);
|
static_assert(sizeof(CClient) == 0x4A4C0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Extended CClient class
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// NOTE: since we interface directly with the engine, we cannot modify the
|
||||||
|
// client structure. In order to add new data to each client instance, we
|
||||||
|
// need to use this new class which we link directly to the corresponding
|
||||||
|
// client instance through its UserID.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
class CClientExtended
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CClientExtended(void)
|
||||||
|
{
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
inline void Reset(void)
|
||||||
|
{
|
||||||
|
m_flCurrentNetProcessTime = 0.0;
|
||||||
|
m_flLastNetProcessTime = 0.0;
|
||||||
|
m_flLastClockSyncTime = 0.0;
|
||||||
|
m_flStringCommandQuotaTimeStart = 0.0;
|
||||||
|
m_nStringCommandQuotaCount = NULL;
|
||||||
|
m_bRetryClockSync = false;
|
||||||
|
m_bInitialConVarsSet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
double m_flCurrentNetProcessTime;
|
||||||
|
double m_flLastNetProcessTime;
|
||||||
|
double m_flLastClockSyncTime;
|
||||||
|
double m_flStringCommandQuotaTimeStart;
|
||||||
|
int m_nStringCommandQuotaCount;
|
||||||
|
bool m_bRetryClockSync;
|
||||||
|
bool m_bInitialConVarsSet;
|
||||||
|
};
|
||||||
|
|
||||||
/* ==== CBASECLIENT ===================================================================================================================================================== */
|
/* ==== CBASECLIENT ===================================================================================================================================================== */
|
||||||
inline CMemory p_CClient_Connect;
|
inline CMemory p_CClient_Connect;
|
||||||
inline bool(*v_CClient_Connect)(CClient* pClient, const char* szName, CNetChan* pNetChan, bool bFakePlayer, CUtlVector<NET_SetConVar::cvar_t>* conVars, char* szMessage, int nMessageSize);
|
inline bool(*v_CClient_Connect)(CClient* pClient, const char* szName, CNetChan* pNetChan, bool bFakePlayer, CUtlVector<NET_SetConVar::cvar_t>* conVars, char* szMessage, int nMessageSize);
|
||||||
|
@ -175,7 +175,6 @@ void NET_RemoveChannel(CClient* pClient, int nIndex, const char* szReason, uint8
|
|||||||
|
|
||||||
pClient->GetNetChan()->Shutdown(szReason, bBadRep, bRemoveNow); // Shutdown NetChannel.
|
pClient->GetNetChan()->Shutdown(szReason, bBadRep, bRemoveNow); // Shutdown NetChannel.
|
||||||
pClient->Clear(); // Reset CClient slot.
|
pClient->Clear(); // Reset CClient slot.
|
||||||
g_ServerPlayer[nIndex].Reset(); // Reset ServerPlayer slot.
|
|
||||||
#endif // !CLIENT_DLL
|
#endif // !CLIENT_DLL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,23 +345,23 @@ bool CNetChan::_ProcessMessages(CNetChan* pChan, bf_read* pBuf)
|
|||||||
if (!pChan->m_MessageHandler) // NetChannel removed?
|
if (!pChan->m_MessageHandler) // NetChannel removed?
|
||||||
return bResult;
|
return bResult;
|
||||||
|
|
||||||
CClient* pClient = reinterpret_cast<CClient*>(pChan->m_MessageHandler);
|
CClient* const pClient = reinterpret_cast<CClient*>(pChan->m_MessageHandler);
|
||||||
ServerPlayer_t* pSlot = &g_ServerPlayer[pClient->GetUserID()];
|
CClientExtended* const pExtended = pClient->GetClientExtended();
|
||||||
|
|
||||||
if (flStartTime - pSlot->m_flLastNetProcessTime >= 1.0 ||
|
if (flStartTime - pExtended->m_flLastNetProcessTime >= 1.0 ||
|
||||||
pSlot->m_flLastNetProcessTime == -1.0)
|
pExtended->m_flLastNetProcessTime == -1.0)
|
||||||
{
|
{
|
||||||
pSlot->m_flLastNetProcessTime = flStartTime;
|
pExtended->m_flLastNetProcessTime = flStartTime;
|
||||||
pSlot->m_flCurrentNetProcessTime = 0.0;
|
pExtended->m_flCurrentNetProcessTime = 0.0;
|
||||||
}
|
}
|
||||||
pSlot->m_flCurrentNetProcessTime +=
|
pExtended->m_flCurrentNetProcessTime +=
|
||||||
(Plat_FloatTime() * 1000) - (flStartTime * 1000);
|
(Plat_FloatTime() * 1000) - (flStartTime * 1000);
|
||||||
|
|
||||||
if (pSlot->m_flCurrentNetProcessTime >
|
if (pExtended->m_flCurrentNetProcessTime >
|
||||||
net_processTimeBudget->GetFloat())
|
net_processTimeBudget->GetFloat())
|
||||||
{
|
{
|
||||||
Warning(eDLL_T::SERVER, "Removing netchannel '%s' ('%s' exceeded frame budget by '%3.1f'ms!)\n",
|
Warning(eDLL_T::SERVER, "Removing netchannel '%s' ('%s' exceeded frame budget by '%3.1f'ms!)\n",
|
||||||
pChan->GetName(), pChan->GetAddress(), (pSlot->m_flCurrentNetProcessTime - net_processTimeBudget->GetFloat()));
|
pChan->GetName(), pChan->GetAddress(), (pExtended->m_flCurrentNetProcessTime - net_processTimeBudget->GetFloat()));
|
||||||
pClient->Disconnect(Reputation_t::REP_MARK_BAD, "#DISCONNECT_NETCHAN_OVERFLOW");
|
pClient->Disconnect(Reputation_t::REP_MARK_BAD, "#DISCONNECT_NETCHAN_OVERFLOW");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -95,19 +95,19 @@ void CNetworkStringTableContainer::WriteUpdateMessage(CNetworkStringTableContain
|
|||||||
#ifndef CLIENT_DLL
|
#ifndef CLIENT_DLL
|
||||||
const double currentTime = Plat_FloatTime();
|
const double currentTime = Plat_FloatTime();
|
||||||
|
|
||||||
ServerPlayer_t& clientExtended = g_ServerPlayer[pClient->GetUserID()];
|
CClientExtended* const clientExtended = pClient->GetClientExtended();
|
||||||
int commandTick = -1; // -1 means we update statistics only; see 'CClientState::VProcessServerTick()'.
|
int commandTick = -1; // -1 means we update statistics only; see 'CClientState::VProcessServerTick()'.
|
||||||
|
|
||||||
// NOTE: if we send this message each tick, the client will start to
|
// NOTE: if we send this message each tick, the client will start to
|
||||||
// falter. Unlike other source games, we have to have some delay in
|
// falter. Unlike other source games, we have to have some delay in
|
||||||
// between each server tick message for this to work correctly.
|
// between each server tick message for this to work correctly.
|
||||||
if (clientExtended.m_bRetryClockSync ||
|
if (clientExtended->m_bRetryClockSync ||
|
||||||
(currentTime - clientExtended.m_flLastClockSyncTime) > sv_clockSyncInterval->GetFloat())
|
(currentTime - clientExtended->m_flLastClockSyncTime) > sv_clockSyncInterval->GetFloat())
|
||||||
{
|
{
|
||||||
// Sync the clocks on the client with that of the server's.
|
// Sync the clocks on the client with that of the server's.
|
||||||
commandTick = pClient->GetCommandTick();
|
commandTick = pClient->GetCommandTick();
|
||||||
clientExtended.m_flLastClockSyncTime = currentTime;
|
clientExtended->m_flLastClockSyncTime = currentTime;
|
||||||
clientExtended.m_bRetryClockSync = false;
|
clientExtended->m_bRetryClockSync = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If commandTick == statistics only while server opted out, do not
|
// If commandTick == statistics only while server opted out, do not
|
||||||
@ -132,7 +132,7 @@ void CNetworkStringTableContainer::WriteUpdateMessage(CNetworkStringTableContain
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Assert(0, "Snapshot buffer overflowed before string table update!");
|
Assert(0, "Snapshot buffer overflowed before string table update!");
|
||||||
clientExtended.m_bRetryClockSync = true; // Retry on next snapshot for this client.
|
clientExtended->m_bRetryClockSync = true; // Retry on next snapshot for this client.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // !CLIENT_DLL
|
#endif // !CLIENT_DLL
|
||||||
|
@ -222,4 +222,5 @@ void VServer::Detour(const bool bAttach) const
|
|||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
CServer* g_pServer = nullptr;
|
CServer* g_pServer = nullptr;
|
||||||
|
CClientExtended CServer::sm_ClientsExtended[MAX_PLAYERS];
|
||||||
|
@ -45,7 +45,8 @@ public:
|
|||||||
inline int GetMaxClients(void) const { return m_nMaxClients; }
|
inline int GetMaxClients(void) const { return m_nMaxClients; }
|
||||||
|
|
||||||
inline int64_t GetMaxTeams(void) const { return m_iMaxTeams; }
|
inline int64_t GetMaxTeams(void) const { return m_iMaxTeams; }
|
||||||
inline CClient* GetClient(int nIndex) { Assert(nIndex >= NULL && nIndex < MAX_PLAYERS); return &m_Clients[nIndex]; }
|
inline CClient* GetClient(const int nIndex) { Assert(nIndex >= NULL && nIndex < MAX_PLAYERS); return &m_Clients[nIndex]; }
|
||||||
|
inline CClientExtended* GetClientExtended(const int nIndex) { Assert(nIndex >= NULL && nIndex < MAX_PLAYERS); return &sm_ClientsExtended[nIndex]; }
|
||||||
|
|
||||||
inline float GetTime(void) const { return m_nTickCount * m_flTickInterval; }
|
inline float GetTime(void) const { return m_nTickCount * m_flTickInterval; }
|
||||||
inline float GetCPUUsage(void) const { return m_fCPUPercent; }
|
inline float GetCPUUsage(void) const { return m_fCPUPercent; }
|
||||||
@ -58,7 +59,6 @@ public:
|
|||||||
static CClient* ConnectClient(CServer* pServer, user_creds_s* pChallenge);
|
static CClient* ConnectClient(CServer* pServer, user_creds_s* pChallenge);
|
||||||
|
|
||||||
void BroadcastMessage(CNetMessage* const msg, const bool onlyActive, const bool reliable);
|
void BroadcastMessage(CNetMessage* const msg, const bool onlyActive, const bool reliable);
|
||||||
void UpdateClientClocks(void);
|
|
||||||
static void RunFrame(CServer* pServer);
|
static void RunFrame(CServer* pServer);
|
||||||
static void FrameJob(double flFrameTime, bool bRunOverlays, bool bUpdateFrame);
|
static void FrameJob(double flFrameTime, bool bRunOverlays, bool bUpdateFrame);
|
||||||
#endif // !CLIENT_DLL
|
#endif // !CLIENT_DLL
|
||||||
@ -101,6 +101,11 @@ private:
|
|||||||
float m_fStartTime;
|
float m_fStartTime;
|
||||||
float m_fLastCPUCheckTime;
|
float m_fLastCPUCheckTime;
|
||||||
bool m_bTeams[MAX_TEAMS]; // Something with teams, unclear what this does; see '[r5apex_ds.exe + 0x30CE40]'
|
bool m_bTeams[MAX_TEAMS]; // Something with teams, unclear what this does; see '[r5apex_ds.exe + 0x30CE40]'
|
||||||
|
|
||||||
|
// Maps directly to m_Clients, contains extended client data which we
|
||||||
|
// cannot add to the CClient class as it would otherwise mismatch the
|
||||||
|
// structure in the engine.
|
||||||
|
static CClientExtended sm_ClientsExtended[MAX_PLAYERS];
|
||||||
};
|
};
|
||||||
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
|
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
|
||||||
// !TODO: check if struct size is correct for S1!
|
// !TODO: check if struct size is correct for S1!
|
||||||
|
@ -20,8 +20,5 @@ void HVEngineServer::Detour(const bool bAttach) const
|
|||||||
DetourSetup(&IVEngineServer__PersistenceAvailable, &CVEngineServer::PersistenceAvailable, bAttach);
|
DetourSetup(&IVEngineServer__PersistenceAvailable, &CVEngineServer::PersistenceAvailable, bAttach);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
ServerPlayer_t g_ServerPlayer[MAX_PLAYERS];
|
|
||||||
|
|
||||||
IVEngineServer* g_pEngineServerVFTable = nullptr;
|
IVEngineServer* g_pEngineServerVFTable = nullptr;
|
||||||
CVEngineServer* g_pEngineServer = reinterpret_cast<CVEngineServer*>(&g_pEngineServerVFTable);
|
CVEngineServer* g_pEngineServer = reinterpret_cast<CVEngineServer*>(&g_pEngineServerVFTable);
|
||||||
|
@ -10,34 +10,6 @@ inline bool* m_bIsDedicated = nullptr;
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct ServerPlayer_t
|
|
||||||
{
|
|
||||||
ServerPlayer_t(void)
|
|
||||||
{
|
|
||||||
Reset();
|
|
||||||
}
|
|
||||||
inline void Reset(void)
|
|
||||||
{
|
|
||||||
m_flCurrentNetProcessTime = 0.0;
|
|
||||||
m_flLastNetProcessTime = 0.0;
|
|
||||||
m_flLastClockSyncTime = 0.0;
|
|
||||||
m_flStringCommandQuotaTimeStart = 0.0;
|
|
||||||
m_nStringCommandQuotaCount = NULL;
|
|
||||||
m_bRetryClockSync = false;
|
|
||||||
m_bInitialConVarsSet = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
double m_flCurrentNetProcessTime;
|
|
||||||
double m_flLastNetProcessTime;
|
|
||||||
double m_flLastClockSyncTime;
|
|
||||||
double m_flStringCommandQuotaTimeStart;
|
|
||||||
int m_nStringCommandQuotaCount;
|
|
||||||
bool m_bRetryClockSync;
|
|
||||||
bool m_bInitialConVarsSet;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern ServerPlayer_t g_ServerPlayer[MAX_PLAYERS];
|
|
||||||
|
|
||||||
class CVEngineServer : public IVEngineServer
|
class CVEngineServer : public IVEngineServer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user