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