mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Fixed RCON usage
This commit is contained in:
parent
fee7f5060b
commit
b17ce16262
@ -1430,7 +1430,7 @@ class Server{
|
||||
$this->scheduler = new ServerScheduler();
|
||||
|
||||
if($this->getConfigBoolean("enable-rcon", false) === true){
|
||||
$this->rcon = new RCON($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));
|
||||
$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));
|
||||
}
|
||||
|
||||
$this->maxPlayers = $this->getConfigInt("max-players", 20);
|
||||
|
@ -33,20 +33,21 @@ use pocketmine\utils\TextFormat;
|
||||
|
||||
|
||||
class RCON{
|
||||
/** @var Server */
|
||||
private $server;
|
||||
private $socket;
|
||||
private $password;
|
||||
/** @var RCONInstance[] */
|
||||
private $workers;
|
||||
private $threads;
|
||||
private $clientsPerThread;
|
||||
private $rconSender;
|
||||
|
||||
public function __construct($password, $port = 19132, $interface = "0.0.0.0", $threads = 1, $clientsPerThread = 50){
|
||||
public function __construct(Server $server, $password, $port = 19132, $interface = "0.0.0.0", $threads = 1, $clientsPerThread = 50){
|
||||
$this->server = $server;
|
||||
$this->workers = [];
|
||||
$this->password = (string) $password;
|
||||
MainLogger::getLogger()->info("Starting remote control listener");
|
||||
$this->server->getLogger()->info("Starting remote control listener");
|
||||
if($this->password === ""){
|
||||
MainLogger::getLogger()->critical("RCON can't be started: Empty password");
|
||||
$this->server->getLogger()->critical("RCON can't be started: Empty password");
|
||||
|
||||
return;
|
||||
}
|
||||
@ -54,7 +55,7 @@ class RCON{
|
||||
$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)){
|
||||
MainLogger::getLogger()->critical("RCON can't be started: " . socket_strerror(socket_last_error()));
|
||||
$this->server->getLogger()->critical("RCON can't be started: " . socket_strerror(socket_last_error()));
|
||||
|
||||
return;
|
||||
}
|
||||
@ -64,8 +65,8 @@ class RCON{
|
||||
$this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
|
||||
}
|
||||
@socket_getsockname($this->socket, $addr, $port);
|
||||
MainLogger::getLogger()->info("RCON running on $addr:$port");
|
||||
Server::getInstance()->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "check")), 3);
|
||||
$this->server->getLogger()->info("RCON running on $addr:$port");
|
||||
$this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "check")), 3);
|
||||
}
|
||||
|
||||
public function stop(){
|
||||
@ -84,14 +85,14 @@ class RCON{
|
||||
$this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
|
||||
}elseif($this->workers[$n]->isWaiting()){
|
||||
if($this->workers[$n]->response !== ""){
|
||||
MainLogger::getLogger()->info($this->workers[$n]->response);
|
||||
$this->workers[$n]->synchronized(function($thread){
|
||||
$this->server->getLogger()->info($this->workers[$n]->response);
|
||||
$this->workers[$n]->synchronized(function(RCONInstance $thread){
|
||||
$thread->notify();
|
||||
}, $this->workers[$n]);
|
||||
}else{
|
||||
Server::getInstance()->dispatchCommand($response = new RemoteConsoleCommandSender(), $this->workers[$n]->cmd);
|
||||
$this->server->dispatchCommand($response = new RemoteConsoleCommandSender(), $this->workers[$n]->cmd);
|
||||
$this->workers[$n]->response = TextFormat::clean($response->getMessage());
|
||||
$this->workers[$n]->synchronized(function($thread){
|
||||
$this->workers[$n]->synchronized(function(RCONInstance $thread){
|
||||
$thread->notify();
|
||||
}, $this->workers[$n]);
|
||||
}
|
||||
|
@ -133,9 +133,9 @@ class RCONInstance extends \Thread{
|
||||
if($payload === $this->password){
|
||||
@socket_getpeername($client, $addr, $port);
|
||||
$this->response = "[INFO] Successful Rcon connection from: /$addr:$port";
|
||||
$this->synchronized(function($thread){
|
||||
$thread->wait();
|
||||
}, $this);
|
||||
$this->synchronized(function(){
|
||||
$this->wait();
|
||||
});
|
||||
$this->response = "";
|
||||
$this->writePacket($client, $requestID, 2, "");
|
||||
$this->{"status" . $n} = 1;
|
||||
@ -152,9 +152,9 @@ class RCONInstance extends \Thread{
|
||||
}
|
||||
if(strlen($payload) > 0){
|
||||
$this->cmd = ltrim($payload);
|
||||
$this->synchronized(function($thread){
|
||||
$thread->wait();
|
||||
}, $this);
|
||||
$this->synchronized(function(){
|
||||
$this->wait();
|
||||
});
|
||||
$this->writePacket($client, $requestID, 0, str_replace("\n", "\r\n", trim($this->response)));
|
||||
$this->response = "";
|
||||
$this->cmd = "";
|
||||
|
Loading…
x
Reference in New Issue
Block a user