From 48f4792bc13cff4fc58dde76c3c7220382cc472a Mon Sep 17 00:00:00 2001 From: Koncord Date: Wed, 5 Sep 2018 18:19:34 +0800 Subject: [PATCH] [Server] Add GetMaxPlayers, GetPort and HasPassword functions to API --- apps/openmw-mp/Networking.cpp | 5 +++++ apps/openmw-mp/Networking.hpp | 1 + apps/openmw-mp/Script/Functions/Server.cpp | 15 ++++++++++++++ apps/openmw-mp/Script/Functions/Server.hpp | 24 ++++++++++++++++++++++ 4 files changed, 45 insertions(+) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 4a7538784..7255eb766 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -578,6 +578,11 @@ int Networking::getAvgPing(RakNet::AddressOrGUID addr) const return peer->GetAveragePing(addr); } +unsigned short Networking::getPort() const +{ + return peer->GetMyBoundAddress().GetPort(); +} + MasterClient *Networking::getMasterClient() { return mclient; diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index 3b1801d4c..1814a87ae 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -34,6 +34,7 @@ namespace mwmp unsigned short numberOfConnections() const; unsigned int maxConnections() const; int getAvgPing(RakNet::AddressOrGUID) const; + unsigned short getPort() const; int mainLoop(); diff --git a/apps/openmw-mp/Script/Functions/Server.cpp b/apps/openmw-mp/Script/Functions/Server.cpp index cb5ef5616..eff8e938b 100644 --- a/apps/openmw-mp/Script/Functions/Server.cpp +++ b/apps/openmw-mp/Script/Functions/Server.cpp @@ -57,6 +57,21 @@ const char *ServerFunctions::GetIP(unsigned short pid) noexcept return addr.ToString(false); } +unsigned short ServerFunctions::GetPort() noexcept +{ + return mwmp::Networking::get().getPort(); +} + +unsigned int ServerFunctions::GetMaxPlayers() noexcept +{ + return mwmp::Networking::get().maxConnections(); +} + +bool ServerFunctions::HasPassword() noexcept +{ + return mwmp::Networking::get().isPassworded(); +} + void ServerFunctions::SetGameMode(const char *gameMode) noexcept { if (mwmp::Networking::getPtr()->getMasterClient()) diff --git a/apps/openmw-mp/Script/Functions/Server.hpp b/apps/openmw-mp/Script/Functions/Server.hpp index 595dfb2af..21abac154 100644 --- a/apps/openmw-mp/Script/Functions/Server.hpp +++ b/apps/openmw-mp/Script/Functions/Server.hpp @@ -14,6 +14,9 @@ {"GetProtocolVersion", ServerFunctions::GetProtocolVersion},\ {"GetAvgPing", ServerFunctions::GetAvgPing},\ {"GetIP", ServerFunctions::GetIP},\ + {"GetMaxPlayers", ServerFunctions::GetMaxPlayers},\ + {"GetPort", ServerFunctions::GetPort},\ + {"HasPassword", ServerFunctions::HasPassword},\ \ {"SetGameMode", ServerFunctions::SetGameMode},\ {"SetHostname", ServerFunctions::SetHostname},\ @@ -87,6 +90,27 @@ public: */ static const char* GetIP(unsigned short pid) noexcept; + /** + * \brief Get the port used by the server. + * + * \return Port + */ + static unsigned short GetPort() noexcept; + + /** + * \brief Get the maximum number of players. + * + * \return Max players + */ + static unsigned int GetMaxPlayers() noexcept; + + /** + * \brief Checking if the server requires a password to connect. + * + * @return + */ + static bool HasPassword() noexcept; + /** * \brief Set the game mode of the server, as displayed in the server browser. *