diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 8dc082fa4..716e02469 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -376,6 +376,11 @@ Networking *Networking::getPtr() return sThis; } +RakNet::SystemAddress Networking::getSystemAddress(RakNet::RakNetGUID guid) +{ + return peer->GetSystemAddressFromGuid(guid); +} + PacketPreInit::PluginContainer Networking::getPluginListSample() { PacketPreInit::PluginContainer pls; diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index 92474e727..68ede6255 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -23,6 +23,7 @@ namespace mwmp void newPlayer(RakNet::RakNetGUID guid); void disconnectPlayer(RakNet::RakNetGUID guid); void kickPlayer(RakNet::RakNetGUID guid); + RakNet::SystemAddress getSystemAddress(RakNet::RakNetGUID guid); void processPlayerPacket(RakNet::Packet *packet); void processActorPacket(RakNet::Packet *packet); diff --git a/apps/openmw-mp/Script/ScriptFunctions.cpp b/apps/openmw-mp/Script/ScriptFunctions.cpp index 5ed893b53..55316aead 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.cpp +++ b/apps/openmw-mp/Script/ScriptFunctions.cpp @@ -154,3 +154,11 @@ void ScriptFunctions::SetRuleValue(const char *key, double value) noexcept if (mc) mc->SetRuleValue(key, value); } + +const char *ScriptFunctions::GetIP(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ""); + RakNet::SystemAddress addr = mwmp::Networking::getPtr()->getSystemAddress(player->guid); + return addr.ToString(false); +} diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index 0e3792fef..a6d1177e7 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -69,6 +69,7 @@ public: static void FreeTimer(int timerId) noexcept; static bool IsTimerElapsed(int timerId) noexcept; + static const char* GetIP(unsigned short pid) noexcept; static void Kick(unsigned short pid) noexcept; static const char *GetServerVersion() noexcept; static const char *GetProtocolVersion() noexcept; @@ -105,6 +106,7 @@ public: {"SetRuleValue", ScriptFunctions::SetRuleValue}, {"CleanChatByPid", ScriptFunctions::CleanChatByPid}, {"CleanChat", ScriptFunctions::CleanChat}, + {"GetIP", ScriptFunctions::GetIP}, ACTORAPI, BOOKAPI,