GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
RCON Class Reference

Public Member Functions

 __construct (Server $server, $password, $port=19132, $interface="0.0.0.0", $threads=1, $clientsPerThread=50)
 
 stop ()
 
 check ()
 

Data Fields

const PROTOCOL_VERSION = 3
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Server  $server,
  $password,
  $port = 19132,
  $interface = "0.0.0.0",
  $threads = 1,
  $clientsPerThread = 50 
)

RCON constructor.

Parameters
Server$server
$password
int$port
string$interface
int$threads
int$clientsPerThread
58  {
59  $this->server = $server;
60  $this->workers = [];
61  $this->password = (string) $password;
62  $this->server->getLogger()->info("Starting remote control listener");
63  if($this->password === ""){
64  $this->server->getLogger()->critical("RCON can't be started: Empty password");
65 
66  return;
67  }
68  $this->threads = (int) max(1, $threads);
69  $this->clientsPerThread = (int) max(1, $clientsPerThread);
70  $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
71  if($this->socket === false or !socket_bind($this->socket, $interface, (int) $port) or !socket_listen($this->socket)){
72  $this->server->getLogger()->critical("RCON can't be started: " . socket_strerror(socket_last_error()));
73  $this->threads = 0;
74  return;
75  }
76  socket_set_block($this->socket);
77 
78  for($n = 0; $n < $this->threads; ++$n){
79  $this->workers[$n] = new RCONInstance($this->server->getLogger(), $this->socket, $this->password, $this->clientsPerThread);
80  }
81  socket_getsockname($this->socket, $addr, $port);
82  $this->server->getLogger()->info("RCON running on $addr:$port");
83  }

Member Function Documentation

◆ check()

check ( )
96  {
98 
99  $u = Utils::getMemoryUsage(true);
100  $usage = round(($u[0] / 1024) / 1024, 2) . "/" . round(($d[0] / 1024) / 1024, 2) . "/" . round(($u[1] / 1024) / 1024, 2) . "/" . round(($u[2] / 1024) / 1024, 2) . " MB @ " . Utils::getThreadCount() . " threads";
101  $serverStatus = serialize([
102  "online" => count($this->server->getOnlinePlayers()),
103  "max" => $this->server->getMaxPlayers(),
104  "upload" => round($this->server->getNetwork()->getUpload() / 1024, 2),
105  "download" => round($this->server->getNetwork()->getDownload() / 1024, 2),
106  "tps" => $this->server->getTicksPerSecondAverage(),
107  "load" => $this->server->getTickUsageAverage(),
108  "usage" => $usage
109  ]);
110  for($n = 0; $n < $this->threads; ++$n){
111  if(!$this->workers[$n]->isTerminated()){
112  $this->workers[$n]->serverStatus = $serverStatus;
113  }
114  if($this->workers[$n]->isTerminated() === true){
115  $this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
116  }elseif($this->workers[$n]->isWaiting()){
117  if($this->workers[$n]->response !== ""){
118  $this->server->getLogger()->info($this->workers[$n]->response);
119  $this->workers[$n]->synchronized(function(RCONInstance $thread){
120  $thread->notify();
121  }, $this->workers[$n]);
122  }else{
123 
124  $response = new RemoteConsoleCommandSender();
125  $command = $this->workers[$n]->cmd;
126 
127  $this->server->getPluginManager()->callEvent($ev = new RemoteServerCommandEvent($response, $command));
128 
129  if(!$ev->isCancelled()){
130  $this->server->dispatchCommand($ev->getSender(), $ev->getCommand());
131  }
132 
133  $this->workers[$n]->response = $response->getMessage();
134  $this->workers[$n]->synchronized(function(RCONInstance $thread){
135  $thread->notify();
136  }, $this->workers[$n]);
137  }
138  }
139  }
140  }

◆ stop()

stop ( )
85  {
86  for($n = 0; $n < $this->threads; ++$n){
87  $this->workers[$n]->close();
88  Server::microSleep(50000);
89  $this->workers[$n]->close();
90  $this->workers[$n]->quit();
91  }
92  @socket_close($this->socket);
93  $this->threads = 0;
94  }

Field Documentation

◆ PROTOCOL_VERSION

const PROTOCOL_VERSION = 3

The documentation for this class was generated from the following file: