コード例 #1
0
ファイル: Query.php プロジェクト: kam187/pocketmine-plugins
 public static function fetch($dat, $cfg)
 {
     if (!is_array($dat["content"])) {
         $f = $cfg["path"] . $dat["content"];
         if (is_file($f)) {
             $txt = file($f, FILE_IGNORE_NEW_LINES);
             if ($txt === false) {
                 $txt = "Error reading file";
             }
         } else {
             $txt = [$dat["content"]];
         }
     } else {
         $txt = $dat["content"];
     }
     $opts = explode(",", implode("\n", $txt), 3);
     if (!isset($opts[0])) {
         return "Query missing hostname";
     }
     $host = $opts[0];
     $port = isset($opts[1]) ? $opts[1] : 19132;
     // Default port
     $msg = isset($opts[2]) ? $opts[2] : "{HostName}\n{Players}/{MaxPlayers}";
     $Query = new MinecraftQuery();
     try {
         //echo __METHOD__.",".__LINE__."\n";//##DEBUG
         //echo "host=$host port=$port\n";//##DEBUG
         $Query->Connect($host, $port, 1);
     } catch (MinecraftQueryException $e) {
         return "Query " . $host . " error: " . $e->getMessage();
     }
     $txt = [$msg];
     if (($info = $Query->GetInfo()) !== false) {
         foreach ($info as $i => $j) {
             if (is_array($j)) {
                 continue;
             }
             $txt[] = $i . "\t" . $j;
         }
     }
     if (($players = $Query->GetPlayers()) !== false) {
         $list = "";
         foreach ($players as $p) {
             $list .= $p . "\n";
         }
         $txt[] = "PlayerList" . "\t" . $list;
     }
     //echo __METHOD__.",".__LINE__."\n";//##DEBUG
     //print_r($vars);//##DEBUG
     return $txt;
 }
コード例 #2
0
 public function onRun()
 {
     $this->setResult(["host" => $this->host, "port" => $this->port, "info" => null, "players" => null]);
     $Query = new MinecraftQuery();
     try {
         //echo __METHOD__.",".__LINE__."\n";//##DEBUG
         //echo "host=$host port=$port\n";//##DEBUG
         $Query->Connect($this->host, $this->port, 1);
     } catch (MinecraftQueryException $e) {
         $this->setResult("Query " . $this->host . " error: " . $e->getMessage());
         return;
     }
     $this->setResult(["host" => $this->host, "port" => $this->port, "info" => $Query->GetInfo(), "players" => $Query->GetPlayers()]);
 }
コード例 #3
0
ファイル: PortScanner.php プロジェクト: xpyctum/PortScanner
 /**
  * @param $addr
  * @param $port
  * @param $timeout
  */
 public function scanPort($addr, $port, $timeout)
 {
     $q = new MinecraftQuery();
     try {
         $q->Connect($addr, $port, $timeout);
         if ($q->GetInfo() !== false) {
             $this->success_ports[] = $q->GetInfo();
         } else {
             $this->failed_ports[] = $port;
         }
     } catch (MinecraftQueryException $ex) {
         $e = $ex;
         $this->failed_ports[] = $port;
     }
 }
コード例 #4
0
 private function cmdSummary(CommandSender $c)
 {
     $all = ["servers" => 1, "on-line" => 1, "Players" => count($this->owner->getServer()->getOnlinePlayers()), "MaxPlayers" => $this->owner->getServer()->getMaxPlayers()];
     foreach ($this->servers as $id => $ln) {
         $all["servers"]++;
         $dat = preg_split('/\\s+/', $ln, 3);
         $host = array_shift($dat);
         $port = array_shift($dat);
         $Query = new MinecraftQuery();
         try {
             $Query->Connect($host, $port, 1);
         } catch (MinecraftQueryException $e) {
             $this->owner->getLogger()->warning(mc::_("Query %1% failed: %2%", $host, $e->getMessage()));
             continue;
         }
         if (($info = $Query->GetInfo()) === false) {
             continue;
         }
         $all["on-line"]++;
         foreach (["Players", "MaxPlayers"] as $i) {
             if (isset($info[$i])) {
                 $all[$i] += $info[$i];
             }
         }
     }
     $c->sendMessage(TextFormat::BLUE . mc::_("Network Status"));
     $c->sendMessage(TextFormat::GREEN . mc::_("Servers:%3% %1%/%2%", $all["on-line"], $all["servers"], TextFormat::YELLOW));
     $c->sendMessage(TextFormat::GREEN . mc::_("Players:%3% %1%/%2%", $all["Players"], $all["MaxPlayers"], TextFormat::YELLOW));
     return true;
 }
コード例 #5
0
ファイル: mcservers.php プロジェクト: G4brym/ServerList.pt
 public static function checkQuery($sid, $ip, $port, $day, $month, $year, $timeout = 2)
 {
     $timer = MicroTime(true);
     $query = new MinecraftQuery();
     try {
         $query->Connect($ip, $port, $timeout);
     } catch (MinecraftQueryException $e) {
         $Exception = $e;
     }
     $timer = Number_Format(MicroTime(true) - $timer, 2, '.', '');
     return $query;
     $info = $query->GetInfo();
     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"], 'mcsc_ping' => $timer, 'mcsc_day' => $day, 'mcsc_month' => $month, 'mcsc_year' => $year));
         DB::table('mcservers')->where('mcs_id', $sid)->update(array('mcs_maxplayers' => $info["MaxPlayers"], 'mcs_players' => $info["Players"], 'mcs_status' => 1, 'mcs_map' => substr($info["Map"], 0, 50), 'mcs_plugins' => substr($info["Plugins"], 0, 255), 'mcs_motd' => mcservers::motd(substr($info["HostName"], 0, 255))));
     }
 }
コード例 #6
0
ファイル: view.php プロジェクト: normanfeltz/Minecraft-Query
<?php

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', true);
require_once 'MinecraftQuery.php';
require_once 'MinecraftQueryException.php';
use xPaw\MinecraftQuery;
use xPaw\MinecraftQueryException;
$timer = microtime(true);
$query = new MinecraftQuery();
try {
    $query->connect('localhost', 25580, 1);
} catch (MinecraftQueryException $e) {
    $exception = $e;
}
$timer = number_format(microtime(true) - $timer, 4, '.', '');
?>
<!DOCTYPE html>
<html lang="fr">
    <head>
    	<meta charset="utf-8">
    	<title>Minecraft Query PHP Class</title>

    	<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
    	<style type="text/css">
    		.jumbotron
            {
    			margin-top: 30px;
    			border-radius: 0;
    		}
コード例 #7
0
ファイル: CmdQuery.php プロジェクト: DWWf/pocketmine-plugins
 private function queryServer($id)
 {
     $lst = $this->owner->getModule("ServerList");
     $cc = [];
     if ($this->owner->getModule("query-task") && !$lst->getServerAttr($id, "no-query-task", false)) {
         // Using query daemon cached data...
         foreach (["info", "players"] as $dd) {
             $cc[$dd] = $lst->getQueryData($id, "query." . $dd);
             if ($cc[$dd] === null) {
                 unset($cc[$dd]);
             } else {
                 if (isset($cc[$dd]["age"])) {
                     unset($cc[$dd]["age"]);
                 }
             }
         }
     }
     if (count($cc) == 0) {
         $host = $lst->getServerAttr($id, "query-host");
         $port = $lst->getServerAttr($id, "port");
         $Query = new MinecraftQuery();
         try {
             $Query->Connect($host, $port, 1);
         } catch (MinecraftQueryException $e) {
             return null;
         }
         $cc["info"] = $Query->GetInfo();
         $cc["players"] = $Query->GetPlayers();
         foreach (["info", "players"] as $dd) {
             if ($cc[$dd] === false) {
                 unset($cc[$dd]);
             }
         }
     }
     return $cc;
 }
コード例 #8
0
// if the cache file exists.
if (file_exists($cacheFile)) {
    // check the file time.
    $creation_time = filemtime($cacheFile);
    if (time() - $creation_time >= 60) {
        // If file is older than 60 seconds, make a new query.
        unlink($cacheFile);
    }
}
if (!file_exists($cacheFile)) {
    /**
     * Run MinecraftQuery.php
     */
    // Start ping timer.
    $queryPing = microtime(true);
    $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);
コード例 #9
0
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title><?php 
echo $ip;
?>
 - Minecraft Server</title>

        <!-- Bootstrap core CSS -->
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link href="jumbotron-narrow.css" rel="stylesheet">
    </head>
<?php 
require __DIR__ . '/vendor/autoload.php';
use xPaw\MinecraftQuery;
use xPaw\MinecraftQueryException;
$q = new MinecraftQuery();
$e = array();
try {
    $q->Connect($ip, $port);
    $info = $q->GetInfo();
    $players = $q->GetPlayers();
} catch (MinecraftQueryException $exception) {
    $e[] = $exception->getMessage();
}
?>
    <body>
        <br>
        <div class="container">
            <div class="header clearfix">
                <h3 class="text-muted"><?php 
echo $ip;
コード例 #10
0
<?php

require __DIR__ . '/src/MinecraftQuery.php';
require __DIR__ . '/src/MinecraftQueryException.php';
use xPaw\MinecraftQuery;
use xPaw\MinecraftQueryException;
$Query = new MinecraftQuery();
function posliposly($type, $text)
{
    $date = date("H:i:s");
    $to = '*****@*****.**';
    $subject = $type . " " . $date;
    $message = $text . "<br>Automaticke oznameni zaslane prostrednictvim Unite. unite.minecore.cz";
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $headers .= 'From: info@minecore.cz' . "\r\n" . 'Reply-To: info@minecore.cz' . "\r\n" . 'Bcc: michuk@seznam.cz' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
    echo $subject . "<br>" . $text;
    // mail($to, $subject, $message, $headers);
}
try {
    $Query->Connect('192.168.1.100', 25565);
    $proxy = $Query->GetInfo();
    //echo$proxy["Players"];
    //print_r( $lobby );
    if ($proxy["Players"] == "0") {
        $proxy = "f**k";
    } else {
        $proxy = "ok";
    }
} catch (MinecraftQueryException $e) {
    $proxy = "offline";
コード例 #11
0
ファイル: index.php プロジェクト: alyons/Minecraft-Website
		<!-- CSS -->
		<link rel="stylesheet" href="css/skeleton.css">
	</head>
	<body>
		<div class="container">
			<h1>Welcome to the Server</h1>
			<p>Hey everyone, this is the Minecraft server of Alex. I am currently running a Feed the Beast - Sky Factory 2.5. If you know who I am, please feel free to message me and join the server. If you found this by chance, I must ask that you please don't connect to the server, I am currently running this for friends/as a pet project, and am not looking at moderating a public server.</p>
			<h2>What's Happening</h2>
			<p>When you spawn, press the button.</p>
			<h2>Server Status</h2>
			<?php 
require_once __DIR__ . '/php/MinecraftQuery.php';
require_once __DIR__ . '/php/MinecraftQueryException.php';
use xPaw\MinecraftQuery;
use xPaw\MinecraftQueryException;
$Query = new MinecraftQuery();
try {
    $Query->Connect('localhost', 25565);
    echo "<p>The server is currently online!</p>";
    //print_r( $Query->GetInfo( ) );
    /* Print all of the Players who are online! */
    //print_r( $Query->GetPlayers( ) );
    $players = $Query->GetPlayers();
    $playerCount = count($players);
    //print_r($players);
    $noPlayersOnline = gettype($players) == "boolean";
    echo "<h3>Who's online?</h3>";
    if ($noPlayersOnline) {
        echo "<p>No one is currently online...</p>";
    } else {
        $playerTable = "<table style=\"width:100%\"><tr><th>Avatar</th><th>Name</th></tr>";
コード例 #12
-1
ファイル: view.php プロジェクト: Harkole/MinecraftStatus
<?php

use xPaw\MinecraftQuery;
use xPaw\MinecraftQueryException;
require_once 'common_header.php';
$Query = new MinecraftQuery();
try {
    $Query->Connect(MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_TIMEOUT);
} catch (MinecraftQueryException $e) {
    $Exception = $e;
}
$Timer = Number_Format(MicroTime(true) - $Timer, 4, '.', '');
if (isset($Exception)) {
    ?>
		<div class="panel panel-primary">
			<div class="panel-heading"><?php 
    echo htmlspecialchars($Exception->getMessage());
    ?>
</div>
			<p><?php 
    echo nl2br($e->getTraceAsString(), false);
    ?>
</p>
		</div>
<?php 
} else {
    ?>
		<div class="row">
			<div class="col-sm-6">
				<table class="table table-bordered table-striped">
					<thead>