diff --git a/SourceQuery/Exceptions.class.php b/SourceQuery/Exceptions.class.php index 87c1628..f9b3c29 100644 --- a/SourceQuery/Exceptions.class.php +++ b/SourceQuery/Exceptions.class.php @@ -1,43 +1,43 @@ Buffer->Get( ); $Trimmed = Trim( $Buffer ); - if($Trimmed === 'Bad rcon_password.') + if( $Trimmed === 'Bad rcon_password.' ) { - throw new AuthenticationException($Trimmed, AuthenticationException::BAD_PASSWORD); + throw new AuthenticationException( $Trimmed, AuthenticationException::BAD_PASSWORD ); } - else if($Trimmed === 'You have been banned from this server.') + else if( $Trimmed === 'You have been banned from this server.' ) { - throw new AuthenticationException($Trimmed, AuthenticationException::BANNED); + throw new AuthenticationException( $Trimmed, AuthenticationException::BANNED ); } $ReadMore = false; diff --git a/SourceQuery/Socket.class.php b/SourceQuery/Socket.class.php index e8f46f6..3e3113d 100644 --- a/SourceQuery/Socket.class.php +++ b/SourceQuery/Socket.class.php @@ -1,14 +1,14 @@ Socket === false ) { - throw new SocketException( 'Could not create socket: ' . $ErrStr, SocketException::COULD_NOT_CREATE_SOCKET); + throw new SocketException( 'Could not create socket: ' . $ErrStr, SocketException::COULD_NOT_CREATE_SOCKET ); } Stream_Set_Timeout( $this->Socket, $Timeout ); @@ -146,7 +146,7 @@ public function Read( $Length = 1400 ) if( CRC32( $Buffer ) !== $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 ); } } @@ -154,7 +154,7 @@ public function Read( $Length = 1400 ) } else { - throw new InvalidPacketException( 'Socket read: Raw packet header mismatch. (0x' . DecHex( $Header ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH); + throw new InvalidPacketException( 'Socket read: Raw packet header mismatch. (0x' . DecHex( $Header ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH ); } } diff --git a/SourceQuery/SourceQuery.class.php b/SourceQuery/SourceQuery.class.php index fb359b4..f44e2be 100644 --- a/SourceQuery/SourceQuery.class.php +++ b/SourceQuery/SourceQuery.class.php @@ -143,12 +143,12 @@ public function Connect( $Ip, $Port, $Timeout = 3, $Engine = self :: SOURCE ) if( !is_int( $Timeout ) || $Timeout < 0 ) { - throw new InvalidArgumentException("Timeout must be an integer.", InvalidArgumentException::TIMEOUT_NOT_INTEGER); + throw new InvalidArgumentException( 'Timeout must be an integer.', InvalidArgumentException::TIMEOUT_NOT_INTEGER ); } if( !$this->Socket->Open( $Ip, (int)$Port, $Timeout, (int)$Engine ) ) { - throw new TimeoutException("Could not connect to server.", TimeoutException::TIMEOUT_CONNECT); + throw new TimeoutException( 'Could not connect to server.', TimeoutException::TIMEOUT_CONNECT ); } $this->Connected = true; @@ -279,7 +279,7 @@ public function GetInfo( ) if( $Type !== self :: S2A_INFO ) { - throw new InvalidPacketException("GetInfo: Packet header mismatch. (0x' . DecHex( $Type ) . ')", InvalidPacketException::PACKET_HEADER_MISMATCH); + throw new InvalidPacketException( 'GetInfo: Packet header mismatch. (0x' . DecHex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH ); } $Server[ 'Protocol' ] = $this->Buffer->GetByte( ); @@ -344,8 +344,8 @@ public function GetInfo( ) if( $this->Buffer->Remaining( ) > 0 ) { - throw new InvalidPacketException("GetInfo: unread data? " . $this->Buffer->Remaining( ) . " bytes remaining in the buffer. Please report it to the library developer.", - InvalidPacketException::BUFFER_NOT_EMPTY); + throw new InvalidPacketException( 'GetInfo: unread data? ' . $this->Buffer->Remaining( ) . ' bytes remaining in the buffer. Please report it to the library developer.', + InvalidPacketException::BUFFER_NOT_EMPTY ); } } @@ -386,7 +386,7 @@ public function GetPlayers( ) } else if( $Type !== self :: S2A_PLAYER ) { - throw new InvalidPacketException( 'GetPlayers: Packet header mismatch. (0x' . DecHex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH); + throw new InvalidPacketException( 'GetPlayers: Packet header mismatch. (0x' . DecHex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH ); } break; @@ -443,7 +443,7 @@ public function GetRules( ) } else if( $Type !== self :: S2A_RULES ) { - throw new InvalidPacketException( 'GetRules: Packet header mismatch. (0x' . DecHex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH); + throw new InvalidPacketException( 'GetRules: Packet header mismatch. (0x' . DecHex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH ); } break; @@ -512,7 +512,7 @@ private function GetChallenge( $Header, $ExpectedResult ) } default: { - throw new InvalidPacketException( 'GetChallenge: Packet header mismatch. (0x' . DecHex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH); + throw new InvalidPacketException( 'GetChallenge: Packet header mismatch. (0x' . DecHex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH ); } } } diff --git a/SourceQuery/SourceRcon.class.php b/SourceQuery/SourceRcon.class.php index fd35fbf..d6c9b41 100644 --- a/SourceQuery/SourceRcon.class.php +++ b/SourceQuery/SourceRcon.class.php @@ -1,14 +1,15 @@ RconSocket ) { - throw new TimeoutException( 'Can\'t connect to RCON server: ' . $ErrStr, TimeoutException::TIMEOUT_CONNECT); + throw new TimeoutException( 'Can\'t connect to RCON server: ' . $ErrStr, TimeoutException::TIMEOUT_CONNECT ); } Stream_Set_Timeout( $this->RconSocket, $this->Socket->Timeout ); @@ -78,6 +79,11 @@ public function Read( $Length = 1400 ) { $this->Buffer->Set( FRead( $this->RconSocket, $Length ) ); + if( $this->Buffer->Remaining( ) < 4 ) + { + throw new InvalidPacketException( 'Rcon read: Failed to read any data from socket', InvalidPacketException::BUFFER_EMPTY ); + } + $PacketSize = $this->Buffer->GetLong( ); $Buffer = $this->Buffer->Get( ); @@ -102,11 +108,12 @@ public function Command( $Command ) $this->Read( ); $this->Buffer->GetLong( ); // RequestID - $Type = $this->Buffer->GetLong( ); + + $Type = $this->Buffer->GetLong( ); if( $Type === SourceQuery :: SERVERDATA_AUTH_RESPONSE ) { - throw new AuthenticationException( 'Bad rcon_password.', AuthenticationException::BAD_PASSWORD); + throw new AuthenticationException( 'Bad rcon_password.', AuthenticationException::BAD_PASSWORD ); } else if( $Type !== SourceQuery :: SERVERDATA_RESPONSE_VALUE ) { @@ -163,7 +170,7 @@ public function Authorize( $Password ) if( $RequestID === -1 || $Type !== SourceQuery :: SERVERDATA_AUTH_RESPONSE ) { - throw new AuthenticationException( 'RCON authorization failed.', AuthenticationException::BAD_PASSWORD); + throw new AuthenticationException( 'RCON authorization failed.', AuthenticationException::BAD_PASSWORD ); } return true;