[Client] Add network statistics (CTRL+F2)

new-script-api
Koncord 7 years ago
parent e7a5919477
commit 3495fd43f4

@ -23,6 +23,7 @@ namespace mwmp
GUIChat::GUIChat(int x, int y, int w, int h) GUIChat::GUIChat(int x, int y, int w, int h)
: WindowBase("tes3mp_chat.layout") : WindowBase("tes3mp_chat.layout")
{ {
netStat = false;
setCoord(x, y, w, h); setCoord(x, y, w, h);
getWidget(mCommandLine, "edit_Command"); getWidget(mCommandLine, "edit_Command");
@ -250,10 +251,21 @@ namespace mwmp
this->mMainWidget->setVisible(false); this->mMainWidget->setVisible(false);
} }
} }
if(netStat)
{
auto rss = Main::get().getNetworking()->getNetworkStatistics();
mHistory->setCaption(rss);
}
} }
void GUIChat::setDelay(float delay) void GUIChat::setDelay(float delay)
{ {
this->delay = delay; this->delay = delay;
} }
void GUIChat::switchNetstat()
{
netStat = !netStat;
}
} }

@ -68,6 +68,8 @@ namespace mwmp
void send(const std::string &str); void send(const std::string &str);
void switchNetstat();
protected: protected:
private: private:
@ -82,6 +84,7 @@ namespace mwmp
int windowState; int windowState;
bool editState; bool editState;
bool netStat;
float delay; float delay;
float curTime; float curTime;
}; };

@ -177,6 +177,12 @@ bool mwmp::GUIController::pressedKey(int key)
MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();
if (mChat == nullptr || windowManager->getMode() != MWGui::GM_None) if (mChat == nullptr || windowManager->getMode() != MWGui::GM_None)
return false; return false;
if(key == SDL_SCANCODE_F2 && (SDL_GetModState() & KMOD_CTRL) > 0)
{
mChat->switchNetstat();
return true;
}
if (key == keyChatMode) if (key == keyChatMode)
{ {
mChat->pressedChatMode(); mChat->pressedChatMode();

@ -30,6 +30,7 @@
#include <SDL_messagebox.h> #include <SDL_messagebox.h>
#include <RakSleep.h> #include <RakSleep.h>
#include <RakNetStatistics.h>
#include <iomanip> #include <iomanip>
#include <components/version/version.hpp> #include <components/version/version.hpp>
@ -194,6 +195,7 @@ Networking::~Networking()
RakNet::RakPeerInterface::DestroyInstance(peer); RakNet::RakPeerInterface::DestroyInstance(peer);
} }
void Networking::update() void Networking::update()
{ {
RakNet::Packet *packet; RakNet::Packet *packet;
@ -450,3 +452,11 @@ bool Networking::isConnected()
{ {
return connected; return connected;
} }
std::string Networking::getNetworkStatistics()
{
static char message[2048];
auto rss = peer->GetStatistics(peer->GetSystemAddressFromIndex(0));
StatisticsToString(rss, message, 2);
return message;
}

@ -46,6 +46,8 @@ namespace mwmp
ActorList *getActorList(); ActorList *getActorList();
WorldEvent *getWorldEvent(); WorldEvent *getWorldEvent();
std::string getNetworkStatistics();
private: private:
bool connected; bool connected;
RakNet::RakPeerInterface *peer; RakNet::RakPeerInterface *peer;

Loading…
Cancel
Save