Code: Select all
Server info
HostName Area 51 Minecraft [TownyMod|CRACKED]
GameType SMP
Version 1.2.4
Plugins
Array
(
[0] => WorldEdit 5.3-SNAPSHOT
[1] => iConomy 5.01
[2] => Towny 0.79.1.1
[3] => AuthMe 2.6.3b1
[4] => Lockette 1.5
[5] => PermissionsEx 1.19
[6] => Questioner 0.6
[7] => WorldGuard 5.5.2-SNAPSHOT
[8] => dynmap 0.34-957
[9] => Essentials Dev2.9.33
[10] => TownyChat 0.23
[11] => EssentialsSpawn Dev2.9.33
[12] => HawkEye 1.0.7
[13] => ChestShop 3.36
[14] => Dynmap-Towny 0.17
)
Map area51
Players 1
MaxPlayers 16
HostPort 9987
HostIp 192.168.1.12
RawPlugins CraftBukkit on Bukkit 1.2.4-R0.1-SNAPSHOT: WorldEdit 5.3-SNAPSHOT; iConomy 5.01; Towny 0.79.1.1; AuthMe 2.6.3b1; Lockette 1.5; PermissionsEx 1.19; Questioner 0.6; WorldGuard 5.5.2-SNAPSHOT; dynmap 0.34-957; Essentials Dev2.9.33; TownyChat 0.23; EssentialsSpawn Dev2.9.33; HawkEye 1.0.7; ChestShop 3.36; Dynmap-Towny 0.17
Software CraftBukkit on Bukkit 1.2.4-R0.1-SNAPSHOT
Players
Thecuban27
EX. Above
PHP Class code Below.
Code: Select all
<?php
class MinecraftQueryException extends Exception {}
class MinecraftQuery
{
/*
* Class written by xPaw
*
* Website: http://xpaw.ru
* GitHub: https://github.com/xPaw/PHP-Minecraft-Query
*/
private $Socket;
private $Challenge;
private $Players;
private $Info;
public function Connect( $Ip, $Port = 25565, $Timeout = 3 )
{
if( $this->Socket = FSockOpen( 'udp://' . $Ip, (int)$Port ) )
{
Socket_Set_TimeOut( $this->Socket, $Timeout );
if( !$this->GetChallenge( ) )
{
FClose( $this->Socket );
throw new MinecraftQueryException( "Failed to receive challenge." );
}
if( !$this->GetStatus( ) )
{
FClose( $this->Socket );
throw new MinecraftQueryException( "Failed to receive status." );
}
FClose( $this->Socket );
}
else
{
throw new MinecraftQueryException( "Can't open connection." );
}
}
public function GetInfo( )
{
return isset( $this->Info ) ? $this->Info : false;
}
public function GetPlayers( )
{
return isset( $this->Players ) ? $this->Players : false;
}
private function GetChallenge( )
{
$Data = $this->WriteData( "\x09" );
if( !$Data )
{
return false;
}
$this->Challenge = Pack( 'N', $Data );
return true;
}
private function GetStatus( )
{
$Data = $this->WriteData( "\x00", $this->Challenge . "\x01\x02\x03\x04" );
if( !$Data )
{
return false;
}
$Last = "";
$Info = Array( );
$Data = SubStr( $Data, 11 );
$Data = Explode( "\x00\x00\x01player_\x00\x00", $Data );
$Players = SubStr( $Data[ 1 ], 0, -2 );
$Data = Explode( "\x00", $Data[ 0 ] );
$Keys = Array(
'hostname' => 'HostName',
'gametype' => 'GameType',
'version' => 'Version',
'plugins' => 'Plugins',
'map' => 'Map',
'numplayers' => 'Players',
'maxplayers' => 'MaxPlayers',
'hostport' => 'HostPort',
'hostip' => 'HostIp'
);
foreach( $Data as $Key => $Value )
{
if( ~$Key & 1 )
{
if( !Array_Key_Exists( $Value, $Keys ) )
{
$Last = false;
continue;
}
$Last = $Keys[ $Value ];
$Info[ $Last ] = "";
}
else if( $Last != false )
{
$Info[ $Last ] = $Value;
}
}
$Info[ 'Players' ] = IntVal( $Info[ 'Players' ] );
$Info[ 'MaxPlayers' ] = IntVal( $Info[ 'MaxPlayers' ] );
$Info[ 'HostPort' ] = IntVal( $Info[ 'HostPort' ] );
if( $Info[ 'Plugins' ] )
{
$Data = Explode( ": ", $Info[ 'Plugins' ], 2 );
$Info[ 'RawPlugins' ] = $Info[ 'Plugins' ];
$Info[ 'Software' ] = $Data[ 0 ];
if( Count( $Data ) == 2 )
{
$Info[ 'Plugins' ] = Explode( "; ", $Data[ 1 ] );
}
}
else
{
$Info[ 'Software' ] = 'Vanilla';
}
$this->Info = $Info;
if( $Players )
{
$this->Players = Explode( "\x00", $Players );
}
return true;
}
private function WriteData( $Command, $Append = "" )
{
$Command = "\xFE\xFD" . $Command . "\x01\x02\x03\x04" . $Append;
$Length = StrLen( $Command );
if( $Length !== FWrite( $this->Socket, $Command, $Length ) )
{
return false;
}
$Data = FRead( $this->Socket, 1440 );
if( StrLen( $Data ) < 5 || $Data[ 0 ] != $Command[ 2 ] )
{
return false;
}
return SubStr( $Data, 5 );
}
}