From 82f202c891c9794e125a4f42e90cbf6850a5aa6a Mon Sep 17 00:00:00 2001 From: Koncord Date: Fri, 4 Nov 2016 20:15:14 +0800 Subject: [PATCH] Implement GetAvgPing(pid) function --- apps/openmw-mp/Networking.cpp | 7 ++++++- apps/openmw-mp/Networking.hpp | 1 + apps/openmw-mp/Script/ScriptFunctions.cpp | 9 ++++++++- apps/openmw-mp/Script/ScriptFunctions.hpp | 4 +++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index aa7481fe6..b8cd4c9f1 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -845,4 +845,9 @@ unsigned short Networking::NumberOfConnections() const unsigned int Networking::MaxConnections() const { return peer->GetMaximumIncomingConnections(); -} \ No newline at end of file +} + +int Networking::GetAvgPing(RakNet::AddressOrGUID addr) const +{ + return peer->GetAveragePing(addr); +} diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index afba73f49..7674413e4 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -27,6 +27,7 @@ namespace mwmp unsigned short NumberOfConnections() const; unsigned int MaxConnections() const; + int GetAvgPing(RakNet::AddressOrGUID) const; int MainLoop(); diff --git a/apps/openmw-mp/Script/ScriptFunctions.cpp b/apps/openmw-mp/Script/ScriptFunctions.cpp index 15132bdb3..d58f90a9e 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.cpp +++ b/apps/openmw-mp/Script/ScriptFunctions.cpp @@ -130,4 +130,11 @@ const char *ScriptFunctions::GetProtocolVersion() noexcept { static string version = to_string(TES3MP_PROTO_VERSION); return version.c_str(); -} \ No newline at end of file +} + +int ScriptFunctions::GetAvgPing(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player,-1); + return mwmp::Networking::Get().GetAvgPing(player->guid); +} diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index e3dcef1fd..1e10342a5 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -60,6 +60,7 @@ public: static void Kick(unsigned short pid) noexcept; static const char *GetServerVersion() noexcept; static const char *GetProtocolVersion() noexcept; + static int GetAvgPing(unsigned short pid) noexcept; static constexpr ScriptFunctionData functions[]{ {"CreateTimer", ScriptFunctions::CreateTimer}, @@ -80,7 +81,8 @@ public: {"SendMessage", ScriptFunctions::SendMessage}, {"Kick", ScriptFunctions::Kick}, {"GetServerVersion", ScriptFunctions::GetServerVersion}, - {"GetProtocolVersion", ScriptFunctions::GetProtocolVersion}, + {"GetProtocolVersion", ScriptFunctions::GetProtocolVersion}, + {"GetAvgPing", ScriptFunctions::GetAvgPing}, TRANSLOCATIONFUNCTIONS, STATSFUNCTIONS,