<?php
//disable error reporting
//error_reporting(1);
/*
* This function fetches the data from the Server
*/
function fetch($hostname, $port) {
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$connected = socket_connect($socket, $hostname, $port);
if ($connected) {
$ping_start = microtime(true);
socket_send($socket, "\xFE", 1, 0);
$data = "";
$result = socket_recv($socket, &$data, 1024, 0);
$ping_end = microtime(true);
socket_close($socket);
if ($result != false && substr($data, 0, 1) == "\xFF") {
$info = explode("\xA7", mb_convert_encoding(substr($data, 1), "iso-8859-1", "utf-16be"));
$serverName = substr($info[0], 1);
$playersOnline = $info[1];
$playersMax = $info[2];
$ping = round(($ping_end - $ping_start) * 1000);
if (($ping > '1000') || ($ping < '0')) {
return false;
} else {
return $playersOnline . "/" . $playersMax;
}
} else {
return false;
}
} else {
return false;
}
}
/*
* Generate Image
*/
$image = imagecreatefrompng("banner.png"); //Es muss ein bild namens banner.png im gleichen ordner liegen wie das script
if (!$image) {
die();
}
$font = 10;
$white = imagecolorallocate($image, 255, 255, 255);
$green = imagecolorallocate($image, 0, 255, 0);
$red = imagecolorallocate($image, 255, 0, 0);
$erg = fetch("84.200.27.130", "25670"); //Hier musst du deine serverdaten einfügen
imagestring($image, $font, 10, 5, "Status: ", $white);
if (!$erg) {
imagestring($image, $font, 80, 5, "Offline", $red);
} else {
imagestring($image, $font, 80, 5, "Online", $green);
imagestring($image, $font, 410, 5, "Players: ".$erg, $white);
}
/*
* Return image
*/
//Header('Content-type: image/png');
//imagepng($image);
//imagedestroy($image);
?>