This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.php
104 lines (86 loc) · 2.39 KB
/
index.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace Kers;
use Kers\Utils;
use xPaw\MinecraftQuery;
use xPaw\MinecraftQueryException;
require __DIR__ . '/utils.class.php';
require __DIR__ . '/src/MinecraftQuery.php';
require __DIR__ . '/src/MinecraftQueryException.php';
$Utils = new Utils();
header("Access-Control-Allow-Origin: *");
header('Content-type: application/json');
error_reporting(0);
$array = [
'code' => 201,
'status' => 'offine',
'ip' => 'N/A',
'real' => 'N/A',
'location' => 'N/A',
'port' => 'N/A',
'motd' => 'N/A',
'agreement' => 'N/A',
'version' => 'N/A',
'online' => 0,
'max' => 0,
'gamemode' => 'N/A',
'delay' => 'N/A'
];
if (!$Utils->hasEmpty($_REQUEST['ip'], $_REQUEST['port'])) {
$ip = $_REQUEST['ip'];
$port = $_REQUEST['port'];
if (!isset($_REQUEST['java'])) {
// Edit this ->
define('MQ_SERVER_ADDR', $_REQUEST['ip']);
define('MQ_SERVER_PORT', $_REQUEST['port']);
define('MQ_TIMEOUT', 1);
// Edit this <-
// Display everything in browser, because some people can't look in logs for errors
Error_Reporting(E_ALL | E_STRICT);
Ini_Set('display_errors', true);
$Timer = MicroTime(true);
$Query = new MinecraftQuery();
try {
$Query->Connect(MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_TIMEOUT);
} catch (MinecraftQueryException $e) {
$array['code'] = 201;
$Exception = $e;
}
$Timer = Number_Format(MicroTime(true) - $Timer, 4, '.', '');
} else {
$t1 = microtime(true);
if ($handle = stream_socket_client("udp://{$ip}:{$port}", $errno, $errstr, 2)) {
stream_set_timeout($handle, 2);
fwrite($handle, hex2bin('0100000000240D12D300FFFF00FEFEFEFEFDFDFDFD12345678') . "\n");
$result = strstr(fread($handle, 1024), "MCPE");
fclose($handle);
$data = explode(";", $result);
$data['1'] = preg_replace("/§[a-z A-Z 0-9]{1}/s", '', $data['1']);
if (!$Utils->hasEmpty($data, $data['1'])) {
$t2 = microtime(true);
$real = gethostbyname($ip);
$array = [
'code' => 200,
'status' => 'online',
'ip' => $ip,
'real' => $real,
'location' => $Utils->getLocation($real),
'port' => $port,
'motd' => $data['1'],
'agreement' => $data['2'],
'version' => $data['3'],
'online' => $data['4'],
'max' => $data['5'],
'gamemode' => $data['8'],
'delay' => round($t2 - $t1, 3) * 1000
];
} else {
$array['code'] = 203;
}
} else {
$array['code'] = 202;
}
}
} else {
$array['code'] = 201;
}
exit(json_encode($array));