Added RCON protocol

This commit is contained in:
Shoghi Cervantes Pueyo
2013-04-22 14:22:52 +02:00
parent 70056b8d1f
commit 1cb3e25bf9
3 changed files with 217 additions and 8 deletions

View File

@@ -37,8 +37,7 @@ class ConsoleAPI{
public function init(){
$this->event = $this->server->event("server.tick", array($this, "handle"));
$this->loop = new ConsoleLoop;
$this->loop->start();
$this->loop = new ConsoleLoop();
$this->register("help", "[page|command name]", array($this, "defaultCommands"));
$this->register("status", "", array($this, "defaultCommands"));
$this->register("difficulty", "<0|1>", array($this, "defaultCommands"));
@@ -53,6 +52,7 @@ class ConsoleAPI{
function __destruct(){
$this->server->deleteEvent($this->event);
$this->loop->stop = true;
@fclose(STDIN);
$this->loop->notify();
$this->loop->join();
}
@@ -227,11 +227,6 @@ class ConsoleAPI{
}
if($output != "" and ($issuer instanceof Player)){
$issuer->sendChat(trim($output));
}elseif($output != "" and $issuer === "console"){
$mes = explode("\n", trim($output));
foreach($mes as $m){
console("[CMD] ".$m);
}
}
return $output;
}
@@ -241,7 +236,13 @@ class ConsoleAPI{
if($this->loop->line !== false){
$line = trim($this->loop->line);
$this->loop->line = false;
$this->run($line, "console");
$output = $this->run($line, "console");
if($output != ""){
$mes = explode("\n", trim($output));
foreach($mes as $m){
console("[CMD] ".$m);
}
}
}else{
$this->loop->notify();
}
@@ -255,6 +256,7 @@ class ConsoleLoop extends Thread{
public function __construct(){
$this->line = false;
$this->stop = false;
$this->start();
}
public function run(){
@@ -264,6 +266,7 @@ class ConsoleLoop extends Thread{
$this->wait();
$this->line = false;
}
@fclose($fp);
exit(0);
}
}

View File

@@ -33,6 +33,7 @@ class ServerAPI{
private $config;
private $apiList = array();
private $asyncCnt = 0;
private $rcon;
public static function request(){
return self::$serverRequest;
@@ -113,6 +114,9 @@ class ServerAPI{
"generator-settings" => "",
"level-name" => false,
"server-id" => false,
"enable-rcon" => false,
"rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10),
"rcon.port" => 19132,
"upnp-forwarding" => false,
"send-usage" => true,
));
@@ -340,8 +344,17 @@ class ServerAPI{
$this->server->schedule(6000, array($this, "sendUsage")); //Send the info after 5 minutes have passed
$this->sendUsage();
}
if($this->getProperty("enable-rcon") === true){
$this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", 19132));
}
$this->server->init();
unregister_tick_function(array($this->server, "tick"));
$this->console->__destruct();
if($this->rcon instanceof RCON){
$this->rcon->stop();
}
$this->__destruct();
if($this->getProperty("upnp-forwarding") === true ){
console("[INFO] [UPnP] Removing port forward...");