From b87c9faab9a65868aa4c19ab8b48e43a840cda22 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 23 Jun 2020 19:44:51 +0300 Subject: [PATCH] Fix up some type information --- SourceQuery/BaseSocket.php | 11 +++++++++-- SourceQuery/Exception/SocketException.php | 1 + SourceQuery/GoldSourceRcon.php | 4 +--- SourceQuery/SourceQuery.php | 13 ++++++++++--- Tests/Tests.php | 4 ++-- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/SourceQuery/BaseSocket.php b/SourceQuery/BaseSocket.php index 1b1c01c..ecc6531 100644 --- a/SourceQuery/BaseSocket.php +++ b/SourceQuery/BaseSocket.php @@ -13,13 +13,15 @@ namespace xPaw\SourceQuery; use xPaw\SourceQuery\Exception\InvalidPacketException; - + use xPaw\SourceQuery\Exception\SocketException; + /** * Base socket interface * * @package xPaw\SourceQuery * * @uses xPaw\SourceQuery\Exception\InvalidPacketException + * @uses xPaw\SourceQuery\Exception\SocketException */ abstract class BaseSocket { @@ -58,6 +60,7 @@ $Packets = []; $IsCompressed = false; $ReadMore = false; + $PacketChecksum = null; do { @@ -92,6 +95,10 @@ break; } + default: + { + throw new SocketException( 'Unknown engine.', SocketException::INVALID_ENGINE ); + } } $Packets[ $PacketNumber ] = $Buffer->Get( ); @@ -113,7 +120,7 @@ $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 ); } diff --git a/SourceQuery/Exception/SocketException.php b/SourceQuery/Exception/SocketException.php index a6d9b86..0619398 100644 --- a/SourceQuery/Exception/SocketException.php +++ b/SourceQuery/Exception/SocketException.php @@ -17,4 +17,5 @@ const COULD_NOT_CREATE_SOCKET = 1; const NOT_CONNECTED = 2; const CONNECTION_FAILED = 3; + const INVALID_ENGINE = 3; } diff --git a/SourceQuery/GoldSourceRcon.php b/SourceQuery/GoldSourceRcon.php index 3a94d6c..4665b5b 100644 --- a/SourceQuery/GoldSourceRcon.php +++ b/SourceQuery/GoldSourceRcon.php @@ -33,7 +33,6 @@ private $Socket; private $RconPassword; - private $RconRequestId; private $RconChallenge; public function __construct( $Socket ) @@ -44,7 +43,6 @@ public function Close( ) { $this->RconChallenge = 0; - $this->RconRequestId = 0; $this->RconPassword = 0; } @@ -64,7 +62,7 @@ /** * @param int $Length * @throws AuthenticationException - * @return bool + * @return Buffer */ public function Read( $Length = 1400 ) { diff --git a/SourceQuery/SourceQuery.php b/SourceQuery/SourceQuery.php index af8edcd..8daa12b 100644 --- a/SourceQuery/SourceQuery.php +++ b/SourceQuery/SourceQuery.php @@ -70,14 +70,14 @@ /** * Points to rcon class * - * @var SourceRcon + * @var SourceRcon|GoldSourceRcon|null */ private $Rcon; /** * Points to socket class * - * @var Socket + * @var BaseSocket */ private $Socket; @@ -159,7 +159,7 @@ public function Disconnect( ) { $this->Connected = false; - $this->Challenge = 0; + $this->Challenge = ''; $this->Socket->Close( ); @@ -212,6 +212,7 @@ $Buffer = $this->Socket->Read( ); $Type = $Buffer->GetByte( ); + $Server = []; // Old GoldSource protocol, HLTV still uses it if( $Type === self::S2A_INFO_OLD && $this->Socket->Engine === self::GOLDSOURCE ) @@ -237,6 +238,7 @@ if( $Server[ 'IsMod' ] ) { + $Mod = []; $Mod[ 'Url' ] = $Buffer->GetString( ); $Mod[ 'Download' ] = $Buffer->GetString( ); $Buffer->Get( 1 ); // NULL byte @@ -391,6 +393,7 @@ while( $Count-- > 0 && $Buffer->Remaining( ) > 0 ) { + $Player = []; $Player[ 'Id' ] = $Buffer->GetByte( ); // PlayerID, is it just always 0? $Player[ 'Name' ] = $Buffer->GetString( ); $Player[ 'Frags' ] = $Buffer->GetLong( ); @@ -527,6 +530,10 @@ break; } + default: + { + throw new SocketException( 'Unknown engine.', SocketException::INVALID_ENGINE ); + } } $this->Rcon->Open( ); diff --git a/Tests/Tests.php b/Tests/Tests.php index 3f11357..481f171 100644 --- a/Tests/Tests.php +++ b/Tests/Tests.php @@ -71,7 +71,7 @@ { $this->Socket = new TestableSocket(); $this->SourceQuery = new SourceQuery( $this->Socket ); - $this->SourceQuery->Connect( 1, 2 ); + $this->SourceQuery->Connect( '', 2 ); } public function tearDown() @@ -87,7 +87,7 @@ public function testInvalidTimeout() { $SourceQuery = new SourceQuery( ); - $SourceQuery->Connect( 1, 2, -1 ); + $SourceQuery->Connect( '', 2, -1 ); } /**