<?php
/******************************************************************\
|* Copyright (c) by starlex.de, Alexander Becker
|*
|* Visit:
|* [url="http://starlex.de"]http://starlex.de[/url]
|*
|* License:
|* [url="http://creativecommons.org/licenses/by-sa/3.0/deed.en"]http://creativecommons.org/licenses/by-sa/3.0/deed.en[/url]
|*
\******************************************************************/
$serverstatus = mc_status("176.31.240.28:25567"); // <- your serveraddress here
echo ("motd: ".$serverstatus["motd"]);
echo ("\n<br/>\n");
echo ("players: ".$serverstatus["cur_players"]."/".$serverstatus["max_players"]);
function mc_status( $server ) {
if($socket = stream_socket_client('tcp://'.$server , $errno, $errstr, 1)) // connect to the server
{
fwrite($socket, "\xfe"); // writes the query
$tmp = fread($socket, 2048); // reads the serverinfo
$tmp = str_replace("\x00","",$tmp); // removes all 0x00
$tmp = substr ($tmp,2); // removes the first 2 bytes
$info = explode("§",$tmp); // splits the sting into a array
unset($tmp);
if(count($info) == 3) // check array (if modt contains invalid chars(§))
{
return( // returns a new Array (END)
Array(
"motd" => $info[0],
"cur_players" => $info[1],
"max_players" => $info[2]
)
);
} else if(count($info) > 3){ // DEAL ERRORS - INVALID CHARS : !!! not added in the minecraft client !!!
$tmp = "";
for ($i = 0; $i < count($info) - 2; $i++) {
$tmp .= $info[$i];
if(!($i == count($info) - 2 - 1))
{
$tmp .= "§";
}
}
return( // returns a new Array (END)
Array(
"motd" => $tmp,
"cur_players" => $info[count($info) - 2],
"max_players" => $info[count($info) - 1]
)
);
} else {
return false; // return false (if syntax is wrong)
}
} else {
return false; // return false (if connection failed in first step)
}
}
?>
Witam, powyższy skrypt pokazuję na stronie ile graczy jest online w danym momencie na serwerze Minecraft.
Chciałbym żeby w momencie wyłączenia serwera pokazywał:
-"/".$serverstatus["max_players"]);
np. -/40
Ewentualnie mogę na sztywno zamienić wartość max_players na liczbę slotów.
Ponieważ w tym momencie kiedy serwer jest wyłączony pokazuje on błędy.
Pozdrawiam