mirror of
https://github.com/xPaw/PHP-Source-Query.git
synced 2026-06-08 00:36:01 +02:00
Fix up some type information
This commit is contained in:
@@ -13,13 +13,15 @@
|
|||||||
namespace xPaw\SourceQuery;
|
namespace xPaw\SourceQuery;
|
||||||
|
|
||||||
use xPaw\SourceQuery\Exception\InvalidPacketException;
|
use xPaw\SourceQuery\Exception\InvalidPacketException;
|
||||||
|
use xPaw\SourceQuery\Exception\SocketException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base socket interface
|
* Base socket interface
|
||||||
*
|
*
|
||||||
* @package xPaw\SourceQuery
|
* @package xPaw\SourceQuery
|
||||||
*
|
*
|
||||||
* @uses xPaw\SourceQuery\Exception\InvalidPacketException
|
* @uses xPaw\SourceQuery\Exception\InvalidPacketException
|
||||||
|
* @uses xPaw\SourceQuery\Exception\SocketException
|
||||||
*/
|
*/
|
||||||
abstract class BaseSocket
|
abstract class BaseSocket
|
||||||
{
|
{
|
||||||
@@ -58,6 +60,7 @@
|
|||||||
$Packets = [];
|
$Packets = [];
|
||||||
$IsCompressed = false;
|
$IsCompressed = false;
|
||||||
$ReadMore = false;
|
$ReadMore = false;
|
||||||
|
$PacketChecksum = null;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -92,6 +95,10 @@
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
throw new SocketException( 'Unknown engine.', SocketException::INVALID_ENGINE );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$Packets[ $PacketNumber ] = $Buffer->Get( );
|
$Packets[ $PacketNumber ] = $Buffer->Get( );
|
||||||
@@ -113,7 +120,7 @@
|
|||||||
|
|
||||||
$Data = bzdecompress( $Data );
|
$Data = bzdecompress( $Data );
|
||||||
|
|
||||||
if( CRC32( $Data ) !== $PacketChecksum )
|
if( !is_string( $Data ) || CRC32( $Data ) !== $PacketChecksum )
|
||||||
{
|
{
|
||||||
throw new InvalidPacketException( 'CRC32 checksum mismatch of uncompressed packet data.', InvalidPacketException::CHECKSUM_MISMATCH );
|
throw new InvalidPacketException( 'CRC32 checksum mismatch of uncompressed packet data.', InvalidPacketException::CHECKSUM_MISMATCH );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,5 @@
|
|||||||
const COULD_NOT_CREATE_SOCKET = 1;
|
const COULD_NOT_CREATE_SOCKET = 1;
|
||||||
const NOT_CONNECTED = 2;
|
const NOT_CONNECTED = 2;
|
||||||
const CONNECTION_FAILED = 3;
|
const CONNECTION_FAILED = 3;
|
||||||
|
const INVALID_ENGINE = 3;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
private $Socket;
|
private $Socket;
|
||||||
|
|
||||||
private $RconPassword;
|
private $RconPassword;
|
||||||
private $RconRequestId;
|
|
||||||
private $RconChallenge;
|
private $RconChallenge;
|
||||||
|
|
||||||
public function __construct( $Socket )
|
public function __construct( $Socket )
|
||||||
@@ -44,7 +43,6 @@
|
|||||||
public function Close( )
|
public function Close( )
|
||||||
{
|
{
|
||||||
$this->RconChallenge = 0;
|
$this->RconChallenge = 0;
|
||||||
$this->RconRequestId = 0;
|
|
||||||
$this->RconPassword = 0;
|
$this->RconPassword = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +62,7 @@
|
|||||||
/**
|
/**
|
||||||
* @param int $Length
|
* @param int $Length
|
||||||
* @throws AuthenticationException
|
* @throws AuthenticationException
|
||||||
* @return bool
|
* @return Buffer
|
||||||
*/
|
*/
|
||||||
public function Read( $Length = 1400 )
|
public function Read( $Length = 1400 )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,14 +70,14 @@
|
|||||||
/**
|
/**
|
||||||
* Points to rcon class
|
* Points to rcon class
|
||||||
*
|
*
|
||||||
* @var SourceRcon
|
* @var SourceRcon|GoldSourceRcon|null
|
||||||
*/
|
*/
|
||||||
private $Rcon;
|
private $Rcon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Points to socket class
|
* Points to socket class
|
||||||
*
|
*
|
||||||
* @var Socket
|
* @var BaseSocket
|
||||||
*/
|
*/
|
||||||
private $Socket;
|
private $Socket;
|
||||||
|
|
||||||
@@ -159,7 +159,7 @@
|
|||||||
public function Disconnect( )
|
public function Disconnect( )
|
||||||
{
|
{
|
||||||
$this->Connected = false;
|
$this->Connected = false;
|
||||||
$this->Challenge = 0;
|
$this->Challenge = '';
|
||||||
|
|
||||||
$this->Socket->Close( );
|
$this->Socket->Close( );
|
||||||
|
|
||||||
@@ -212,6 +212,7 @@
|
|||||||
$Buffer = $this->Socket->Read( );
|
$Buffer = $this->Socket->Read( );
|
||||||
|
|
||||||
$Type = $Buffer->GetByte( );
|
$Type = $Buffer->GetByte( );
|
||||||
|
$Server = [];
|
||||||
|
|
||||||
// Old GoldSource protocol, HLTV still uses it
|
// Old GoldSource protocol, HLTV still uses it
|
||||||
if( $Type === self::S2A_INFO_OLD && $this->Socket->Engine === self::GOLDSOURCE )
|
if( $Type === self::S2A_INFO_OLD && $this->Socket->Engine === self::GOLDSOURCE )
|
||||||
@@ -237,6 +238,7 @@
|
|||||||
|
|
||||||
if( $Server[ 'IsMod' ] )
|
if( $Server[ 'IsMod' ] )
|
||||||
{
|
{
|
||||||
|
$Mod = [];
|
||||||
$Mod[ 'Url' ] = $Buffer->GetString( );
|
$Mod[ 'Url' ] = $Buffer->GetString( );
|
||||||
$Mod[ 'Download' ] = $Buffer->GetString( );
|
$Mod[ 'Download' ] = $Buffer->GetString( );
|
||||||
$Buffer->Get( 1 ); // NULL byte
|
$Buffer->Get( 1 ); // NULL byte
|
||||||
@@ -391,6 +393,7 @@
|
|||||||
|
|
||||||
while( $Count-- > 0 && $Buffer->Remaining( ) > 0 )
|
while( $Count-- > 0 && $Buffer->Remaining( ) > 0 )
|
||||||
{
|
{
|
||||||
|
$Player = [];
|
||||||
$Player[ 'Id' ] = $Buffer->GetByte( ); // PlayerID, is it just always 0?
|
$Player[ 'Id' ] = $Buffer->GetByte( ); // PlayerID, is it just always 0?
|
||||||
$Player[ 'Name' ] = $Buffer->GetString( );
|
$Player[ 'Name' ] = $Buffer->GetString( );
|
||||||
$Player[ 'Frags' ] = $Buffer->GetLong( );
|
$Player[ 'Frags' ] = $Buffer->GetLong( );
|
||||||
@@ -527,6 +530,10 @@
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
throw new SocketException( 'Unknown engine.', SocketException::INVALID_ENGINE );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->Rcon->Open( );
|
$this->Rcon->Open( );
|
||||||
|
|||||||
+2
-2
@@ -71,7 +71,7 @@
|
|||||||
{
|
{
|
||||||
$this->Socket = new TestableSocket();
|
$this->Socket = new TestableSocket();
|
||||||
$this->SourceQuery = new SourceQuery( $this->Socket );
|
$this->SourceQuery = new SourceQuery( $this->Socket );
|
||||||
$this->SourceQuery->Connect( 1, 2 );
|
$this->SourceQuery->Connect( '', 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
public function testInvalidTimeout()
|
public function testInvalidTimeout()
|
||||||
{
|
{
|
||||||
$SourceQuery = new SourceQuery( );
|
$SourceQuery = new SourceQuery( );
|
||||||
$SourceQuery->Connect( 1, 2, -1 );
|
$SourceQuery->Connect( '', 2, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user