Advertisement
Guest User

Untitled

a guest
Jun 17th, 2009
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. <?
  2.  
  3. /*
  4. PHP Quake 3 Library
  5. Copyright (C) 2006-2007 Gerald Kaszuba
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  20. */
  21.  
  22. class q3query {
  23.  
  24.     private $rconpassword;
  25.     private $fp;
  26.     private $cmd;
  27.     private $lastcmd;
  28.  
  29.     public function __construct($address, $port) {
  30.         $this->cmd = str_repeat(chr(255), 4);
  31.         $this->fp = fsockopen("udp://$address", $port, $errno, $errstr, 30);
  32.         if (!$this->fp)
  33.             die("$errstr ($errno)<br />\n");
  34.     }
  35.  
  36.     public function set_rconpassword($p) {
  37.         $this->rconpassword = $p;
  38.     }
  39.  
  40.     public function rcon($s) {
  41.         sleep(1);
  42.         $this->send('rcon '.$this->rconpassword.' '.$s);
  43.     }
  44.  
  45.     public function get_response($timeout=5) {
  46.         $s = '';
  47.         $bang = time() + $timeout;
  48.         while (!strlen($s) and time() < $bang) {
  49.             $s = $this->recv();
  50.         }
  51.         if (substr($s, 0, 4) != $this->cmd) {
  52.         }
  53.         return substr($s, 4);
  54.     }
  55.  
  56.     private function send($string) {
  57.         fwrite($this->fp, $this->cmd . $string . "\n");
  58.     }
  59.  
  60.     private function recv() {
  61.         return fread($this->fp, 9999);
  62.     }
  63.  
  64. }
  65.  
  66. ?>
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement