Skip to content

Commit 10ecdb8

Browse files
author
REH.TW《旋風之音》
committed
Initial commit
1 parent 2c2978e commit 10ecdb8

File tree

8 files changed

+722
-1
lines changed

8 files changed

+722
-1
lines changed

ApiPing.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/*
3+
PHP Minecraft Query API
4+
https://github.com/MCServerStatus/PHP-Minecraft-Query-API
5+
*/
6+
use xPaw\MinecraftPing;
7+
use xPaw\MinecraftPingException;
8+
9+
require __DIR__ . '/src/MinecraftPing.php';
10+
require __DIR__ . '/src/MinecraftPingException.php';
11+
12+
$Timer = MicroTime( true );
13+
14+
$InfoPing = false;
15+
$QueryPing = null;
16+
17+
try
18+
{
19+
$QueryPing = new MinecraftPing( MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_TIMEOUT );
20+
21+
$InfoPing = $QueryPing->Query( );
22+
23+
if( $InfoPing === false )
24+
{
25+
$QueryPing->Close( );
26+
$QueryPing->Connect( );
27+
28+
$InfoPing = $QueryPing->QueryOldPre17( );
29+
}
30+
}
31+
catch( MinecraftPingException $e )
32+
{
33+
$Exception = $e;
34+
}
35+
36+
if( $QueryPing !== null )
37+
{
38+
$QueryPing->Close( );
39+
}
40+
41+
$Timer = Number_Format( MicroTime( true ) - $Timer, 4, '.', '' );
42+
?>

ApiQuery.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/*
3+
PHP Minecraft Query API
4+
https://github.com/MCServerStatus/PHP-Minecraft-Query-API
5+
*/
6+
use xPaw\MinecraftQuery;
7+
use xPaw\MinecraftQueryException;
8+
9+
define( 'MQ_SERVER_ADDR', $host );
10+
define( 'MQ_SERVER_PORT', $port );
11+
define( 'MQ_TIMEOUT', 1 );
12+
13+
require __DIR__ . '/src/MinecraftQuery.php';
14+
require __DIR__ . '/src/MinecraftQueryException.php';
15+
16+
$Timer = MicroTime( true );
17+
18+
$Query = new MinecraftQuery( );
19+
20+
try
21+
{
22+
$Query->Connect( MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_TIMEOUT );
23+
}
24+
catch( MinecraftQueryException $e )
25+
{
26+
$Exception = $e;
27+
}
28+
29+
$Timer = Number_Format( MicroTime( true ) - $Timer, 4, '.', '' );
30+
?>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# PHP-Minecraft-Query-API
1+
# PHP Minecraft Query API
22
Query Minecraft Server Status API

json.php

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?php
2+
/*
3+
PHP Minecraft Query API
4+
https://github.com/MCServerStatus/PHP-Minecraft-Query-API
5+
*/
6+
header('Content-type:text/json');
7+
8+
$host = $_GET['host'];
9+
$port = $_GET['port'];
10+
11+
require 'ApiQuery.php';
12+
require 'ApiPing.php';
13+
14+
if (($Info = $Query->GetInfo()) !== false){
15+
$CleanHostName = str_replace("§k","",$Info['HostName']);
16+
$CleanHostName = str_replace("§l","",$CleanHostName);
17+
$CleanHostName = str_replace("§m","",$CleanHostName);
18+
$CleanHostName = str_replace("§n","",$CleanHostName);
19+
$CleanHostName = str_replace("§o","",$CleanHostName);
20+
$CleanHostName = str_replace("§r","",$CleanHostName);
21+
$CleanHostName = str_replace("§1","",$CleanHostName);
22+
$CleanHostName = str_replace("§2","",$CleanHostName);
23+
$CleanHostName = str_replace("§3","",$CleanHostName);
24+
$CleanHostName = str_replace("§4","",$CleanHostName);
25+
$CleanHostName = str_replace("§5","",$CleanHostName);
26+
$CleanHostName = str_replace("§6","",$CleanHostName);
27+
$CleanHostName = str_replace("§7","",$CleanHostName);
28+
$CleanHostName = str_replace("§8","",$CleanHostName);
29+
$CleanHostName = str_replace("§9","",$CleanHostName);
30+
$CleanHostName = str_replace("§a","",$CleanHostName);
31+
$CleanHostName = str_replace("§b","",$CleanHostName);
32+
$CleanHostName = str_replace("§c","",$CleanHostName);
33+
$CleanHostName = str_replace("§d","",$CleanHostName);
34+
$CleanHostName = str_replace("§e","",$CleanHostName);
35+
$CleanHostName = str_replace("§f","",$CleanHostName);
36+
if ($Info['GameName'] == 'MINECRAFT') {
37+
$json = array(
38+
'status' => 'Online',
39+
'platform' => 'Minecraft',
40+
'gametype' => $Info['GameType'],
41+
'motd' => array(
42+
'motd' => $Info['HostName'],
43+
'clean_motd' => $CleanHostName
44+
),
45+
'host' => array(
46+
'host' => $host,
47+
'hostip' => $Info['HostIp'],
48+
'port' => $Info['HostPort']
49+
),
50+
'players' => array(
51+
'max' => $Info['MaxPlayers'],
52+
'online' => $Info['Players']
53+
),
54+
'version' => array(
55+
'version' => $Info['Version'],
56+
'software' => $Info['Software']
57+
),
58+
'queryinfo' => array(
59+
'agreement' => 'Query',
60+
'processed' => $Timer
61+
)
62+
);
63+
} else if ($Info['GameName'] == 'MINECRAFTPE') {
64+
$json = array(
65+
'status' => 'Online',
66+
'platform' => 'Minecraft: Pocket Edition',
67+
'gametype' => $Info['GameType'],
68+
'motd' => array(
69+
'motd' => $Info['HostName'],
70+
'clean_motd' => $CleanHostName
71+
),
72+
'host' => array(
73+
'host' => $host,
74+
'hostip' => $Info['HostIp'],
75+
'port' => $Info['HostPort']
76+
),
77+
'players' => array(
78+
'max' => $Info['MaxPlayers'],
79+
'online' => $Info['Players']
80+
),
81+
'version' => array(
82+
'version' => $Info['Version'],
83+
'software' => $Info['Software']
84+
),
85+
'queryinfo' => array(
86+
'agreement' => 'Query',
87+
'processed' => $Timer
88+
)
89+
);
90+
} else {
91+
$json = array(
92+
'status' => 'Online',
93+
'platform' => $Info['GameName'],
94+
'gametype' => $Info['GameType'],
95+
'motd' => array(
96+
'motd' => $Info['HostName'],
97+
'clean_motd' => $CleanHostName
98+
),
99+
'host' => array(
100+
'host' => $host,
101+
'hostip' => $Info['HostIp'],
102+
'port' => $Info['HostPort']
103+
),
104+
'players' => array(
105+
'max' => $Info['MaxPlayers'],
106+
'online' => $Info['Players']
107+
),
108+
'version' => array(
109+
'version' => $Info['Version'],
110+
'software' => $Info['Software']
111+
),
112+
'queryinfo' => array(
113+
'agreement' => 'Query',
114+
'processed' => $Timer
115+
)
116+
);
117+
}
118+
} else if ($InfoPing !== false){
119+
$version = explode(" ",$InfoPing['version']['name'],2);
120+
$CleanHostName = str_replace("§k","",$InfoPing['description']);
121+
$CleanHostName = str_replace("§l","",$CleanHostName);
122+
$CleanHostName = str_replace("§m","",$CleanHostName);
123+
$CleanHostName = str_replace("§n","",$CleanHostName);
124+
$CleanHostName = str_replace("§o","",$CleanHostName);
125+
$CleanHostName = str_replace("§r","",$CleanHostName);
126+
$CleanHostName = str_replace("§1","",$CleanHostName);
127+
$CleanHostName = str_replace("§2","",$CleanHostName);
128+
$CleanHostName = str_replace("§3","",$CleanHostName);
129+
$CleanHostName = str_replace("§4","",$CleanHostName);
130+
$CleanHostName = str_replace("§5","",$CleanHostName);
131+
$CleanHostName = str_replace("§6","",$CleanHostName);
132+
$CleanHostName = str_replace("§7","",$CleanHostName);
133+
$CleanHostName = str_replace("§8","",$CleanHostName);
134+
$CleanHostName = str_replace("§9","",$CleanHostName);
135+
$CleanHostName = str_replace("§a","",$CleanHostName);
136+
$CleanHostName = str_replace("§b","",$CleanHostName);
137+
$CleanHostName = str_replace("§c","",$CleanHostName);
138+
$CleanHostName = str_replace("§d","",$CleanHostName);
139+
$CleanHostName = str_replace("§e","",$CleanHostName);
140+
$CleanHostName = str_replace("§f","",$CleanHostName);
141+
$json = array(
142+
'status' => 'Online',
143+
'motd' => array(
144+
'motd' => $InfoPing['description'],
145+
'clean_motd' => $CleanHostName
146+
),
147+
'host' => array(
148+
'host' => $host,
149+
'port' => $port
150+
),
151+
'players' => array(
152+
'max' => $InfoPing['players']['max'],
153+
'online' => $InfoPing['players']['online']
154+
),
155+
'version' => array(
156+
'version' => $version[1],
157+
'protocol' => $InfoPing['version']['protocol']
158+
),
159+
'queryinfo' => array(
160+
'agreement' => 'Ping',
161+
'processed' => $Timer
162+
)
163+
);
164+
} else {
165+
$json = array(
166+
'status' => 'Offline',
167+
'host' => $host,
168+
'port' => $port
169+
);
170+
}
171+
echo json_encode($json, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
172+
?>

0 commit comments

Comments
 (0)