From 780051724e02110347dc066af7958da3f57278f4 Mon Sep 17 00:00:00 2001 From: AvarianKnight Date: Thu, 3 Aug 2023 23:46:12 -0500 Subject: [PATCH] feat(net): attribute proper packet names for timeout if a player times out instead of getting the packet hash they will get the packet name --- .../citizen-server-gui/src/PlayerList.cpp | 52 +++++-------------- .../include/GameServerNet.h | 2 + .../src/GameServerNet.ENet.cpp | 12 +++++ code/components/debug-net/src/NetDebug.cpp | 51 +++--------------- 4 files changed, 33 insertions(+), 84 deletions(-) diff --git a/code/components/citizen-server-gui/src/PlayerList.cpp b/code/components/citizen-server-gui/src/PlayerList.cpp index f59d79a309..b852acd80c 100644 --- a/code/components/citizen-server-gui/src/PlayerList.cpp +++ b/code/components/citizen-server-gui/src/PlayerList.cpp @@ -10,37 +10,11 @@ #include +#include "net/PacketNames.h" + static void SvPlayerList_Render(fx::ServerInstanceBase* instance); static SvGuiModule svplayerlist("Player List", "svplayerlist", ImGuiWindowFlags_NoCollapse, SvPlayerList_Render); -static std::pair g_knownPackets[] -{ - { HashRageString("msgConVars"),"msgConVars" }, - { HashRageString("msgEnd"), "msgEnd" }, - { HashRageString("msgEntityCreate"),"msgEntityCreate" }, - { HashRageString("msgNetGameEvent"),"msgNetGameEvent" }, - { HashRageString("msgObjectIds"),"msgObjectIds" }, - { HashRageString("msgPackedAcks"),"msgPackedAcks" }, - { HashRageString("msgPackedClones"),"msgPackedClones" }, - { HashRageString("msgPaymentRequest"),"msgPaymentRequest" }, - { HashRageString("msgRequestObjectIds"),"msgRequestObjectIds" }, - { HashRageString("msgResStart"),"msgResStart" }, - { HashRageString("msgResStop"),"msgResStop" }, - { HashRageString("msgRoute"),"msgRoute" }, - { HashRageString("msgRpcEntityCreation"),"msgRpcEntityCreation" }, - { HashRageString("msgRpcNative"),"msgRpcNative" }, - { HashRageString("msgServerCommand"),"msgServerCommand" }, - { HashRageString("msgServerEvent"),"msgServerEvent" }, - { HashRageString("msgTimeSync"),"msgTimeSync" }, - { HashRageString("msgTimeSyncReq"),"msgTimeSyncReq" }, - { HashRageString("msgWorldGrid"),"msgWorldGrid" }, - { HashRageString("msgFrame"),"msgFrame" }, - { HashRageString("msgIHost"),"msgIHost" }, - { HashRageString("gameStateAck"),"gameStateAck" }, - { HashRageString("gameStateNAck"),"gameStateNAck" }, - { HashRageString("msgNetEvent"),"msgNetEvent" }, -}; - struct PlayerAdvancedData { void Reset() @@ -67,12 +41,12 @@ struct PlayerAdvancedData // the callbacks will add to this automatically over time std::atomic_uint32_t bytesOutRaw; std::atomic_uint32_t bytesInRaw; - // # of times each packet was seen. (Array sizeof g_knownPackets) - std::atomic_uint16_t pktOccurancesRecv[std::size(g_knownPackets)]; - std::atomic_uint16_t pktOccurancesSend[std::size(g_knownPackets)]; - // # of bytes used per packet type. (Array sizeof g_knownPackets) - std::atomic_uint16_t pktBytesRecv[std::size(g_knownPackets)]; - std::atomic_uint16_t pktBytesSend[std::size(g_knownPackets)]; + // # of times each packet was seen. (Array sizeof net::PacketNames) + std::atomic_uint16_t pktOccurancesRecv[std::size(net::PacketNames)]; + std::atomic_uint16_t pktOccurancesSend[std::size(net::PacketNames)]; + // # of bytes used per packet type. (Array sizeof net::PacketNames) + std::atomic_uint16_t pktBytesRecv[std::size(net::PacketNames)]; + std::atomic_uint16_t pktBytesSend[std::size(net::PacketNames)]; // After it is time for a Graph update, the collect function will shove the number into the record here(graph requires float type) std::deque clientOutBytes; @@ -165,7 +139,7 @@ void RecvFromClient_Callback(fx::Client* client, uint32_t packetId, net::Buffer& // first 4 bytes are the rageHash uint32_t pktHash = *(uint32_t*)data.data(); int i = 0; - for (auto hash : g_knownPackets) + for (auto hash : net::PacketNames) { if (hash.first == pktHash) { @@ -197,7 +171,7 @@ void SendToClient_Callback(fx::Client* client, int channel, const net::Buffer& b // first 4 bytes are the rageHash uint32_t pktHash = *(uint32_t*)data.data(); int i = 0; - for (auto hash : g_knownPackets) + for (auto hash : net::PacketNames) { if (hash.first == pktHash) { @@ -267,17 +241,17 @@ static void CollectAdvancedDataForPlayer(PlayerAdvancedData* entry) entry->pktsSeenRecv.clear(); entry->pktsSeenSend.clear(); - for (int i = 0; i < std::size(g_knownPackets); i++) + for (int i = 0; i < std::size(net::PacketNames); i++) { if (entry->pktOccurancesRecv[i] > 0) { - entry->pktsSeenRecv.push_back(fmt::sprintf("%s[x%d] - %dB\n", g_knownPackets[i].second, entry->pktOccurancesRecv[i], entry->pktBytesRecv[i])); + entry->pktsSeenRecv.push_back(fmt::sprintf("%s[x%d] - %dB\n", net::PacketNames[i].second, entry->pktOccurancesRecv[i], entry->pktBytesRecv[i])); entry->pktOccurancesRecv[i] = 0; entry->pktBytesRecv[i] = 0; } if (entry->pktOccurancesSend[i] > 0) { - entry->pktsSeenSend.push_back(fmt::sprintf("%s[x%d] - %dB\n", g_knownPackets[i].second, entry->pktOccurancesSend[i], entry->pktBytesSend[i])); + entry->pktsSeenSend.push_back(fmt::sprintf("%s[x%d] - %dB\n", net::PacketNames[i].second, entry->pktOccurancesSend[i], entry->pktBytesSend[i])); entry->pktOccurancesSend[i] = 0; entry->pktBytesSend[i] = 0; } diff --git a/code/components/citizen-server-impl/include/GameServerNet.h b/code/components/citizen-server-impl/include/GameServerNet.h index d9e2860ab6..1587cce897 100644 --- a/code/components/citizen-server-impl/include/GameServerNet.h +++ b/code/components/citizen-server-impl/include/GameServerNet.h @@ -40,6 +40,8 @@ namespace fx uint32_t type; uint32_t timeAgo; size_t size; + // if type is msgNetEvent this will be the event name + // if the type is a known packet it will be the packet name, i.e. msgStateBag std::string eventName; }; diff --git a/code/components/citizen-server-impl/src/GameServerNet.ENet.cpp b/code/components/citizen-server-impl/src/GameServerNet.ENet.cpp index da12812dca..7f58f3b9c5 100644 --- a/code/components/citizen-server-impl/src/GameServerNet.ENet.cpp +++ b/code/components/citizen-server-impl/src/GameServerNet.ENet.cpp @@ -17,6 +17,7 @@ #include #include +#include namespace fx { @@ -314,6 +315,17 @@ namespace fx { info.eventName = std::string{ (const char*)packet->data + 8 }; } + else + { + for (const auto hash : net::PacketNames) + { + if (hash.first == info.type) + { + info.eventName = std::string{ hash.second }; + break; + } + } + } if (auto outIt = outgoingCommandsMap.find(packet); outIt != outgoingCommandsMap.end()) { diff --git a/code/components/debug-net/src/NetDebug.cpp b/code/components/debug-net/src/NetDebug.cpp index ebf3a4f0c4..f04c0d6f62 100644 --- a/code/components/debug-net/src/NetDebug.cpp +++ b/code/components/debug-net/src/NetDebug.cpp @@ -16,6 +16,8 @@ #include +#include + #include #include @@ -32,12 +34,11 @@ const int g_netOverlaySampleCount = 150; class RageHashList { public: - template - RageHashList(const char* (&list)[Size]) + RageHashList() { - for (int i = 0; i < Size; i++) + for (const auto packet : net::PacketNames) { - m_lookupList.insert({ HashRageString(list[i]), list[i] }); + m_lookupList.emplace(packet); } } @@ -57,47 +58,7 @@ class RageHashList std::map m_lookupList; }; -// rg -i '"msg' | grep -oP '"msg[A-Z].*?"' | sed 's/"$/",/g' | sort -u | clip -static const char* g_knownPackets[] -{ - "msgArrayUpdate", - "msgCloneAcks", - "msgCloneRemove", - "msgConVars", - "msgConfirm", - "msgEnd", - "msgEntityCreate", - "msgFrame", - "msgHeHost", - "msgIHost", - "msgIQuit", - "msgNetEvent", - "msgNetGameEvent", - "msgObjectIds", - "msgPackedAcks", - "msgPackedClones", - "msgPaymentRequest", - "msgReassembledEvent", - "msgRequestObjectIds", - "msgResStart", - "msgResStop", - "msgRoute", - "msgRpcEntityCreation", - "msgRpcNative", - "msgServerCommand", - "msgServerEvent", - "msgStateBag", - "msgTimeSync", - "msgTimeSyncReq", - "msgWorldGrid", - "msgWorldGrid3", - - // manual list that doesn't start with 'msg' - "gameStateAck", - "gameStateNAck", -}; - -static RageHashList g_hashes{ g_knownPackets }; +static RageHashList g_hashes; class NetOverlayMetricSink : public INetMetricSink {