Upload files to "/"
This commit is contained in:
55
minecraft_status.php
Normal file
55
minecraft_status.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
function ping($host, $port, $timeout){return fSockOpen($host, $port, $errno, $errstr, $timeout);}
|
||||||
|
|
||||||
|
class ServerStatus {
|
||||||
|
private $status = array();
|
||||||
|
public function __construct($status) {$this->status = $status;}
|
||||||
|
public function getMOTD() {return $this->status["motd"];}
|
||||||
|
public function getVersion() {return $this->status["version"];}
|
||||||
|
public function getCurrentPlayers() {return $this->status["players"];}
|
||||||
|
public function getAddress() {return $this->status["address"];}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ServerStatusQuery {
|
||||||
|
public function __construct() {}
|
||||||
|
|
||||||
|
public function getServerInfo($address = "127.0.0.1", $port = 25565, $timeout = 5) {
|
||||||
|
if(!filter_var($address, FILTER_VALIDATE_IP)) {$address = gethostbyname($address);}
|
||||||
|
$ping_start = microtime(true);
|
||||||
|
$socket = stream_socket_client("tcp://" . $address . ":" . $port, $errorNumber, $errorString, $timeout );
|
||||||
|
|
||||||
|
if (!$socket) {return false;}
|
||||||
|
else {
|
||||||
|
stream_set_timeout($socket, $timeout );
|
||||||
|
fwrite ($socket, "\XFE\01");
|
||||||
|
$data = fread( $socket, 2048);
|
||||||
|
fclose($socket);
|
||||||
|
$ping = microtime(true) - $ping_start;
|
||||||
|
if($data == null) {return false;}
|
||||||
|
|
||||||
|
if (substr((String) $data, 3, 5) == "\00\xa7\x00\x31\x00") {
|
||||||
|
$content = explode( "\x00", mb_convert_encoding(substr((String)$data, 15), 'UTF-8', 'UCS-2' ) );
|
||||||
|
$content[1] = preg_replace("/(§.)/", "",$content[1]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$content = explode('§', mb_convert_encoding(substr((String)$data, 3), 'UTF-8', 'UCS-2'));
|
||||||
|
$content[1] = "";
|
||||||
|
foreach ($content as $key => $string) {
|
||||||
|
if($key != sizeof($content)-1 && $key != sizeof($content)-2 && $key != 0) {$content[1] .= '§'.$string;}
|
||||||
|
}
|
||||||
|
$content[1] = preg_replace("/(§.)/", "", $content[1]);
|
||||||
|
}
|
||||||
|
$content[1] = preg_replace("/[^[:alnum:][:punct:] ]/", "", $content[1]);
|
||||||
|
|
||||||
|
$info = array(
|
||||||
|
"version" => $content[1],
|
||||||
|
"motd" => $content[2],
|
||||||
|
"players" => $content[3],
|
||||||
|
"address" => $address
|
||||||
|
);
|
||||||
|
|
||||||
|
return new ServerStatus($info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user