Example #1
0
 public static function check($hostname, $port, $version = '1.7.10')
 {
     try {
         $query = new MinecraftPing($hostname, $port);
         if ($version > '1.7') {
             return $query->Query();
         } else {
             return $query->QueryOldPre17();
         }
     } catch (xPaw\MinecraftPingException $e) {
         return false;
     }
 }
<?php

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', true);
require_once 'MinecraftPing.php';
require_once 'MinecraftPingException.php';
use xPaw\MinecraftPing;
use xPaw\MinecraftPingException;
$timer = microtime(true);
$info = false;
$query = null;
try {
    $query = new MinecraftPing('localhost', 25565, 1);
    $info = $query->query();
    if ($info === false) {
        $query->close();
        $query->connect();
        $info = $query->queryOldPre17();
    }
    if ($info === false) {
        $query->close();
        $query->connect();
        $info = $query->queryBungeeCord();
    }
} catch (MinecraftPingException $e) {
    $exception = $e;
}
if ($query !== null) {
    $query->close();
}
$timer = number_format(microtime(true) - $timer, 4, '.', '');
Example #3
0
 public static function checkNoQuery($sid, $ip, $port, $day, $month, $year, $timeout = 2)
 {
     $timer = MicroTime(true);
     $info = false;
     $query = null;
     try {
         $query = new MinecraftPing($ip, $port, $timeout);
         $info = $query->Query();
         if ($info === false) {
             $query->Close();
             $query->Connect();
             $info = $query->QueryOldPre17();
         }
     } catch (MinecraftPingException $e) {
         $Exception = $e;
     }
     if ($query !== null) {
         $query->Close();
     }
     $timer = Number_Format(MicroTime(true) - $timer, 2, '.', '');
     if ($info == false) {
         DB::table('mcserverschecks')->insert(array('mcsc_sid' => $sid, 'mcsc_online' => 0, 'mcsc_players' => 0, 'mcsc_ping' => 0, 'mcsc_day' => $day, 'mcsc_month' => $month, 'mcsc_year' => $year));
         DB::table('mcservers')->where('mcs_id', $sid)->update(array('mcs_players' => 0, 'mcs_status' => 0));
     } else {
         DB::table('mcserverschecks')->insert(array('mcsc_sid' => $sid, 'mcsc_online' => 1, 'mcsc_players' => $info["players"]["online"], 'mcsc_ping' => $timer, 'mcsc_day' => $day, 'mcsc_month' => $month, 'mcsc_year' => $year));
         DB::table('mcservers')->where('mcs_id', $sid)->update(array('mcs_maxplayers' => $info["players"]["max"], 'mcs_players' => $info["players"]["online"], 'mcs_status' => 1, 'mcs_motd' => mcservers::motd(substr($info["description"], 0, 255))));
     }
 }
<?php

use xPaw\MinecraftPing;
use xPaw\MinecraftPingException;
require_once 'common_header.php';
$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, '.', '');
if (isset($Exception)) {
Example #5
0
 $query = new MinecraftQuery();
 try {
     // Create connection.
     $query->Connect($mc_server_ip, $mc_server_port, 2);
 } catch (MinecraftQueryException $queryE) {
     $queryException = $queryE->getMessage();
 }
 // Stop ping and format to milliseconds.
 $queryPing = round((microtime(true) - $queryPing) * 1000);
 /**
  * Run MinecraftPing.php
  */
 // Start ping timer.
 $pingPing = microtime(true);
 try {
     $ping = new MinecraftPing($mc_server_ip, $mc_server_port, 2);
     $pingInfo = $ping->Query();
     if ($pingInfo === false) {
         // Old server
         $ping->Close();
         $ping->Connect();
         $pingInfo = $ping->QueryOldPre17();
     }
 } catch (MinecraftPingException $e) {
     $Exception = $e;
 }
 if ($ping !== null) {
     $ping->Close();
 }
 // Stop ping and format to milliseconds.
 $pingPing = round((microtime(true) - $pingPing) * 1000);