|
|
@ -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?
|
|
|
|
if( !is_int( $Timeout ) || $Timeout < 0 )
|
|
|
|
*/
|
|
|
|
|
|
|
|
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( )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new InvalidArgumentException( 'Timeout must be an integer.' );
|
|
|
|
$this->Buffer = new SourceQueryBuffer( );
|
|
|
|
|
|
|
|
$this->Socket = new SourceQuerySocket( $this->Buffer );
|
|
|
|
|
|
|
|
$this->Rcon = new SourceQueryRcon( $this->Buffer, $this->Socket );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( !$this->Socket->Open( $Ip, (int)$Port, $Timeout, (int)$Engine ) )
|
|
|
|
public function __destruct( )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new SourceQueryException( 'Can\'t connect to the server.' );
|
|
|
|
$this->Disconnect( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->Connected = true;
|
|
|
|
/**
|
|
|
|
}
|
|
|
|
* 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( );
|
|
|
|
|
|
|
|
$this->Challenge = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
if( !is_int( $Timeout ) || $Timeout < 0 )
|
|
|
|
* Closes all open connections
|
|
|
|
{
|
|
|
|
*/
|
|
|
|
throw new InvalidArgumentException( 'Timeout must be an integer.' );
|
|
|
|
public function Disconnect( )
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->Connected = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->Socket->Close( );
|
|
|
|
if( !$this->Socket->Open( $Ip, (int)$Port, $Timeout, (int)$Engine ) )
|
|
|
|
$this->Rcon->Close( );
|
|
|
|
{
|
|
|
|
}
|
|
|
|
throw new SourceQueryException( 'Can\'t connect to the server.' );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
$this->Connected = true;
|
|
|
|
* 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( );
|
|
|
|
* Closes all open connections
|
|
|
|
|
|
|
|
*/
|
|
|
|
return $this->Buffer->GetByte( ) == self :: S2A_PING;
|
|
|
|
public function Disconnect( )
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Get server information
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @throws SourceQueryException
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return bool|array Returns array with information on success, false on failure
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function GetInfo( )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !$this->Connected )
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
$this->Connected = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->Socket->Close( );
|
|
|
|
|
|
|
|
$this->Rcon->Close( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->Socket->Write( self :: A2S_INFO, "Source Engine Query\0" );
|
|
|
|
/**
|
|
|
|
$this->Socket->Read( );
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$Type = $this->Buffer->GetByte( );
|
|
|
|
$this->Socket->Write( self :: A2S_PING );
|
|
|
|
|
|
|
|
$this->Socket->Read( );
|
|
|
|
|
|
|
|
|
|
|
|
if( $Type == 0 )
|
|
|
|
return $this->Buffer->GetByte( ) == self :: S2A_PING;
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Old GoldSource protocol, HLTV still uses it
|
|
|
|
/**
|
|
|
|
if( $Type == self :: S2A_INFO_OLD && $this->Socket->Engine == self :: GOLDSOURCE )
|
|
|
|
* Get server information
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @throws SourceQueryException
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return bool|array Returns array with information on success, false on failure
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function GetInfo( )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
if( !$this->Connected )
|
|
|
|
* If we try to read data again, and we get the result with type S2A_INFO (0x49)
|
|
|
|
{
|
|
|
|
* That means this server is running dproto,
|
|
|
|
return false;
|
|
|
|
* Because it sends answer for both protocols
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
$this->Socket->Write( self :: A2S_INFO, "Source Engine Query\0" );
|
|
|
|
|
|
|
|
$this->Socket->Read( );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$Type = $this->Buffer->GetByte( );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( $Type == 0 )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Old GoldSource protocol, HLTV still uses it
|
|
|
|
|
|
|
|
if( $Type == self :: S2A_INFO_OLD && $this->Socket->Engine == self :: GOLDSOURCE )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 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[ 'Address' ] = $this->Buffer->GetString( );
|
|
|
|
$Server[ 'Secure' ] = $this->Buffer->GetByte( ) == 1;
|
|
|
|
|
|
|
|
$Server[ 'Bots' ] = $this->Buffer->GetByte( );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( isset( $Mod ) )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$Server[ 'Mod' ] = $Mod;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $Server;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( $Type != self :: S2A_INFO )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new SourceQueryException( 'GetInfo: Packet header mismatch. (0x' . DecHex( $Type ) . ')' );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$Server[ 'Protocol' ] = $this->Buffer->GetByte( );
|
|
|
|
$Server[ 'HostName' ] = $this->Buffer->GetString( );
|
|
|
|
$Server[ 'HostName' ] = $this->Buffer->GetString( );
|
|
|
|
$Server[ 'Map' ] = $this->Buffer->GetString( );
|
|
|
|
$Server[ 'Map' ] = $this->Buffer->GetString( );
|
|
|
|
$Server[ 'ModDir' ] = $this->Buffer->GetString( );
|
|
|
|
$Server[ 'ModDir' ] = $this->Buffer->GetString( );
|
|
|
|
$Server[ 'ModDesc' ] = $this->Buffer->GetString( );
|
|
|
|
$Server[ 'ModDesc' ] = $this->Buffer->GetString( );
|
|
|
|
|
|
|
|
$Server[ 'AppID' ] = $this->Buffer->GetShort( );
|
|
|
|
$Server[ 'Players' ] = $this->Buffer->GetByte( );
|
|
|
|
$Server[ 'Players' ] = $this->Buffer->GetByte( );
|
|
|
|
$Server[ 'MaxPlayers' ] = $this->Buffer->GetByte( );
|
|
|
|
$Server[ 'MaxPlayers' ] = $this->Buffer->GetByte( );
|
|
|
|
$Server[ 'Protocol' ] = $this->Buffer->GetByte( );
|
|
|
|
$Server[ 'Bots' ] = $this->Buffer->GetByte( );
|
|
|
|
$Server[ 'Dedicated' ] = Chr( $this->Buffer->GetByte( ) );
|
|
|
|
$Server[ 'Dedicated' ] = Chr( $this->Buffer->GetByte( ) );
|
|
|
|
$Server[ 'Os' ] = Chr( $this->Buffer->GetByte( ) );
|
|
|
|
$Server[ 'Os' ] = Chr( $this->Buffer->GetByte( ) );
|
|
|
|
$Server[ 'Password' ] = $this->Buffer->GetByte( ) == 1;
|
|
|
|
$Server[ 'Password' ] = $this->Buffer->GetByte( ) == 1;
|
|
|
|
$Server[ 'IsMod' ] = $this->Buffer->GetByte( ) == 1;
|
|
|
|
$Server[ 'Secure' ] = $this->Buffer->GetByte( ) == 1;
|
|
|
|
|
|
|
|
|
|
|
|
if( $Server[ 'IsMod' ] )
|
|
|
|
// The Ship
|
|
|
|
|
|
|
|
if( $Server[ 'AppID' ] == 2400 )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$Mod[ 'Url' ] = $this->Buffer->GetString( );
|
|
|
|
$Server[ 'GameMode' ] = $this->Buffer->GetByte( );
|
|
|
|
$Mod[ 'Download' ] = $this->Buffer->GetString( );
|
|
|
|
$Server[ 'WitnessCount' ] = $this->Buffer->GetByte( );
|
|
|
|
$this->Buffer->Get( 1 ); // NULL byte
|
|
|
|
$Server[ 'WitnessTime' ] = $this->Buffer->GetByte( );
|
|
|
|
$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[ 'Version' ] = $this->Buffer->GetString( );
|
|
|
|
$Server[ 'Bots' ] = $this->Buffer->GetByte( );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( isset( $Mod ) )
|
|
|
|
// Extra Data Flags
|
|
|
|
|
|
|
|
if( $this->Buffer->Remaining( ) > 0 )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$Server[ 'Mod' ] = $Mod;
|
|
|
|
$Flags = $this->Buffer->GetByte( );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The server's game port
|
|
|
|
|
|
|
|
if( $Flags & 0x80 )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$Server[ 'GamePort' ] = $this->Buffer->GetShort( );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The server's SteamID - does this serve any purpose?
|
|
|
|
|
|
|
|
if( $Flags & 0x10 )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$Server[ 'ServerID' ] = $this->Buffer->GetUnsignedLong( ) | ( $this->Buffer->GetUnsignedLong( ) << 32 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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 )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$Server[ 'GameTags' ] = $this->Buffer->GetString( );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 0x01 - The server's 64-bit GameID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $Server;
|
|
|
|
return $Server;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( $Type != self :: S2A_INFO )
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Get players on the server
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @throws SourceQueryException
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return bool|array Returns array with players on success, false on failure
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function GetPlayers( )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new SourceQueryException( 'GetInfo: Packet header mismatch. (0x' . DecHex( $Type ) . ')' );
|
|
|
|
if( !$this->Connected )
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$Server[ 'Protocol' ] = $this->Buffer->GetByte( );
|
|
|
|
switch( $this->GetChallenge( self :: A2S_PLAYER, self :: S2A_PLAYER ) )
|
|
|
|
$Server[ 'HostName' ] = $this->Buffer->GetString( );
|
|
|
|
{
|
|
|
|
$Server[ 'Map' ] = $this->Buffer->GetString( );
|
|
|
|
case self :: GETCHALLENGE_FAILED:
|
|
|
|
$Server[ 'ModDir' ] = $this->Buffer->GetString( );
|
|
|
|
{
|
|
|
|
$Server[ 'ModDesc' ] = $this->Buffer->GetString( );
|
|
|
|
return false;
|
|
|
|
$Server[ 'AppID' ] = $this->Buffer->GetShort( );
|
|
|
|
}
|
|
|
|
$Server[ 'Players' ] = $this->Buffer->GetByte( );
|
|
|
|
case self :: GETCHALLENGE_ALL_CLEAR:
|
|
|
|
$Server[ 'MaxPlayers' ] = $this->Buffer->GetByte( );
|
|
|
|
{
|
|
|
|
$Server[ 'Bots' ] = $this->Buffer->GetByte( );
|
|
|
|
$this->Socket->Write( self :: A2S_PLAYER, $this->Challenge );
|
|
|
|
$Server[ 'Dedicated' ] = Chr( $this->Buffer->GetByte( ) );
|
|
|
|
$this->Socket->Read( );
|
|
|
|
$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( );
|
|
|
|
|
|
|
|
$Server[ 'WitnessCount' ] = $this->Buffer->GetByte( );
|
|
|
|
|
|
|
|
$Server[ 'WitnessTime' ] = $this->Buffer->GetByte( );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$Server[ 'Version' ] = $this->Buffer->GetString( );
|
|
|
|
$Type = $this->Buffer->GetByte( );
|
|
|
|
|
|
|
|
|
|
|
|
// Extra Data Flags
|
|
|
|
if( $Type == 0 )
|
|
|
|
if( $this->Buffer->Remaining( ) > 0 )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
$Flags = $this->Buffer->GetByte( );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( $Type != self :: S2A_PLAYER )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new SourceQueryException( 'GetPlayers: Packet header mismatch. (0x' . DecHex( $Type ) . ')' );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The server's game port
|
|
|
|
break;
|
|
|
|
if( $Flags & 0x80 )
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
$Server[ 'GamePort' ] = $this->Buffer->GetShort( );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The server's SteamID - does this serve any purpose?
|
|
|
|
$Players = Array( );
|
|
|
|
if( $Flags & 0x10 )
|
|
|
|
$Count = $this->Buffer->GetByte( );
|
|
|
|
{
|
|
|
|
|
|
|
|
$Server[ 'ServerID' ] = $this->Buffer->GetUnsignedLong( ) | ( $this->Buffer->GetUnsignedLong( ) << 32 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The spectator port and then the spectator server name
|
|
|
|
while( $Count-- > 0 && $this->Buffer->Remaining( ) > 0 )
|
|
|
|
if( $Flags & 0x40 )
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$Server[ 'SpecPort' ] = $this->Buffer->GetShort( );
|
|
|
|
$Player[ 'Id' ] = $this->Buffer->GetByte( ); // PlayerID, is it just always 0?
|
|
|
|
$Server[ 'SpecName' ] = $this->Buffer->GetString( );
|
|
|
|
$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' ] );
|
|
|
|
|
|
|
|
|
|
|
|
// The game tag data string for the server
|
|
|
|
$Players[ ] = $Player;
|
|
|
|
if( $Flags & 0x20 )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$Server[ 'GameTags' ] = $this->Buffer->GetString( );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 0x01 - The server's 64-bit GameID
|
|
|
|
return $Players;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $Server;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Get players on the server
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @throws SourceQueryException
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return bool|array Returns array with players on success, false on failure
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function GetPlayers( )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !$this->Connected )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch( $this->GetChallenge( self :: A2S_PLAYER, self :: S2A_PLAYER ) )
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Get rules (cvars) from the server
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @throws SourceQueryException
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return bool|array Returns array with rules on success, false on failure
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function GetRules( )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case self :: GETCHALLENGE_FAILED:
|
|
|
|
if( !$this->Connected )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case self :: GETCHALLENGE_ALL_CLEAR:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->Socket->Write( self :: A2S_PLAYER, $this->Challenge );
|
|
|
|
|
|
|
|
$this->Socket->Read( );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$Type = $this->Buffer->GetByte( );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( $Type == 0 )
|
|
|
|
switch( $this->GetChallenge( self :: A2S_RULES, self :: S2A_RULES ) )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case self :: GETCHALLENGE_FAILED:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( $Type != self :: S2A_PLAYER )
|
|
|
|
case self :: GETCHALLENGE_ALL_CLEAR:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new SourceQueryException( 'GetPlayers: Packet header mismatch. (0x' . DecHex( $Type ) . ')' );
|
|
|
|
$this->Socket->Write( self :: A2S_RULES, $this->Challenge );
|
|
|
|
}
|
|
|
|
$this->Socket->Read( );
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
$Type = $this->Buffer->GetByte( );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$Players = Array( );
|
|
|
|
if( $Type == 0 )
|
|
|
|
$Count = $this->Buffer->GetByte( );
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( $Type != self :: S2A_RULES )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new SourceQueryException( 'GetRules: Packet header mismatch. (0x' . DecHex( $Type ) . ')' );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while( $Count-- > 0 && $this->Buffer->Remaining( ) > 0 )
|
|
|
|
break;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
$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;
|
|
|
|
$Rules = Array( );
|
|
|
|
}
|
|
|
|
$Count = $this->Buffer->GetShort( );
|
|
|
|
|
|
|
|
|
|
|
|
return $Players;
|
|
|
|
while( $Count-- > 0 && $this->Buffer->Remaining( ) > 0 )
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
$Rule = $this->Buffer->GetString( );
|
|
|
|
|
|
|
|
$Value = $this->Buffer->GetString( );
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
if( !Empty( $Rule ) )
|
|
|
|
* Get rules (cvars) from the server
|
|
|
|
{
|
|
|
|
*
|
|
|
|
$Rules[ $Rule ] = $Value;
|
|
|
|
* @throws SourceQueryException
|
|
|
|
}
|
|
|
|
*
|
|
|
|
}
|
|
|
|
* @return bool|array Returns array with rules on success, false on failure
|
|
|
|
|
|
|
|
*/
|
|
|
|
return $Rules;
|
|
|
|
public function GetRules( )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !$this->Connected )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch( $this->GetChallenge( self :: A2S_RULES, self :: S2A_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 )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case self :: GETCHALLENGE_FAILED:
|
|
|
|
if( $this->Challenge )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return self :: GETCHALLENGE_ALL_CLEAR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case self :: GETCHALLENGE_ALL_CLEAR:
|
|
|
|
|
|
|
|
|
|
|
|
$this->Socket->Write( $Header, 0xFFFFFFFF );
|
|
|
|
|
|
|
|
$this->Socket->Read( );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$Type = $this->Buffer->GetByte( );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch( $Type )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->Socket->Write( self :: A2S_RULES, $this->Challenge );
|
|
|
|
case self :: S2A_CHALLENGE:
|
|
|
|
$this->Socket->Read( );
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->Challenge = $this->Buffer->Get( 4 );
|
|
|
|
|
|
|
|
|
|
|
|
$Type = $this->Buffer->GetByte( );
|
|
|
|
return self :: GETCHALLENGE_ALL_CLEAR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case $ExpectedResult:
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Goldsource (HLTV)
|
|
|
|
|
|
|
|
|
|
|
|
if( $Type == 0 )
|
|
|
|
return self :: GETCHALLENGE_CONTAINS_ANSWER;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return self :: GETCHALLENGE_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( $Type != self :: S2A_RULES )
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new SourceQueryException( 'GetRules: Packet header mismatch. (0x' . DecHex( $Type ) . ')' );
|
|
|
|
throw new SourceQueryException( 'GetChallenge: Packet header mismatch. (0x' . DecHex( $Type ) . ')' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$Rules = Array( );
|
|
|
|
/**
|
|
|
|
$Count = $this->Buffer->GetShort( );
|
|
|
|
* Sets rcon password, for future use in Rcon()
|
|
|
|
|
|
|
|
*
|
|
|
|
while( $Count-- > 0 && $this->Buffer->Remaining( ) > 0 )
|
|
|
|
* @param string $Password Rcon Password
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return bool True on success, false on failure
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function SetRconPassword( $Password )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$Rule = $this->Buffer->GetString( );
|
|
|
|
if( !$this->Connected )
|
|
|
|
$Value = $this->Buffer->GetString( );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( !Empty( $Rule ) )
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$Rules[ $Rule ] = $Value;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $Rules;
|
|
|
|
$this->Rcon->Open( );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
return $this->Rcon->Authorize( $Password );
|
|
|
|
* 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_ALL_CLEAR;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->Socket->Write( $Header, 0xFFFFFFFF );
|
|
|
|
/**
|
|
|
|
$this->Socket->Read( );
|
|
|
|
* Sets rcon password, for future use in Rcon()
|
|
|
|
|
|
|
|
*
|
|
|
|
$Type = $this->Buffer->GetByte( );
|
|
|
|
* @param string $Command Command to execute on the server
|
|
|
|
|
|
|
|
*
|
|
|
|
switch( $Type )
|
|
|
|
* @return bool|string Answer from server in string, false on failure
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function Rcon( $Command )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case self :: S2A_CHALLENGE:
|
|
|
|
if( !$this->Connected )
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->Challenge = $this->Buffer->Get( 4 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return self :: GETCHALLENGE_ALL_CLEAR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case $ExpectedResult:
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Goldsource (HLTV)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string $Password Rcon Password
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return bool True on success, false on failure
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function SetRconPassword( $Password )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !$this->Connected )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->Rcon->Open( );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->Rcon->Authorize( $Password );
|
|
|
|
return $this->Rcon->Command( $Command );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Sets rcon password, for future use in Rcon()
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this->Rcon->Command( $Command );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|