diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 716e02469..91ab33911 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -477,6 +477,16 @@ void Networking::kickPlayer(RakNet::RakNetGUID guid) peer->CloseConnection(guid, true); } +void Networking::banAddress(const char *ipAddress) +{ + peer->AddToBanList(ipAddress); +} + +void Networking::unbanAddress(const char *ipAddress) +{ + peer->RemoveFromBanList(ipAddress); +} + unsigned short Networking::numberOfConnections() const { return peer->NumberOfConnections(); diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index 68ede6255..7deadd537 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -23,6 +23,9 @@ namespace mwmp void newPlayer(RakNet::RakNetGUID guid); void disconnectPlayer(RakNet::RakNetGUID guid); void kickPlayer(RakNet::RakNetGUID guid); + + void banAddress(const char *ipAddress); + void unbanAddress(const char *ipAddress); RakNet::SystemAddress getSystemAddress(RakNet::RakNetGUID guid); void processPlayerPacket(RakNet::Packet *packet); diff --git a/apps/openmw-mp/Script/ScriptFunctions.cpp b/apps/openmw-mp/Script/ScriptFunctions.cpp index 55316aead..604a3f8ba 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.cpp +++ b/apps/openmw-mp/Script/ScriptFunctions.cpp @@ -108,6 +108,16 @@ void ScriptFunctions::Kick(unsigned short pid) noexcept mwmp::Networking::getPtr()->kickPlayer(player->guid); } +void ScriptFunctions::BanAddress(const char *ipAddress) noexcept +{ + mwmp::Networking::getPtr()->banAddress(ipAddress); +} + +void ScriptFunctions::UnbanAddress(const char *ipAddress) noexcept +{ + mwmp::Networking::getPtr()->unbanAddress(ipAddress); +} + const char *ScriptFunctions::GetServerVersion() noexcept { return TES3MP_VERSION; @@ -126,6 +136,14 @@ int ScriptFunctions::GetAvgPing(unsigned short pid) noexcept return mwmp::Networking::get().getAvgPing(player->guid); } +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); +} + void ScriptFunctions::SetModname(const char *name) noexcept { mwmp::Networking::getPtr()->getMasterClient()->SetModname(name); @@ -154,11 +172,3 @@ 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 6ad47a55d..c46cd8917 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -69,11 +69,14 @@ 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 void BanAddress(const char *ipAddress) noexcept; + static void UnbanAddress(const char *ipAddress) noexcept; + static const char *GetServerVersion() noexcept; static const char *GetProtocolVersion() noexcept; static int GetAvgPing(unsigned short pid) noexcept; + static const char* GetIP(unsigned short pid) noexcept; static void SetModname(const char* name) noexcept; static void SetHostname(const char* name) noexcept; static void SetServerPassword(const char *passw) noexcept; @@ -95,7 +98,11 @@ public: {"StopServer", ScriptFunctions::StopServer}, {"SendMessage", ScriptFunctions::SendMessage}, + {"Kick", ScriptFunctions::Kick}, + {"BanAddress", ScriptFunctions::BanAddress}, + {"UnbanAddress", ScriptFunctions::UnbanAddress}, + {"GetServerVersion", ScriptFunctions::GetServerVersion}, {"GetProtocolVersion", ScriptFunctions::GetProtocolVersion}, {"GetAvgPing", ScriptFunctions::GetAvgPing}, diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index ff9375b25..5e10478c9 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -295,7 +295,7 @@ void Networking::connect(const std::string &ip, unsigned short port, std::vector case ID_DISCONNECTION_NOTIFICATION: throw runtime_error("ID_DISCONNECTION_NOTIFICATION.\n"); case ID_CONNECTION_BANNED: - throw runtime_error("ID_CONNECTION_BANNED.\n"); + throw runtime_error("You have been banned from this server.\n"); case ID_CONNECTION_LOST: throw runtime_error("ID_CONNECTION_LOST.\n"); default: