Exemplo n.º 1
0
 public function __construct($IP, $Port = 25565, $Timeout = 2)
 {
     require "MinecraftServerPing.php";
     $Query = null;
     try {
         $Query = new MinecraftPing($IP, $Port, $Timeout);
         $this->Info = $Query->Query();
         if ($this->Info === false) {
             $Query->Close();
             $Query->Connect();
             $this->Info = $Query->QueryOldPre17();
             $this->New = false;
         }
     } catch (MinecraftPingException $e) {
         $this->Online = false;
     }
     if ($Query !== null) {
         $Query->Close();
     }
     if ($this->New) {
         $this->OnlinePlayers = $this->Info['players']['online'];
         $this->MaxPlayers = $this->Info['players']['max'];
         $this->Version = $this->Info['version']['name'];
         $this->Description = $this->Description['description']['text'];
     } else {
         $this->OnlinePlayers = $this->Info['Players'];
         $this->MaxPlayers = $this->Info['MaxPlayers'];
         $this->Version = $this->Info['Version'];
     }
     $this->Online = true;
 }
$Info = false;
$Query = null;
try {
    $Query = new MinecraftPing(MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_TIMEOUT);
    $Info = $Query->Query();
    if ($Info === false) {
        /*
         * If this server is older than 1.7, we can try querying it again using older protocol
         * This function returns data in a different format, you will have to manually map
         * things yourself if you want to match 1.7's output
         *
         * If you know for sure that this server is using an older version,
         * you then can directly call QueryOldPre17 and avoid Query() and then reconnection part
         */
        $Query->Close();
        $Query->Connect();
        $Info = $Query->QueryOldPre17();
    }
} catch (MinecraftPingException $e) {
    $Exception = $e;
}
if ($Query !== null) {
    $Query->Close();
}
$Timer = Number_Format(MicroTime(true) - $Timer, 4, '.', '');
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Minecraft Ping PHP Class</title>