Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Created by Thomas 'tjone270' Jones - 12-01-17 6:39pm
- class QL_Server {
- public $ip, $persistant;
- protected $rconport, $rconpassword;
- private $zmq, $connectionString;
- const IDENTITY = "ControlPanel";
- const WAIT_uS = 1000000;
- public function __construct($ip, $rconpassword, $rconport = "28960", $persistant = true) {
- $this->ip = $ip;
- $this->rconport = $rconport;
- $this->rconpassword = $rconpassword;
- $this->persistant = $persistant;
- $this->connectionString = ("tcp://${ip}:${rconport}");
- $this->zmq = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_DEALER);
- $this->zmq->setSockOpt(ZMQ::SOCKOPT_PLAIN_USERNAME, "rcon");
- $this->zmq->setSockOpt(ZMQ::SOCKOPT_PLAIN_PASSWORD, $this->rconpassword);
- $this->zmq->setSockOpt(ZMQ::SOCKOPT_IDENTITY, self::IDENTITY);
- $this->zmq->setSockOpt(ZMQ::SOCKOPT_ZAP_DOMAIN, "rcon");
- $this->zmq->connect($this->connectionString);
- $this->zmq->send("register");
- }
- public function __destruct() {
- if (!$this->persistant) {
- $this->zmq->disconnect($this->connectionString);
- }
- }
- public function command($command, $filter = true) {
- $this->zmq->send($command);
- usleep(self::WAIT_uS); // otherwise the server crashes...
- $done = false;
- while (!$done) {
- $recv = $this->zmq->recv();
- if ($recv) {
- $response[] = $recv;
- } else {
- $done = true;
- }
- }
- if ($filter) {
- array_shift($response);
- }
- return implode($response);
- }
- }
Add Comment
Please, Sign In to add comment