From dcc2c6224b848e83ceb89928006c6a834d1312fa Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 20 Sep 2022 02:00:52 +0200 Subject: [PATCH] Improve NetChan process time limit * Check if m_MessageHandler is removed before running limit test. * Add warning DevMsg if client exceeds value. * Default 'net_processTimeBudget' value to '200'. --- r5dev/engine/net_chan.cpp | 12 +++++++++--- r5dev/tier1/IConVar.cpp | 2 +- r5dev/tier1/cvar.cpp | 2 +- r5dev/tier1/cvar.h | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/r5dev/engine/net_chan.cpp b/r5dev/engine/net_chan.cpp index 12639b95..1e63a76c 100644 --- a/r5dev/engine/net_chan.cpp +++ b/r5dev/engine/net_chan.cpp @@ -216,12 +216,15 @@ void CNetChan::Clear(bool bStopProcessing) bool CNetChan::ProcessMessages(CNetChan* pChan, bf_read* pMsg) { #ifndef CLIENT_DLL - if (!ThreadInServerFrameThread() || !net_processLimit->GetInt()) + if (!ThreadInServerFrameThread() || !net_processTimeBudget->GetInt()) return v_NetChan_ProcessMessages(pChan, pMsg); const double flStartTime = Plat_FloatTime(); const bool bResult = v_NetChan_ProcessMessages(pChan, pMsg); + if (!pChan->m_MessageHandler) // NetChannel removed? + return bResult; + CClient* pClient = reinterpret_cast(pChan->m_MessageHandler); ServerPlayer_t* pSlot = &g_ServerPlayer[pClient->GetUserID()]; @@ -235,9 +238,12 @@ bool CNetChan::ProcessMessages(CNetChan* pChan, bf_read* pMsg) (Plat_FloatTime() * 1000) - (flStartTime * 1000); if (pSlot->m_flCurrentNetProcessTime > - net_processLimit->GetDouble()) + net_processTimeBudget->GetDouble()) { - pClient->Disconnect(REP_MARK, "#DISCONNECT_NETCHAN_OVERFLOW"); + Warning(eDLL_T::ENGINE, "Removing netchannel '%s' ('%s' exceeded frame budget by '%3.1f'ms!)\n", + pChan->GetName(), pChan->GetAddress(), (pSlot->m_flCurrentNetProcessTime - net_processTimeBudget->GetDouble())); + pClient->Disconnect(Reputation_t::REP_MARK, "#DISCONNECT_NETCHAN_OVERFLOW"); + return false; } diff --git a/r5dev/tier1/IConVar.cpp b/r5dev/tier1/IConVar.cpp index 4d339371..9d7952fe 100644 --- a/r5dev/tier1/IConVar.cpp +++ b/r5dev/tier1/IConVar.cpp @@ -203,7 +203,7 @@ void ConVar::Init(void) const net_tracePayload = ConVar::Create("net_tracePayload" , "0", FCVAR_DEVELOPMENTONLY , "Log the payload of the send/recv datagram to a file on the disk.", false, 0.f, false, 0.f, nullptr, nullptr); net_encryptionEnable = ConVar::Create("net_encryptionEnable" , "1", FCVAR_DEVELOPMENTONLY | FCVAR_REPLICATED , "Use AES encryption on game packets.", false, 0.f, false, 0.f, nullptr, nullptr); net_useRandomKey = ConVar::Create("net_useRandomKey" , "1" , FCVAR_RELEASE , "Use random AES encryption key for game packets.", false, 0.f, false, 0.f, &NET_UseRandomKeyChanged_f, nullptr); - net_processLimit = ConVar::Create("net_processLimit" , "0" , FCVAR_RELEASE , "Net message process budget in milliseconds (removing netchannel if exceeded).", true, 0.f, false, 0.f, nullptr, "0 = disabled."); + net_processTimeBudget = ConVar::Create("net_processTimeBudget" ,"200" , FCVAR_RELEASE , "Net message process budget in milliseconds (removing netchannel if exceeded).", true, 0.f, false, 0.f, nullptr, "0 = disabled."); //------------------------------------------------------------------------- // NETWORKSYSTEM | pylon_matchmaking_hostname = ConVar::Create("pylon_matchmaking_hostname", "ms.r5reloaded.com", FCVAR_RELEASE , "Holds the pylon matchmaking hostname.", false, 0.f, false, 0.f, &MP_HostName_Changed_f, nullptr); diff --git a/r5dev/tier1/cvar.cpp b/r5dev/tier1/cvar.cpp index 13963f3d..45003d49 100644 --- a/r5dev/tier1/cvar.cpp +++ b/r5dev/tier1/cvar.cpp @@ -172,7 +172,7 @@ ConVar* net_tracePayload = nullptr; ConVar* net_encryptionEnable = nullptr; ConVar* net_useRandomKey = nullptr; ConVar* net_usesocketsforloopback = nullptr; -ConVar* net_processLimit = nullptr; +ConVar* net_processTimeBudget = nullptr; ConVar* pylon_matchmaking_hostname = nullptr; ConVar* pylon_host_update_interval = nullptr; ConVar* pylon_showdebuginfo = nullptr; diff --git a/r5dev/tier1/cvar.h b/r5dev/tier1/cvar.h index 6ba32f97..612716ab 100644 --- a/r5dev/tier1/cvar.h +++ b/r5dev/tier1/cvar.h @@ -167,7 +167,7 @@ extern ConVar* net_tracePayload; extern ConVar* net_encryptionEnable; extern ConVar* net_useRandomKey; extern ConVar* net_usesocketsforloopback; -extern ConVar* net_processLimit; +extern ConVar* net_processTimeBudget; extern ConVar* pylon_matchmaking_hostname; extern ConVar* pylon_host_update_interval; extern ConVar* pylon_showdebuginfo;