Add comments and fix whitespacing, no real changes

pull/13/head
xPaw 12 years ago
parent e27db7670f
commit bc9d574122

@ -1,170 +1,177 @@
<?php <?php
class SourceQueryBuffer
{
/** /**
* Buffer * Class written by xPaw
*
* @var string
*/
private $Buffer;
/**
* Buffer length
*
* @var int
*/
private $Length;
/**
* Current position in buffer
*
* @var int
*/
private $Position;
/**
* Sets buffer
* *
* @param string $Buffer Buffer * Website: http://xpaw.ru
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
*/ */
public function Set( $Buffer )
{
$this->Buffer = $Buffer;
$this->Length = StrLen( $Buffer );
$this->Position = 0;
}
/** class SourceQueryBuffer
* 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 ) /**
{ * Buffer
// Why even bother *
return ""; * @var string
} */
private $Buffer;
/**
* Buffer length
*
* @var int
*/
private $Length;
$Remaining = $this->Remaining( ); /**
* Current position in buffer
*
* @var int
*/
private $Position;
if( $Length == -1 ) /**
* Sets buffer
*
* @param string $Buffer Buffer
*/
public function Set( $Buffer )
{ {
$Length = $Remaining; $this->Buffer = $Buffer;
$this->Length = StrLen( $Buffer );
$this->Position = 0;
} }
else if( $Length > $Remaining )
/**
* Resets buffer
*/
public function Reset( )
{ {
return ""; $this->Buffer = "";
$this->Length = 0;
$this->Position = 0;
} }
$Data = SubStr( $this->Buffer, $this->Position, $Length ); /**
* Get remaining bytes
$this->Position += $Length; *
* @return int Remaining bytes in buffer
return $Data; */
} public function Remaining( )
{
/** return $this->Length - $this->Position;
* 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 ]; /**
} * Gets data from buffer
*
/** * @param int $Length Bytes to read
* Get long from buffer *
* * @return string
* @return int */
*/ public function Get( $Length = -1 )
public function GetLong( ) {
{ if( $Length == 0 )
$Data = UnPack( 'l', $this->Get( 4 ) ); {
// Why even bother
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;
}
return $Data[ 1 ]; /**
} * Get byte from buffer
*
/** * @return int
* Get float from buffer */
* public function GetByte( )
* @return float {
*/ return Ord( $this->Get( 1 ) );
public function GetFloat( ) }
{
$Data = UnPack( 'f', $this->Get( 4 ) );
return $Data[ 1 ]; /**
} * Get short from buffer
*
/** * @return int
* Get unsigned long from buffer */
* public function GetShort( )
* @return int {
*/ $Data = UnPack( 'v', $this->Get( 2 ) );
public function GetUnsignedLong( )
{ return $Data[ 1 ];
$Data = UnPack( 'V', $this->Get( 4 ) ); }
return $Data[ 1 ]; /**
} * Get long from buffer
*
/** * @return int
* Read one string from buffer ending with null byte */
* public function GetLong( )
* @return string {
*/ $Data = UnPack( 'l', $this->Get( 4 ) );
public function GetString( )
{ return $Data[ 1 ];
$ZeroBytePosition = StrPos( $this->Buffer, "\0", $this->Position ); }
if( $ZeroBytePosition === false ) /**
* Get float from buffer
*
* @return float
*/
public function GetFloat( )
{ {
$String = ""; $Data = UnPack( 'f', $this->Get( 4 ) );
return $Data[ 1 ];
} }
else
/**
* Get unsigned long from buffer
*
* @return int
*/
public function GetUnsignedLong( )
{ {
$String = $this->Get( $ZeroBytePosition - $this->Position ); $Data = UnPack( 'V', $this->Get( 4 ) );
$this->Position++; return $Data[ 1 ];
} }
return $String; /**
* 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,5 +1,12 @@
<?php <?php
class SourceQueryException extends Exception /**
{ * Class written by xPaw
// Exception thrown by SourceQuery class *
} * Website: http://xpaw.ru
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
*/
class SourceQueryException extends Exception
{
// Exception thrown by SourceQuery class
}

@ -1,251 +1,258 @@
<?php <?php
class SourceQueryRcon
{
/** /**
* Points to buffer class * Class written by xPaw
* *
* @var SourceQueryBuffer * Website: http://xpaw.ru
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
*/ */
private $Buffer;
/** class SourceQueryRcon
* Points to socket class
*
* @var SourceQuerySocket
*/
private $Socket;
private $RconSocket;
private $RconPassword;
private $RconRequestId;
private $RconChallenge;
public function __construct( $Buffer, $Socket )
{ {
$this->Buffer = $Buffer; /**
$this->Socket = $Socket; * Points to buffer class
} *
* @var SourceQueryBuffer
public function Close( ) */
{ private $Buffer;
if( $this->RconSocket )
/**
* Points to socket class
*
* @var SourceQuerySocket
*/
private $Socket;
private $RconSocket;
private $RconPassword;
private $RconRequestId;
private $RconChallenge;
public function __construct( $Buffer, $Socket )
{ {
FClose( $this->RconSocket ); $this->Buffer = $Buffer;
$this->Socket = $Socket;
$this->RconSocket = null;
} }
$this->RconChallenge = 0; public function Close( )
$this->RconRequestId = 0;
$this->RconPassword = 0;
}
public function Open( )
{
if( !$this->RconSocket && $this->Socket->Engine == SourceQuery :: SOURCE )
{ {
$this->RconSocket = @FSockOpen( $this->Socket->Ip, $this->Socket->Port, $ErrNo, $ErrStr, $this->Socket->Timeout ); if( $this->RconSocket )
if( $ErrNo || !$this->RconSocket )
{ {
throw new SourceQueryException( 'Can\'t connect to RCON server: ' . $ErrStr ); FClose( $this->RconSocket );
$this->RconSocket = null;
} }
Stream_Set_Timeout( $this->RconSocket, $this->Socket->Timeout ); $this->RconChallenge = 0;
Stream_Set_Blocking( $this->RconSocket, true ); $this->RconRequestId = 0;
$this->RconPassword = 0;
} }
}
public function Open( )
public function Write( $Header, $String = '' )
{
switch( $this->Socket->Engine )
{ {
case SourceQuery :: GOLDSOURCE: if( !$this->RconSocket && $this->Socket->Engine == SourceQuery :: SOURCE )
{ {
$Command = Pack( 'cccca*', 0xFF, 0xFF, 0xFF, 0xFF, $String ); $this->RconSocket = @FSockOpen( $this->Socket->Ip, $this->Socket->Port, $ErrNo, $ErrStr, $this->Socket->Timeout );
$Length = StrLen( $Command );
return $Length === FWrite( $this->Socket->Socket, $Command, $Length ); if( $ErrNo || !$this->RconSocket )
} {
case SourceQuery :: SOURCE: throw new SourceQueryException( 'Can\'t connect to RCON server: ' . $ErrStr );
{ }
// Pack the packet together
$Command = Pack( 'VV', ++$this->RequestId, $Header ) . $String . "\x00\x00\x00";
// Prepend packet length
$Command = Pack( 'V', StrLen( $Command ) ) . $Command;
$Length = StrLen( $Command );
return $Length === FWrite( $this->RconSocket, $Command, $Length ); Stream_Set_Timeout( $this->RconSocket, $this->Socket->Timeout );
Stream_Set_Blocking( $this->RconSocket, true );
} }
} }
}
public function Write( $Header, $String = '' )
public function Read( $Length = 1400 )
{
switch( $this->Socket->Engine )
{ {
case SourceQuery :: GOLDSOURCE: switch( $this->Socket->Engine )
{ {
// GoldSource RCON has same structure as Query case SourceQuery :: GOLDSOURCE:
$this->Socket->Read( );
if( $this->Buffer->GetByte( ) != SourceQuery :: S2A_RCON )
{ {
return false; $Command = Pack( 'cccca*', 0xFF, 0xFF, 0xFF, 0xFF, $String );
$Length = StrLen( $Command );
return $Length === FWrite( $this->Socket->Socket, $Command, $Length );
} }
case SourceQuery :: SOURCE:
$Buffer = $this->Buffer->Get( );
$Trimmed = Trim( $Buffer );
if( $Trimmed == 'Bad rcon_password.'
|| $Trimmed == 'You have been banned from this server.' )
{ {
throw new SourceQueryException( $Trimmed ); // Pack the packet together
$Command = Pack( 'VV', ++$this->RequestId, $Header ) . $String . "\x00\x00\x00";
// Prepend packet length
$Command = Pack( 'V', StrLen( $Command ) ) . $Command;
$Length = StrLen( $Command );
return $Length === FWrite( $this->RconSocket, $Command, $Length );
} }
}
$ReadMore = false; }
// There is no indentifier of the end, so we just need to continue reading public function Read( $Length = 1400 )
// TODO: Needs to be looked again, it causes timeouts {
do switch( $this->Socket->Engine )
{
case SourceQuery :: GOLDSOURCE:
{ {
// GoldSource RCON has same structure as Query
$this->Socket->Read( ); $this->Socket->Read( );
$ReadMore = $this->Buffer->Remaining( ) > 0 && $this->Buffer->GetByte( ) == SourceQuery :: S2A_RCON; if( $this->Buffer->GetByte( ) != SourceQuery :: S2A_RCON )
{
return false;
}
$Buffer = $this->Buffer->Get( );
$Trimmed = Trim( $Buffer );
if( $Trimmed == 'Bad rcon_password.'
|| $Trimmed == 'You have been banned from this server.' )
{
throw new SourceQueryException( $Trimmed );
}
$ReadMore = false;
if( $ReadMore ) // There is no indentifier of the end, so we just need to continue reading
// TODO: Needs to be looked again, it causes timeouts
do
{ {
$Packet = $this->Buffer->Get( ); $this->Socket->Read( );
$Buffer .= SubStr( $Packet, 0, -2 );
// Let's assume if this packet is not long enough, there are no more after this one $ReadMore = $this->Buffer->Remaining( ) > 0 && $this->Buffer->GetByte( ) == SourceQuery :: S2A_RCON;
$ReadMore = StrLen( $Packet ) > 1000; // use 1300?
if( $ReadMore )
{
$Packet = $this->Buffer->Get( );
$Buffer .= SubStr( $Packet, 0, -2 );
// Let's assume if this packet is not long enough, there are no more after this one
$ReadMore = StrLen( $Packet ) > 1000; // use 1300?
}
} }
while( $ReadMore );
$this->Buffer->Set( Trim( $Buffer ) );
break;
}
case SourceQuery :: SOURCE:
{
$this->Buffer->Set( FRead( $this->RconSocket, $Length ) );
$Buffer = "";
$PacketSize = $this->Buffer->GetLong( );
$Buffer .= $this->Buffer->Get( );
// TODO: multi packet reading
$this->Buffer->Set( $Buffer );
break;
} }
while( $ReadMore );
$this->Buffer->Set( Trim( $Buffer ) );
break;
}
case SourceQuery :: SOURCE:
{
$this->Buffer->Set( FRead( $this->RconSocket, $Length ) );
$Buffer = "";
$PacketSize = $this->Buffer->GetLong( );
$Buffer .= $this->Buffer->Get( );
// TODO: multi packet reading
$this->Buffer->Set( $Buffer );
break;
} }
} }
}
public function Command( $Command )
{
if( !$this->RconChallenge )
{
return false;
}
$Buffer = false; public function Command( $Command )
switch( $this->Socket->Engine )
{ {
case SourceQuery :: GOLDSOURCE: if( !$this->RconChallenge )
{ {
$this->Write( 0, 'rcon ' . $this->RconChallenge . ' "' . $this->RconPassword . '" ' . $Command . "\0" ); return false;
$this->Read( );
$Buffer = $this->Buffer->Get( );
break;
} }
case SourceQuery :: SOURCE:
$Buffer = false;
switch( $this->Socket->Engine )
{ {
$this->Write( SourceQuery :: SERVERDATA_EXECCOMMAND, $Command ); case SourceQuery :: GOLDSOURCE:
$this->Read( );
$RequestID = $this->Buffer->GetLong( );
$Type = $this->Buffer->GetLong( );
if( $Type == SourceQuery :: SERVERDATA_AUTH_RESPONSE )
{ {
throw new SourceQueryException( 'Bad rcon_password.' ); $this->Write( 0, 'rcon ' . $this->RconChallenge . ' "' . $this->RconPassword . '" ' . $Command . "\0" );
$this->Read( );
$Buffer = $this->Buffer->Get( );
break;
} }
else if( $Type != SourceQuery :: SERVERDATA_RESPONSE_VALUE ) case SourceQuery :: SOURCE:
{ {
return false; $this->Write( SourceQuery :: SERVERDATA_EXECCOMMAND, $Command );
$this->Read( );
$RequestID = $this->Buffer->GetLong( );
$Type = $this->Buffer->GetLong( );
if( $Type == SourceQuery :: SERVERDATA_AUTH_RESPONSE )
{
throw new SourceQueryException( 'Bad rcon_password.' );
}
else if( $Type != SourceQuery :: SERVERDATA_RESPONSE_VALUE )
{
return false;
}
// TODO: It should use GetString, but there are no null bytes at the end, why?
// $Buffer = $this->Buffer->GetString( );
$Buffer = $this->Buffer->Get( );
break;
} }
// TODO: It should use GetString, but there are no null bytes at the end, why?
// $Buffer = $this->Buffer->GetString( );
$Buffer = $this->Buffer->Get( );
break;
} }
return $Buffer;
} }
return $Buffer; public function Authorize( $Password )
}
public function Authorize( $Password )
{
$this->RconPassword = $Password;
switch( $this->Socket->Engine )
{ {
case SourceQuery :: GOLDSOURCE: $this->RconPassword = $Password;
switch( $this->Socket->Engine )
{ {
$this->Write( 0, 'challenge rcon' ); case SourceQuery :: GOLDSOURCE:
$this->Socket->Read( );
if( $this->Buffer->Get( 14 ) != 'challenge rcon' )
{ {
return false; $this->Write( 0, 'challenge rcon' );
} $this->Socket->Read( );
$this->RconChallenge = Trim( $this->Buffer->Get( ) ); if( $this->Buffer->Get( 14 ) != 'challenge rcon' )
{
break; return false;
} }
case SourceQuery :: SOURCE:
{ $this->RconChallenge = Trim( $this->Buffer->Get( ) );
$this->Write( SourceQuery :: SERVERDATA_AUTH, $Password );
$this->Read( ); break;
}
$RequestID = $this->Buffer->GetLong( ); case SourceQuery :: SOURCE:
$Type = $this->Buffer->GetLong( );
// If we receive SERVERDATA_RESPONSE_VALUE, then we need to read again
// More info: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Additional_Comments
if( $Type == SourceQuery :: SERVERDATA_RESPONSE_VALUE )
{ {
$this->Write( SourceQuery :: SERVERDATA_AUTH, $Password );
$this->Read( ); $this->Read( );
$RequestID = $this->Buffer->GetLong( ); $RequestID = $this->Buffer->GetLong( );
$Type = $this->Buffer->GetLong( ); $Type = $this->Buffer->GetLong( );
// If we receive SERVERDATA_RESPONSE_VALUE, then we need to read again
// More info: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Additional_Comments
if( $Type == SourceQuery :: SERVERDATA_RESPONSE_VALUE )
{
$this->Read( );
$RequestID = $this->Buffer->GetLong( );
$Type = $this->Buffer->GetLong( );
}
if( $RequestID == -1 || $Type != SourceQuery :: SERVERDATA_AUTH_RESPONSE )
{
throw new SourceQueryException( 'RCON authorization failed.' );
}
$this->RconChallenge = 1;
break;
} }
if( $RequestID == -1 || $Type != SourceQuery :: SERVERDATA_AUTH_RESPONSE )
{
throw new SourceQueryException( 'RCON authorization failed.' );
}
$this->RconChallenge = 1;
break;
} }
return true;
} }
return true;
} }
}

@ -1,148 +1,155 @@
<?php <?php
class SourceQuerySocket
{
public $Socket;
public $Engine;
public $Ip;
public $Port;
public $Timeout;
/** /**
* Points to buffer class * Class written by xPaw
* *
* @var SourceQueryBuffer * Website: http://xpaw.ru
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
*/ */
private $Buffer;
public function __construct( $Buffer )
{
$this->Buffer = $Buffer;
}
public function Close( ) class SourceQuerySocket
{ {
if( $this->Socket ) public $Socket;
{ public $Engine;
FClose( $this->Socket );
public $Ip;
$this->Socket = null; public $Port;
} public $Timeout;
}
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 ); /**
* Points to buffer class
*
* @var SourceQueryBuffer
*/
private $Buffer;
if( $ErrNo || $this->Socket === false ) public function __construct( $Buffer )
{ {
throw new Exception( 'Could not create socket: ' . $ErrStr ); $this->Buffer = $Buffer;
} }
Stream_Set_Timeout( $this->Socket, $Timeout ); public function Close( )
Stream_Set_Blocking( $this->Socket, true ); {
if( $this->Socket )
{
FClose( $this->Socket );
$this->Socket = null;
}
}
return true; public function Open( $Ip, $Port, $Timeout, $Engine )
} {
$this->Timeout = $Timeout;
public function Write( $Header, $String = '' ) $this->Engine = $Engine;
{ $this->Port = $Port;
$Command = Pack( 'ccccca*', 0xFF, 0xFF, 0xFF, 0xFF, $Header, $String ); $this->Ip = $Ip;
$Length = StrLen( $Command );
$this->Socket = @FSockOpen( 'udp://' . $Ip, $Port, $ErrNo, $ErrStr, $Timeout );
if( $ErrNo || $this->Socket === false )
{
throw new Exception( 'Could not create socket: ' . $ErrStr );
}
Stream_Set_Timeout( $this->Socket, $Timeout );
Stream_Set_Blocking( $this->Socket, true );
return true;
}
return $Length === FWrite( $this->Socket, $Command, $Length ); public function Write( $Header, $String = '' )
} {
$Command = Pack( 'ccccca*', 0xFF, 0xFF, 0xFF, 0xFF, $Header, $String );
public function Read( $Length = 1400 ) $Length = StrLen( $Command );
{
$this->Buffer->Set( FRead( $this->Socket, $Length ) ); return $Length === FWrite( $this->Socket, $Command, $Length );
}
if( $this->Buffer->Remaining( ) > 0 && $this->Buffer->GetLong( ) == -2 ) public function Read( $Length = 1400 )
{ {
$Packets = Array( ); $this->Buffer->Set( FRead( $this->Socket, $Length ) );
$IsCompressed = false;
$ReadMore = false;
do if( $this->Buffer->Remaining( ) > 0 && $this->Buffer->GetLong( ) == -2 )
{ {
$RequestID = $this->Buffer->GetLong( ); $Packets = Array( );
$IsCompressed = false;
$ReadMore = false;
switch( $this->Engine ) do
{ {
case SourceQuery :: GOLDSOURCE: $RequestID = $this->Buffer->GetLong( );
switch( $this->Engine )
{ {
$PacketCountAndNumber = $this->Buffer->GetByte( ); case SourceQuery :: GOLDSOURCE:
$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 $PacketCountAndNumber = $this->Buffer->GetByte( );
$PacketCount = $PacketCountAndNumber & 0xF;
$PacketNumber = $PacketCountAndNumber >> 4;
$PacketChecksum = $this->Buffer->GetUnsignedLong( ); break;
} }
else case SourceQuery :: SOURCE:
{ {
$this->Buffer->GetShort( ); // Split size $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;
} }
break;
} }
$Packets[ $PacketNumber ] = $this->Buffer->Get( );
$ReadMore = $PacketCount > sizeof( $Packets );
} }
while( $ReadMore && $this->Sherlock( $Length ) );
$Packets[ $PacketNumber ] = $this->Buffer->Get( ); $Buffer = Implode( $Packets );
$ReadMore = $PacketCount > sizeof( $Packets ); // TODO: Test this
} if( $IsCompressed )
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.' ); // 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.' );
}
$Data = bzdecompress( $Data );
if( CRC32( $Data ) != $PacketChecksum )
{
throw new SourceQueryException( 'CRC32 checksum mismatch of uncompressed packet data.' );
}
} }
$Data = bzdecompress( $Data ); $this->Buffer->Set( SubStr( $Buffer, 4 ) );
if( CRC32( $Data ) != $PacketChecksum )
{
throw new SourceQueryException( 'CRC32 checksum mismatch of uncompressed packet data.' );
}
} }
$this->Buffer->Set( SubStr( $Buffer, 4 ) );
} }
}
private function Sherlock( $Length )
{
$Data = FRead( $this->Socket, $Length );
if( StrLen( $Data ) < 4 ) private function Sherlock( $Length )
{ {
return false; $Data = FRead( $this->Socket, $Length );
if( StrLen( $Data ) < 4 )
{
return false;
}
$this->Buffer->Set( $Data );
return $this->Buffer->GetLong( ) == -2;
} }
$this->Buffer->Set( $Data );
return $this->Buffer->GetLong( ) == -2;
} }
}

@ -1,16 +1,4 @@
<?php <?php
if( !defined( '__DIR__' ) ) // PHP < 5.3
{
define( '__DIR__', dirname( __FILE__ ) );
}
require __DIR__ . '/Exception.class.php';
require __DIR__ . '/Buffer.class.php';
require __DIR__ . '/Socket.class.php';
require __DIR__ . '/Rcon.class.php';
class SourceQuery
{
/** /**
* Class written by xPaw * Class written by xPaw
* *
@ -21,481 +9,493 @@ class SourceQuery
* I used it as a reference at some points. * I used it as a reference at some points.
*/ */
/** if( !defined( '__DIR__' ) ) // PHP < 5.3
* Values returned by GetChallenge()
*
* TODO: Get rid of this? Improve? Do something else?
*/
const GETCHALLENGE_FAILED = 0;
const GETCHALLENGE_ALL_CLEAR = 1;
const GETCHALLENGE_CONTAINS_ANSWER = 2;
/**
* Engines
*/
const GOLDSOURCE = 0;
const SOURCE = 1;
/**
* Packets sent
*/
const A2S_PING = 0x69;
const A2S_INFO = 0x54;
const A2S_PLAYER = 0x55;
const A2S_RULES = 0x56;
/**
* Packets received
*/
const S2A_PING = 0x6A;
const S2A_CHALLENGE = 0x41;
const S2A_INFO = 0x49;
const S2A_INFO_OLD = 0x6D; // Old GoldSource, HLTV uses it
const S2A_PLAYER = 0x44;
const S2A_RULES = 0x45;
const S2A_RCON = 0x6C;
/**
* Source rcon sent
*/
const SERVERDATA_EXECCOMMAND = 2;
const SERVERDATA_AUTH = 3;
/**
* Source rcon received
*/
const SERVERDATA_RESPONSE_VALUE = 0;
const SERVERDATA_AUTH_RESPONSE = 2;
/**
* Points to rcon class
*
* @var SourceQueryRcon
*/
private $Rcon;
/**
* Points to buffer class
*
* @var SourceQueryBuffer
*/
private $Buffer;
/**
* Points to socket class
*
* @var SourceQuerySocket
*/
private $Socket;
/**
* True if connection is open, false if not
*
* @var bool
*/
private $Connected;
/**
* Contains challenge
*
* @var string
*/
private $Challenge;
public function __construct( )
{ {
$this->Buffer = new SourceQueryBuffer( ); define( '__DIR__', dirname( __FILE__ ) );
$this->Socket = new SourceQuerySocket( $this->Buffer );
$this->Rcon = new SourceQueryRcon( $this->Buffer, $this->Socket );
} }
public function __destruct( ) require __DIR__ . '/Exception.class.php';
{ require __DIR__ . '/Buffer.class.php';
$this->Disconnect( ); require __DIR__ . '/Socket.class.php';
} require __DIR__ . '/Rcon.class.php';
/** class SourceQuery
* Opens connection to server
*
* @param string $Ip Server ip
* @param int $Port Server port
* @param int $Timeout Timeout period
* @param int $Engine Engine the server runs on (goldsource, source)
*
* @throws SourceQueryException
* @throws InvalidArgumentException If timeout is not an integer
*/
public function Connect( $Ip, $Port, $Timeout = 3, $Engine = self :: SOURCE )
{ {
$this->Disconnect( ); /**
$this->Buffer->Reset( ); * Values returned by GetChallenge()
$this->Challenge = 0; *
* TODO: Get rid of this? Improve? Do something else?
*/
const GETCHALLENGE_FAILED = 0;
const GETCHALLENGE_ALL_CLEAR = 1;
const GETCHALLENGE_CONTAINS_ANSWER = 2;
if( !is_int( $Timeout ) || $Timeout < 0 ) /**
{ * Engines
throw new InvalidArgumentException( 'Timeout must be an integer.' ); */
} const GOLDSOURCE = 0;
const SOURCE = 1;
if( !$this->Socket->Open( $Ip, (int)$Port, $Timeout, (int)$Engine ) ) /**
{ * Packets sent
throw new SourceQueryException( 'Can\'t connect to the server.' ); */
} const A2S_PING = 0x69;
const A2S_INFO = 0x54;
const A2S_PLAYER = 0x55;
const A2S_RULES = 0x56;
$this->Connected = true; /**
} * Packets received
*/
/** const S2A_PING = 0x6A;
* Closes all open connections const S2A_CHALLENGE = 0x41;
*/ const S2A_INFO = 0x49;
public function Disconnect( ) const S2A_INFO_OLD = 0x6D; // Old GoldSource, HLTV uses it
{ const S2A_PLAYER = 0x44;
$this->Connected = false; const S2A_RULES = 0x45;
const S2A_RCON = 0x6C;
$this->Socket->Close( ); /**
$this->Rcon->Close( ); * Source rcon sent
} */
const SERVERDATA_EXECCOMMAND = 2;
/** const SERVERDATA_AUTH = 3;
* Sends ping packet to the server
* NOTE: This may not work on some games (TF2 for example)
*
* @return bool True on success, false on failure
*/
public function Ping( )
{
if( !$this->Connected )
{
return false;
}
$this->Socket->Write( self :: A2S_PING ); /**
$this->Socket->Read( ); * Source rcon received
*/
const SERVERDATA_RESPONSE_VALUE = 0;
const SERVERDATA_AUTH_RESPONSE = 2;
return $this->Buffer->GetByte( ) == self :: S2A_PING; /**
} * Points to rcon class
*
/** * @var SourceQueryRcon
* Get server information */
* private $Rcon;
* @throws SourceQueryException
* /**
* @return bool|array Returns array with information on success, false on failure * Points to buffer class
*/ *
public function GetInfo( ) * @var SourceQueryBuffer
{ */
if( !$this->Connected ) private $Buffer;
{
return false;
}
$this->Socket->Write( self :: A2S_INFO, "Source Engine Query\0" ); /**
$this->Socket->Read( ); * Points to socket class
*
* @var SourceQuerySocket
*/
private $Socket;
$Type = $this->Buffer->GetByte( ); /**
* True if connection is open, false if not
*
* @var bool
*/
private $Connected;
if( $Type == 0 ) /**
* Contains challenge
*
* @var string
*/
private $Challenge;
public function __construct( )
{ {
return false; $this->Buffer = new SourceQueryBuffer( );
$this->Socket = new SourceQuerySocket( $this->Buffer );
$this->Rcon = new SourceQueryRcon( $this->Buffer, $this->Socket );
} }
// Old GoldSource protocol, HLTV still uses it public function __destruct( )
if( $Type == self :: S2A_INFO_OLD && $this->Socket->Engine == self :: GOLDSOURCE )
{ {
/** $this->Disconnect( );
* If we try to read data again, and we get the result with type S2A_INFO (0x49) }
* That means this server is running dproto,
* Because it sends answer for both protocols /**
*/ * Opens connection to server
*
$Server[ 'Address' ] = $this->Buffer->GetString( ); * @param string $Ip Server ip
$Server[ 'HostName' ] = $this->Buffer->GetString( ); * @param int $Port Server port
$Server[ 'Map' ] = $this->Buffer->GetString( ); * @param int $Timeout Timeout period
$Server[ 'ModDir' ] = $this->Buffer->GetString( ); * @param int $Engine Engine the server runs on (goldsource, source)
$Server[ 'ModDesc' ] = $this->Buffer->GetString( ); *
$Server[ 'Players' ] = $this->Buffer->GetByte( ); * @throws SourceQueryException
$Server[ 'MaxPlayers' ] = $this->Buffer->GetByte( ); * @throws InvalidArgumentException If timeout is not an integer
$Server[ 'Protocol' ] = $this->Buffer->GetByte( ); */
$Server[ 'Dedicated' ] = Chr( $this->Buffer->GetByte( ) ); public function Connect( $Ip, $Port, $Timeout = 3, $Engine = self :: SOURCE )
$Server[ 'Os' ] = Chr( $this->Buffer->GetByte( ) ); {
$Server[ 'Password' ] = $this->Buffer->GetByte( ) == 1; $this->Disconnect( );
$Server[ 'IsMod' ] = $this->Buffer->GetByte( ) == 1; $this->Buffer->Reset( );
$this->Challenge = 0;
if( $Server[ 'IsMod' ] ) if( !is_int( $Timeout ) || $Timeout < 0 )
{ {
$Mod[ 'Url' ] = $this->Buffer->GetString( ); throw new InvalidArgumentException( 'Timeout must be an integer.' );
$Mod[ 'Download' ] = $this->Buffer->GetString( );
$this->Buffer->Get( 1 ); // NULL byte
$Mod[ 'Version' ] = $this->Buffer->GetLong( );
$Mod[ 'Size' ] = $this->Buffer->GetLong( );
$Mod[ 'ServerSide' ] = $this->Buffer->GetByte( ) == 1;
$Mod[ 'CustomDLL' ] = $this->Buffer->GetByte( ) == 1;
} }
$Server[ 'Secure' ] = $this->Buffer->GetByte( ) == 1; if( !$this->Socket->Open( $Ip, (int)$Port, $Timeout, (int)$Engine ) )
$Server[ 'Bots' ] = $this->Buffer->GetByte( );
if( isset( $Mod ) )
{ {
$Server[ 'Mod' ] = $Mod; throw new SourceQueryException( 'Can\'t connect to the server.' );
} }
return $Server; $this->Connected = true;
} }
if( $Type != self :: S2A_INFO ) /**
* Closes all open connections
*/
public function Disconnect( )
{ {
throw new SourceQueryException( 'GetInfo: Packet header mismatch. (0x' . DecHex( $Type ) . ')' ); $this->Connected = false;
$this->Socket->Close( );
$this->Rcon->Close( );
} }
$Server[ 'Protocol' ] = $this->Buffer->GetByte( ); /**
$Server[ 'HostName' ] = $this->Buffer->GetString( ); * Sends ping packet to the server
$Server[ 'Map' ] = $this->Buffer->GetString( ); * NOTE: This may not work on some games (TF2 for example)
$Server[ 'ModDir' ] = $this->Buffer->GetString( ); *
$Server[ 'ModDesc' ] = $this->Buffer->GetString( ); * @return bool True on success, false on failure
$Server[ 'AppID' ] = $this->Buffer->GetShort( ); */
$Server[ 'Players' ] = $this->Buffer->GetByte( ); public function Ping( )
$Server[ 'MaxPlayers' ] = $this->Buffer->GetByte( );
$Server[ 'Bots' ] = $this->Buffer->GetByte( );
$Server[ 'Dedicated' ] = Chr( $this->Buffer->GetByte( ) );
$Server[ 'Os' ] = Chr( $this->Buffer->GetByte( ) );
$Server[ 'Password' ] = $this->Buffer->GetByte( ) == 1;
$Server[ 'Secure' ] = $this->Buffer->GetByte( ) == 1;
// The Ship
if( $Server[ 'AppID' ] == 2400 )
{ {
$Server[ 'GameMode' ] = $this->Buffer->GetByte( ); if( !$this->Connected )
$Server[ 'WitnessCount' ] = $this->Buffer->GetByte( ); {
$Server[ 'WitnessTime' ] = $this->Buffer->GetByte( ); return false;
}
$this->Socket->Write( self :: A2S_PING );
$this->Socket->Read( );
return $this->Buffer->GetByte( ) == self :: S2A_PING;
} }
$Server[ 'Version' ] = $this->Buffer->GetString( ); /**
* Get server information
// Extra Data Flags *
if( $this->Buffer->Remaining( ) > 0 ) * @throws SourceQueryException
*
* @return bool|array Returns array with information on success, false on failure
*/
public function GetInfo( )
{ {
$Flags = $this->Buffer->GetByte( ); if( !$this->Connected )
// The server's game port
if( $Flags & 0x80 )
{ {
$Server[ 'GamePort' ] = $this->Buffer->GetShort( ); return false;
} }
// The server's SteamID - does this serve any purpose? $this->Socket->Write( self :: A2S_INFO, "Source Engine Query\0" );
if( $Flags & 0x10 ) $this->Socket->Read( );
$Type = $this->Buffer->GetByte( );
if( $Type == 0 )
{ {
$Server[ 'ServerID' ] = $this->Buffer->GetUnsignedLong( ) | ( $this->Buffer->GetUnsignedLong( ) << 32 ); return false;
} }
// The spectator port and then the spectator server name // Old GoldSource protocol, HLTV still uses it
if( $Flags & 0x40 ) if( $Type == self :: S2A_INFO_OLD && $this->Socket->Engine == self :: GOLDSOURCE )
{ {
$Server[ 'SpecPort' ] = $this->Buffer->GetShort( ); /**
$Server[ 'SpecName' ] = $this->Buffer->GetString( ); * If we try to read data again, and we get the result with type S2A_INFO (0x49)
* That means this server is running dproto,
* Because it sends answer for both protocols
*/
$Server[ 'Address' ] = $this->Buffer->GetString( );
$Server[ 'HostName' ] = $this->Buffer->GetString( );
$Server[ 'Map' ] = $this->Buffer->GetString( );
$Server[ 'ModDir' ] = $this->Buffer->GetString( );
$Server[ 'ModDesc' ] = $this->Buffer->GetString( );
$Server[ 'Players' ] = $this->Buffer->GetByte( );
$Server[ 'MaxPlayers' ] = $this->Buffer->GetByte( );
$Server[ 'Protocol' ] = $this->Buffer->GetByte( );
$Server[ 'Dedicated' ] = Chr( $this->Buffer->GetByte( ) );
$Server[ 'Os' ] = Chr( $this->Buffer->GetByte( ) );
$Server[ 'Password' ] = $this->Buffer->GetByte( ) == 1;
$Server[ 'IsMod' ] = $this->Buffer->GetByte( ) == 1;
if( $Server[ 'IsMod' ] )
{
$Mod[ 'Url' ] = $this->Buffer->GetString( );
$Mod[ 'Download' ] = $this->Buffer->GetString( );
$this->Buffer->Get( 1 ); // NULL byte
$Mod[ 'Version' ] = $this->Buffer->GetLong( );
$Mod[ 'Size' ] = $this->Buffer->GetLong( );
$Mod[ 'ServerSide' ] = $this->Buffer->GetByte( ) == 1;
$Mod[ 'CustomDLL' ] = $this->Buffer->GetByte( ) == 1;
}
$Server[ 'Secure' ] = $this->Buffer->GetByte( ) == 1;
$Server[ 'Bots' ] = $this->Buffer->GetByte( );
if( isset( $Mod ) )
{
$Server[ 'Mod' ] = $Mod;
}
return $Server;
} }
// The game tag data string for the server if( $Type != self :: S2A_INFO )
if( $Flags & 0x20 )
{ {
$Server[ 'GameTags' ] = $this->Buffer->GetString( ); throw new SourceQueryException( 'GetInfo: Packet header mismatch. (0x' . DecHex( $Type ) . ')' );
} }
// 0x01 - The server's 64-bit GameID $Server[ 'Protocol' ] = $this->Buffer->GetByte( );
} $Server[ 'HostName' ] = $this->Buffer->GetString( );
$Server[ 'Map' ] = $this->Buffer->GetString( );
return $Server; $Server[ 'ModDir' ] = $this->Buffer->GetString( );
} $Server[ 'ModDesc' ] = $this->Buffer->GetString( );
$Server[ 'AppID' ] = $this->Buffer->GetShort( );
/** $Server[ 'Players' ] = $this->Buffer->GetByte( );
* Get players on the server $Server[ 'MaxPlayers' ] = $this->Buffer->GetByte( );
* $Server[ 'Bots' ] = $this->Buffer->GetByte( );
* @throws SourceQueryException $Server[ 'Dedicated' ] = Chr( $this->Buffer->GetByte( ) );
* $Server[ 'Os' ] = Chr( $this->Buffer->GetByte( ) );
* @return bool|array Returns array with players on success, false on failure $Server[ 'Password' ] = $this->Buffer->GetByte( ) == 1;
*/ $Server[ 'Secure' ] = $this->Buffer->GetByte( ) == 1;
public function GetPlayers( )
{ // The Ship
if( !$this->Connected ) if( $Server[ 'AppID' ] == 2400 )
{
return false;
}
switch( $this->GetChallenge( self :: A2S_PLAYER, self :: S2A_PLAYER ) )
{
case self :: GETCHALLENGE_FAILED:
{ {
return false; $Server[ 'GameMode' ] = $this->Buffer->GetByte( );
$Server[ 'WitnessCount' ] = $this->Buffer->GetByte( );
$Server[ 'WitnessTime' ] = $this->Buffer->GetByte( );
} }
case self :: GETCHALLENGE_ALL_CLEAR:
$Server[ 'Version' ] = $this->Buffer->GetString( );
// Extra Data Flags
if( $this->Buffer->Remaining( ) > 0 )
{ {
$this->Socket->Write( self :: A2S_PLAYER, $this->Challenge ); $Flags = $this->Buffer->GetByte( );
$this->Socket->Read( );
$Type = $this->Buffer->GetByte( ); // The server's game port
if( $Flags & 0x80 )
{
$Server[ 'GamePort' ] = $this->Buffer->GetShort( );
}
if( $Type == 0 ) // The server's SteamID - does this serve any purpose?
if( $Flags & 0x10 )
{ {
return false; $Server[ 'ServerID' ] = $this->Buffer->GetUnsignedLong( ) | ( $this->Buffer->GetUnsignedLong( ) << 32 );
} }
else if( $Type != self :: S2A_PLAYER )
// The spectator port and then the spectator server name
if( $Flags & 0x40 )
{
$Server[ 'SpecPort' ] = $this->Buffer->GetShort( );
$Server[ 'SpecName' ] = $this->Buffer->GetString( );
}
// The game tag data string for the server
if( $Flags & 0x20 )
{ {
throw new SourceQueryException( 'GetPlayers: Packet header mismatch. (0x' . DecHex( $Type ) . ')' ); $Server[ 'GameTags' ] = $this->Buffer->GetString( );
} }
break; // 0x01 - The server's 64-bit GameID
} }
}
$Players = Array( );
$Count = $this->Buffer->GetByte( );
while( $Count-- > 0 && $this->Buffer->Remaining( ) > 0 )
{
$Player[ 'Id' ] = $this->Buffer->GetByte( ); // PlayerID, is it just always 0?
$Player[ 'Name' ] = $this->Buffer->GetString( );
$Player[ 'Frags' ] = $this->Buffer->GetLong( );
$Player[ 'Time' ] = (int)$this->Buffer->GetFloat( );
$Player[ 'TimeF' ] = GMDate( ( $Player[ 'Time' ] > 3600 ? "H:i:s" : "i:s" ), $Player[ 'Time' ] );
$Players[ ] = $Player; return $Server;
}
return $Players;
}
/**
* Get rules (cvars) from the server
*
* @throws SourceQueryException
*
* @return bool|array Returns array with rules on success, false on failure
*/
public function GetRules( )
{
if( !$this->Connected )
{
return false;
} }
switch( $this->GetChallenge( self :: A2S_RULES, self :: S2A_RULES ) ) /**
* Get players on the server
*
* @throws SourceQueryException
*
* @return bool|array Returns array with players on success, false on failure
*/
public function GetPlayers( )
{ {
case self :: GETCHALLENGE_FAILED: if( !$this->Connected )
{ {
return false; return false;
} }
case self :: GETCHALLENGE_ALL_CLEAR:
switch( $this->GetChallenge( self :: A2S_PLAYER, self :: S2A_PLAYER ) )
{ {
$this->Socket->Write( self :: A2S_RULES, $this->Challenge ); case self :: GETCHALLENGE_FAILED:
$this->Socket->Read( );
$Type = $this->Buffer->GetByte( );
if( $Type == 0 )
{ {
return false; return false;
} }
else if( $Type != self :: S2A_RULES ) case self :: GETCHALLENGE_ALL_CLEAR:
{ {
throw new SourceQueryException( 'GetRules: Packet header mismatch. (0x' . DecHex( $Type ) . ')' ); $this->Socket->Write( self :: A2S_PLAYER, $this->Challenge );
$this->Socket->Read( );
$Type = $this->Buffer->GetByte( );
if( $Type == 0 )
{
return false;
}
else if( $Type != self :: S2A_PLAYER )
{
throw new SourceQueryException( 'GetPlayers: Packet header mismatch. (0x' . DecHex( $Type ) . ')' );
}
break;
} }
break;
} }
}
$Rules = Array( );
$Count = $this->Buffer->GetShort( );
while( $Count-- > 0 && $this->Buffer->Remaining( ) > 0 )
{
$Rule = $this->Buffer->GetString( );
$Value = $this->Buffer->GetString( );
if( !Empty( $Rule ) ) $Players = Array( );
$Count = $this->Buffer->GetByte( );
while( $Count-- > 0 && $this->Buffer->Remaining( ) > 0 )
{ {
$Rules[ $Rule ] = $Value; $Player[ 'Id' ] = $this->Buffer->GetByte( ); // PlayerID, is it just always 0?
$Player[ 'Name' ] = $this->Buffer->GetString( );
$Player[ 'Frags' ] = $this->Buffer->GetLong( );
$Player[ 'Time' ] = (int)$this->Buffer->GetFloat( );
$Player[ 'TimeF' ] = GMDate( ( $Player[ 'Time' ] > 3600 ? "H:i:s" : "i:s" ), $Player[ 'Time' ] );
$Players[ ] = $Player;
} }
return $Players;
} }
return $Rules; /**
} * Get rules (cvars) from the server
*
/** * @throws SourceQueryException
* Get challenge (used for players/rules packets) *
* * @return bool|array Returns array with rules on success, false on failure
* @return bool True if all went well, false if server uses old GoldSource protocol, and it already contains answer */
*/ public function GetRules( )
private function GetChallenge( $Header, $ExpectedResult )
{
if( $this->Challenge )
{ {
return self :: GETCHALLENGE_ALL_CLEAR; if( !$this->Connected )
}
$this->Socket->Write( $Header, 0xFFFFFFFF );
$this->Socket->Read( );
$Type = $this->Buffer->GetByte( );
switch( $Type )
{
case self :: S2A_CHALLENGE:
{ {
$this->Challenge = $this->Buffer->Get( 4 ); return false;
return self :: GETCHALLENGE_ALL_CLEAR;
} }
case $ExpectedResult:
switch( $this->GetChallenge( self :: A2S_RULES, self :: S2A_RULES ) )
{ {
// Goldsource (HLTV) case self :: GETCHALLENGE_FAILED:
{
return false;
}
case self :: GETCHALLENGE_ALL_CLEAR:
{
$this->Socket->Write( self :: A2S_RULES, $this->Challenge );
$this->Socket->Read( );
$Type = $this->Buffer->GetByte( );
if( $Type == 0 )
{
return false;
}
else if( $Type != self :: S2A_RULES )
{
throw new SourceQueryException( 'GetRules: Packet header mismatch. (0x' . DecHex( $Type ) . ')' );
}
break;
}
}
$Rules = Array( );
$Count = $this->Buffer->GetShort( );
while( $Count-- > 0 && $this->Buffer->Remaining( ) > 0 )
{
$Rule = $this->Buffer->GetString( );
$Value = $this->Buffer->GetString( );
return self :: GETCHALLENGE_CONTAINS_ANSWER; if( !Empty( $Rule ) )
{
$Rules[ $Rule ] = $Value;
}
} }
case 0:
return $Rules;
}
/**
* Get challenge (used for players/rules packets)
*
* @return bool True if all went well, false if server uses old GoldSource protocol, and it already contains answer
*/
private function GetChallenge( $Header, $ExpectedResult )
{
if( $this->Challenge )
{ {
return self :: GETCHALLENGE_FAILED; return self :: GETCHALLENGE_ALL_CLEAR;
} }
default:
$this->Socket->Write( $Header, 0xFFFFFFFF );
$this->Socket->Read( );
$Type = $this->Buffer->GetByte( );
switch( $Type )
{ {
throw new SourceQueryException( 'GetChallenge: Packet header mismatch. (0x' . DecHex( $Type ) . ')' ); case self :: S2A_CHALLENGE:
{
$this->Challenge = $this->Buffer->Get( 4 );
return self :: GETCHALLENGE_ALL_CLEAR;
}
case $ExpectedResult:
{
// Goldsource (HLTV)
return self :: GETCHALLENGE_CONTAINS_ANSWER;
}
case 0:
{
return self :: GETCHALLENGE_FAILED;
}
default:
{
throw new SourceQueryException( 'GetChallenge: Packet header mismatch. (0x' . DecHex( $Type ) . ')' );
}
} }
} }
}
/**
/** * Sets rcon password, for future use in Rcon()
* Sets rcon password, for future use in Rcon() *
* * @param string $Password Rcon Password
* @param string $Password Rcon Password *
* * @return bool True on success, false on failure
* @return bool True on success, false on failure */
*/ public function SetRconPassword( $Password )
public function SetRconPassword( $Password )
{
if( !$this->Connected )
{ {
return false; if( !$this->Connected )
{
return false;
}
$this->Rcon->Open( );
return $this->Rcon->Authorize( $Password );
} }
$this->Rcon->Open( ); /**
* Sets rcon password, for future use in Rcon()
return $this->Rcon->Authorize( $Password ); *
} * @param string $Command Command to execute on the server
*
/** * @return bool|string Answer from server in string, false on failure
* Sets rcon password, for future use in Rcon() */
* public function Rcon( $Command )
* @param string $Command Command to execute on the server
*
* @return bool|string Answer from server in string, false on failure
*/
public function Rcon( $Command )
{
if( !$this->Connected )
{ {
return false; if( !$this->Connected )
{
return false;
}
return $this->Rcon->Command( $Command );
} }
return $this->Rcon->Command( $Command );
} }
}

@ -31,7 +31,7 @@
$Query->Disconnect( ); $Query->Disconnect( );
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Source Query PHP Class</title> <title>Source Query PHP Class</title>

Loading…
Cancel
Save