From 7bf466cf3f6ad9a9dfd87f67479f26dea4639f3a Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Thu, 10 Feb 2022 16:10:31 -0500 Subject: [PATCH] [Commands] Cleanup #netstats Command. (#1970) - Utilize popup over chat messages. --- zone/gm_commands/netstats.cpp | 294 +++++++++++++++++++--------------- 1 file changed, 161 insertions(+), 133 deletions(-) diff --git a/zone/gm_commands/netstats.cpp b/zone/gm_commands/netstats.cpp index 6bd56f4fa..87fd11a4c 100755 --- a/zone/gm_commands/netstats.cpp +++ b/zone/gm_commands/netstats.cpp @@ -2,140 +2,168 @@ void command_netstats(Client *c, const Seperator *sep) { - if (c) { - auto client = c; - if (c->GetTarget() && c->GetTarget()->IsClient()) { - client = c->GetTarget()->CastToClient(); - } + bool is_full = !strcasecmp(sep->arg[1], "full"); + bool is_reset = !strcasecmp(sep->arg[1], "reset"); - if (strcasecmp(sep->arg[1], "reset") == 0) { - auto connection = c->Connection(); - c->Message(Chat::White, "Resetting client stats (packet loss will not read correctly after reset)."); - connection->ResetStats(); - return; - } - - auto connection = c->Connection(); - auto opts = connection->GetManager()->GetOptions(); - auto eqs_stats = connection->GetStats(); - auto &stats = eqs_stats.DaybreakStats; - auto now = EQ::Net::Clock::now(); - auto sec_since_stats_reset = std::chrono::duration_cast>( - now - stats.created - ).count(); - - c->Message(Chat::White, "Netstats:"); - c->Message(Chat::White, "--------------------------------------------------------------------"); - c->Message( - Chat::White, - "Sent Bytes: %u (%.2f/sec)", - stats.sent_bytes, - stats.sent_bytes / sec_since_stats_reset - ); - c->Message( - Chat::White, - "Recv Bytes: %u (%.2f/sec)", - stats.recv_bytes, - stats.recv_bytes / sec_since_stats_reset - ); - c->Message( - Chat::White, "Bytes Before Encode (Sent): %u, Compression Rate: %.2f%%", stats.bytes_before_encode, - static_cast(stats.bytes_before_encode - stats.sent_bytes) / - static_cast(stats.bytes_before_encode) * 100.0 - ); - c->Message( - Chat::White, "Bytes After Decode (Recv): %u, Compression Rate: %.2f%%", stats.bytes_after_decode, - static_cast(stats.bytes_after_decode - stats.recv_bytes) / - static_cast(stats.bytes_after_decode) * 100.0 - ); - c->Message(Chat::White, "Min Ping: %u", stats.min_ping); - c->Message(Chat::White, "Max Ping: %u", stats.max_ping); - c->Message(Chat::White, "Last Ping: %u", stats.last_ping); - c->Message(Chat::White, "Average Ping: %u", stats.avg_ping); - c->Message(Chat::White, "--------------------------------------------------------------------"); - c->Message( - Chat::White, - "(Realtime) Recv Packets: %u (%.2f/sec)", - stats.recv_packets, - stats.recv_packets / sec_since_stats_reset - ); - c->Message( - Chat::White, - "(Realtime) Sent Packets: %u (%.2f/sec)", - stats.sent_packets, - stats.sent_packets / sec_since_stats_reset - ); - c->Message(Chat::White, "(Sync) Recv Packets: %u", stats.sync_recv_packets); - c->Message(Chat::White, "(Sync) Sent Packets: %u", stats.sync_sent_packets); - c->Message(Chat::White, "(Sync) Remote Recv Packets: %u", stats.sync_remote_recv_packets); - c->Message(Chat::White, "(Sync) Remote Sent Packets: %u", stats.sync_remote_sent_packets); - c->Message( - Chat::White, - "Packet Loss In: %.2f%%", - 100.0 * (1.0 - static_cast(stats.sync_recv_packets) / - static_cast(stats.sync_remote_sent_packets))); - c->Message( - Chat::White, - "Packet Loss Out: %.2f%%", - 100.0 * (1.0 - static_cast(stats.sync_remote_recv_packets) / - static_cast(stats.sync_sent_packets))); - c->Message(Chat::White, "--------------------------------------------------------------------"); - c->Message( - Chat::White, - "Resent Packets: %u (%.2f/sec)", - stats.resent_packets, - stats.resent_packets / sec_since_stats_reset - ); - c->Message( - Chat::White, - "Resent Fragments: %u (%.2f/sec)", - stats.resent_fragments, - stats.resent_fragments / sec_since_stats_reset - ); - c->Message( - Chat::White, - "Resent Non-Fragments: %u (%.2f/sec)", - stats.resent_full, - stats.resent_full / sec_since_stats_reset - ); - c->Message( - Chat::White, - "Dropped Datarate Packets: %u (%.2f/sec)", - stats.dropped_datarate_packets, - stats.dropped_datarate_packets / sec_since_stats_reset - ); - - if (opts.daybreak_options.outgoing_data_rate > 0.0) { - c->Message( - Chat::White, - "Outgoing Link Saturation %.2f%% (%.2fkb/sec)", - 100.0 * (1.0 - ((opts.daybreak_options.outgoing_data_rate - stats.datarate_remaining) / - opts.daybreak_options.outgoing_data_rate)), - opts.daybreak_options.outgoing_data_rate - ); - } - - if (strcasecmp(sep->arg[1], "full") == 0) { - c->Message(Chat::White, "--------------------------------------------------------------------"); - c->Message(Chat::White, "Sent Packet Types"); - for (auto i = 0; i < _maxEmuOpcode; ++i) { - auto cnt = eqs_stats.SentCount[i]; - if (cnt > 0) { - c->Message(Chat::White, "%s: %u (%.2f / sec)", OpcodeNames[i], cnt, cnt / sec_since_stats_reset); - } - } - - c->Message(Chat::White, "--------------------------------------------------------------------"); - c->Message(Chat::White, "Recv Packet Types"); - for (auto i = 0; i < _maxEmuOpcode; ++i) { - auto cnt = eqs_stats.RecvCount[i]; - if (cnt > 0) { - c->Message(Chat::White, "%s: %u (%.2f / sec)", OpcodeNames[i], cnt, cnt / sec_since_stats_reset); - } - } - } - - c->Message(Chat::White, "--------------------------------------------------------------------"); + if (is_reset) { + auto connection = c->Connection(); + c->Message(Chat::White, "Resetting client stats (packet loss will not read correctly after reset)."); + connection->ResetStats(); + return; } + + auto connection = c->Connection(); + auto opts = connection->GetManager()->GetOptions(); + auto eqs_stats = connection->GetStats(); + auto &stats = eqs_stats.DaybreakStats; + auto now = EQ::Net::Clock::now(); + auto sec_since_stats_reset = std::chrono::duration_cast>( + now - stats.created + ).count(); + + std::string popup_text = ""; + + popup_text += fmt::format( + "", + stats.sent_bytes, + stats.sent_bytes / sec_since_stats_reset + ); + + popup_text += fmt::format( + "", + stats.recv_bytes, + stats.recv_bytes / sec_since_stats_reset + ); + + popup_text += "

"; + + popup_text += fmt::format( + "", + stats.bytes_before_encode, + static_cast(stats.bytes_before_encode - stats.sent_bytes) / + static_cast(stats.bytes_before_encode) * 100.0 + ); + + popup_text += fmt::format( + "", + stats.bytes_after_decode, + static_cast(stats.bytes_after_decode - stats.recv_bytes) / + static_cast(stats.bytes_after_decode) * 100.0 + ); + + popup_text += "

"; + + popup_text += fmt::format("
", stats.min_ping); + popup_text += fmt::format("", stats.max_ping); + popup_text += fmt::format("", stats.last_ping); + popup_text += fmt::format("", stats.avg_ping); + + popup_text += "

"; + + popup_text += fmt::format( + "", + stats.recv_packets, + stats.recv_packets / sec_since_stats_reset + ); + + popup_text += fmt::format( + "", + stats.sent_packets, + stats.sent_packets / sec_since_stats_reset + ); + + popup_text += "

"; + + popup_text += fmt::format("", stats.sync_recv_packets); + popup_text += fmt::format("", stats.sync_sent_packets); + popup_text += fmt::format("", stats.sync_remote_recv_packets); + popup_text += fmt::format("", stats.sync_remote_sent_packets); + + popup_text += "

"; + + popup_text += fmt::format( + "", + (100.0 * (1.0 - static_cast(stats.sync_recv_packets) / static_cast(stats.sync_remote_sent_packets))) + ); + + popup_text += fmt::format( + "", + (100.0 * (1.0 - static_cast(stats.sync_remote_recv_packets) / static_cast(stats.sync_sent_packets))) + ); + + popup_text += "

"; + + popup_text += fmt::format( + "
", + stats.resent_packets, + stats.resent_packets / sec_since_stats_reset + ); + + popup_text += fmt::format( + "", + stats.resent_fragments, + stats.resent_fragments / sec_since_stats_reset + ); + + popup_text += fmt::format( + "", + stats.resent_full, + stats.resent_full / sec_since_stats_reset + ); + + popup_text += "

"; + + popup_text += fmt::format( + "", + stats.dropped_datarate_packets, + stats.dropped_datarate_packets / sec_since_stats_reset + ); + + if (opts.daybreak_options.outgoing_data_rate > 0.0) { + popup_text += fmt::format( + "", + (100.0 * (1.0 - ((opts.daybreak_options.outgoing_data_rate - stats.datarate_remaining) / opts.daybreak_options.outgoing_data_rate))), + opts.daybreak_options.outgoing_data_rate + ); + } + + if (is_full) { + popup_text += "

"; + + popup_text += ""; + for (auto i = 0; i < _maxEmuOpcode; ++i) { + auto cnt = eqs_stats.SentCount[i]; + if (cnt > 0) { + popup_text += fmt::format( + "", + OpcodeNames[i], + cnt, + cnt / sec_since_stats_reset + ); + } + } + + popup_text += "

"; + + popup_text += ""; + for (auto i = 0; i < _maxEmuOpcode; ++i) { + auto cnt = eqs_stats.RecvCount[i]; + if (cnt > 0) { + popup_text += fmt::format( + "", + OpcodeNames[i], + cnt, + cnt / sec_since_stats_reset + ); + } + } + } + + popup_text += "
Sent Bytes{} ({:.2f} Per Second)
Received Bytes{} ({:.2f} Per Second)
Bytes Before Encode (Sent){}Compression Rate{:.2f}%%
Bytes After Decode (Received){}Compression Rate{:.2f}%%
Min Ping{}
Max Ping{}
Last Ping{}
Average Ping{}
(Realtime) Received Packets{} ({:.2f} Per Second)
(Realtime) Sent Packets{} ({:.2f} Per Second)
(Sync) Received Packets{}
(Sync) Sent Packets{}
(Sync) Remote Received Packets{}
(Sync) Remote Sent Packets{}
Packet Loss In{:.2f}%%
Packet Loss Out{:.2f}%%
Resent Packets{} ({:.2f} Per Second)
Resent Fragments{} ({:.2f} Per Second)
Resent Non-Fragments{} ({:.2f} Per Second)
Dropped Datarate Packets{} ({:.2f} Per Second)
Outgoing Link Saturation{:.2f}%% ({:.2f}kb Per Second)
Sent Packet Types
{}{} ({:.2f} Per Second)
Received Packet Types
{}{} ({:.2f} Per Second)
"; + + c->SendPopupToClient( + "Network Statistics", + popup_text.c_str() + ); }