mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Server: improve extended client class
Use setters/getters and make members private and only accessible from CClient or CClientExtended.
This commit is contained in:
parent
b1eb8ae26f
commit
c5808e1117
@ -41,6 +41,7 @@ void CClient::VClear(CClient* pClient)
|
||||
pClient->Clear();
|
||||
}
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
//---------------------------------------------------------------------------------
|
||||
// Purpose: gets the extended client data
|
||||
// Output : CClientExtended* -
|
||||
@ -49,6 +50,7 @@ CClientExtended* CClient::GetClientExtended(void) const
|
||||
{
|
||||
return m_pServer->GetClientExtended(m_nUserID);
|
||||
}
|
||||
#endif // !CLIENT_DLL
|
||||
|
||||
|
||||
static const char JWT_PUBLIC_KEY[] =
|
||||
|
@ -74,7 +74,9 @@ public:
|
||||
inline CNetChan* GetNetChan(void) const { return m_NetChannel; }
|
||||
inline CServer* GetServer(void) const { return m_pServer; }
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
CClientExtended* GetClientExtended(void) const;
|
||||
#endif // !CLIENT_DLL
|
||||
|
||||
inline int GetCommandTick(void) const { return m_nCommandTick; }
|
||||
inline const char* GetServerName(void) const { return m_szServerName; }
|
||||
@ -221,6 +223,7 @@ static_assert(sizeof(CClient) == 0x4A4C0);
|
||||
//-----------------------------------------------------------------------------
|
||||
class CClientExtended
|
||||
{
|
||||
friend class CClient;
|
||||
public:
|
||||
CClientExtended(void)
|
||||
{
|
||||
@ -228,8 +231,8 @@ public:
|
||||
}
|
||||
inline void Reset(void)
|
||||
{
|
||||
m_flCurrentNetProcessTime = 0.0;
|
||||
m_flLastNetProcessTime = 0.0;
|
||||
m_flNetProcessingTimeMsecs = 0.0;
|
||||
m_flNetProcessTimeBase = 0.0;
|
||||
m_flLastClockSyncTime = 0.0;
|
||||
m_flStringCommandQuotaTimeStart = 0.0;
|
||||
m_nStringCommandQuotaCount = NULL;
|
||||
@ -237,13 +240,40 @@ public:
|
||||
m_bInitialConVarsSet = false;
|
||||
}
|
||||
|
||||
double m_flCurrentNetProcessTime;
|
||||
double m_flLastNetProcessTime;
|
||||
public: // Inlines:
|
||||
inline void SetNetProcessingTimeMsecs(const double flStartTime, const double flCurrentTime)
|
||||
{ m_flNetProcessingTimeMsecs = (flCurrentTime * 1000) - (flStartTime * 1000); }
|
||||
inline double GetNetProcessingTimeMsecs(void) const { return m_flNetProcessingTimeMsecs; }
|
||||
|
||||
inline void SetNetProcessingTimeBase(const double flTime) { m_flNetProcessTimeBase = flTime; }
|
||||
inline double GetNetProcessingTimeBase(void) const { return m_flNetProcessTimeBase; }
|
||||
|
||||
inline void SetLastClockSyncTime(const double flTime) { m_flLastClockSyncTime = flTime; }
|
||||
inline double GetLastClockSyncTime(void) const { return m_flLastClockSyncTime; }
|
||||
|
||||
inline void SetStringCommandQuotaTimeStart(const double flTime) { m_flStringCommandQuotaTimeStart = flTime; }
|
||||
inline double GetStringCommandQuotaTimeStart(void) const { return m_flStringCommandQuotaTimeStart; }
|
||||
|
||||
inline void SetStringCommandQuotaCount(const int iCount) { m_nStringCommandQuotaCount = iCount; }
|
||||
inline int GetStringCommandQuotaCount(void) const { return m_nStringCommandQuotaCount; }
|
||||
|
||||
inline void SetRetryClockSync(const bool bSet) { m_bRetryClockSync = bSet; }
|
||||
inline bool ShouldRetryClockSync() const { return m_bRetryClockSync; }
|
||||
|
||||
private:
|
||||
// Measure how long this client's packets took to process.
|
||||
double m_flNetProcessingTimeMsecs;
|
||||
double m_flNetProcessTimeBase;
|
||||
|
||||
// When was the last clock sync?
|
||||
double m_flLastClockSyncTime;
|
||||
|
||||
// The start time of the first stringcmd since reset.
|
||||
double m_flStringCommandQuotaTimeStart;
|
||||
int m_nStringCommandQuotaCount;
|
||||
bool m_bRetryClockSync;
|
||||
bool m_bInitialConVarsSet;
|
||||
|
||||
bool m_bRetryClockSync; // Whether or not we should retry sending clock sync msg.
|
||||
bool m_bInitialConVarsSet; // Whether or not the initial ConVar KV's are set
|
||||
};
|
||||
|
||||
/* ==== CBASECLIENT ===================================================================================================================================================== */
|
||||
|
@ -348,20 +348,20 @@ bool CNetChan::_ProcessMessages(CNetChan* pChan, bf_read* pBuf)
|
||||
CClient* const pClient = reinterpret_cast<CClient*>(pChan->m_MessageHandler);
|
||||
CClientExtended* const pExtended = pClient->GetClientExtended();
|
||||
|
||||
if (flStartTime - pExtended->m_flLastNetProcessTime >= 1.0 ||
|
||||
pExtended->m_flLastNetProcessTime == -1.0)
|
||||
// Reset every second.
|
||||
if ((flStartTime - pExtended->GetNetProcessingTimeBase()) > 1.0)
|
||||
{
|
||||
pExtended->m_flLastNetProcessTime = flStartTime;
|
||||
pExtended->m_flCurrentNetProcessTime = 0.0;
|
||||
pExtended->SetNetProcessingTimeBase(flStartTime);
|
||||
pExtended->SetNetProcessingTimeMsecs(0.0, 0.0);
|
||||
}
|
||||
pExtended->m_flCurrentNetProcessTime +=
|
||||
(Plat_FloatTime() * 1000) - (flStartTime * 1000);
|
||||
|
||||
if (pExtended->m_flCurrentNetProcessTime >
|
||||
net_processTimeBudget->GetFloat())
|
||||
const double flCurrentTime = Plat_FloatTime();
|
||||
pExtended->SetNetProcessingTimeMsecs(flStartTime, flCurrentTime);
|
||||
|
||||
if (pExtended->GetNetProcessingTimeMsecs() > net_processTimeBudget->GetFloat())
|
||||
{
|
||||
Warning(eDLL_T::SERVER, "Removing netchannel '%s' ('%s' exceeded frame budget by '%3.1f'ms!)\n",
|
||||
pChan->GetName(), pChan->GetAddress(), (pExtended->m_flCurrentNetProcessTime - net_processTimeBudget->GetFloat()));
|
||||
Warning(eDLL_T::SERVER, "Removing netchannel '%s' ('%s' exceeded time budget by '%3.1f'ms!)\n",
|
||||
pChan->GetName(), pChan->GetAddress(), (pExtended->GetNetProcessingTimeMsecs() - net_processTimeBudget->GetFloat()));
|
||||
pClient->Disconnect(Reputation_t::REP_MARK_BAD, "#DISCONNECT_NETCHAN_OVERFLOW");
|
||||
|
||||
return false;
|
||||
|
@ -101,13 +101,14 @@ void CNetworkStringTableContainer::WriteUpdateMessage(CNetworkStringTableContain
|
||||
// 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
|
||||
// between each server tick message for this to work correctly.
|
||||
if (clientExtended->m_bRetryClockSync ||
|
||||
(currentTime - clientExtended->m_flLastClockSyncTime) > sv_clockSyncInterval->GetFloat())
|
||||
if (clientExtended->ShouldRetryClockSync() ||
|
||||
(currentTime - clientExtended->GetLastClockSyncTime()) > sv_clockSyncInterval->GetFloat())
|
||||
{
|
||||
// Sync the clocks on the client with that of the server's.
|
||||
commandTick = pClient->GetCommandTick();
|
||||
clientExtended->m_flLastClockSyncTime = currentTime;
|
||||
clientExtended->m_bRetryClockSync = false;
|
||||
|
||||
clientExtended->SetLastClockSyncTime(currentTime);
|
||||
clientExtended->SetRetryClockSync(false);
|
||||
}
|
||||
|
||||
// If commandTick == statistics only while server opted out, do not
|
||||
@ -132,7 +133,7 @@ void CNetworkStringTableContainer::WriteUpdateMessage(CNetworkStringTableContain
|
||||
else
|
||||
{
|
||||
Assert(0, "Snapshot buffer overflowed before string table update!");
|
||||
clientExtended->m_bRetryClockSync = true; // Retry on next snapshot for this client.
|
||||
clientExtended->SetRetryClockSync(true); // Retry on next snapshot for this client.
|
||||
}
|
||||
}
|
||||
#endif // !CLIENT_DLL
|
||||
|
Loading…
x
Reference in New Issue
Block a user