From b942db837c13f923e87c47ad131bdd1cb6ccc2fe Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 31 Mar 2024 15:20:29 +0200 Subject: [PATCH] Engine: reimplement netmsg debuggers Reimplement logic for cvars: "net_showmsg", "net_blockmsg", "net_showpeaks". --- r5dev/common/global.cpp | 8 ++++++++ r5dev/common/global.h | 4 ++++ r5dev/engine/net_chan.cpp | 40 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/r5dev/common/global.cpp b/r5dev/common/global.cpp index 244583bf..d18725d6 100644 --- a/r5dev/common/global.cpp +++ b/r5dev/common/global.cpp @@ -111,6 +111,10 @@ ConVar* net_usesocketsforloopback; ConVar* net_data_block_enabled = nullptr; ConVar* net_datablock_networkLossForSlowSpeed = nullptr; ConVar* net_compressDataBlock = nullptr; + +ConVar* net_showmsg = nullptr; +ConVar* net_blockmsg = nullptr; +ConVar* net_showpeaks = nullptr; //----------------------------------------------------------------------------- // RUI | #ifndef DEDICATED @@ -183,6 +187,10 @@ void ConVar_InitShipped(void) net_datablock_networkLossForSlowSpeed = g_pCVar->FindVar("net_datablock_networkLossForSlowSpeed"); net_usesocketsforloopback = g_pCVar->FindVar("net_usesocketsforloopback"); + + net_showmsg = g_pCVar->FindVar("net_showmsg"); + net_blockmsg = g_pCVar->FindVar("net_blockmsg"); + net_showpeaks = g_pCVar->FindVar("net_showpeaks"); #ifndef CLIENT_DLL sv_stats = g_pCVar->FindVar("sv_stats"); diff --git a/r5dev/common/global.h b/r5dev/common/global.h index 568b42b5..e958199b 100644 --- a/r5dev/common/global.h +++ b/r5dev/common/global.h @@ -98,6 +98,10 @@ extern ConVar* net_data_block_enabled; extern ConVar* net_datablock_networkLossForSlowSpeed; extern ConVar* net_compressDataBlock; +extern ConVar* net_showmsg; +extern ConVar* net_blockmsg; +extern ConVar* net_showpeaks; + extern ConVar ssl_verify_peer; extern ConVar curl_timeout; extern ConVar curl_debug; diff --git a/r5dev/engine/net_chan.cpp b/r5dev/engine/net_chan.cpp index 2645d95b..16fefd21 100644 --- a/r5dev/engine/net_chan.cpp +++ b/r5dev/engine/net_chan.cpp @@ -417,7 +417,25 @@ bool CNetChan::_ProcessMessages(CNetChan* pChan, bf_read* pBuf) bool CNetChan::ProcessMessages(bf_read* buf) { m_bStopProcessing = false; - //const double flStartTime = Plat_FloatTime(); + + const char* showMsgName = net_showmsg->GetString(); + const char* blockMsgName = net_blockmsg->GetString(); + const int netPeak = net_showpeaks->GetInt(); + + if (*showMsgName == '0') + { + showMsgName = NULL; // dont do strcmp all the time + } + + if (*blockMsgName == '0') + { + blockMsgName = NULL; // dont do strcmp all the time + } + + if (netPeak > 0 && netPeak < buf->GetNumBytesLeft()) + { + showMsgName = "1"; // show messages for this packet only + } while (true) { @@ -457,6 +475,26 @@ bool CNetChan::ProcessMessages(bf_read* buf) return false; } + if (showMsgName) + { + if ((*showMsgName == '1') || !Q_stricmp(showMsgName, netMsg->GetName())) + { + Msg(eDLL_T::ENGINE, "%s(%s): Received: %s\n", + __FUNCTION__, GetAddress(), netMsg->ToString()); + } + } + + if (blockMsgName) + { + if ((*blockMsgName == '1') || !Q_stricmp(blockMsgName, netMsg->GetName())) + { + Msg(eDLL_T::ENGINE, "%s(%s): Blocked: %s\n", + __FUNCTION__, GetAddress(), netMsg->ToString()); + + continue; + } + } + // Netmessage calls the Process function that was registered by // it's MessageHandler. m_bProcessingMessages = true;