-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathServer.php
53 lines (44 loc) · 1.78 KB
/
Server.php
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace MinecraftServerChecker;
class Server
{
public static function getServerData(String $server_ip)
{
$api = \XF::options()->msc_api;
$client = \XF::app()->http()->client(['headers' => ['Accept' => 'application/json']]);
$status = 0;
$online = 0;
$max = 1;
if ($api === "mcsrvstatus") {
$response = $client->get('https://api.mcsrvstat.us/2/' . $server_ip);
$rawdata = \GuzzleHttp\json_decode($response->getBody(), true);
$status = ($rawdata['online'] === true) ? 1 : 0;
if ($rawdata['online']) {
$online = $rawdata['players']['online'];
$max = $rawdata['players']['max'];
}
} else if ($api === "mcapius") {
$response = $client->get('https://mcapi.us/server/status?ip=' . $server_ip . '&port=25565');
$rawdata = \GuzzleHttp\json_decode($response->getBody(), true);
$status = ($rawdata['online'] === true) ? 1 : 0;
if ($rawdata['online']) {
$online = $rawdata['players']['now'];
$max = $rawdata['players']['max'];
}
} else {
$response = $client->get('https://api.keyubu.net/minecraft/json.php?host=' . $server_ip . '&port=25565');
$rawdata = \GuzzleHttp\json_decode($response->getBody(), true);
$status = ($rawdata['online'] === true) ? 1 : 0;
if ($rawdata['online']) {
$online = $rawdata['players']['online'];
$max = $rawdata['players']['max'];
}
}
$data = [
'status' => $status,
'online' => $online,
'max' => $max
];
return $data;
}
}