3333
3434
3535class 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 }
0 commit comments