the include file...
<?php
include_once("gsQuery.php");
class q3a extends gsQuery
{
function query_server($getPlayers=TRUE,$getRules=TRUE)
{
$this->playerkeys=array();
$this->debug=array();
$this->password=-1;
$command="\xFF\xFF\xFF\xFF\x02getstatus\x0a\x00";
if(!($result=$this->_sendCommand($this->address,$this->queryport,$command))) {
$this->errstr="No reply received";
return FALSE;
}
$temp=explode("\x0a",$result);
$rawdata=explode("\\",substr($temp[1],1,strlen($temp[1])));
// get rules and basic infos
for($i=0;$i< count($rawdata);$i++) {
switch ($rawdata[$i++]) {
case "g_gametypestring":
$this->gametype=$rawdata[$i];
break;
case "gamename":
$this->gametype=$rawdata[$i];
$this->gamename="q3a_" . preg_replace("/[ ]/", "_", strtolower($rawdata[$i]));
break;
case "version":
$this->gameversion=$rawdata[$i];
break;
// for CoD
case "shortversion":
$this->gameversion=$rawdata[$i];
break;
case "sv_hostname":
$this->servertitle=$rawdata[$i];
break;
case "sv_pure":
$this->sv_pure=$rawdata[$i];
break;
case "mapname":
$this->mapname=$rawdata[$i];
break;
case "g_needpass":
$this->password=$rawdata[$i];
break;
// for CoD
case "pswrd":
$this->password=$rawdata[$i];
break;
case "sv_maplist":
$this->maplist=explode(" ", $rawdata[$i]);
break;
default:
$this->rules[$rawdata[$i-1]] = $rawdata[$i];
}
}
// for MoHAA
if(!$this->gamename && eregi("Medal of Honor", $this->gameversion)) {
$this->gamename="mohaa";
}
if(!empty($this->maplist)) {
$i=0;
while($this->mapname!=$this->maplist[$i++] && $i<count($this->maplist));
$this->nextmap=$this->maplist[$i % count($this->maplist)];
}
//for MoHAA
$this->maptitle = $this->rules["g_obj_alliedtext1"];
$this->map = $this->mapname;
$this->mappic = $this->rules["g_scoreboardpic"];
$this->URL = $this->rules["URL"];
$this->hostport = $this->queryport;
$this->maxplayers = $this->rules["sv_maxclients"]-$this->rules["sv_privateClients"];
$this->ip = $this->address;
$this->Url = $this->rules["Url"];
$this->objdm1="The Hunt";
$this->objdm2="V2 Rocket Facility";
$this->objdm4="The Bridge";
$this->mohdm1="Southern France";
$this->mohdm2="Destroyed Village";
$this->mohdm3="Remagen";
$this->mohdm4="The Crossroads";
$this->mohdm5="Snowy Park";
$this->mohdm6="Stalingrad";
$this->mohdm7="Algiers";
//get playerdata
$temp=substr($result,strlen($temp[0])+strlen($temp[1])+1,strlen($result));
$allplayers=explode("\n", $temp);
$this->numplayers=count($allplayers)-2;
// get players
if(count($allplayers)-2 && $getPlayers) {
for($i=1;$i< count($allplayers)-1;$i++) {
// match with team info
if(preg_match("/(\d+)[^0-9](\d+)[^0-9](\d+)[^0-9]\"(.*)\"/", $allplayers[$i], $curplayer)) {
if($curplayer[3]>2) {
next; // ignore spectators
}
$players[$i-1]["name"]=$curplayer[4];
$players[$i-1]["score"]=$curplayer[1];
$players[$i-1]["ping"]=$curplayer[2];
$players[$i-1]["team"]=$curplayer[3];
$teamInfo=TRUE;
$pingOnly=TRUE;
} elseif(preg_match("/(\d+)[^0-9](\d+)[^0-9]\"(.*)\"/", $allplayers[$i], $curplayer)) {
$players[$i-1]["name"]=$curplayer[3];
$players[$i-1]["score"]=$curplayer[1];
$players[$i-1]["ping"]=$curplayer[2];
$pingOnly=TRUE;
$teamInfo=TRUE;
}
else {
if(preg_match("/(\d+).\"(.*)\"/", $allplayers[$i], $curplayer)) {
$players[$i-1]["name"]=$curplayer[2];
$players[$i-1]["score"]=$curplayer[3];
$players[$i-1]["ping"]=$curplayer[1];
$pingOnly=TRUE;
$teaminfo=TRUE; //For Moha
}
else {
$this->errstr="Could not extract player infos!";
return FALSE;
}
}
}
$this->playerkeys["name"]=TRUE;
if(!$pingOnly) {
$this->playerkeys["score"]=TRUE;
if($teamInfo) {
$this->playerkeys["team"]=TRUE;
}
}
$this->playerkeys["ping"]=TRUE;
$this->players=$players;
}
return TRUE;
}
/**
* @brief Sends a rcon command to the game server
*
* @param command the command to send
* @param rcon_pwd rcon password to authenticate with
* @return the result of the command or FALSE on failure
*/
function rcon_query_server($command, $rcon_pwd)
{
$command="\xFF\xFF\xFF\xFF\x02rcon ".$rcon_pwd." ".$command."\x0a\x00";
if(!($result=$this->_sendCommand($this->address,$this->queryport,$command))) {
$this->errstr="Error sending rcon command";
return FALSE;
} else {
return $result;
}
}
/**
* @brief htmlizes the given raw string
*
* @param var a raw string from the gameserver that might contain special chars
* @return a html version of the given string
*/
function htmlize($var)
{
$var = htmlspecialchars($var);
while(ereg('\^([0-9])', $var)) {
foreach(array('black', 'red', 'darkgreen', 'yellow', 'blue', 'cyan', 'pink', 'white', 'blue-night', 'red-night') as $num_color => $name_color) {
if (ereg('\^([0-9])(.*)\^([0-9])', $var)) {
$var = preg_replace("#\^".$num_color."(.*)\^([0-9])#Usi", "<span class=\"gsquery-".$name_color."\">$1</span>^$2", $var);
} else {
$var = preg_replace("#\^".$num_color."(.*)$#Usi", "<span class=\"gsquery-".$name_color."\">$1</span>", $var);
}
}
}
return $var;
}
}
?>
its a litle bit difrent π
You are free 2 try @ www.GiGGes.Tk