From f41e4b551c1a6a98537831a9fc89895b4899001f Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 19 Oct 2015 21:43:07 +0300 Subject: [PATCH] Throw an exception when nothing was read from socket --- SourceQuery/Socket.php | 5 ++--- SourceQuery/SourceQuery.php | 17 ----------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/SourceQuery/Socket.php b/SourceQuery/Socket.php index 1a19adf..554584d 100644 --- a/SourceQuery/Socket.php +++ b/SourceQuery/Socket.php @@ -82,15 +82,14 @@ if( $Buffer->Remaining( ) === 0 ) { - // TODO: Should we throw an exception here? - return; + throw new InvalidPacketException( 'Failed to read any data from socket', InvalidPacketException::BUFFER_EMPTY ); } $Header = $Buffer->GetLong( ); if( $Header === -1 ) // Single packet { - // We don't have to do anything + // We don't have to do anything } else if( $Header === -2 ) // Split packet { diff --git a/SourceQuery/SourceQuery.php b/SourceQuery/SourceQuery.php index b4fe8e3..1e4770d 100644 --- a/SourceQuery/SourceQuery.php +++ b/SourceQuery/SourceQuery.php @@ -192,8 +192,6 @@ if( !$this->Connected ) { throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED ); - - return false; } $this->Socket->Write( self::A2S_PING ); @@ -215,8 +213,6 @@ if( !$this->Connected ) { throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED ); - - return false; } $this->Socket->Write( self::A2S_INFO, "Source Engine Query\0" ); @@ -224,11 +220,6 @@ $Type = $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 ) { @@ -361,8 +352,6 @@ if( !$this->Connected ) { throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED ); - - return false; } switch( $this->GetChallenge( self::A2S_PLAYER, self::S2A_PLAYER ) ) @@ -422,8 +411,6 @@ if( !$this->Connected ) { throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED ); - - return false; } switch( $this->GetChallenge( self::A2S_RULES, self::S2A_RULES ) ) @@ -537,8 +524,6 @@ if( !$this->Connected ) { throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED ); - - return false; } switch( $this->Socket->Engine ) @@ -578,8 +563,6 @@ if( !$this->Connected ) { throw new SocketException( 'Not connected.', SocketException::NOT_CONNECTED ); - - return false; } return $this->Rcon->Command( $Command );