-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.php
More file actions
36 lines (30 loc) · 1.4 KB
/
Copy pathquery.php
File metadata and controls
36 lines (30 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php declare(strict_types=1);
use DevLancer\MinecraftStatus\Exception\ConnectionException;
use DevLancer\MinecraftStatus\Exception\InvalidResponseException;
use DevLancer\MinecraftStatus\Exception\ProtocolException;
use DevLancer\MinecraftStatus\Exception\ReceiveStatusException;
use DevLancer\MinecraftStatus\Exception\TimeoutException;
use DevLancer\MinecraftStatus\MinecraftJavaQuery;
require_once __DIR__ . '/../vendor/autoload.php';
$query = new MinecraftJavaQuery('mc.server-query.loc');
try {
$result = $query->fetch()->getResult();
echo sprintf(
"Server %s:%d answered Query\n",
$query->getHost(),
$query->getPort()
);
echo sprintf("MOTD: %s\n", $result->motd());
echo sprintf("Players: %d/%d\n", $result->onlinePlayers(), $result->maxPlayers());
echo sprintf("Host IP: %s\n", $result->hostIp);
print_r($result->players);
print_r($result->raw());
} catch (ConnectionException $exception) {
echo "Connection failed: " . $exception->getMessage() . "\n";
} catch (TimeoutException $exception) {
echo "Server read timed out: " . $exception->getMessage() . "\n";
} catch (ProtocolException | InvalidResponseException $exception) {
echo "Invalid Query response: " . $exception->getMessage() . "\n";
} catch (ReceiveStatusException $exception) {
echo "Query could not be received. Check enable-query and query.port: " . $exception->getMessage() . "\n";
}