diff --git a/r5dev/engine/client/client.cpp b/r5dev/engine/client/client.cpp index 4aef78e8..d0c649f8 100644 --- a/r5dev/engine/client/client.cpp +++ b/r5dev/engine/client/client.cpp @@ -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[] = diff --git a/r5dev/engine/client/client.h b/r5dev/engine/client/client.h index 5451edbd..5f962c4b 100644 --- a/r5dev/engine/client/client.h +++ b/r5dev/engine/client/client.h @@ -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 ===================================================================================================================================================== */ diff --git a/r5dev/engine/net_chan.cpp b/r5dev/engine/net_chan.cpp index 80062655..4f2103c7 100644 --- a/r5dev/engine/net_chan.cpp +++ b/r5dev/engine/net_chan.cpp @@ -348,20 +348,20 @@ bool CNetChan::_ProcessMessages(CNetChan* pChan, bf_read* pBuf) CClient* const pClient = reinterpret_cast(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; diff --git a/r5dev/engine/networkstringtable.cpp b/r5dev/engine/networkstringtable.cpp index cb4a1e92..9dd7cebb 100644 --- a/r5dev/engine/networkstringtable.cpp +++ b/r5dev/engine/networkstringtable.cpp @@ -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