Implement GetAvgPing(pid) function

This commit is contained in:
Koncord 2016-11-04 20:15:14 +08:00
parent 37e9cafbf7
commit 82f202c891
4 changed files with 18 additions and 3 deletions

View file

@ -846,3 +846,8 @@ unsigned int Networking::MaxConnections() const
{ {
return peer->GetMaximumIncomingConnections(); return peer->GetMaximumIncomingConnections();
} }
int Networking::GetAvgPing(RakNet::AddressOrGUID addr) const
{
return peer->GetAveragePing(addr);
}

View file

@ -27,6 +27,7 @@ namespace mwmp
unsigned short NumberOfConnections() const; unsigned short NumberOfConnections() const;
unsigned int MaxConnections() const; unsigned int MaxConnections() const;
int GetAvgPing(RakNet::AddressOrGUID) const;
int MainLoop(); int MainLoop();

View file

@ -131,3 +131,10 @@ const char *ScriptFunctions::GetProtocolVersion() noexcept
static string version = to_string(TES3MP_PROTO_VERSION); static string version = to_string(TES3MP_PROTO_VERSION);
return version.c_str(); return version.c_str();
} }
int ScriptFunctions::GetAvgPing(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player,-1);
return mwmp::Networking::Get().GetAvgPing(player->guid);
}

View file

@ -60,6 +60,7 @@ public:
static void Kick(unsigned short pid) noexcept; static void Kick(unsigned short pid) noexcept;
static const char *GetServerVersion() noexcept; static const char *GetServerVersion() noexcept;
static const char *GetProtocolVersion() noexcept; static const char *GetProtocolVersion() noexcept;
static int GetAvgPing(unsigned short pid) noexcept;
static constexpr ScriptFunctionData functions[]{ static constexpr ScriptFunctionData functions[]{
{"CreateTimer", ScriptFunctions::CreateTimer}, {"CreateTimer", ScriptFunctions::CreateTimer},
@ -81,6 +82,7 @@ public:
{"Kick", ScriptFunctions::Kick}, {"Kick", ScriptFunctions::Kick},
{"GetServerVersion", ScriptFunctions::GetServerVersion}, {"GetServerVersion", ScriptFunctions::GetServerVersion},
{"GetProtocolVersion", ScriptFunctions::GetProtocolVersion}, {"GetProtocolVersion", ScriptFunctions::GetProtocolVersion},
{"GetAvgPing", ScriptFunctions::GetAvgPing},
TRANSLOCATIONFUNCTIONS, TRANSLOCATIONFUNCTIONS,
STATSFUNCTIONS, STATSFUNCTIONS,