Sections
Timeline
Sub-Sections
Last Change
Annotate
Revision Log
Download
Plain Text
Original Format
Metanav
Preferences
About Trac
Links
Slowchop Studios
Gerald Kaszuba
Advertisement

root/q3query/trunk/q3query.php

Revision 4, 1.6 kB (checked in by gak, 19 months ago)

added GPL license

Line 
1<?
2
3/*
4PHP Quake 3 Library
5Copyright (C) 2006-2007 Gerald Kaszuba
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; either version 2
10of the License, or (at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20*/
21
22class 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?>
Note: See TracBrowser for help on using the browser.