mirror of
https://e.coding.net/circlecloud/McAccount.git
synced 2024-11-22 01:48:55 +00:00
67 lines
2.0 KiB
PHP
67 lines
2.0 KiB
PHP
|
<?php
|
||
|
class server_model extends AmysqlModel {
|
||
|
function QueryMinecraft($IP, $Port = 25565, $Timeout = 2) {
|
||
|
$Socket = Socket_Create ( AF_INET, SOCK_STREAM, SOL_TCP );
|
||
|
|
||
|
Socket_Set_Option ( $Socket, SOL_SOCKET, SO_SNDTIMEO, array (
|
||
|
'sec' => ( int ) $Timeout,
|
||
|
'usec' => 0
|
||
|
) );
|
||
|
Socket_Set_Option ( $Socket, SOL_SOCKET, SO_RCVTIMEO, array (
|
||
|
'sec' => ( int ) $Timeout,
|
||
|
'usec' => 0
|
||
|
) );
|
||
|
|
||
|
if ($Socket === FALSE || @Socket_Connect ( $Socket, $IP, ( int ) $Port ) === FALSE) {
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
Socket_Send ( $Socket, "\xFE\x01", 2, 0 );
|
||
|
// Socket_Send ( $Socket, "\x0F\0x00\x04\x09\x31\x32\x37\x2E\x30\x2E\x30\x2E\x31\x63\xDD\x01", 16, 0);
|
||
|
// Socket_Send ( $Socket, "\x01\x00", 2, 0 );
|
||
|
$Len = Socket_Recv ( $Socket, $Data, 1024, 0 );
|
||
|
Socket_Close ( $Socket );
|
||
|
|
||
|
// return FALSE;
|
||
|
// if ($Len < 4 || $Data [0] !== "\xFF") {
|
||
|
// return FALSE;
|
||
|
// }
|
||
|
|
||
|
// $Data = SubStr ( $Data, 3 );
|
||
|
echo($Len);
|
||
|
echo("</p>");
|
||
|
|
||
|
// $Data = iconv( 'UTF-16BE', 'UTF-8', $Data );
|
||
|
print_r($Data);
|
||
|
echo("</p>");
|
||
|
$zData = Explode ( "\x00", $Data );
|
||
|
echo(count($zData));
|
||
|
echo("</p>");
|
||
|
print_r($zData);
|
||
|
echo("</p>");
|
||
|
$aData = Explode ( "\xA7", $Data );
|
||
|
echo(count($aData));
|
||
|
echo("</p>");
|
||
|
print_r($aData);
|
||
|
// if ($Data [1] === "\xA7" && $Data [2] === "\x31") {
|
||
|
// $Data = Explode ( "\x00", $Data );
|
||
|
// var_dump($Data [3]);
|
||
|
// return Array (
|
||
|
// 'HostName' => $Data [3],
|
||
|
// 'Players' => IntVal ( $Data [4] ),
|
||
|
// 'MaxPlayers' => IntVal ( $Data [5] ),
|
||
|
// 'Protocol' => IntVal ( $Data [1] ),
|
||
|
// 'Version' => $Data [2]
|
||
|
// );
|
||
|
// }
|
||
|
|
||
|
// $Data = Explode ( "\xA7", $Data );
|
||
|
// return Array (
|
||
|
// 'HostName' => SubStr ( $Data [0], 0, - 1 ),
|
||
|
// 'Players' => isset ( $Data [1] ) ? IntVal ( $Data [1] ) : 0,
|
||
|
// 'MaxPlayers' => isset ( $Data [2] ) ? IntVal ( $Data [2] ) : 0,
|
||
|
// 'Protocol' => 0,
|
||
|
// 'Version' => '1.3'
|
||
|
// );
|
||
|
}
|
||
|
}
|