-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.php
73 lines (62 loc) · 2.08 KB
/
main.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
<?php
class MCServerStatus {
public $server,$online, $motd, $online_players, $max_players,$error = "No Error";
function __construct($url, $port = '25565') {
$this->server = array(
"url" => $url,
"port" => $port
);
if ( $sock = @stream_socket_client('tcp://'.$url.':'.$port, $errno, $errstr, 1) ) {
$this->online = true;
fwrite($sock, "\xfe");
$a = fread($sock, 2048);
$a = str_replace("\x00", '', $a);
$a = substr($a, 2);
$data = explode("\xa7", $a);
unset($a);
fclose($sock);
if (sizeof($data) == 3) {
$this->motd = $data[0];
$this->online_players = (int) $data[1];
$this->max_players = (int) $data[2];
}elseif(sizeof($data) != 1){
$this->motd = $data[0];
$x=1;
$color=array(
"§0"=>"000000", //Black
"§1"=>"0000AA", //Dark blue
"§2"=>"00AA00", //Dark green
"§3"=>"00AAAA", //Dark aqua
"§4"=>"AA0000", //Dark red
"§5"=>"AA00AA", //Dark purple
"§6"=>"FFAA00", //Gold
"§7"=>"AAAAAA", //Gray
"§8"=>"555555", //Dark gray
"§9"=>"5555FF", //Blue
"§a"=>"55FF55", //Green
"§b"=>"55FFFF", //Aqua
"§c"=>"FF5555", //Red
"§d"=>"FF55FF", //Light purple
"§e"=>"FFFF55", //Yellow
"§f"=>"FFFFFF", //White
);
while($x != sizeof($data)-2){
$colorcode="§".substr($data[$x],0,1);
$colorcode=$color["$colorcode"];
$this->motd .="<color style='color:#$colorcode'>".substr($data[$x],1)."</color>";
$x++;
}
$this->online_players = (int) $data[sizeof($data)-2];
$this->max_players = (int) $data[sizeof($data)-1];
}else{
$this->error = "Unknown error";
}
}else{
$this->online = false;
$this->error = "Server Offline";
}
}
}
$connect=new MCServerStatus("localhost","25565");
print_r($connect);
?>