GetPlayers() 공개 메소드

public GetPlayers ( )
예제 #1
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;
 }
예제 #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
<?php 
    }
    ?>
					</tbody>
				</table>
			</div>
			<div class="col-sm-6">
				<table class="table table-bordered table-striped">
					<thead>
						<tr>
							<th>Players</th>
						</tr>
					</thead>
					<tbody>
<?php 
    if (($Players = $Query->GetPlayers()) !== false) {
        foreach ($Players as $Player) {
            ?>
						<tr>
							<td><?php 
            echo htmlspecialchars($Player);
            ?>
</td>
						</tr>
<?php 
        }
    } else {
        ?>
						<tr>
							<td>No players in da house</td>
						</tr>
예제 #4
0
 private function cmdPlayers(CommandSender $c, $pageNumber)
 {
     $all = [];
     foreach ($this->owner->getServer()->getOnlinePlayers() as $p) {
         $all[$p->getName()] = mc::_("*current-server*");
     }
     foreach ($this->servers as $id => $ln) {
         $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 (($players = $Query->GetPlayers()) === false) {
             continue;
         }
         if (count($players) == 0) {
             continue;
         }
         foreach ($players as $p) {
             if ($c->hasPermission("gb.cmd.query.players.showip")) {
                 $all[$p] = "{$id} ({$host}:{$port})";
             } else {
                 $all[$p] = "{$id}";
             }
         }
     }
     if (count($all) == 0) {
         $c->sendMessage(TextFormat::YELLOW . "Nobody is on-line at the moment");
     }
     $txt = [mc::n(mc::_("One player found"), mc::_("%1% players found", count($all)), count($all))];
     ksort($all, SORT_NATURAL);
     foreach ($all as $i => $j) {
         $txt[] = $i . " @ " . $j;
     }
     return $this->paginateText($c, $pageNumber, $txt);
 }
예제 #5
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;
 }
예제 #6
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.
예제 #7
0
 - 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">
<?php 
예제 #8
0
			<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>";
        for ($i = 0; $i < $playerCount; $i++) {
            $playerTable .= "<tr>";
            $playerTable .= "<td><img src=\"https://mcapi.ca/skin/3d/" . $players[$i] . "/55\"></td>";
            $playerTable .= "<td>" . $players[$i] . "</td>";
            $playerTable .= "</tr>";
        }
        $playerTable .= "</table>";