Skip to content

Commit

Permalink
The motd and server-icon can now be modified
Browse files Browse the repository at this point in the history
  • Loading branch information
shoghicp committed Jun 29, 2014
1 parent a29298c commit 4c761a3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
3 changes: 3 additions & 0 deletions resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion src/shoghicp/BigBrother/BigBrother.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 10 additions & 3 deletions src/shoghicp/BigBrother/network/ServerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 === ""){
Expand Down
13 changes: 10 additions & 3 deletions src/shoghicp/BigBrother/network/ServerThread.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ServerThread extends \Thread{
/** @var \ThreadedLogger */
protected $logger;
protected $loader;
protected $data = [];

public $loadPaths = [];

Expand All @@ -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");
Expand All @@ -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));
Expand Down Expand Up @@ -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"]);
}
}
11 changes: 7 additions & 4 deletions src/shoghicp/BigBrother/network/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function process(){
"id" => $id
];
}
$data = json_encode([
$data = [
"version" => [
"name" => Info::VERSION,
"protocol" => Info::PROTOCOL
Expand All @@ -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);
Expand Down

0 comments on commit 4c761a3

Please sign in to comment.