Minor cosmetic changes, throw an error when rcon read fails (#42)

pull/56/head
xPaw 10 years ago
parent 3bae84ca68
commit 50729990c6

@ -10,7 +10,7 @@ namespace xPaw\SourceQuery\Exception;
abstract class SourceQueryException extends \Exception
{
// Base exception class
}
class InvalidArgumentException extends SourceQueryException
@ -26,9 +26,9 @@ class TimeoutException extends SourceQueryException
class InvalidPacketException extends SourceQueryException
{
const PACKET_HEADER_MISMATCH = 1;
const BUFFER_NOT_EMPTY = 2;
const CHECKSUM_MISMATCH = 3;
const BUFFER_EMPTY = 2;
const BUFFER_NOT_EMPTY = 3;
const CHECKSUM_MISMATCH = 4;
}
class AuthenticationException extends SourceQueryException

@ -1,7 +1,4 @@
<?php
use xPaw\SourceQuery\Exception\InvalidPacketException;
use xPaw\SourceQuery\Exception\SocketException;
/**
* Class written by xPaw
*
@ -9,6 +6,9 @@ use xPaw\SourceQuery\Exception\SocketException;
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
*/
use xPaw\SourceQuery\Exception\InvalidPacketException;
use xPaw\SourceQuery\Exception\SocketException;
class SourceQuerySocket
{
public $Socket;

@ -143,12 +143,12 @@
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 @@
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,7 +344,7 @@
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.",
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 );
}
}

@ -1,7 +1,4 @@
<?php
use xPaw\SourceQuery\Exception\AuthenticationException;
use xPaw\SourceQuery\Exception\TimeoutException;
/**
* Class written by xPaw
*
@ -9,6 +6,10 @@ use xPaw\SourceQuery\Exception\TimeoutException;
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
*/
use xPaw\SourceQuery\Exception\AuthenticationException;
use xPaw\SourceQuery\Exception\TimeoutException;
use xPaw\SourceQuery\Exception\InvalidPacketException;
class SourceQuerySourceRcon
{
/**
@ -78,6 +79,11 @@ use xPaw\SourceQuery\Exception\TimeoutException;
{
$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,6 +108,7 @@ use xPaw\SourceQuery\Exception\TimeoutException;
$this->Read( );
$this->Buffer->GetLong( ); // RequestID
$Type = $this->Buffer->GetLong( );
if( $Type === SourceQuery :: SERVERDATA_AUTH_RESPONSE )

Loading…
Cancel
Save