parent
7a1d29b47f
commit
45f5f422b4
@ -0,0 +1 @@
|
|||||||
|
* text=auto
|
@ -1,30 +1,30 @@
|
|||||||
<?php
|
<?php
|
||||||
require __DIR__ . '/SourceQuery/SourceQuery.class.php';
|
require __DIR__ . '/SourceQuery/SourceQuery.class.php';
|
||||||
|
|
||||||
// For the sake of this example
|
// For the sake of this example
|
||||||
Header( 'Content-Type: text/plain' );
|
Header( 'Content-Type: text/plain' );
|
||||||
Header( 'X-Content-Type-Options: nosniff' );
|
Header( 'X-Content-Type-Options: nosniff' );
|
||||||
|
|
||||||
// Edit this ->
|
// Edit this ->
|
||||||
define( 'SQ_SERVER_ADDR', 'localhost' );
|
define( 'SQ_SERVER_ADDR', 'localhost' );
|
||||||
define( 'SQ_SERVER_PORT', 27015 );
|
define( 'SQ_SERVER_PORT', 27015 );
|
||||||
define( 'SQ_TIMEOUT', 1 );
|
define( 'SQ_TIMEOUT', 1 );
|
||||||
define( 'SQ_ENGINE', SourceQuery :: SOURCE );
|
define( 'SQ_ENGINE', SourceQuery :: SOURCE );
|
||||||
// Edit this <-
|
// Edit this <-
|
||||||
|
|
||||||
$Query = new SourceQuery( );
|
$Query = new SourceQuery( );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE );
|
$Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE );
|
||||||
|
|
||||||
print_r( $Query->GetInfo( ) );
|
print_r( $Query->GetInfo( ) );
|
||||||
print_r( $Query->GetPlayers( ) );
|
print_r( $Query->GetPlayers( ) );
|
||||||
print_r( $Query->GetRules( ) );
|
print_r( $Query->GetRules( ) );
|
||||||
}
|
}
|
||||||
catch( Exception $e )
|
catch( Exception $e )
|
||||||
{
|
{
|
||||||
echo $e->getMessage( );
|
echo $e->getMessage( );
|
||||||
}
|
}
|
||||||
|
|
||||||
$Query->Disconnect( );
|
$Query->Disconnect( );
|
||||||
|
@ -1,176 +1,176 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Class written by xPaw
|
* Class written by xPaw
|
||||||
*
|
*
|
||||||
* Website: http://xpaw.me
|
* Website: https://xpaw.me
|
||||||
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
|
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class SourceQueryBuffer
|
class SourceQueryBuffer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Buffer
|
* Buffer
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $Buffer;
|
private $Buffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buffer length
|
* Buffer length
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $Length;
|
private $Length;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current position in buffer
|
* Current position in buffer
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $Position;
|
private $Position;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets buffer
|
* Sets buffer
|
||||||
*
|
*
|
||||||
* @param string $Buffer Buffer
|
* @param string $Buffer Buffer
|
||||||
*/
|
*/
|
||||||
public function Set( $Buffer )
|
public function Set( $Buffer )
|
||||||
{
|
{
|
||||||
$this->Buffer = $Buffer;
|
$this->Buffer = $Buffer;
|
||||||
$this->Length = StrLen( $Buffer );
|
$this->Length = StrLen( $Buffer );
|
||||||
$this->Position = 0;
|
$this->Position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets buffer
|
* Resets buffer
|
||||||
*/
|
*/
|
||||||
public function Reset( )
|
public function Reset( )
|
||||||
{
|
{
|
||||||
$this->Buffer = "";
|
$this->Buffer = "";
|
||||||
$this->Length = 0;
|
$this->Length = 0;
|
||||||
$this->Position = 0;
|
$this->Position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get remaining bytes
|
* Get remaining bytes
|
||||||
*
|
*
|
||||||
* @return int Remaining bytes in buffer
|
* @return int Remaining bytes in buffer
|
||||||
*/
|
*/
|
||||||
public function Remaining( )
|
public function Remaining( )
|
||||||
{
|
{
|
||||||
return $this->Length - $this->Position;
|
return $this->Length - $this->Position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets data from buffer
|
* Gets data from buffer
|
||||||
*
|
*
|
||||||
* @param int $Length Bytes to read
|
* @param int $Length Bytes to read
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function Get( $Length = -1 )
|
public function Get( $Length = -1 )
|
||||||
{
|
{
|
||||||
if( $Length === 0 )
|
if( $Length === 0 )
|
||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$Remaining = $this->Remaining( );
|
$Remaining = $this->Remaining( );
|
||||||
|
|
||||||
if( $Length === -1 )
|
if( $Length === -1 )
|
||||||
{
|
{
|
||||||
$Length = $Remaining;
|
$Length = $Remaining;
|
||||||
}
|
}
|
||||||
else if( $Length > $Remaining )
|
else if( $Length > $Remaining )
|
||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$Data = SubStr( $this->Buffer, $this->Position, $Length );
|
$Data = SubStr( $this->Buffer, $this->Position, $Length );
|
||||||
|
|
||||||
$this->Position += $Length;
|
$this->Position += $Length;
|
||||||
|
|
||||||
return $Data;
|
return $Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get byte from buffer
|
* Get byte from buffer
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function GetByte( )
|
public function GetByte( )
|
||||||
{
|
{
|
||||||
return Ord( $this->Get( 1 ) );
|
return Ord( $this->Get( 1 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get short from buffer
|
* Get short from buffer
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function GetShort( )
|
public function GetShort( )
|
||||||
{
|
{
|
||||||
$Data = UnPack( 'v', $this->Get( 2 ) );
|
$Data = UnPack( 'v', $this->Get( 2 ) );
|
||||||
|
|
||||||
return $Data[ 1 ];
|
return $Data[ 1 ];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get long from buffer
|
* Get long from buffer
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function GetLong( )
|
public function GetLong( )
|
||||||
{
|
{
|
||||||
$Data = UnPack( 'l', $this->Get( 4 ) );
|
$Data = UnPack( 'l', $this->Get( 4 ) );
|
||||||
|
|
||||||
return $Data[ 1 ];
|
return $Data[ 1 ];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get float from buffer
|
* Get float from buffer
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function GetFloat( )
|
public function GetFloat( )
|
||||||
{
|
{
|
||||||
$Data = UnPack( 'f', $this->Get( 4 ) );
|
$Data = UnPack( 'f', $this->Get( 4 ) );
|
||||||
|
|
||||||
return $Data[ 1 ];
|
return $Data[ 1 ];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get unsigned long from buffer
|
* Get unsigned long from buffer
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function GetUnsignedLong( )
|
public function GetUnsignedLong( )
|
||||||
{
|
{
|
||||||
$Data = UnPack( 'V', $this->Get( 4 ) );
|
$Data = UnPack( 'V', $this->Get( 4 ) );
|
||||||
|
|
||||||
return $Data[ 1 ];
|
return $Data[ 1 ];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read one string from buffer ending with null byte
|
* Read one string from buffer ending with null byte
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function GetString( )
|
public function GetString( )
|
||||||
{
|
{
|
||||||
$ZeroBytePosition = StrPos( $this->Buffer, "\0", $this->Position );
|
$ZeroBytePosition = StrPos( $this->Buffer, "\0", $this->Position );
|
||||||
|
|
||||||
if( $ZeroBytePosition === false )
|
if( $ZeroBytePosition === false )
|
||||||
{
|
{
|
||||||
$String = "";
|
$String = "";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$String = $this->Get( $ZeroBytePosition - $this->Position );
|
$String = $this->Get( $ZeroBytePosition - $this->Position );
|
||||||
|
|
||||||
$this->Position++;
|
$this->Position++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $String;
|
return $String;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,174 +1,174 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Class written by xPaw
|
* Class written by xPaw
|
||||||
*
|
*
|
||||||
* Website: http://xpaw.me
|
* Website: https://xpaw.me
|
||||||
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
|
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use xPaw\SourceQuery\Exception\InvalidPacketException;
|
use xPaw\SourceQuery\Exception\InvalidPacketException;
|
||||||
use xPaw\SourceQuery\Exception\SocketException;
|
use xPaw\SourceQuery\Exception\SocketException;
|
||||||
|
|
||||||
class SourceQuerySocket
|
class SourceQuerySocket
|
||||||
{
|
{
|
||||||
public $Socket;
|
public $Socket;
|
||||||
public $Engine;
|
public $Engine;
|
||||||
|
|
||||||
public $Ip;
|
public $Ip;
|
||||||
public $Port;
|
public $Port;
|
||||||
public $Timeout;
|
public $Timeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Points to buffer class
|
* Points to buffer class
|
||||||
*
|
*
|
||||||
* @var SourceQueryBuffer
|
* @var SourceQueryBuffer
|
||||||
*/
|
*/
|
||||||
private $Buffer;
|
private $Buffer;
|
||||||
|
|
||||||
public function __construct( $Buffer )
|
public function __construct( $Buffer )
|
||||||
{
|
{
|
||||||
$this->Buffer = $Buffer;
|
$this->Buffer = $Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Close( )
|
public function Close( )
|
||||||
{
|
{
|
||||||
if( $this->Socket )
|
if( $this->Socket )
|
||||||
{
|
{
|
||||||
FClose( $this->Socket );
|
FClose( $this->Socket );
|
||||||
|
|
||||||
$this->Socket = null;
|
$this->Socket = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Open( $Ip, $Port, $Timeout, $Engine )
|
public function Open( $Ip, $Port, $Timeout, $Engine )
|
||||||
{
|
{
|
||||||
$this->Timeout = $Timeout;
|
$this->Timeout = $Timeout;
|
||||||
$this->Engine = $Engine;
|
$this->Engine = $Engine;
|
||||||
$this->Port = $Port;
|
$this->Port = $Port;
|
||||||
$this->Ip = $Ip;
|
$this->Ip = $Ip;
|
||||||
|
|
||||||
$this->Socket = @FSockOpen( 'udp://' . $Ip, $Port, $ErrNo, $ErrStr, $Timeout );
|
$this->Socket = @FSockOpen( 'udp://' . $Ip, $Port, $ErrNo, $ErrStr, $Timeout );
|
||||||
|
|
||||||
if( $ErrNo || $this->Socket === false )
|
if( $ErrNo || $this->Socket === false )
|
||||||
{
|
{
|
||||||
throw new SocketException( 'Could not create socket: ' . $ErrStr, SocketException::COULD_NOT_CREATE_SOCKET );
|
throw new SocketException( 'Could not create socket: ' . $ErrStr, SocketException::COULD_NOT_CREATE_SOCKET );
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream_Set_Timeout( $this->Socket, $Timeout );
|
Stream_Set_Timeout( $this->Socket, $Timeout );
|
||||||
Stream_Set_Blocking( $this->Socket, true );
|
Stream_Set_Blocking( $this->Socket, true );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Write( $Header, $String = '' )
|
public function Write( $Header, $String = '' )
|
||||||
{
|
{
|
||||||
$Command = Pack( 'ccccca*', 0xFF, 0xFF, 0xFF, 0xFF, $Header, $String );
|
$Command = Pack( 'ccccca*', 0xFF, 0xFF, 0xFF, 0xFF, $Header, $String );
|
||||||
$Length = StrLen( $Command );
|
$Length = StrLen( $Command );
|
||||||
|
|
||||||
return $Length === FWrite( $this->Socket, $Command, $Length );
|
return $Length === FWrite( $this->Socket, $Command, $Length );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Read( $Length = 1400 )
|
public function Read( $Length = 1400 )
|
||||||
{
|
{
|
||||||
$this->Buffer->Set( FRead( $this->Socket, $Length ) );
|
$this->Buffer->Set( FRead( $this->Socket, $Length ) );
|
||||||
|
|
||||||
if( $this->Buffer->Remaining( ) === 0 )
|
if( $this->Buffer->Remaining( ) === 0 )
|
||||||
{
|
{
|
||||||
// TODO: Should we throw an exception here?
|
// TODO: Should we throw an exception here?
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$Header = $this->Buffer->GetLong( );
|
$Header = $this->Buffer->GetLong( );
|
||||||
|
|
||||||
if( $Header === -1 ) // Single packet
|
if( $Header === -1 ) // Single packet
|
||||||
{
|
{
|
||||||
// We don't have to do anything
|
// We don't have to do anything
|
||||||
}
|
}
|
||||||
else if( $Header === -2 ) // Split packet
|
else if( $Header === -2 ) // Split packet
|
||||||
{
|
{
|
||||||
$Packets = Array( );
|
$Packets = Array( );
|
||||||
$IsCompressed = false;
|
$IsCompressed = false;
|
||||||
$ReadMore = false;
|
$ReadMore = false;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
$RequestID = $this->Buffer->GetLong( );
|
$RequestID = $this->Buffer->GetLong( );
|
||||||
|
|
||||||
switch( $this->Engine )
|
switch( $this->Engine )
|
||||||
{
|
{
|
||||||
case SourceQuery :: GOLDSOURCE:
|
case SourceQuery :: GOLDSOURCE:
|
||||||
{
|
{
|
||||||
$PacketCountAndNumber = $this->Buffer->GetByte( );
|
$PacketCountAndNumber = $this->Buffer->GetByte( );
|
||||||
$PacketCount = $PacketCountAndNumber & 0xF;
|
$PacketCount = $PacketCountAndNumber & 0xF;
|
||||||
$PacketNumber = $PacketCountAndNumber >> 4;
|
$PacketNumber = $PacketCountAndNumber >> 4;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SourceQuery :: SOURCE:
|
case SourceQuery :: SOURCE:
|
||||||
{
|
{
|
||||||
$IsCompressed = ( $RequestID & 0x80000000 ) !== 0;
|
$IsCompressed = ( $RequestID & 0x80000000 ) !== 0;
|
||||||
$PacketCount = $this->Buffer->GetByte( );
|
$PacketCount = $this->Buffer->GetByte( );
|
||||||
$PacketNumber = $this->Buffer->GetByte( ) + 1;
|
$PacketNumber = $this->Buffer->GetByte( ) + 1;
|
||||||
|
|
||||||
if( $IsCompressed )
|
if( $IsCompressed )
|
||||||
{
|
{
|
||||||
$this->Buffer->GetLong( ); // Split size
|
$this->Buffer->GetLong( ); // Split size
|
||||||
|
|
||||||
$PacketChecksum = $this->Buffer->GetUnsignedLong( );
|
$PacketChecksum = $this->Buffer->GetUnsignedLong( );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->Buffer->GetShort( ); // Split size
|
$this->Buffer->GetShort( ); // Split size
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$Packets[ $PacketNumber ] = $this->Buffer->Get( );
|
$Packets[ $PacketNumber ] = $this->Buffer->Get( );
|
||||||
|
|
||||||
$ReadMore = $PacketCount > sizeof( $Packets );
|
$ReadMore = $PacketCount > sizeof( $Packets );
|
||||||
}
|
}
|
||||||
while( $ReadMore && $this->Sherlock( $Length ) );
|
while( $ReadMore && $this->Sherlock( $Length ) );
|
||||||
|
|
||||||
$Buffer = Implode( $Packets );
|
$Buffer = Implode( $Packets );
|
||||||
|
|
||||||
// TODO: Test this
|
// TODO: Test this
|
||||||
if( $IsCompressed )
|
if( $IsCompressed )
|
||||||
{
|
{
|
||||||
// Let's make sure this function exists, it's not included in PHP by default
|
// Let's make sure this function exists, it's not included in PHP by default
|
||||||
if( !Function_Exists( 'bzdecompress' ) )
|
if( !Function_Exists( 'bzdecompress' ) )
|
||||||
{
|
{
|
||||||
throw new RuntimeException( 'Received compressed packet, PHP doesn\'t have Bzip2 library installed, can\'t decompress.' );
|
throw new RuntimeException( 'Received compressed packet, PHP doesn\'t have Bzip2 library installed, can\'t decompress.' );
|
||||||
}
|
}
|
||||||
|
|
||||||
$Buffer = bzdecompress( $Buffer );
|
$Buffer = bzdecompress( $Buffer );
|
||||||
|
|
||||||
if( CRC32( $Buffer ) !== $PacketChecksum )
|
if( CRC32( $Buffer ) !== $PacketChecksum )
|
||||||
{
|
{
|
||||||
throw new InvalidPacketException( 'CRC32 checksum mismatch of uncompressed packet data.', InvalidPacketException::CHECKSUM_MISMATCH );
|
throw new InvalidPacketException( 'CRC32 checksum mismatch of uncompressed packet data.', InvalidPacketException::CHECKSUM_MISMATCH );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->Buffer->Set( SubStr( $Buffer, 4 ) );
|
$this->Buffer->Set( SubStr( $Buffer, 4 ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new InvalidPacketException( 'Socket read: Raw packet header mismatch. (0x' . DecHex( $Header ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH );
|
throw new InvalidPacketException( 'Socket read: Raw packet header mismatch. (0x' . DecHex( $Header ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function Sherlock( $Length )
|
private function Sherlock( $Length )
|
||||||
{
|
{
|
||||||
$Data = FRead( $this->Socket, $Length );
|
$Data = FRead( $this->Socket, $Length );
|
||||||
|
|
||||||
if( StrLen( $Data ) < 4 )
|
if( StrLen( $Data ) < 4 )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->Buffer->Set( $Data );
|
$this->Buffer->Set( $Data );
|
||||||
|
|
||||||
return $this->Buffer->GetLong( ) === -2;
|
return $this->Buffer->GetLong( ) === -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,180 +1,180 @@
|
|||||||
<?php
|
<?php
|
||||||
require __DIR__ . '/SourceQuery/SourceQuery.class.php';
|
require __DIR__ . '/SourceQuery/SourceQuery.class.php';
|
||||||
|
|
||||||
// Edit this ->
|
// Edit this ->
|
||||||
define( 'SQ_SERVER_ADDR', 'localhost' );
|
define( 'SQ_SERVER_ADDR', 'localhost' );
|
||||||
define( 'SQ_SERVER_PORT', 27015 );
|
define( 'SQ_SERVER_PORT', 27015 );
|
||||||
define( 'SQ_TIMEOUT', 3 );
|
define( 'SQ_TIMEOUT', 3 );
|
||||||
define( 'SQ_ENGINE', SourceQuery :: SOURCE );
|
define( 'SQ_ENGINE', SourceQuery :: SOURCE );
|
||||||
// Edit this <-
|
// Edit this <-
|
||||||
|
|
||||||
$Timer = MicroTime( true );
|
$Timer = MicroTime( true );
|
||||||
|
|
||||||
$Query = new SourceQuery( );
|
$Query = new SourceQuery( );
|
||||||
|
|
||||||
$Info = Array( );
|
$Info = Array( );
|
||||||
$Rules = Array( );
|
$Rules = Array( );
|
||||||
$Players = Array( );
|
$Players = Array( );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE );
|
$Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE );
|
||||||
//$Query->SetUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound
|
//$Query->SetUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound
|
||||||
|
|
||||||
$Info = $Query->GetInfo( );
|
$Info = $Query->GetInfo( );
|
||||||
$Players = $Query->GetPlayers( );
|
$Players = $Query->GetPlayers( );
|
||||||
$Rules = $Query->GetRules( );
|
$Rules = $Query->GetRules( );
|
||||||
}
|
}
|
||||||
catch( Exception $e )
|
catch( Exception $e )
|
||||||
{
|
{
|
||||||
$Exception = $e;
|
$Exception = $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
$Query->Disconnect( );
|
$Query->Disconnect( );
|
||||||
|
|
||||||
$Timer = Number_Format( MicroTime( true ) - $Timer, 4, '.', '' );
|
$Timer = Number_Format( MicroTime( true ) - $Timer, 4, '.', '' );
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>Source Query PHP Class</title>
|
<title>Source Query PHP Class</title>
|
||||||
|
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.jumbotron {
|
.jumbotron {
|
||||||
margin-top: 30px;
|
margin-top: 30px;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table thead th {
|
.table thead th {
|
||||||
background-color: #428BCA;
|
background-color: #428BCA;
|
||||||
border-color: #428BCA !important;
|
border-color: #428BCA !important;
|
||||||
color: #FFF;
|
color: #FFF;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="jumbotron">
|
<div class="jumbotron">
|
||||||
<h1>Source Query PHP Class</h1>
|
<h1>Source Query PHP Class</h1>
|
||||||
|
|
||||||
<p>This class was created to query game server which use the Source (Steamworks) query protocol.</p>
|
<p>This class was created to query game server which use the Source (Steamworks) query protocol.</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<a class="btn btn-large btn-primary" href="http://xpaw.me">Made by xPaw</a>
|
<a class="btn btn-large btn-primary" href="http://xpaw.me">Made by xPaw</a>
|
||||||
<a class="btn btn-large btn-primary" href="https://github.com/xPaw/PHP-Source-Query-Class">View on GitHub</a>
|
<a class="btn btn-large btn-primary" href="https://github.com/xPaw/PHP-Source-Query-Class">View on GitHub</a>
|
||||||
<a class="btn btn-large btn-danger" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">CC BY-NC-SA 3.0</a>
|
<a class="btn btn-large btn-danger" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">CC BY-NC-SA 3.0</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php if( isset( $Exception ) ): ?>
|
<?php if( isset( $Exception ) ): ?>
|
||||||
<div class="panel panel-primary">
|
<div class="panel panel-primary">
|
||||||
<div class="panel-heading"><?php echo Get_Class( $Exception ); ?> at line <?php echo $Exception->getLine( ); ?></div>
|
<div class="panel-heading"><?php echo Get_Class( $Exception ); ?> at line <?php echo $Exception->getLine( ); ?></div>
|
||||||
<p><b><?php echo htmlspecialchars( $Exception->getMessage( ) ); ?></b></p>
|
<p><b><?php echo htmlspecialchars( $Exception->getMessage( ) ); ?></b></p>
|
||||||
<p><?php echo nl2br( $e->getTraceAsString(), false ); ?></p>
|
<p><?php echo nl2br( $e->getTraceAsString(), false ); ?></p>
|
||||||
</div>
|
</div>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<table class="table table-bordered table-striped">
|
<table class="table table-bordered table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="2">Server Info <span class="label label-<?php echo $Timer > 1.0 ? 'danger' : 'success'; ?>"><?php echo $Timer; ?>s</span></th>
|
<th colspan="2">Server Info <span class="label label-<?php echo $Timer > 1.0 ? 'danger' : 'success'; ?>"><?php echo $Timer; ?>s</span></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php if( Is_Array( $Info ) ): ?>
|
<?php if( Is_Array( $Info ) ): ?>
|
||||||
<?php foreach( $Info as $InfoKey => $InfoValue ): ?>
|
<?php foreach( $Info as $InfoKey => $InfoValue ): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo htmlspecialchars( $InfoKey ); ?></td>
|
<td><?php echo htmlspecialchars( $InfoKey ); ?></td>
|
||||||
<td><?php
|
<td><?php
|
||||||
if( Is_Array( $InfoValue ) )
|
if( Is_Array( $InfoValue ) )
|
||||||
{
|
{
|
||||||
echo "<pre>";
|
echo "<pre>";
|
||||||
print_r( $InfoValue );
|
print_r( $InfoValue );
|
||||||
echo "</pre>";
|
echo "</pre>";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( $InfoValue === true )
|
if( $InfoValue === true )
|
||||||
{
|
{
|
||||||
echo 'true';
|
echo 'true';
|
||||||
}
|
}
|
||||||
else if( $InfoValue === false )
|
else if( $InfoValue === false )
|
||||||
{
|
{
|
||||||
echo 'false';
|
echo 'false';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
echo htmlspecialchars( $InfoValue );
|
echo htmlspecialchars( $InfoValue );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?></td>
|
?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">No information received</td>
|
<td colspan="2">No information received</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<table class="table table-bordered table-striped">
|
<table class="table table-bordered table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Player</th>
|
<th>Player</th>
|
||||||
<th>Frags</th>
|
<th>Frags</th>
|
||||||
<th>Time</th>
|
<th>Time</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php if( Is_Array( $Players ) ): ?>
|
<?php if( Is_Array( $Players ) ): ?>
|
||||||
<?php foreach( $Players as $Player ): ?>
|
<?php foreach( $Players as $Player ): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo htmlspecialchars( $Player[ 'Name' ] ); ?></td>
|
<td><?php echo htmlspecialchars( $Player[ 'Name' ] ); ?></td>
|
||||||
<td><?php echo $Player[ 'Frags' ]; ?></td>
|
<td><?php echo $Player[ 'Frags' ]; ?></td>
|
||||||
<td><?php echo $Player[ 'TimeF' ]; ?></td>
|
<td><?php echo $Player[ 'TimeF' ]; ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3">No players received</td>
|
<td colspan="3">No players received</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<table class="table table-bordered table-striped">
|
<table class="table table-bordered table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="2">Rules</th>
|
<th colspan="2">Rules</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php if( Is_Array( $Rules ) ): ?>
|
<?php if( Is_Array( $Rules ) ): ?>
|
||||||
<?php foreach( $Rules as $Rule => $Value ): ?>
|
<?php foreach( $Rules as $Rule => $Value ): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo htmlspecialchars( $Rule ); ?></td>
|
<td><?php echo htmlspecialchars( $Rule ); ?></td>
|
||||||
<td><?php echo htmlspecialchars( $Value ); ?></td>
|
<td><?php echo htmlspecialchars( $Value ); ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">No rules received</td>
|
<td colspan="2">No rules received</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in new issue