[Server] Add GetMaxPlayers, GetPort and HasPassword functions to API

pull/471/head
Koncord 6 years ago
parent 3bd8aa82fe
commit 48f4792bc1

@ -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;

@ -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();

@ -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())

@ -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.
*

Loading…
Cancel
Save