PHP7 changes

This commit is contained in:
Shoghi Cervantes 2015-08-03 09:42:16 +02:00
parent 7f8b39a63c
commit b47cebb1d5
4 changed files with 27 additions and 9 deletions

View File

@ -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)){

View File

@ -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){

View File

@ -25,27 +25,37 @@ 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;
}
}
/**
* Reads a line from console, if available. Returns null if not available
@ -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);