GetInfo() public method

public GetInfo ( )
Esempio n. 1
0
 /**
  * @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;
     }
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
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()]);
 }
Esempio n. 4
0
} else {
    ?>
		<div class="row">
			<div class="col-sm-6">
				<table class="table table-bordered table-striped">
					<thead>
						<tr>
							<th colspan="2">Server Info <em>(queried in <?php 
    echo $Timer;
    ?>
s)</em></th>
						</tr>
					</thead>
					<tbody>
<?php 
    if (($Info = $Query->GetInfo()) !== false) {
        foreach ($Info as $InfoKey => $InfoValue) {
            ?>
						<tr>
							<td><?php 
            echo htmlspecialchars($InfoKey);
            ?>
</td>
							<td><?php 
            if (Is_Array($InfoValue)) {
                echo "<pre>";
                print_r($InfoValue);
                echo "</pre>";
            } else {
                echo htmlspecialchars($InfoValue);
            }
Esempio n. 5
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;
 }
Esempio n. 6
0
 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))));
     }
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
        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));
    fclose($fp);
}
$data = json_decode(file_get_contents($cacheFile), true);
if ($data['mcQuery']['getInfo'] == false and $data['mcPing']['query'] == null) {
    // No data
    $isOffline = true;
    $limitedSupport = false;
} elseif ($data['mcQuery']['getInfo'] == false and $data['mcPing']['query'] != null and $data['mcPing']['query']['players']['sample'] != null and $data['mcPing']['query']['players']['online'] != 0) {
    // Cannot mcQuery, can mcPing. mcPing has a player list and there are players online.
    $isOffline = false;
    $limitedSupport = false;
} elseif ($data['mcQuery']['getInfo'] == false and $data['mcPing']['query'] != null and $data['mcPing']['query']['players']['sample'] == null and $data['mcPing']['query']['players']['online'] == 0) {
    // Cannot mcQuery, can mcPing. mcPing does not have a player list and there are no online players.
?>
 - 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;
?>
 - Minecraft Server</h3>
            </div>
            <div class="jumbotron">
Esempio n. 10
0
$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";
    //echo $e->getMessage( );
}
try {
    $Query->Connect('192.168.1.100', 25567);
    $survival = $Query->GetInfo();
    //print_r( $survival );