From 409fc282d2e6918b8e2ffe23a00cfa15952cc2f8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 4 Jul 2017 11:17:47 +0100 Subject: [PATCH] Cleaned up ping response and added missing fields (#1114) --- src/pocketmine/Server.php | 15 ++++++++++++++ src/pocketmine/network/SourceInterface.php | 2 +- .../network/mcpe/RakLibInterface.php | 20 ++++++++++++------- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 25c5d948e..25ef2dca1 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -441,6 +441,21 @@ class Server{ return "UNKNOWN"; } + public static function getGamemodeName(int $mode) : string{ + switch($mode){ + case Player::SURVIVAL: + return "Survival"; + case Player::CREATIVE: + return "Creative"; + case Player::ADVENTURE: + return "Adventure"; + case Player::SPECTATOR: + return "Spectator"; + default: + throw new \InvalidArgumentException("Invalid gamemode $mode"); + } + } + /** * Parses a string and returns a gamemode integer, -1 if not found * diff --git a/src/pocketmine/network/SourceInterface.php b/src/pocketmine/network/SourceInterface.php index bd7f41ef7..92a1d18ac 100644 --- a/src/pocketmine/network/SourceInterface.php +++ b/src/pocketmine/network/SourceInterface.php @@ -58,7 +58,7 @@ interface SourceInterface{ /** * @param string $name */ - public function setName($name); + public function setName(string $name); /** * @return bool diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index 00237b7d3..3b0ec4e7f 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -165,15 +165,21 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ } - public function setName($name){ + public function setName(string $name){ $info = $this->server->getQueryInformation(); - $this->interface->sendOption("name", - "MCPE;" . rtrim(addcslashes($name, ";"), '\\') . ";" . - ProtocolInfo::CURRENT_PROTOCOL . ";" . - ProtocolInfo::MINECRAFT_VERSION_NETWORK . ";" . - $info->getPlayerCount() . ";" . - $info->getMaxPlayerCount() + $this->interface->sendOption("name", implode(";", + [ + "MCPE", + rtrim(addcslashes($name, ";"), '\\'), + ProtocolInfo::CURRENT_PROTOCOL, + ProtocolInfo::MINECRAFT_VERSION_NETWORK, + $info->getPlayerCount(), + $info->getMaxPlayerCount(), + "-1", + $this->server->getName(), + Server::getGamemodeName($this->server->getGamemode()) + ]) ); }