diff --git a/src/network/net.cpp b/src/network/net.cpp index 57cad60cc1..85e36ccf5b 100644 --- a/src/network/net.cpp +++ b/src/network/net.cpp @@ -84,6 +84,14 @@ CUSTOM_CVAR(Int, net_extratic, 0, CVAR_SERVERINFO | CVAR_NOSAVE) } } +ADD_STAT(net) +{ + if (network) + return network->GetStats(); + else + return "Network object is null!"; +} + #if 0 CVAR(Int, net_fakelatency, 0, 0); diff --git a/src/network/net.h b/src/network/net.h index 6b89c299d1..9ffc435474 100644 --- a/src/network/net.h +++ b/src/network/net.h @@ -62,6 +62,7 @@ public: // Statistics virtual int GetPing(int player) const = 0; int GetHighPingThreshold() const { return ((BACKUPTICS / 2 - 1)) * (1000 / TICRATE); } + virtual FString GetStats() = 0; // CCMDs virtual void ListPingTimes() = 0; diff --git a/src/network/netclient.cpp b/src/network/netclient.cpp index 89c103bc1e..cdd263158e 100644 --- a/src/network/netclient.cpp +++ b/src/network/netclient.cpp @@ -230,6 +230,13 @@ int NetClient::GetPing(int player) const return 0; } +FString NetClient::GetStats() +{ + FString out; + out.Format("Tic ping = %d, unacked outbound data (%s)", mSendTic - mReceiveTic, mOutput.GetStats().GetChars()); + return out; +} + void NetClient::ListPingTimes() { } diff --git a/src/network/netclient.h b/src/network/netclient.h index d2fb766442..38a099af74 100644 --- a/src/network/netclient.h +++ b/src/network/netclient.h @@ -47,6 +47,7 @@ public: void WriteBotInput(int player, const ticcmd_t &cmd) override; int GetPing(int player) const override; + FString GetStats() override; void ListPingTimes() override; void Network_Controller(int playernum, bool add) override; diff --git a/src/network/netnode.cpp b/src/network/netnode.cpp index da11e24198..56d9c73070 100644 --- a/src/network/netnode.cpp +++ b/src/network/netnode.cpp @@ -81,6 +81,20 @@ void NetNodeOutput::AckPacket(uint8_t headerFlags, uint16_t serial, uint16_t ack } } +FString NetNodeOutput::GetStats() +{ + int total = 0; + int count = 0; + for (auto& msg : mMessages) + { + total += msg->size; + count++; + } + FString out; + out.Format("messages = %d, bytes = %d", count, total); + return out; +} + ///////////////////////////////////////////////////////////////////////////// bool NetNodeInput::IsMessageAvailable() diff --git a/src/network/netnode.h b/src/network/netnode.h index 524becea0c..5806aa13cb 100644 --- a/src/network/netnode.h +++ b/src/network/netnode.h @@ -15,6 +15,8 @@ public: void WriteMessage(const void *data, size_t size, bool unreliable); void Send(doomcom_t* comm, int nodeIndex); void AckPacket(uint8_t headerFlags, uint16_t serial, uint16_t ack); + + FString GetStats(); private: struct Message diff --git a/src/network/netserver.cpp b/src/network/netserver.cpp index 681458f1c0..3c5b68d691 100644 --- a/src/network/netserver.cpp +++ b/src/network/netserver.cpp @@ -203,6 +203,13 @@ int NetServer::GetPing(int player) const return 0; } +FString NetServer::GetStats() +{ + FString out; + out = "NetServer"; + return out; +} + void NetServer::ListPingTimes() { #if 0 diff --git a/src/network/netserver.h b/src/network/netserver.h index 7b3ee80731..54c24f7a7c 100644 --- a/src/network/netserver.h +++ b/src/network/netserver.h @@ -68,6 +68,7 @@ public: void WriteBotInput(int player, const ticcmd_t &cmd) override; int GetPing(int player) const override; + FString GetStats() override; void ListPingTimes() override; void Network_Controller(int playernum, bool add) override; diff --git a/src/network/netsingle.cpp b/src/network/netsingle.cpp index 41737cfe6b..9ca43face9 100644 --- a/src/network/netsingle.cpp +++ b/src/network/netsingle.cpp @@ -123,3 +123,8 @@ void NetSinglePlayer::ListPingTimes() void NetSinglePlayer::Network_Controller(int playernum, bool add) { } + +FString NetSinglePlayer::GetStats() +{ + return "Not in a multiplayer game"; +} diff --git a/src/network/netsingle.h b/src/network/netsingle.h index 4c5b26a6b1..d0926910f7 100644 --- a/src/network/netsingle.h +++ b/src/network/netsingle.h @@ -43,6 +43,7 @@ public: void WriteBotInput(int player, const ticcmd_t &cmd) override; int GetPing(int player) const override; + FString GetStats() override; void ListPingTimes() override; void Network_Controller(int playernum, bool add) override;