예제 #1
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))));
     }
 }
예제 #2
0
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)) {
    ?>
		<div class="panel panel-primary">
			<div class="panel-heading"><?php 
    echo htmlspecialchars($Exception->getMessage());
예제 #3
0
 } 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);
 // Store data.
 $rdata = array('mcQuery' => array('getInfo' => $query->GetInfo(), 'getPlayers' => $query->GetPlayers()), 'mcPing' => array('query' => $pingInfo), 'pingTimes' => array('queryPing' => $queryPing, 'pingPing' => $pingPing, 'avgPing' => round(($queryPing + $pingPing) / 2, 0)), 'lastUpdate' => date("Y-m-d H:i:s"));
 $fp = fopen($cacheFile, 'w');
 fwrite($fp, json_encode($rdata, JSON_PRETTY_PRINT));