tjone270

PHP Quake Live ZMQ implementation

Jul 31st, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. function qlServerExecute($command, $server, $password, $timeout = 1.5, $filter = true) {
  2.   $identity = "WebControlPanel";
  3.   $client = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_DEALER);
  4.  
  5.   $client->setSockOpt(ZMQ::SOCKOPT_PLAIN_USERNAME, "rcon");
  6.   $client->setSockOpt(ZMQ::SOCKOPT_PLAIN_PASSWORD, $password);
  7.   $client->setSockOpt(ZMQ::SOCKOPT_IDENTITY, $identity);
  8.   $client->setSockOpt(ZMQ::SOCKOPT_ZAP_DOMAIN, "rcon");
  9.  
  10.   $client->connect("tcp://" . $server);
  11.  
  12.   $client->send("register");
  13.   $client->send($command, ZMQ::MODE_NOBLOCK);
  14.   sleep($timeout); // otherwise the server crashes...
  15.   $response = $client->recv(ZMQ::MODE_NOBLOCK);
  16.  
  17.   $client->disconnect("tcp://" . $server);
  18.  
  19.   if ($filter) {
  20.     return substr($response, (24 + strlen($identity)));
  21.   } else {
  22.     return $response;
  23.   }
  24. }
  25.  
  26. var_dump(qlServerExecute("map campgrounds", "ip:28960", "password"));
Add Comment
Please, Sign In to add comment