Raised This Month: $ Target: $400
 0% 

php code


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ibrahim
BANNED
Join Date: May 2012
Location: sharjah
Old 07-11-2012 , 13:19   php code
Reply With Quote #1

why this doesn't works?
PHP Code:
<?php
header
("Content-type: image/png");
error_reporting(0);
ob_start;
function 
myTruncate2($string$limit$break ""$pad "...")
{
// return with no change if string is shorter than $limit
if (strlen($string) <= $limit)
return 
$string;
$string substr($string0$limit);
if (
false !== ($breakpoint strrpos($string$break))) {
$string substr($string0$breakpoint);
}
return 
$string $pad;
}
function 
pingDomain($domain$port)
{
$starttime microtime(true);
$file fsockopen($domain$port$errno$errstr0.5);
$stoptime microtime(true);
$status 0;
if (!
$file) {
return 
false;
} else {
fclose($file);
return 
true;
}
}
class 
serverQuery
{
// Server Info
private $serverIp null;
private 
$serverPort null;

// Server Connection / Query
private $serverConnection null;
private 
$serverResponse null;
private 
$players null;

// Server Information
private $serverInformation = array();
private 
$challengeCode null;
private 
$playerData = array();
private 
$serverSettings = array();

public function 
__construct($server)
{
$server explode(":"$server);
$this->serverIp $server[0];
$this->serverPort $server[1];
$this->queryServer();
$this->parseServerResponse();
}

public function 
queryServer()
{
// Open a Connection to the Server
$this->serverConnection pfsockopen("udp://" $this->serverIp$this->
serverPort$errorNumber$errorString1);
stream_set_blocking($this->serverConnection1);
if (!
$this->serverConnection) {
return 
false;
} else {
// Send Query to Server For General Details
$this->serverResponse substr($this->query("\xFF\xFF\xFF\xFF\x54Source Engine Query\0"),
2);
// Get the Challenge Code for a Player and Rules Query
$this->challengeCode substr($this->query("\xFF\xFF\xFF\xFF\x57"), 1);
$this->players $this->query("\xFF\xFF\xFF\xFF\x55" $this->challengeCode);
$this->serverSettings $this->parseRules($this->query("\xFF\xFF\xFF\xFF\x56" .
$this->challengeCode));
fclose($this->serverConnection);
return 
true;
}
}

private function 
query($queryData)
{
// Query Function -- Removes 'Junk' [\xFF\xFF\xFF\xFF] -- Returns Data
fwrite($this->serverConnection$queryData);
fread($this->serverConnection4);
$serverStatus stream_get_meta_data($this->serverConnection);
return 
fread($this->serverConnection$serverStatus['unread_bytes']);
}

public function 
parseServerResponse()
{
/*
All of These Values are directory from the Developer Wiki
(http://developer.valvesoftware.com/wiki/Server_Queries)
*/
$this->serverInformation['hostname'] = trim(str_replace("\x01"""$this->
getString($this->serverResponse)));
$this->serverInformation['map'] = $this->getString($this->serverResponse);
$this->serverInformation['dir'] = $this->getString($this->serverResponse);
$this->serverInformation['description'] = $this->getString($this->
serverResponse);
$this->serverInformation['appid'] = $this->getShort($this->serverResponse);
$this->serverInformation['players'] = $this->getByte($this->serverResponse);
$this->serverInformation['maxplayers'] = $this->getByte($this->serverResponse);
$this->serverInformation['bots'] = $this->getByte($this->serverResponse);
$this->serverInformation['type'] = (chr($this->getByte($this->serverResponse)) ==
"d") ? "Dedicated" "Listen";
$this->serverInformation['os'] = (chr($this->getByte($this->serverResponse)) ==
"l") ? "Linux" "Windows";
$this->serverInformation['pass'] = $this->getByte($this->serverResponse);
$this->serverInformation['vac'] = $this->getByte($this->serverResponse);
$this->serverInformation['version'] = $this->getString($this->serverResponse);

// Removes First Byte of Player Response and Uses The Next Byte as the Counter
$this->getByte($this->players);
$count $this->getByte($this->players);

// Itterate Through and Get Cooresponding Values
for ($x 0$x $count$x++) {
$this->playerData[$x]['id'] = $this->getByte($this->players);
$this->playerData[$x]['name'] = $this->getString($this->players);
$this->playerData[$x]['kills'] = $this->getLong($this->players);
$playerTime round($this->getFloat($this->players));
$this->playerData[$x]['time'] = round($playerTime 3600) . ":" round(($playerTime %
3600) / 60) . ":" round($playerTime 60);
}
return 
true;
}

private function 
getByte(&$source)
{
$byte ord(substr($source01));
$source substr($source1);
return 
$byte;
}

private function 
getLong(&$source)
{
$long unpack("L"substr($source04));
$source substr($source4);
return 
$long[1];
}

private function 
getShort(&$source)
{
$short unpack("S"substr($source02));
$source substr($source2);
return 
$short[1];
}

private function 
getChar(&$source)
{
$char substr($source01);
$source substr($source1);
return 
$char;
}

private function 
getFloat(&$source)
{
$float unpack("f"substr($source04));
$source substr($source4);
return 
$float[1];
}

private function 
getString(&$source)
{
$string "";
$loop true;
while (
$loop) {
$stringPart $this->getChar($source);
if (
ord($stringPart) != 0) {
$string .= $stringPart;
} else {
$loop false;
}
}
return 
$string;
}

private function 
parseRules($rules)
{
$newRules = array();

$this->getByte($rules);

if (
$this->getByte($rules) != 0) {
$rules explode(chr(0), $rules);
for (
$x 1$x count($rules) - 1$x += 2) {
$newRules[$rules[$x]] = $rules[$x 1];
}
}
return 
$newRules;
}

// Data access Functions
public function getServerInformation()
{
return 
$this->serverInformation;
}

public function 
getPlayerInformation()
{
return 
$this->playerData;
}

public function 
getServerSettings()
{
return 
$this->serverSettings;
}
}
ob_clean;
$font 'C:\WINDOWS\Fonts\calibri.ttf';
$S explode(':'$_GET['s']);
$ip $S[0];
$po $S[1];
if (!
pingDomain($ip$po)) {
$im imagecreatefrompng("./banners/offline.png");
$white imagecolorallocate($im225225225);
imagettftext($im100813$white$fontstrtoupper('server ' $ip ":" .
$po));
imagepng($im);
imagedestroy($im);
exit;
}

$serverQuery = new serverQuery($_GET['s']);
$SvIn $serverQuery->getServerInformation();

if (
$SvIn['dir'] == 'cstrike') {
$im imagecreatefrompng("Images/cstrike.png");
$colour imagecolorallocate($im225225225);
} elseif (
$SvIn['dir'] == 'hl2mp') {
$im imagecreatefrompng("banners/hl2mp.png");
$colour imagecolorallocate($im225225225);
} elseif (
$SvIn['dir'] == 'tf') {
$im imagecreatefrompng("banners/tf.png");
$colour imagecolorallocate($im000);
} elseif (
$SvIn['dir'] == 'dod') {
$im imagecreatefrompng("banners/dod.png");
$colour imagecolorallocate($im225225225);
} elseif (
$SvIn['dir'] == 'left4dead' || $SvIn['dir'] == 'left4dead2') {
$im imagecreatefrompng("banners/left4dead.png");
$colour imagecolorallocate($im225225225);
} else {
$im imagecreatefrompng("Images/offline.png");
$colour imagecolorallocate($im225225225);
imagettftext($im1001595$colour$font'MOD: ' $SvIn['description']);
}
$px = (imagesx($im) - 7.5 strlen($string)) / 2;
$status 'ONLINE';
$server strtoupper(myTruncate2($SvIn['hostname'], 22''));
$map strtoupper(myTruncate2($SvIn['map'], 22''));
$players $SvIn['players'] . ' OF ' $SvIn['maxplayers'];
$cut $SvIn['players'] / $SvIn['maxplayers'] * 360;

imagettftext($im10018519$colour$font$server);
imagettftext($im10018534$colour$fontmyTruncate2(strtoupper($ip) .
':' $po22''));
imagettftext($im10018549$colour$font$map);
imagettftext($im10018565$colour$font$players);
imagettftext($im10018580$colour$font$status);

imagepng($im);
imagedestroy($im);
?>
Ibrahim is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:43.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode