mirror of
https://github.com/xPaw/PHP-Source-Query.git
synced 2026-05-18 14:33:34 +02:00
Minor cosmetic changes, throw an error when rcon read fails (#42)
This commit is contained in:
@@ -10,7 +10,7 @@ namespace xPaw\SourceQuery\Exception;
|
|||||||
|
|
||||||
abstract class SourceQueryException extends \Exception
|
abstract class SourceQueryException extends \Exception
|
||||||
{
|
{
|
||||||
|
// Base exception class
|
||||||
}
|
}
|
||||||
|
|
||||||
class InvalidArgumentException extends SourceQueryException
|
class InvalidArgumentException extends SourceQueryException
|
||||||
@@ -26,9 +26,9 @@ class TimeoutException extends SourceQueryException
|
|||||||
class InvalidPacketException extends SourceQueryException
|
class InvalidPacketException extends SourceQueryException
|
||||||
{
|
{
|
||||||
const PACKET_HEADER_MISMATCH = 1;
|
const PACKET_HEADER_MISMATCH = 1;
|
||||||
const BUFFER_NOT_EMPTY = 2;
|
const BUFFER_EMPTY = 2;
|
||||||
|
const BUFFER_NOT_EMPTY = 3;
|
||||||
const CHECKSUM_MISMATCH = 3;
|
const CHECKSUM_MISMATCH = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
class AuthenticationException extends SourceQueryException
|
class AuthenticationException extends SourceQueryException
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
use xPaw\SourceQuery\Exception\InvalidPacketException;
|
|
||||||
use xPaw\SourceQuery\Exception\SocketException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class written by xPaw
|
* Class written by xPaw
|
||||||
*
|
*
|
||||||
@@ -9,6 +6,9 @@ use xPaw\SourceQuery\Exception\SocketException;
|
|||||||
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
|
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use xPaw\SourceQuery\Exception\InvalidPacketException;
|
||||||
|
use xPaw\SourceQuery\Exception\SocketException;
|
||||||
|
|
||||||
class SourceQuerySocket
|
class SourceQuerySocket
|
||||||
{
|
{
|
||||||
public $Socket;
|
public $Socket;
|
||||||
|
|||||||
@@ -143,12 +143,12 @@
|
|||||||
|
|
||||||
if( !is_int( $Timeout ) || $Timeout < 0 )
|
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 ) )
|
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;
|
$this->Connected = true;
|
||||||
@@ -279,7 +279,7 @@
|
|||||||
|
|
||||||
if( $Type !== self :: S2A_INFO )
|
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( );
|
$Server[ 'Protocol' ] = $this->Buffer->GetByte( );
|
||||||
@@ -344,7 +344,7 @@
|
|||||||
|
|
||||||
if( $this->Buffer->Remaining( ) > 0 )
|
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 );
|
InvalidPacketException::BUFFER_NOT_EMPTY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
use xPaw\SourceQuery\Exception\AuthenticationException;
|
|
||||||
use xPaw\SourceQuery\Exception\TimeoutException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class written by xPaw
|
* Class written by xPaw
|
||||||
*
|
*
|
||||||
@@ -9,6 +6,10 @@ use xPaw\SourceQuery\Exception\TimeoutException;
|
|||||||
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
|
* 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
|
class SourceQuerySourceRcon
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -78,6 +79,11 @@ use xPaw\SourceQuery\Exception\TimeoutException;
|
|||||||
{
|
{
|
||||||
$this->Buffer->Set( FRead( $this->RconSocket, $Length ) );
|
$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( );
|
$PacketSize = $this->Buffer->GetLong( );
|
||||||
|
|
||||||
$Buffer = $this->Buffer->Get( );
|
$Buffer = $this->Buffer->Get( );
|
||||||
@@ -102,6 +108,7 @@ use xPaw\SourceQuery\Exception\TimeoutException;
|
|||||||
$this->Read( );
|
$this->Read( );
|
||||||
|
|
||||||
$this->Buffer->GetLong( ); // RequestID
|
$this->Buffer->GetLong( ); // RequestID
|
||||||
|
|
||||||
$Type = $this->Buffer->GetLong( );
|
$Type = $this->Buffer->GetLong( );
|
||||||
|
|
||||||
if( $Type === SourceQuery :: SERVERDATA_AUTH_RESPONSE )
|
if( $Type === SourceQuery :: SERVERDATA_AUTH_RESPONSE )
|
||||||
|
|||||||
Reference in New Issue
Block a user