Suggestion - Minecraft Status Page

Forum rules
- Ask questions about or share code from languages other than Source Engine scripting.
- Start new topic titles with the code language in brackets (i.e. [C#], [C++], [PHP], etc.)
Locked
User avatar
Blake
500+ Posts
500+ Posts
Posts: 588
Joined: Mon Jul 05, 2010 8:51 pm
Location: Ontario, Canada

Suggestion - Minecraft Status Page

Post by Blake » Wed Mar 28, 2012 10:09 pm

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
Make a Status Page for the Minecraft Server
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 );
	}
}
Unkown wrote: Life’s too short to worry about the little things.
Albert Einstein wrote: You do not really understand something unless you can explain it to your grandmother.

[GR]doodleninja
1000+ Posts
1000+ Posts
Posts: 1086
Joined: Mon Feb 27, 2012 11:08 am

Re: Suggestion - Minecraft Status Page

Post by [GR]doodleninja » Fri Mar 30, 2012 12:25 pm

looks adorable

User avatar
Bob1337
Server Admin
Posts: 542
Joined: Fri Apr 09, 2010 10:02 pm

Re: Suggestion - Minecraft Status Page

Post by Bob1337 » Fri Mar 30, 2012 2:59 pm

I don't really see the point.
Please dont ask me how to script.
Instead, click this.
Btw; I'm an asshole to idiots.
Bob1337 wrote:Explosive buddha killers. That shit is gay.

User avatar
ant_8490
Site Admin
Posts: 4384
Joined: Fri Apr 09, 2010 3:20 pm
Location: United States
Contact:

Re: Suggestion - Minecraft Status Page

Post by ant_8490 » Fri Mar 30, 2012 5:29 pm

i guess it could be part of the www.area51cheatserver.com/status page
[GR]Ant_8490{A}
Area 51 Servers - Owner
Image
Image
Image
Image

MSI GE76 Raider
i9-11980HK 2.6GHz 8-Core Processor
32GB 3200Mhz DDR4 RAM
NVIDIA GeForce RTX 3080 Laptop GPU 16GB
2TB Samsung 980 Pro SSD
Windows 10

User avatar
Blake
500+ Posts
500+ Posts
Posts: 588
Joined: Mon Jul 05, 2010 8:51 pm
Location: Ontario, Canada

Re: Suggestion - Minecraft Status Page

Post by Blake » Fri Mar 30, 2012 8:27 pm

ant_8490 wrote:i guess it could be part of the http://www.area51cheatserver.com/status page
Well I guess, It's useful if the server has the Query port enabled in the server.properties otherwise it just throws an error.
Unkown wrote: Life’s too short to worry about the little things.
Albert Einstein wrote: You do not really understand something unless you can explain it to your grandmother.

Locked