mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Fixed crashes starting RCON
This commit is contained in:
parent
c09a5ab301
commit
8cd31c2dc4
@ -1486,7 +1486,18 @@ class Server{
|
||||
$this->scheduler = new ServerScheduler();
|
||||
|
||||
if($this->getConfigBoolean("enable-rcon", false) === true){
|
||||
$this->rcon = new RCON($this, $this->getConfigString("rcon.password", ""), $this->getConfigInt("rcon.port", $this->getPort()), ($ip = $this->getIp()) != "" ? $ip : "0.0.0.0", $this->getConfigInt("rcon.threads", 1), $this->getConfigInt("rcon.clients-per-thread", 50));
|
||||
try{
|
||||
$this->rcon = new RCON(
|
||||
$this,
|
||||
$this->getConfigString("rcon.password", ""),
|
||||
$this->getConfigInt("rcon.port", $this->getPort()),
|
||||
($ip = $this->getIp()) != "" ? $ip : "0.0.0.0",
|
||||
$this->getConfigInt("rcon.threads", 1),
|
||||
$this->getConfigInt("rcon.clients-per-thread", 50)
|
||||
);
|
||||
}catch(\Throwable $e){
|
||||
$this->getLogger()->critical("RCON can't be started: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$this->entityMetadata = new EntityMetadataStore();
|
||||
|
@ -47,23 +47,23 @@ class RCON{
|
||||
$this->password = (string) $password;
|
||||
$this->server->getLogger()->info("Starting remote control listener");
|
||||
if($this->password === ""){
|
||||
$this->server->getLogger()->critical("RCON can't be started: Empty password");
|
||||
|
||||
return;
|
||||
throw new \InvalidArgumentException("Empty password");
|
||||
}
|
||||
|
||||
$this->threads = (int) max(1, $threads);
|
||||
$this->clientsPerThread = (int) max(1, $clientsPerThread);
|
||||
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
if($this->socket === false or !socket_bind($this->socket, $interface, (int) $port) or !socket_listen($this->socket)){
|
||||
$this->server->getLogger()->critical("RCON can't be started: " . socket_strerror(socket_last_error()));
|
||||
$this->threads = 0;
|
||||
return;
|
||||
|
||||
if($this->socket === false or !@socket_bind($this->socket, $interface, (int) $port) or !@socket_listen($this->socket)){
|
||||
throw new \RuntimeException(trim(socket_strerror(socket_last_error())));
|
||||
}
|
||||
|
||||
socket_set_block($this->socket);
|
||||
|
||||
for($n = 0; $n < $this->threads; ++$n){
|
||||
$this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
|
||||
}
|
||||
|
||||
socket_getsockname($this->socket, $addr, $port);
|
||||
$this->server->getLogger()->info("RCON running on $addr:$port");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user