<?php
return [
'account/login' => [
'controller' => 'account',
'action' => 'login',
]
];
public function Query( )
{
$TimeStart = microtime(true); // for read timeout purposes
// See http://wiki.vg/Protocol (Status Ping)
$Data = "\x00"; // packet ID = 0 (varint)
$Data .= "\x04"; // Protocol version (varint)
$Data .= Pack( 'c', StrLen( $this->ServerAddress ) ) . $this->ServerAddress; // Server (varint len + UTF-8 addr)
$Data .= Pack( 'n', $this->ServerPort ); // Server port (unsigned short)
$Data .= "\x01"; // Next state: status (varint)
$Data = Pack( 'c', StrLen( $Data ) ) . $Data; // prepend length of packet ID + data
fwrite( $this->Socket, $Data ); // handshake
fwrite( $this->Socket, "\x01\x00" ); // status ping
$Length = $this->ReadVarInt( ); // full packet length
if( $Length < 10 )
{
return FALSE;
}
fgetc( $this->Socket ); // packet type, in server ping it's 0
$Length = $this->ReadVarInt( ); // string length
$Data = "";
do
{
if (microtime(true) - $TimeStart > $this->Timeout)
{
throw new MinecraftPingException( 'Server read timed out' );
}
$Remainder = $Length - StrLen( $Data );
$block = fread( $this->Socket, $Remainder ); // and finally the json string
// abort if there is no progress
if (!$block)
{
throw new MinecraftPingException( 'Server returned too few data' );
}
$Data .= $block;
} while( StrLen($Data) < $Length );
if( $Data === FALSE )
{
throw new MinecraftPingException( 'Server didn\'t return any data' );
}
$Data = JSON_Decode( $Data, true );
if( JSON_Last_Error( ) !== JSON_ERROR_NONE )
{
if( Function_Exists( 'json_last_error_msg' ) )
{
throw new MinecraftPingException( JSON_Last_Error_Msg( ) );
}
else
{
throw new MinecraftPingException( 'JSON parsing failed' );
}
return FALSE;
}
return $Data;
}