Fixed crashes starting RCON

This commit is contained in:
Dylan K. Taylor
2017-06-21 18:15:57 +01:00
parent c09a5ab301
commit 8cd31c2dc4
2 changed files with 19 additions and 8 deletions

View File

@ -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");
}