01.
public
function
Query()
02.
{
03.
04.
$Data
=
$this
->WriteData( self :: HANDSHAKE );
05.
if
(
$Data
=== false )
06.
{
07.
$this
->error=
"Failed to receive challenge"
;
08.
}
09.
$challenge
=pack(
'N'
,
$Data
);
10.
11.
12.
$Data
=
$this
->WriteData( self :: STATISTIC,
$challenge
. pack(
'c*'
, 0x00, 0x00, 0x00, 0x00 ) );
13.
14.
if
( !
$Data
)
15.
{
16.
$this
->error=
"Failed to receive status"
;
17.
}
18.
19.
$Last
=
''
;
20.
$Info
= Array( );
21.
22.
$Data
=
substr
(
$Data
, 11 );
23.
$Data
=
explode
(
"\x00\x00\x01player_\x00\x00"
,
$Data
);
24.
25.
if
(
count
(
$Data
) !== 2 )
26.
{
27.
$this
->error=
"Failed to parse server's response"
;
28.
}
29.
30.
$Players
= @
substr
(
$Data
[ 1 ], 0, -2 );
31.
$Data
=
explode
(
"\x00"
,
$Data
[ 0 ] );
32.
33.
34.
35.
$Keys
= Array(
36.
'hostname'
=>
'HostName'
,
37.
'gametype'
=>
'GameType'
,
38.
'version'
=>
'Version'
,
39.
'plugins'
=>
'Plugins'
,
40.
'map'
=>
'Map'
,
41.
'numplayers'
=>
'Players'
,
42.
'maxplayers'
=>
'MaxPlayers'
,
43.
'hostport'
=>
'HostPort'
,
44.
'hostip'
=>
'HostIp'
,
45.
'game_id'
=>
'GameName'
46.
);
47.
48.
foreach
(
$Data
as
$Key
=>
$Value
)
49.
{
50.
if
( ~
$Key
& 1 )
51.
{
52.
if
( !
array_key_exists
(
$Value
,
$Keys
) )
53.
{
54.
$Last
= false;
55.
continue
;
56.
}
57.
58.
$Last
=
$Keys
[
$Value
];
59.
$Info
[
$Last
] =
''
;
60.
}
61.
else
if
(
$Last
!= false )
62.
{
63.
$Info
[
$Last
] =
$Value
;
64.
}
65.
}
66.
67.
68.
$Info
[
'Players'
] =
$this
->error==null?@
intval
(
$Info
[
'Players'
] ):null;
69.
$Info
[
'MaxPlayers'
] =
$this
->error==null?@
intval
(
$Info
[
'MaxPlayers'
] ):null;
70.
$Info
[
'HostPort'
] =
$this
->error==null?@
intval
(
$Info
[
'HostPort'
] ):null;
71.
72.
73.
if
( @
$Info
[
'Plugins'
] )
74.
{
75.
$Data
=
explode
(
": "
,
$Info
[
'Plugins'
], 2 );
76.
77.
$Info
[
'RawPlugins'
] =
$Info
[
'Plugins'
];
78.
$Info
[
'Software'
] =
$Data
[ 0 ];
79.
80.
if
(
count
(
$Data
) == 2 )
81.
{
82.
$Info
[
'Plugins'
] =
explode
(
"; "
,
$Data
[ 1 ] );
83.
}
84.
}
85.
else
86.
{
87.
$Info
[
'Software'
] =
$this
->error==null?
'Vanilla'
:null;
88.
}
89.
90.
$this
->Info =
$Info
;
91.
92.
if
(
$Players
)
93.
{
94.
$this
->Players =
explode
(
"\x00"
,
$Players
);
95.
}
96.
}