how did this cause sigsegv on nper </3

This commit is contained in:
GameHerobrine 2025-06-03 19:21:16 +03:00
parent c408b622eb
commit f572605472
2 changed files with 8 additions and 9 deletions

View file

@ -1,7 +1,7 @@
<?php <?php
class ConsoleAPI{ class ConsoleAPI{
private static $loop; //why no Thread::kill in pthreads3 private $loop; //why no Thread::kill in pthreads3. Making it static causes crashes of other threads on some servers(hi nper)
private $server, $event, $help, $cmds, $alias; private $server, $event, $help, $cmds, $alias;
public $last; public $last;
function __construct(){ function __construct(){
@ -15,7 +15,7 @@ class ConsoleAPI{
public function init(){ public function init(){
$this->server->schedule(2, [$this, "handle"], [], true); $this->server->schedule(2, [$this, "handle"], [], true);
if(!defined("NO_THREADS")){ if(!defined("NO_THREADS")){
self::$loop = new ConsoleLoop(); $this->loop = new ConsoleLoop();
} }
$this->register("help", "[page|command name]", [$this, "defaultCommands"]); $this->register("help", "[page|command name]", [$this, "defaultCommands"]);
$this->register("status", "", [$this, "defaultCommands"]); $this->register("status", "", [$this, "defaultCommands"]);
@ -51,8 +51,8 @@ class ConsoleAPI{
function __destruct(){ function __destruct(){
$this->server->deleteEvent($this->event); $this->server->deleteEvent($this->event);
if(!defined("NO_THREADS")){ if(!defined("NO_THREADS")){
self::$loop->stop(); $this->loop->stop();
self::$loop->notify(); $this->loop->notify();
usleep(50000); usleep(50000);
} }
} }
@ -66,10 +66,10 @@ class ConsoleAPI{
if(defined("NO_THREADS")){ if(defined("NO_THREADS")){
return; return;
} }
$line = self::$loop->line; $line = $this->loop->line;
if($line !== false){ if($line !== false){
$line = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", trim($line)); $line = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", trim($line));
self::$loop->line = false; $this->loop->line = false;
$output = $this->run($line, "console"); $output = $this->run($line, "console");
if($output != ""){ if($output != ""){
$mes = explode("\n", trim($output)); $mes = explode("\n", trim($output));
@ -78,7 +78,7 @@ class ConsoleAPI{
} }
} }
}else{ }else{
self::$loop->notify(); $this->loop->notify();
} }
} }
@ -214,7 +214,7 @@ class ConsoleAPI{
} }
return "TPS: {$info["tps"]}, Memory usage: {$info["memory_usage"]} (Peak {$info["memory_peak_usage"]})"; return "TPS: {$info["tps"]}, Memory usage: {$info["memory_usage"]} (Peak {$info["memory_peak_usage"]})";
case "stop": case "stop":
self::$loop->stop = true; $this->loop->stop = true;
$this->server->close(); $this->server->close();
return "Stopping the server\n"; return "Stopping the server\n";
case "difficulty": case "difficulty":

View file

@ -610,7 +610,6 @@ class PocketMinecraftServer{
public static function clientID($ip, $port){ public static function clientID($ip, $port){
return crc32($ip . $port) ^ crc32($port . $ip . BOOTUP_RANDOM); return crc32($ip . $port) ^ crc32($port . $ip . BOOTUP_RANDOM);
//return $ip . ":" . $port;
} }
public function send(Packet $packet){ public function send(Packet $packet){