diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 082205d8b..f39138132 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -127,8 +127,12 @@ namespace pocketmine { define("pocketmine\\DATA", isset($opts["data"]) ? $opts["data"] . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR); define("pocketmine\\PLUGIN_PATH", isset($opts["plugins"]) ? $opts["plugins"] . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR); + + echo "HAHA"; Terminal::init(); + echo "HAHA"; + define("pocketmine\\ANSI", Terminal::hasFormattingCodes()); if(!file_exists(\pocketmine\DATA)){ diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index ca45a2974..13d58a62b 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2039,7 +2039,8 @@ class Server{ $this->properties->save(); $this->getLogger()->debug("Closing console"); - $this->console->kill(); + $this->console->shutdown(); + $this->console->detach(); $this->getLogger()->debug("Stopping network interfaces"); foreach($this->network->getInterfaces() as $interface){ diff --git a/src/pocketmine/command/CommandReader.php b/src/pocketmine/command/CommandReader.php index 15287692e..54f25cc23 100644 --- a/src/pocketmine/command/CommandReader.php +++ b/src/pocketmine/command/CommandReader.php @@ -25,26 +25,36 @@ use pocketmine\Thread; class CommandReader extends Thread{ private $readline; - /** @var \Threaded */ protected $buffer; + private $shutdown = false; public function __construct(){ $this->buffer = \ThreadedFactory::create(); $this->start(); } + public function shutdown(){ + $this->shutdown = true; + } + private function readLine(){ if(!$this->readline){ - $line = trim(fgets(fopen("php://stdin", "r"))); + global $stdin; + + if(!is_resource($stdin)){ + return ""; + } + + return trim(fgets($stdin)); }else{ $line = trim(readline("> ")); if($line != ""){ readline_add_history($line); } - } - return $line; + return $line; + } } /** @@ -65,15 +75,18 @@ class CommandReader extends Thread{ if(extension_loaded("readline") and !isset($opts["disable-readline"])){ $this->readline = true; }else{ + global $stdin; + $stdin = fopen("php://stdin", "r"); + stream_set_blocking($stdin, 0); $this->readline = false; } $lastLine = microtime(true); - while(true){ + while(!$this->shutdown){ if(($line = $this->readLine()) !== ""){ $this->buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", $line); - }elseif((microtime(true) - $lastLine) <= 0.1){ //Non blocking! Sleep to save CPU - usleep(40000); + }elseif(!$this->shutdown and (microtime(true) - $lastLine) <= 0.1){ //Non blocking! Sleep to save CPU + usleep(10000); } $lastLine = microtime(true); diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index b8f99cdff..dbc6fb7b0 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -220,7 +220,7 @@ class Utils{ self::$os = "other"; } } - + return self::$os; }