<?php
/******************************************************************\
|* Copyright (c) by starlex.de, Alexander Becker
|*
|* Visit:
|*
|* License:
|*
\******************************************************************/
$serverstatus = mc_status("176.31.240.28:25567"); // <- your serveraddress here
echo ("motd: ".$serverstatus["motd"]); 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
if(count($info) == 3) // check array (if modt contains invalid chars(§)) {
return( // returns a new Array (END)
"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)
"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.
-/40Ewentualnie 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
Ten post edytował Karolus 20.02.2012, 14:13:35