Esempio 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;
 }
Esempio n. 2
0
 public function isOnline($server_ip, $server_port, $player_name)
 {
     $Info = false;
     $Query = null;
     try {
         $Query = new MinecraftPing($server_ip, $server_port, MQ_TIMEOUT);
         $Info = $Query->Query();
     } catch (MinecraftPingException $e) {
         $Exception = $e;
     }
     if ($Query !== null) {
         $Query->Close();
     }
     if ($Info['players']['online'] == 0) {
         return false;
     } else {
         for ($row = 0; $row < $Info['players']['online']; $row++) {
             if (in_array($player_name, $Info['players']['sample'][$row])) {
                 return true;
                 break;
             }
         }
     }
 }
<?php

// Edit this ->
define('MQ_SERVER_ADDR', 'mc.ecocitycraft.com');
define('MQ_SERVER_PORT', 25565);
define('MQ_TIMEOUT', 1);
// Edit this <-
// Display everything in browser, because some people can't look in logs for errors
Error_Reporting(E_ALL | E_STRICT);
Ini_Set('display_errors', true);
require __DIR__ . '/MinecraftServerPing.php';
$Timer = MicroTime(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) {
 public function getQuery()
 {
     $input = Input::only('ip', 'port', 'version');
     $server = false;
     if (!$input['version']) {
         $input['version'] = '1.7.10';
     }
     try {
         $query = new MinecraftPing($input['ip'], $input['port']);
         if ($input['version'] > '1.7') {
             $server = $query->Query();
         } else {
             $server = $query->QueryOldPre17();
         }
     } catch (xPaw\MinecraftPingException $e) {
     }
     return View::make('servers.query', ['server' => $server]);
 }
Esempio n. 5
0
require __DIR__ . '/MinecraftPingException.php';
require __DIR__ . '/MinecraftSkin.php';
///////////// CONFIG /////////////
$SERVER_URL = null;
// Don't set it if you dont have a server url
$SERVER_IP = '';
$PORT = '';
$players = array('test', 'test1');
// players to be displayed
//////////////////////////////////
$mc = new MinecraftSkin();
foreach ($players as $player) {
    $mc->getFace($player);
}
try {
    $Query = new MinecraftPing($SERVER_IP, $PORT);
    $data = $Query->Query();
    $status = 'online';
} catch (MinecraftPingException $e) {
    echo $e->getMessage();
    $status = 'offline';
} finally {
    $Query->Close();
}
?>
<!DOCTYPE html>
<html>
	<head>
        <meta charset="utf-8">
        <title>Minecraft Server Status</title>
        <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css">