22declare(strict_types=1);
 
   24namespace pocketmine\console;
 
   26use pmmp\thread\Thread as NativeThread;
 
   27use pmmp\thread\ThreadSafeArray;
 
   29use 
function cli_set_process_title;
 
   33use 
function is_numeric;
 
   37if(count($argv) !== 2 || !is_numeric($argv[1])){
 
   38    echo 
"Usage: " . $argv[0] . 
" <command token seed>" . PHP_EOL;
 
   42$commandTokenSeed = (int) $argv[1];
 
   44require dirname(__DIR__, 2) . 
'/vendor/autoload.php';
 
   46@cli_set_process_title(
'PocketMine-MP Console Reader');
 
   49$channel = 
new ThreadSafeArray();
 
   50$thread = 
new class($channel) extends NativeThread{
 
   54    public function __construct(
 
   55        private ThreadSafeArray $channel,
 
   58    public function run() : void{
 
   59        require dirname(__DIR__, 2) . 
'/vendor/autoload.php';
 
   61        $channel = $this->channel;
 
   62        $reader = 
new ConsoleReader();
 
   64            $line = $reader->readLine();
 
   66                $channel->synchronized(
function() use ($channel, $line) : 
void{
 
   75$thread->start(NativeThread::INHERIT_NONE);
 
   77    $line = $channel->synchronized(
function() use ($channel) : ?
string{
 
   78        if(count($channel) === 0){
 
   79            $channel->wait(1_000_000);
 
   81        return $channel->shift();
 
   84    if(@fwrite(STDOUT, $message . 
"\n") === 
false){
 
   95Process::kill(Process::pid());
 
static createMessage(string $line, int &$counter)