workers = array(); $this->password = (string) $password; console("[INFO] Starting remote control listener"); if($this->password === ""){ console("[ERROR] RCON can't be started: Empty password"); return; } $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)){ console("[ERROR] RCON can't be started: " . socket_strerror(socket_last_error())); return; } @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); console("[INFO] RCON running on $addr:$port"); Server::getInstance()->schedule(2, array($this, "check"), array(), true); } public function stop(){ for($n = 0; $n < $this->threads; ++$n){ $this->workers[$n]->close(); $this->workers[$n]->join(); usleep(50000); $this->workers[$n]->kill(); } @socket_close($this->socket); $this->threads = 0; } public function check(){ for($n = 0; $n < $this->threads; ++$n){ if($this->workers[$n]->isTerminated() === true){ $this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread); }elseif($this->workers[$n]->isWaiting()){ if($this->workers[$n]->response !== ""){ console($this->workers[$n]->response); $this->workers[$n]->notify(); }else{ $this->workers[$n]->response = Server::getInstance()->api->console->run($this->workers[$n]->cmd, "rcon"); $this->workers[$n]->notify(); } } } } }