mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 18:59:00 +00:00
PHP7 changes
This commit is contained in:
parent
7f8b39a63c
commit
b47cebb1d5
@ -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)){
|
||||
|
@ -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){
|
||||
|
@ -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);
|
||||
|
@ -220,7 +220,7 @@ class Utils{
|
||||
self::$os = "other";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return self::$os;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user