Skip to content

Commit

Permalink
Add net stat
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed Jun 5, 2020
1 parent 377f4c5 commit 81ecf88
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/network/net.cpp
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/network/net.h
Expand Up @@ -62,6 +62,7 @@ class Network
// 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;
Expand Down
7 changes: 7 additions & 0 deletions src/network/netclient.cpp
Expand Up @@ -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()
{
}
Expand Down
1 change: 1 addition & 0 deletions src/network/netclient.h
Expand Up @@ -47,6 +47,7 @@ class NetClient : public Network
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;
Expand Down
14 changes: 14 additions & 0 deletions src/network/netnode.cpp
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/network/netnode.h
Expand Up @@ -15,6 +15,8 @@ class NetNodeOutput
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
Expand Down
7 changes: 7 additions & 0 deletions src/network/netserver.cpp
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/network/netserver.h
Expand Up @@ -68,6 +68,7 @@ class NetServer : public Network
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;
Expand Down
5 changes: 5 additions & 0 deletions src/network/netsingle.cpp
Expand Up @@ -123,3 +123,8 @@ void NetSinglePlayer::ListPingTimes()
void NetSinglePlayer::Network_Controller(int playernum, bool add)
{
}

FString NetSinglePlayer::GetStats()
{
return "Not in a multiplayer game";
}
1 change: 1 addition & 0 deletions src/network/netsingle.h
Expand Up @@ -43,6 +43,7 @@ class NetSinglePlayer : public Network
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;
Expand Down

1 comment on commit 81ecf88

@Epictyphlosion
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this actually had something done in 2020!

Now work on it more.

Please sign in to comment.