From 3495fd43f476d49b1d5f202ff72c84bff5d341c7 Mon Sep 17 00:00:00 2001 From: Koncord Date: Sat, 28 Oct 2017 00:36:57 +0800 Subject: [PATCH] [Client] Add network statistics (CTRL+F2) --- apps/openmw/mwmp/GUI/GUIChat.cpp | 12 ++++++++++++ apps/openmw/mwmp/GUI/GUIChat.hpp | 3 +++ apps/openmw/mwmp/GUIController.cpp | 6 ++++++ apps/openmw/mwmp/Networking.cpp | 10 ++++++++++ apps/openmw/mwmp/Networking.hpp | 2 ++ 5 files changed, 33 insertions(+) diff --git a/apps/openmw/mwmp/GUI/GUIChat.cpp b/apps/openmw/mwmp/GUI/GUIChat.cpp index 414f40269..1bd677348 100644 --- a/apps/openmw/mwmp/GUI/GUIChat.cpp +++ b/apps/openmw/mwmp/GUI/GUIChat.cpp @@ -23,6 +23,7 @@ namespace mwmp GUIChat::GUIChat(int x, int y, int w, int h) : WindowBase("tes3mp_chat.layout") { + netStat = false; setCoord(x, y, w, h); getWidget(mCommandLine, "edit_Command"); @@ -250,10 +251,21 @@ namespace mwmp this->mMainWidget->setVisible(false); } } + + if(netStat) + { + auto rss = Main::get().getNetworking()->getNetworkStatistics(); + mHistory->setCaption(rss); + } } void GUIChat::setDelay(float delay) { this->delay = delay; } + + void GUIChat::switchNetstat() + { + netStat = !netStat; + } } diff --git a/apps/openmw/mwmp/GUI/GUIChat.hpp b/apps/openmw/mwmp/GUI/GUIChat.hpp index 059882561..82769b000 100644 --- a/apps/openmw/mwmp/GUI/GUIChat.hpp +++ b/apps/openmw/mwmp/GUI/GUIChat.hpp @@ -68,6 +68,8 @@ namespace mwmp void send(const std::string &str); + void switchNetstat(); + protected: private: @@ -82,6 +84,7 @@ namespace mwmp int windowState; bool editState; + bool netStat; float delay; float curTime; }; diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp index cff86664a..2985141dd 100644 --- a/apps/openmw/mwmp/GUIController.cpp +++ b/apps/openmw/mwmp/GUIController.cpp @@ -177,6 +177,12 @@ bool mwmp::GUIController::pressedKey(int key) MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager(); if (mChat == nullptr || windowManager->getMode() != MWGui::GM_None) return false; + + if(key == SDL_SCANCODE_F2 && (SDL_GetModState() & KMOD_CTRL) > 0) + { + mChat->switchNetstat(); + return true; + } if (key == keyChatMode) { mChat->pressedChatMode(); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 38dd17245..eb389f4d5 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -194,6 +195,7 @@ Networking::~Networking() RakNet::RakPeerInterface::DestroyInstance(peer); } + void Networking::update() { RakNet::Packet *packet; @@ -450,3 +452,11 @@ bool Networking::isConnected() { return connected; } + +std::string Networking::getNetworkStatistics() +{ + static char message[2048]; + auto rss = peer->GetStatistics(peer->GetSystemAddressFromIndex(0)); + StatisticsToString(rss, message, 2); + return message; +} diff --git a/apps/openmw/mwmp/Networking.hpp b/apps/openmw/mwmp/Networking.hpp index 2041d28b7..99d202ec8 100644 --- a/apps/openmw/mwmp/Networking.hpp +++ b/apps/openmw/mwmp/Networking.hpp @@ -46,6 +46,8 @@ namespace mwmp ActorList *getActorList(); WorldEvent *getWorldEvent(); + std::string getNetworkStatistics(); + private: bool connected; RakNet::RakPeerInterface *peer;