mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-05 09:39:56 +00:00
parent
61e8828f94
commit
d84f990574
@ -28,6 +28,7 @@ class CommandReader extends Thread{
|
|||||||
/** @var \Threaded */
|
/** @var \Threaded */
|
||||||
protected $buffer;
|
protected $buffer;
|
||||||
private $shutdown = false;
|
private $shutdown = false;
|
||||||
|
private $streamBlocking = false;
|
||||||
|
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
$this->buffer = new \Threaded;
|
$this->buffer = new \Threaded;
|
||||||
@ -40,15 +41,28 @@ class CommandReader extends Thread{
|
|||||||
$this->shutdown = true;
|
$this->shutdown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function initStdin(){
|
||||||
|
global $stdin;
|
||||||
|
$stdin = fopen("php://stdin", "r");
|
||||||
|
$this->streamBlocking = (stream_set_blocking($stdin, 0) === false);
|
||||||
|
}
|
||||||
|
|
||||||
private function readLine(){
|
private function readLine(){
|
||||||
if(!$this->readline){
|
if(!$this->readline){
|
||||||
global $stdin;
|
global $stdin;
|
||||||
|
|
||||||
if(!is_resource($stdin)){
|
if(!is_resource($stdin)){
|
||||||
return "";
|
$this->initStdin();
|
||||||
}
|
}
|
||||||
|
|
||||||
return trim(fgets($stdin));
|
$line = fgets($stdin);
|
||||||
|
|
||||||
|
if($line === false and $this->streamBlocking === true){ //windows sucks
|
||||||
|
$this->initStdin();
|
||||||
|
$line = fgets($stdin);
|
||||||
|
}
|
||||||
|
|
||||||
|
return trim($line);
|
||||||
}else{
|
}else{
|
||||||
$line = trim(readline("> "));
|
$line = trim(readline("> "));
|
||||||
if($line != ""){
|
if($line != ""){
|
||||||
@ -74,9 +88,7 @@ class CommandReader extends Thread{
|
|||||||
|
|
||||||
public function run(){
|
public function run(){
|
||||||
if(!$this->readline){
|
if(!$this->readline){
|
||||||
global $stdin;
|
$this->initStdin();
|
||||||
$stdin = fopen("php://stdin", "r");
|
|
||||||
stream_set_blocking($stdin, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$lastLine = microtime(true);
|
$lastLine = microtime(true);
|
||||||
@ -91,6 +103,11 @@ class CommandReader extends Thread{
|
|||||||
|
|
||||||
$lastLine = microtime(true);
|
$lastLine = microtime(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!$this->readline){
|
||||||
|
global $stdin;
|
||||||
|
fclose($stdin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getThreadName(){
|
public function getThreadName(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user