Skip to content

Commit b17ce16

Browse files
committed
Fixed RCON usage
1 parent fee7f50 commit b17ce16

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

src/pocketmine/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ public function __construct(\SplClassLoader $autoloader, \ThreadedLogger $logger
14301430
$this->scheduler = new ServerScheduler();
14311431

14321432
if($this->getConfigBoolean("enable-rcon", false) === true){
1433-
$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));
1433+
$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));
14341434
}
14351435

14361436
$this->maxPlayers = $this->getConfigInt("max-players", 20);

src/pocketmine/network/rcon/RCON.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,29 @@
3333

3434

3535
class RCON{
36+
/** @var Server */
37+
private $server;
3638
private $socket;
3739
private $password;
3840
/** @var RCONInstance[] */
3941
private $workers;
40-
private $threads;
4142
private $clientsPerThread;
42-
private $rconSender;
4343

44-
public function __construct($password, $port = 19132, $interface = "0.0.0.0", $threads = 1, $clientsPerThread = 50){
44+
public function __construct(Server $server, $password, $port = 19132, $interface = "0.0.0.0", $threads = 1, $clientsPerThread = 50){
45+
$this->server = $server;
4546
$this->workers = [];
4647
$this->password = (string) $password;
47-
MainLogger::getLogger()->info("Starting remote control listener");
48+
$this->server->getLogger()->info("Starting remote control listener");
4849
if($this->password === ""){
49-
MainLogger::getLogger()->critical("RCON can't be started: Empty password");
50+
$this->server->getLogger()->critical("RCON can't be started: Empty password");
5051

5152
return;
5253
}
5354
$this->threads = (int) max(1, $threads);
5455
$this->clientsPerThread = (int) max(1, $clientsPerThread);
5556
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
5657
if($this->socket === false or !socket_bind($this->socket, $interface, (int) $port) or !socket_listen($this->socket)){
57-
MainLogger::getLogger()->critical("RCON can't be started: " . socket_strerror(socket_last_error()));
58+
$this->server->getLogger()->critical("RCON can't be started: " . socket_strerror(socket_last_error()));
5859

5960
return;
6061
}
@@ -64,8 +65,8 @@ public function __construct($password, $port = 19132, $interface = "0.0.0.0", $t
6465
$this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
6566
}
6667
@socket_getsockname($this->socket, $addr, $port);
67-
MainLogger::getLogger()->info("RCON running on $addr:$port");
68-
Server::getInstance()->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "check")), 3);
68+
$this->server->getLogger()->info("RCON running on $addr:$port");
69+
$this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "check")), 3);
6970
}
7071

7172
public function stop(){
@@ -84,14 +85,14 @@ public function check(){
8485
$this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
8586
}elseif($this->workers[$n]->isWaiting()){
8687
if($this->workers[$n]->response !== ""){
87-
MainLogger::getLogger()->info($this->workers[$n]->response);
88-
$this->workers[$n]->synchronized(function($thread){
88+
$this->server->getLogger()->info($this->workers[$n]->response);
89+
$this->workers[$n]->synchronized(function(RCONInstance $thread){
8990
$thread->notify();
9091
}, $this->workers[$n]);
9192
}else{
92-
Server::getInstance()->dispatchCommand($response = new RemoteConsoleCommandSender(), $this->workers[$n]->cmd);
93+
$this->server->dispatchCommand($response = new RemoteConsoleCommandSender(), $this->workers[$n]->cmd);
9394
$this->workers[$n]->response = TextFormat::clean($response->getMessage());
94-
$this->workers[$n]->synchronized(function($thread){
95+
$this->workers[$n]->synchronized(function(RCONInstance $thread){
9596
$thread->notify();
9697
}, $this->workers[$n]);
9798
}

src/pocketmine/network/rcon/RCONInstance.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ public function run(){
133133
if($payload === $this->password){
134134
@socket_getpeername($client, $addr, $port);
135135
$this->response = "[INFO] Successful Rcon connection from: /$addr:$port";
136-
$this->synchronized(function($thread){
137-
$thread->wait();
138-
}, $this);
136+
$this->synchronized(function(){
137+
$this->wait();
138+
});
139139
$this->response = "";
140140
$this->writePacket($client, $requestID, 2, "");
141141
$this->{"status" . $n} = 1;
@@ -152,9 +152,9 @@ public function run(){
152152
}
153153
if(strlen($payload) > 0){
154154
$this->cmd = ltrim($payload);
155-
$this->synchronized(function($thread){
156-
$thread->wait();
157-
}, $this);
155+
$this->synchronized(function(){
156+
$this->wait();
157+
});
158158
$this->writePacket($client, $requestID, 0, str_replace("\n", "\r\n", trim($this->response)));
159159
$this->response = "";
160160
$this->cmd = "";

0 commit comments

Comments
 (0)