From 4c761a33115772a7b3a038399518fc4ab7719529 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 30 Jun 2014 01:36:24 +0200 Subject: [PATCH] The motd and server-icon can now be modified --- resources/config.yml | 3 +++ src/shoghicp/BigBrother/BigBrother.php | 7 ++++++- src/shoghicp/BigBrother/network/ServerManager.php | 13 ++++++++++--- src/shoghicp/BigBrother/network/ServerThread.php | 13 ++++++++++--- src/shoghicp/BigBrother/network/Session.php | 11 +++++++---- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/resources/config.yml b/resources/config.yml index 336a6a46..55f5f847 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -4,6 +4,9 @@ interface: 0.0.0.0 port: 25565 +#Sets the server description on the server list +motd: "§bPocketMine-MP server using §6§lBigBrother§r§b plugin\n§aConnect to Minecraft: PE servers from PC clients" + #Use Mojang services to authenticate players online-mode: true diff --git a/src/shoghicp/BigBrother/BigBrother.php b/src/shoghicp/BigBrother/BigBrother.php index 876def8a..5a3a3e49 100644 --- a/src/shoghicp/BigBrother/BigBrother.php +++ b/src/shoghicp/BigBrother/BigBrother.php @@ -64,6 +64,7 @@ class_exists("phpseclib\\Crypt\\AES", true); public function onEnable(){ $this->saveDefaultConfig(); + $this->saveResource("server-icon.png", false); $this->reloadConfig(); //TODO: work on online mode @@ -73,6 +74,10 @@ public function onEnable(){ $this->getLogger()->notice("no mcrypt detected, online-mode has been disabled. Try using the latest PHP binaries"); } + if(!$this->getConfig()->exists("motd")){ + $this->getLogger()->warning("No motd has been set. The server description will be empty."); + } + if(Info::CURRENT_PROTOCOL === 16){ $this->translator = new Translator_16(); }else{ @@ -106,7 +111,7 @@ protected function enableServer(){ $port = (int) $this->getConfig()->get("port"); $interface = $this->getConfig()->get("interface"); $this->getLogger()->info("Starting Minecraft: PC server on ".($interface === "0.0.0.0" ? "*" : $interface).":$port version ".MCInfo::VERSION); - $this->thread = new ServerThread($this->getServer()->getLogger(), $this->getServer()->getLoader(), $port, $interface); + $this->thread = new ServerThread($this->getServer()->getLogger(), $this->getServer()->getLoader(), $port, $interface, (string) $this->getConfig()->get("motd"), $this->getDataFolder() . "server-icon.png"); $this->interface = new ProtocolInterface($this, $this->thread, $this->translator); $this->getServer()->addInterface($this->interface); diff --git a/src/shoghicp/BigBrother/network/ServerManager.php b/src/shoghicp/BigBrother/network/ServerManager.php index 857720c6..300bedf5 100644 --- a/src/shoghicp/BigBrother/network/ServerManager.php +++ b/src/shoghicp/BigBrother/network/ServerManager.php @@ -82,10 +82,17 @@ class ServerManager{ public $maxPlayers = 20; /** @var string[] */ public $sample = []; - public $description = "§bPocketMine-MP server using §6§lBigBrother§r§b plugin\n§aConnect to Minecraft: PE servers from PC clients"; - public $favicon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA6mAAAOpgGH3KlvAAAAB3RJTUUH3gIJDS8ZnYfI6wAAA3VJREFUeNrtW8tOFEEUrXZmGNhNjAHjEwGBoLige1AGE2cH+AMakRATTYyJfoGsiF9gogY1ajQaP0AJiTEYYOTRDZEEA0p4iGhmVhM3MsBMu+WcxZ30wlXf2t2u6pqq03XOvbeqxhoaGvLNnpLL5faaJpvNgl0oFIxUtra2zP8slZWVYn08Hge7pqYG7OrqarD3mZAXBSDsAEQ3NjbgQT6fF1/YTCbxgY8Yth1uB9tbnQTbQooaK2KBXfpbBNuuTWF/axn8glURsE/MfQmkYUoBBSDsGlCO84nuG8hxCzk3s4QcN0dPI4djRPriDpju9ymwncbz4njs2g7ShM843q7rqGkjT0SNUwooAGHXAPaLvzrPol9eRY7ajWmwk61p8QdmFsawfQty3ElfE993R59h3GC2MQzZLtEnjYK5cqoV7MOzrq4ABUAB2KMBnL/7fgztGHLKHGxAO7eKnP34FBGO+di+tIsaMfoSNSLdh5yP4Teyj3XSJ4xQ/5hLGMo1eL5KAQUg7BrAD9ra+oL1QJxzGilWXx6jXGCXNAL9updBv+8XyM9HUKPcxXHab8ApWRVxXQEKgAIQQAO8iRfod+s6KH/PiPm9cxL99F3npjiAnv3yAIf/LOKDQ01or2Fsb6d6xf7WP33QFaAAKACCBjCnjY+xPO/jWxURMdbnkkjIA+ItSj5XsFkDOPbfRM3w1nA/44CuAAVAARA1wK7vFP3u++5mscN37Ocz8gBaWtDOUHs+S/RmXmOccKsf45DhBXzf2tYVoAAoAEHiAPLj7tgrsYOBkSUxbkilmkWOc0mlSEPuU25wu7fMlDBO8Yu+rgAFQAEIoAFz2WlEqCoqdjDY1STWX3z4HOx7C5RrGLx/MDCPnB08YwWqd5dx/E4DnkWuT03oClAAFAApDohifu/vxOQ4YF72sxy7k5suW3oe4PvetByXOBf6dQUoAApAAA3g+/d+CTXATl7B/QCDsbg7/gZ7pC1CpwPfdyffBhogx/JO+1UaD51l/v6GmrGC9wiP0HyVAgpA2DWA/2NT581gizL3BZzjeDfY+zErtz93CfN7cxkb0L5+sqk92Izo/kH9Vw/rab5KAQUg7BqQoMM6vk+ff3ynjKPms8OimAtwXMFl9ife+fHpb4p2Ud7nzw8/Eut5vkoBBSDkxdL/DisFFIBQl3+nqxY3IYpcCgAAAABJRU5ErkJggg=="; + public $description; + public $favicon; + + public function __construct(ServerThread $thread, $port, $interface, $description = "", $favicon = null){ + $this->description = $description; + if($favicon === null or ($image = file_get_contents($favicon)) == ""){ + $this->favicon = null; + }else{ + $this->favicon = "data:image/png;base64,".base64_encode($favicon); + } - public function __construct(ServerThread $thread, $port, $interface){ $this->logger = $thread->getLogger(); $this->fp = $thread->getInternalIPC(); if($interface === ""){ diff --git a/src/shoghicp/BigBrother/network/ServerThread.php b/src/shoghicp/BigBrother/network/ServerThread.php index 20849cc8..c076d64e 100644 --- a/src/shoghicp/BigBrother/network/ServerThread.php +++ b/src/shoghicp/BigBrother/network/ServerThread.php @@ -24,6 +24,7 @@ class ServerThread extends \Thread{ /** @var \ThreadedLogger */ protected $logger; protected $loader; + protected $data = []; public $loadPaths = []; @@ -37,10 +38,12 @@ class ServerThread extends \Thread{ * @param \SplAutoloader $loader * @param int $port 1-65536 * @param string $interface + * @param string $motd + * @param string $icon * * @throws \Exception */ - public function __construct(\ThreadedLogger $logger, \SplAutoloader $loader, $port, $interface = "0.0.0.0"){ + public function __construct(\ThreadedLogger $logger, \SplAutoloader $loader, $port, $interface = "0.0.0.0", $motd = "Minecraft: PE server", $icon = null){ $this->port = (int) $port; if($port < 1 or $port > 65536){ throw new \Exception("Invalid port range"); @@ -49,6 +52,10 @@ public function __construct(\ThreadedLogger $logger, \SplAutoloader $loader, $po $this->interface = $interface; $this->logger = $logger; $this->loader = $loader; + $this->data = serialize([ + "motd" => $motd, + "icon" => $icon + ]); $loadPaths = []; $this->addDependency($loadPaths, new \ReflectionClass($logger)); $this->addDependency($loadPaths, new \ReflectionClass($loader)); @@ -124,7 +131,7 @@ public function run(){ } } $this->loader->register(); - - $manager = new ServerManager($this, $this->port, $this->interface); + $data = unserialize($this->data); + $manager = new ServerManager($this, $this->port, $this->interface, $data["motd"], $data["icon"]); } } \ No newline at end of file diff --git a/src/shoghicp/BigBrother/network/Session.php b/src/shoghicp/BigBrother/network/Session.php index ffabce54..d3bc50e7 100644 --- a/src/shoghicp/BigBrother/network/Session.php +++ b/src/shoghicp/BigBrother/network/Session.php @@ -118,7 +118,7 @@ public function process(){ "id" => $id ]; } - $data = json_encode([ + $data = [ "version" => [ "name" => Info::VERSION, "protocol" => Info::PROTOCOL @@ -128,9 +128,12 @@ public function process(){ "online" => $this->manager->players, "sample" => $sample, ], - "description" => $this->manager->description, - "favicon" => $this->manager->favicon - ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + "description" => json_decode(TextFormat::toJSON($this->manager->description)) + ]; + if($this->manager->favicon !== null){ + $data["favicon"] = $this->manager->favicon; + } + $data = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); $data = Binary::writeVarInt(0x00) . Binary::writeVarInt(strlen($data)) . $data; $this->writeRaw($data);