Thursday, October 14, 2010

Source engine query with php part2

include 'query.php';
$Server = 'SERVERSIP+PORT';
if(isset($_GET['server'])){
 $Server = $_GET['server'];
}
//-----------------------------------------------------------------
//Query + Server data Out + filtering
$q = source_query($Server);
$Sv = explode(':', $Server);
$SvIp = $Sv[0];
$SvPo = $Sv[1];
$q['appid'] = str_replace(160, 'Garrysmod', $q['appid']);
$q['appid'] = str_replace(184, 'Team_Fortress_2', $q['appid']);
$q['appid'] = str_replace(240, 'Counter-Strike:_Source', $q['appid']);
$map = substr($q['map'],0,14);
print_r($q);
//------------------------------------------------------------------
// Template Image

$im = imagecreatefrompng ("banner.png");

//------------------------------------------------------------------
//Check to see if i have a pic of the map
$mappic = "maps/".$q['map'].".png";
$nomap = "none.png";
if (file_exists($mappic)) {
    echo "GOOD I HAVE A PIC OF THE MAP!   ";
 $insert = imagecreatefrompng($mappic); 
 
} else {
    echo "SAD FACE I DON'T HAVE PIC OF MAP   ";
 $insert = imagecreatefrompng($nomap);
}
print_r($mappic);
$insert_x = imagesx($insert); 
$insert_y = imagesy($insert);
//-----------------------------------------------------------------
//PICK SOME COLOURS!!!!! IN RGB PLEASE
$colour = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);
$green = imagecolorallocate($im, 34, 139, 34);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
//------------------------------------------------------------------
//FONTS!!!! ADD MORE IF YOU WANT
$font = 'pirulen.ttf';

//------------------------------------------------------------------
//SEE IF SERVER IS ONLINE????

if ($q['name'] != ''){
 
 $name = substr($q['name'],0,26);
 $namecolour = $green;
 
}
else 
{
 $name = "OFFLINE";
 $namecolour = $red;
}
//--------------------------------------------------------------------
//OUTPUT FILTERED SERVER DATA TO PIC
$maxplayers = $q['max'];
$player = $q['players'];
$ip = $SvIp;
$map = $map;
$port = $SvPo;
$players = $player."/".$maxplayers;
// PUT TEXT ON IMAGE (SIZE,ROTATE,X,Y,COLOUR,FONT,DATA)
imagettftext($im, 10, 0, 120, 32, $namecolour, $font, $name);
imagettftext($im, 10, 0, 120, 60, $colour, $font, $ip);
imagettftext($im, 10, 0, 120, 86, $colour, $font, $map);
imagettftext($im, 10, 0, 295, 60, $colour, $font, $port);
imagettftext($im, 10, 0, 350, 86, $colour, $font, $players);

//make the pic + put map pic ontop
imagecopymerge($im,$insert,455,20,0,0,$insert_x,$insert_y,100); 
imagepng($im,'serverbanner.png');
imagedestroy($im);
This php code will create a image file much like game trackers output.
This is the input file.

 This is the output of the file, if i had i pic of the map it would display in the map box.

No comments:

Post a Comment