/[svn]/web/madquery.php
ViewVC logotype

Contents of /web/madquery.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (hide annotations) (download)
Sun Sep 21 04:29:43 2008 UTC (15 years, 7 months ago) by cstrike
File size: 22798 byte(s)
Merged in (by hand) changes from brywright.co.uk version of madquery.php
1 cstrike 20 <?php
2    
3     /***************************************************
4     * Copyright (C) 2002 madCoder *
5     * http://www.utdallas.edu/~madcoder/ *
6     * COMMENTS (NO support requests)may be sent to: *
7     * madCoder@student.utdallas.edu *
8     ***************************************************
9     * Use of this class assumes agreement to all *
10     * of the following terms of use: *
11     ***************************************************
12     * 1) This class is provided as-is, with no *
13     * offering of technical support, or help *
14     * in any way with setting up this class. *
15     * 2) madCoder will not, in any way, take *
16     * responsibility for what you do with this *
17     * script. *
18     * 3) This class may not be reproduced, or *
19     * altered, without prior authoriazation from *
20     * madCoder. *
21     * 4) ALL Copyright and credit notices MUST remain *
22     * intact, as released. *
23     ***************************************************/
24    
25    
26     define("ERROR_NOERROR" ,0);
27     define("ERROR_NOSERVER",-1);
28     define("ERROR_INSOCKET",-2);
29     //define("DEBUG",1);
30     define("OLDQUERIES",0);
31    
32     function get_float32($fourchars) {
33     $bin='';
34     for($loop = 0; $loop <= 3; $loop++) {
35     $bin = str_pad(decbin(ord(substr($fourchars, $loop, 1))), 8, '0', STR_PAD_LEFT).$bin;
36     }
37     $exponent = bindec(substr($bin, 1, 8));
38     $exponent = ($exponent)? $exponent - 127 : $exponent;
39     if($exponent) {
40     $int = bindec('1'.substr($bin, 9, $exponent));
41     $dec = bindec(substr($bin, 9 + $exponent));
42     $time = "$int.$dec";
43     return number_format($time / 60, 2);
44     } else {
45     return 0.0;
46     }
47     }
48    
49     /******
50     * getmicrotime()
51     * as provided in the PHP manual
52     ******/
53     function getmicrotime(){
54     list($usec, $sec) = explode(" ",microtime());
55     return ((float)$usec + (float)$sec);
56     }
57    
58     function dodebug($dbgstr="") {
59     if(defined('DEBUG')) echo "<!-- [DEBUG] " . $dbgstr . " -->\n";
60     }
61     /***********************************************
62     * madQuery Class
63     ***********************************************/
64     class madQuery {
65     var $_arr=array();
66     var $_ip="";
67     var $_port=0;
68     var $_isconnected=0;
69     var $_players=array();
70     var $_rules=array();
71     var $_errorcode=ERROR_NOERROR;
72     var $_seed="madQuery for server (%s:%d)";
73     var $_sk; //socket
74     var $_challengenum;
75     var $_type;
76    
77     //rcon extension
78     var $_rcon_challenge=0; // No challenge
79     var $_rcon_password="";
80     var $_rcon_allow=1;
81     //rcon-extended version information
82     var $_exe_build="";
83     var $_exe_ver="";
84    
85     //Constructor
86     function madQuery($serverip, $serverport=27015)
87     {
88     $this->_ip=$serverip;
89     $this->_port=$serverport;
90     $this->_seed="\x0a\x3c\x21\x2d\x2d\x20\x20\x20\x20\x20\x20\x20\x53\x65\x72\x76\x65\x72\x20\x6d\x61\x64\x51\x75\x65\x72\x79\x20\x43"
91     ."\x6c\x61\x73\x73\x20\x20\x20\x20\x20\x20\x20\x2d\x2d\x3e\x0a\x3c\x21\x2d\x2d\x20\x20\x20\x20\x43\x6f\x70\x79\x72\x69"
92     ."\x67\x68\x74\x20\x28\x43\x29\x20\x32\x30\x30\x32\x20\x6d\x61\x64\x43\x6f\x64\x65\x72\x20\x20\x20\x20\x2d\x2d\x3e\x0a"
93     ."\x3c\x21\x2d\x2d\x20\x20\x20\x6d\x61\x64\x63\x6f\x64\x65\x72\x40\x73\x74\x75\x64\x65\x6e\x74\x2e\x75\x74\x64\x61\x6c"
94     ."\x6c\x61\x73\x2e\x65\x64\x75\x20\x20\x20\x2d\x2d\x3e\x0a\x3c\x21\x2d\x2d\x20\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77"
95     ."\x2e\x75\x74\x64\x61\x6c\x6c\x61\x73\x2e\x65\x64\x75\x2f\x7e\x6d\x61\x64\x63\x6f\x64\x65\x72\x20\x2d\x2d\x3e\x0a\x0a";
96     $this->_arr=array_pad($this->_arr, 22, 0);
97     $errno=0;$errstr='';
98     $this->_sk = fsockopen("udp://" . $this->_ip, $this->_port, $errno, $errstr, 3);
99     socket_set_timeout($this->_sk, 2,0);
100     if($tmp=$this->_sockstate()) {
101     //echo $tmp;
102     if(!$this->_sk)
103     echo "ERROR #" .$errno.": ".$errstr;
104     //exit;
105     }
106     if (!OLDQUERIES) {
107     $this->_send("\xFF\xFF\xFF\xFF\x57"); //get challenge
108     $tmp=$this->_getmore();
109     $this->_challengenum=substr($tmp, 5, 4);
110     }
111     dodebug("[Initialized]");
112     // $this->_brand_seed();
113     return !(!$this->_sk);
114     }
115    
116     //Sets error code
117     function seterror($code) {
118     dodebug("[Setting Error Code (".$code.")]<BR>\n");
119     $this->_errorcode=$code;
120     }
121    
122     //Obtains ping value to server
123     function _ping()
124     {
125     dodebug("[Getting Ping]");
126     if($tmp=$this->_sockstate()){
127     //echo $tmp;
128     dodebug("[Error in Socket]");
129     $this->seterror(ERROR_INSOCKET);
130     return -1; //Error in socket
131     } else {
132     $tmp="";
133     $start = getmicrotime()*1000;
134     if (OLDQUERIES) $this->_send("ÿÿÿÿping".chr(0));
135     else $this->_send("ÿÿÿÿi".chr(0));
136     while(strlen($tmp)<4 && (getmicrotime()*1000-$start)<1000) {
137     $tmp=$this->_getmore();
138     }
139     if(strlen($tmp)>=4 && substr($tmp,4,1)=='j') {
140     $end=getmicrotime()*1000;
141     if($end<$start) echo $end .'\n'.$start;
142     return ($end-$start); //($end-$start)>=0 ? ($end-$start) : -1; //Will be numeric ping
143     } else {
144     //echo "Server didn't respond!";
145     //exit;
146     $this->seterror(ERROR_NOSERVER);
147     dodebug("[ERROR: No pong from server]");
148     return -1; //Server isn't responding...
149     }
150     }
151     return 0;
152     }
153    
154     function getall() {
155     $this->getdetails();
156     $this->getplayers();
157     $this->getrules();
158     }
159    
160     //Populates details array
161     function getdetails()
162     {
163     dodebug("[Getting Details]");
164     if($tmp=$this->_sockstate()) {
165     //echo $tmp;
166     $this->seterror(ERROR_INSOCKET);
167     return -1;
168     } else {
169     if (OLDQUERIES) $this->_send("ÿÿÿÿdetails".chr(0));
170     else $this->_send("\xFF\xFF\xFF\xFF\x54Source Engine Query\x00");
171     $buffer=$this->_getmore();
172     $tbuff=$buffer;
173     /*echo $buffer;
174     for ($i=0; $i < strlen($buffer); $i++) {
175     echo '['.substr($buffer,$i,1).'='.ord(substr($buffer,$i,1)).'] ';
176     }
177     exit;*/
178     $tmp=substr($buffer,0,5);
179     $this->_type=substr($tmp,4,1);
180     $buffer=substr($buffer,5);
181     $text="";
182     $count=0;
183     $arr=array();
184     if ($this->_type == "\x6D" || OLDQUERIES ) {
185     do {
186     $tmp=substr($buffer,0,1);$buffer=substr($buffer,1);
187     if (!ord($tmp)) { $this->_arr[$count++]=$text; $text=""; }
188     else { $text.=$tmp; }
189     } while ($count<5);
190     for($i=0;$i<=6;$i++, $count++) {
191     $tmp=substr($buffer,0,1);$buffer=substr($buffer,1);
192     if($count==8 || $count==9)
193     $this->_arr[$count]=$tmp;
194     else
195     $this->_arr[$count]=ord($tmp);
196     } //count = 12
197     if($this->_arr[$count-1]) { //if ismod
198     do {
199     $tmp=substr($buffer,0,1);$buffer=substr($buffer,1);
200     $this->_arr[$count]="";
201     if (ord($tmp)!=0)
202     $this->_arr[$count].=$tmp; // mod website [12]
203     } while(ord($tmp)!=0);
204     $count++;
205     do {
206     $tmp=substr($buffer,0,1);$buffer=substr($buffer,1);
207     $this->_arr[$count]="";
208     if (ord($tmp)!=0)
209     $this->_arr[$count].=$tmp; // mod FTP [13]
210     } while(ord($tmp)!=0);
211     $count++; //[14]==Not Used
212     $this->_arr[$count++]=ord(substr($buffer,0,1)); $buffer=substr($buffer,1);
213     $tmp=substr($buffer,0,4);$buffer=substr($buffer,4);
214     for($j=0;$j<4;$j++) {
215     $this->_arr[$count]+=(pow(256,$j) * ord(substr($tmp,$j,1))); //Ver [15]
216     } $count++;
217     $tmp=substr($buffer,0,4);$buffer=substr($buffer,4);
218     for($j=0;$j<4;$j++) {
219     $this->_arr[$count]+=(pow(256,$j) * ord(substr($tmp,$j,1))); //Size [16]
220     } $count++;
221     $this->_arr[$count++]=ord(substr($buffer,0,1));$buffer=substr($buffer,1); //server-only [17]
222     $this->_arr[$count++]=ord(substr($buffer,0,1));$buffer=substr($buffer,1); //custom client.dll [18]
223     $this->_arr[$count++]=ord(substr($buffer,0,1));$buffer=substr($buffer,1); //Secure! [19]
224     $this->_arr[$count++]=ord(substr($buffer,0,1));$buffer=substr($buffer,1); //Num of bots [20]
225     } else {
226     for($i=0;$i<8;$i++)
227     $this->_arr[$count++]="\0";
228     }
229     } elseif ($this->_type == "\x49") {
230     $tmp=substr($buffer,0,1);$buffer=substr($buffer,1);
231     $this->_arr[$count++] = $tmp;
232     do {
233     $tmp=substr($buffer,0,1);$buffer=substr($buffer,1);
234     if (!ord($tmp)) { $this->_arr[$count++]=$text; $text=""; }
235     else { $text.=$tmp; }
236     } while ($count<5);
237     $tmp_lower = substr($buffer, 0, 1);
238     $tmp_higher = substr($buffer, 1, 1);
239     $buffer=substr($buffer,2);
240     $this->_arr[$count++] = ($tmp_higher << 8) | $tmp_lower;
241     for($i=0;$i<=6;$i++, $count++) {
242     $tmp=substr($buffer,0,1);$buffer=substr($buffer,1);
243     if($count==9 || $count==10)
244     $this->_arr[$count]=$tmp;
245     else
246     $this->_arr[$count]=ord($tmp);
247     } //count = 13
248     }
249     }
250     $this->_arr[$count++]=round($this->_ping(),1);
251     $this->_arr[$count++]=$tbuff;
252     $this->_arr[$count++]=$buffer;
253     //print_r($this->_arr);
254     return 0;
255     }
256    
257     // Sets players array
258     function getplayers()
259     {
260     dodebug("[Getting Players]");
261     //$fp = fsockopen("udp://" . $this->_ip, $this->_port);
262     if($tmp=$this->_sockstate()) {
263     //echo $tmp;
264     $this->seterror(ERROR_INSOCKET);
265     return -1;
266     } else {
267     if (OLDQUERIES) $this->_send("ÿÿÿÿplayers".chr(0));
268     else $this->_send("\xFF\xFF\xFF\xFF\x55".$this->_challengenum);
269     $buffer=$this->_getmore();
270     $buffer=substr($buffer,5);
271     $count=ord(substr($buffer,0,1)); //Num active players
272     $buffer=substr($buffer,1);
273     $tfrags="";
274     $ttime=0;
275     $arr=array();
276     for($i=0;$i<$count;$i++)
277     {
278     $rfrags=0.0;
279     $rtime=0;
280     $stime=0;
281     $tind=ord(substr($buffer,0,1));
282     $buffer=substr($buffer,1);
283     $tname="";
284     do {
285     $tmp=substr($buffer,0,1);
286     $buffer=substr($buffer,1);
287     if(ord($tmp)!=0) $tname.=$tmp;
288     }while(ord($tmp)!=0);
289     $tfrags=substr($buffer,0,4);
290     $buffer=substr($buffer,4);
291     for($j=0;$j<4;$j++) {
292     $rfrags+=(pow(256,$j) * ord(substr($tfrags,$j,1)));
293     }
294     if($rfrags > 2147483648) {
295     $rfrags-=4294967296;
296     }
297     $tmp=substr($buffer,0,4);
298     $buffer=substr($buffer,4);
299     $rtime=get_float32($tmp);
300     $arr[$i]=array("Index" => $tind,"Name" => $tname,"Frags" => $rfrags, "Time" => $rtime);
301     }
302     }
303     $this->_players=$arr;
304     return 0;
305     }
306    
307     function getrules() {
308     dodebug("[Getting Rules]");
309     $multi=0;
310     //$cvars=array();
311     if($tmp=$this->_sockstate()) {
312     $this->seterror(ERROR_INSOCKET);
313     return -1;
314     }
315     if (OLDQUERIES) $this->_send("ÿÿÿÿrules".chr(0));
316     else $this->_send("\xFF\xFF\xFF\xFF\x56".$this->_challengenum);
317     $buffer=$this->_getmore();
318     if(strlen($buffer)==0) $buffer=$this->_getmore();
319     $tmp=substr($buffer,0,5);
320     $buffer=substr($buffer,5);
321     if(substr($tmp,0,4)==chr(254).chr(255).chr(255).chr(255)) {
322     //Now, 5 more bytes to look at..
323     $multi=1;
324     for($ti=0;$ti<4;$ti++) {
325     $tmp=substr($buffer,0,1);
326     $buffer=substr($buffer,1);
327     }
328     $tmp=substr($buffer,0,5); //yyyyE = Rules Response
329     $buffer=substr($buffer,5);
330     }
331     $count=ord(substr($buffer,0,1));$buffer=substr($buffer,2); //Num rules
332     $i=0;
333     $svar="";
334     while($i<$count) {
335     if(strlen($buffer)==0 && $multi==1) {
336     $buffer=$this->_getmore();
337     $tmp=substr($buffer,0,5); //pyyy_
338     $buffer=substr($buffer,5);
339     $buffer=substr($buffer,4);
340     }
341     $tmp=substr($buffer,0,1);
342     $buffer=substr($buffer,1);
343     if(ord($tmp)==0)
344     $i+=0.5;
345     $svar=$svar.$tmp;
346     }
347     $vars=explode(chr(0),$svar);
348     for($i=0;$i<(int)(count($vars))-1;$i+=2) {
349     $cvars[$vars[$i]]=$vars[$i+1];
350     }
351     if(sizeof($cvars)>0) ksort($cvars);
352     $this->_rules=$cvars;
353     return 0;
354     }
355    
356     function _sockstate() {
357     if(!$this->_sk)
358     return 8;
359     $stat=socket_get_status($this->_sk);
360     $ret=0;
361     if($stat["timed_out"]) {
362     //echo "ERROR: Socket timed out.<BR>\n";
363     $ret|=1;
364     }
365     if($stat["eof"]) {
366     //echo "ERROR: Socket closed by remote host.<BR>\n";
367     $ret|=2;
368     }
369     if($stat["blocked"]) {
370     //echo "PORT BLOCKED!";
371     //exit;
372     //$ret|=4;
373     }
374     return $ret;
375     //return (!$stat["timed_out"] && !$stat["eof"] && !(!$this->_sk));
376     }
377    
378     function _send($outstr) {
379     if(!$this->_sockstate()) {
380     fwrite($this->_sk,$outstr,strlen($outstr));
381     } else
382     return "\0";
383     }
384    
385     function _getmore() {
386     if(!$this->_sockstate()) {
387     $tmp=fread($this->_sk,1);
388     $stat=socket_get_status($this->_sk);
389     $tmp.=fread($this->_sk, $stat["unread_bytes"]);
390     return $tmp;
391     } else
392     return "\0";
393     }
394    
395     function rcon_sync($rcon_pass) {
396     echo "Syncing rcon...\n";
397     if($rcon_pass=="") return 0;
398     //if(!$_sk) return 0;
399     if(!$this->_rcon_challenge) {
400     $this->_rcon_challenge=$this->_rcon_get_challenge();
401     if(!$this->_rcon_challenge) return 0;
402     }
403     $this->_rcon_password=$rcon_pass;
404     $this->_rcon_send("version");
405     $buff=$this->_getmore();
406     if(!strncmp($buff,"\xff\xff\xff\xfflBad rcon_password",22)) {
407     $this->_rcon_password="";
408     $this->_rcon_challenge=0;
409     return 0;
410     }
411     $buff=substr($buff,5);
412     foreach(split("\n",$buff) as $line) {
413     if(!strncmp($line,"Exe version",11)) { $this->_exe_ver = substr($line,12); }
414     elseif(!strncmp($line,"Exe build",9)) { $this->_exe_build = substr($line,11); }
415     //echo "$line<BR>\n";
416     }
417     // echo $buff;
418     return 1;
419     }
420    
421     function rcon_expand_players() {
422     if(!isset($this->_players) || sizeof($this->_players)==0 || $this->_rcon_password=="" || $this->_rcon_challenge=="")
423     return 0;
424     foreach($this->_players as $id => $plyr) {
425     $this->_rcon_send("user \"".$plyr["Name"]."\"");
426     $buff=trim($this->_getmore());
427     if(strlen($buff)==0) $buff=trim($this->_getmore());
428     $buff=substr($buff,5);
429     foreach(split("\n",$buff) as $line) {
430     list($key,$val)=split("[ ]+",$line);
431     if($key!="name") $this->_players[$id][$key]=$val;
432     //echo "$key => $val<br>\n";
433     if($key=="model") {
434     if(preg_match("/(gign|sas|gsg9)/",$val)) $this->_players[$id]["Team"]="CT";
435     elseif(preg_match("/(terror|arctic|leet|urban)/",$val)) $this->_players[$id]["Team"]="T";
436     }
437     }
438     ksort($this->_players[$id]);
439     reset($this->_players[$id]);
440     }
441     $this->_rcon_send("status");
442     $buff=substr(trim($this->_getmore()),5);
443     //echo $buff."\n\n";
444     foreach(split("\n",$buff) as $line) {
445     //# 1 "Warez:" 217 1935516 5 26:41 168 0 4.3.210.202:27005
446     //# 2 "The [OnE]" 213 2772131 30 43:32 316 0 172.157.20.64:27005
447     if(preg_match("/^#\s+([0-9]+)\s+\"([^\"]+)\"\s+([0-9]+)\s+([0-9]+)\s+([-0-9]+)\s+([:0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([.:0-9]+)\s*$/",$line,$regs)) {
448     $ind=$regs[1];
449     foreach($this->_players as $i => $p) {
450     if($p["Name"]==$regs[2]) { $ind=$i; }
451     }
452     $this->_players[$ind]["SID"]=$regs[3];
453     $this->_players[$ind]["WONID"]=$regs[4];
454     $this->_players[$ind]["strTime"]=$regs[6];
455     $this->_players[$ind]["Ping"]=$regs[7];
456     $this->_players[$ind]["Loss"]=$regs[8];
457     $this->_players[$ind]["Address"]=$regs[9];
458     //print_r($regs);
459     ksort($this->_players[$ind]);
460     reset($this->_players[$ind]);
461     } //else echo "Line: $line\n";
462     }
463     return 1;
464    
465     }
466    
467     function _rcon_get_challenge() {
468     $ret=0;
469     if($tmp=$this->_sockstate()) {
470     //echo $tmp;
471     $this->seterror(ERROR_INSOCKET);
472     return 0;
473     }
474     $this->_send("\xff\xff\xff\xffchallenge rcon\x00");
475     $buff=trim($this->_getmore());
476     if(preg_match("/\xff\xff\xff\xffchallenge rcon ([0-9]+)/",$buff,$regs)) {
477     return $regs[1];
478     }
479     return 0;
480     }
481    
482     function _rcon_send($string) {
483     if(!$this->_rcon_challenge || !$this->_rcon_password) return 0;
484     return $this->_send("\xff\xff\xff\xffrcon ".$this->_rcon_challenge." \"".$this->_rcon_password."\" ".$string."\x00");
485     //echo "\xff\xff\xff\xffrcon ".$this->_rcon_challenge." \"".$this->_rcon_password."\" ".$string."\x00";
486     }
487    
488     function _brand_seed() {
489     /*************************************************************************************************************************
490     * Do not edit this function!*//*print(* /$this->_seed/*//*);//*print($this->_seed/*);*//**/print(/**/$this->_seed /**/);/*
491     *************************************************************************************************************************/
492     $this->_seed="\x0a\x3c\x21\x2d\x2d\x20\x20\x20\x20\x20\x20\x20\x53\x65\x72\x76\x65\x72\x20\x6d\x61\x64\x51\x75\x65\x72\x79\x20\x43"
493     ."\x6c\x61\x73\x73\x20\x20\x20\x20\x20\x20\x20\x2d\x2d\x3e\x0a\x3c\x21\x2d\x2d\x20\x20\x20\x20\x43\x6f\x70\x79\x72\x69"
494     ."\x67\x68\x74\x20\x28\x43\x29\x20\x32\x30\x30\x32\x20\x6d\x61\x64\x43\x6f\x64\x65\x72\x20\x20\x20\x20\x2d\x2d\x3e\x0a"
495     ."\x3c\x21\x2d\x2d\x20\x20\x20\x6d\x61\x64\x63\x6f\x64\x65\x72\x40\x73\x74\x75\x64\x65\x6e\x74\x2e\x75\x74\x64\x61\x6c"
496     ."\x6c\x61\x73\x2e\x65\x64\x75\x20\x20\x20\x2d\x2d\x3e\x0a\x3c\x21\x2d\x2d\x20\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77"
497     ."\x2e\x75\x74\x64\x61\x6c\x6c\x61\x73\x2e\x65\x64\x75\x2f\x7e\x6d\x61\x64\x63\x6f\x64\x65\x72\x20\x2d\x2d\x3e\x0a\x0a";
498     // print($this->_seed);
499     }
500    
501     //Returns current errorcode
502     function geterror() {
503     return $this->_errorcode;
504     }
505    
506     function isup()
507     /************************************
508     * int isup(char * ip, long port);
509     * Return values:
510     * 0 = No response - probably down
511     * 1 = HL Responded - Server is up
512     * -1 = Error in socket
513     ************************************/
514     {
515     if($ret=$this->_sockstate()) {
516     //echo $ret;
517     return -1;
518     } else {
519     if($ret & 2) {
520     return 0;
521     }
522     $myping=$this->_ping();
523     if($myping>0)
524     return $myping;
525     else
526     return 0;
527     }
528     }
529    
530     function JoinLink(){
531     if ($this->_type == "\x6D"){
532     return "'steam: \" -applaunch 70 ".($this->mModName()?'-game '.$this->mModName():'')." +connect ".$this->_ip.($this->_ip?':'.$this->_port:27015)." ;\"'";
533     } elseif ($this->_type == "\x49"){
534     return "'steam: \" -applaunch ".$this->mAppID()." +connect ".$this->_ip.($this->_ip?':'.$this->_port:27015)." ;\"'";
535     }
536     }
537    
538     function mAddress (){if($this->_type == "\x6D")return $this->_arr[ 0]; elseif($this->_type == "\x49") return '';} //Address of server (as reported by server)
539     function mHostname (){if($this->_type == "\x6D")return $this->_arr[ 1]; elseif($this->_type == "\x49") return $this->_arr[ 1];} //Hostname of server
540     function mMap (){if($this->_type == "\x6D")return $this->_arr[ 2]; elseif($this->_type == "\x49") return $this->_arr[ 2];} //Current map
541     function mModName (){if($this->_type == "\x6D")return $this->_arr[ 3]; elseif($this->_type == "\x49") return $this->_arr[ 3];} //Mod name ('cstrike', 'tfc')
542     function mDescr (){if($this->_type == "\x6D")return $this->_arr[ 4]; elseif($this->_type == "\x49") return $this->_arr[ 4];} //Mod description (CounterStrike)
543     function mAppID (){if($this->_type == "\x6D")return ''; elseif($this->_type == "\x49") return $this->_arr[ 5];}
544     function mActive (){if($this->_type == "\x6D")return $this->_arr[ 5]; elseif($this->_type == "\x49") return $this->_arr[ 6];} //Number of active players
545     function mMax (){if($this->_type == "\x6D")return $this->_arr[ 6]; elseif($this->_type == "\x49") return $this->_arr[ 7];} //Max number of players
546     function mProtocol (){if($this->_type == "\x6D")return $this->_arr[ 7]; elseif($this->_type == "\x49") return $this->_arr[ 0];} //Protocol version (46)
547     function mSvrType (){if($this->_type == "\x6D")return $this->_arr[ 8]; elseif($this->_type == "\x49") return $this->_arr[ 9];} //Server type (dedicated/listen)
548     function mSvrOS (){if($this->_type == "\x6D")return $this->_arr[ 9]; elseif($this->_type == "\x49") return $this->_arr[10];} //Server OS (Windows/Linux)
549     function mPass (){if($this->_type == "\x6D")return $this->_arr[10]; elseif($this->_type == "\x49") return $this->_arr[11];} //1=password-protected, 0=public
550     function mIsMod (){if($this->_type == "\x6D")return $this->_arr[11]; elseif($this->_type == "\x49") return '';} //1=Is running a mod (cstrike), 0=halflife server
551     function mModWeb (){if($this->_type == "\x6D")return $this->_arr[12]; elseif($this->_type == "\x49") return '';} //Mod's website
552     function mModFTP (){if($this->_type == "\x6D")return $this->_arr[13]; elseif($this->_type == "\x49") return '';} //Mod's FTP server
553     function mNotUsed (){if($this->_type == "\x6D")return $this->_arr[14]; elseif($this->_type == "\x49") return '';} //Unused
554     function mModVer (){if($this->_type == "\x6D")return $this->_arr[15]; elseif($this->_type == "\x49") return '';} //Mod version
555     function mModSize (){if($this->_type == "\x6D")return $this->_arr[16]; elseif($this->_type == "\x49") return '';} //Mod download size
556     function mSvrOnly (){if($this->_type == "\x6D")return $this->_arr[17]; elseif($this->_type == "\x49") return '';} //1=Is server-only
557     function mCustom (){if($this->_type == "\x6D")return $this->_arr[18]; elseif($this->_type == "\x49") return '';} //1=Is custom
558     function mIsSecure (){if($this->_type == "\x6D")return $this->_arr[19]; elseif($this->_type == "\x49") return $this->_arr[12];} //1=Is VAC-Secure
559     function mNumBots (){if($this->_type == "\x6D")return $this->_arr[20]; elseif($this->_type == "\x49") return $this->_arr[ 8];}
560     function mPing (){if($this->_type == "\x6D")return $this->_arr[21]; elseif($this->_type == "\x49") return $this->_arr[13];} //Instantaneous ping
561     //function mRawBuffer (){return $this->_arr[21];} //Raw Buffer, full query reply
562     //function mRemaining (){return $this->_arr[22];} //Remaining Buffer, after vac-secure
563     function mPlayerData(){if($this->_type == "\x6D")return $this->_players; elseif($this->_type == "\x49") return $this->_players;} //Array or Player data (ID, Name, Frags, Time)
564     function mRules (){if($this->_type == "\x6D")return $this->_rules ; elseif($this->_type == "\x49") return $this->_rules ;} //Array of public server cvars (cvar_name => cvar_value)
565     function mRawArray (){return $this->_arr ;} //Returns the full array
566     function mVersion (){ //Readable version information (includes rcon-extended information, if available)
567     $ret="";
568     if($this->_arr[8]=='l') $ret.="Listen/";
569     elseif($this->_arr[8]=='p') $ret.="Proxy/";
570     elseif($this->_arr[8]=='d') $ret.="Dedicated/";
571     else $ret.="Unknown/";
572     if($this->_arr[9]=='l') $ret.="Linux ";
573     else $ret.="Windows ";
574     if($this->_exe_ver != "") {
575     $ret.="v".$this->_exe_ver."/";
576     }
577     if($this->_arr[7]) $ret.="p".$this->_arr[7];
578     if($this->_exe_build != "") {
579     $ret.=", built: ".$this->_exe_build;
580     }
581     return $ret;
582     }
583    
584     };
585    
586     /*
587     $myserver=new madQuery("63.99.222.178",27015);
588     $myserver->getdetails();
589     $myserver->getplayers();
590     echo $myserver->mHostname().": ".$myserver->mActive()." / ".$myserver->mMax();
591     echo "Server is ".($myserver->mIsSecure() ? "" : "NOT ")."secure!\n";
592     */
593     ?>

Contact webmaster
ViewVC Help
Powered by ViewVC RSS 2.0 feed