Skip to content

Commit b87c9fa

Browse files
committed
Fix up some type information
1 parent 1078e47 commit b87c9fa

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

SourceQuery/BaseSocket.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
namespace xPaw\SourceQuery;
1414

1515
use xPaw\SourceQuery\Exception\InvalidPacketException;
16-
16+
use xPaw\SourceQuery\Exception\SocketException;
17+
1718
/**
1819
* Base socket interface
1920
*
2021
* @package xPaw\SourceQuery
2122
*
2223
* @uses xPaw\SourceQuery\Exception\InvalidPacketException
24+
* @uses xPaw\SourceQuery\Exception\SocketException
2325
*/
2426
abstract class BaseSocket
2527
{
@@ -58,6 +60,7 @@ protected function ReadInternal( $Buffer, $Length, $SherlockFunction )
5860
$Packets = [];
5961
$IsCompressed = false;
6062
$ReadMore = false;
63+
$PacketChecksum = null;
6164

6265
do
6366
{
@@ -92,6 +95,10 @@ protected function ReadInternal( $Buffer, $Length, $SherlockFunction )
9295

9396
break;
9497
}
98+
default:
99+
{
100+
throw new SocketException( 'Unknown engine.', SocketException::INVALID_ENGINE );
101+
}
95102
}
96103

97104
$Packets[ $PacketNumber ] = $Buffer->Get( );
@@ -113,7 +120,7 @@ protected function ReadInternal( $Buffer, $Length, $SherlockFunction )
113120

114121
$Data = bzdecompress( $Data );
115122

116-
if( CRC32( $Data ) !== $PacketChecksum )
123+
if( !is_string( $Data ) || CRC32( $Data ) !== $PacketChecksum )
117124
{
118125
throw new InvalidPacketException( 'CRC32 checksum mismatch of uncompressed packet data.', InvalidPacketException::CHECKSUM_MISMATCH );
119126
}

SourceQuery/Exception/SocketException.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ class SocketException extends SourceQueryException
1717
const COULD_NOT_CREATE_SOCKET = 1;
1818
const NOT_CONNECTED = 2;
1919
const CONNECTION_FAILED = 3;
20+
const INVALID_ENGINE = 3;
2021
}

SourceQuery/GoldSourceRcon.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class GoldSourceRcon
3333
private $Socket;
3434

3535
private $RconPassword;
36-
private $RconRequestId;
3736
private $RconChallenge;
3837

3938
public function __construct( $Socket )
@@ -44,7 +43,6 @@ public function __construct( $Socket )
4443
public function Close( )
4544
{
4645
$this->RconChallenge = 0;
47-
$this->RconRequestId = 0;
4846
$this->RconPassword = 0;
4947
}
5048

@@ -64,7 +62,7 @@ public function Write( $Header, $String = '' )
6462
/**
6563
* @param int $Length
6664
* @throws AuthenticationException
67-
* @return bool
65+
* @return Buffer
6866
*/
6967
public function Read( $Length = 1400 )
7068
{

SourceQuery/SourceQuery.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ class SourceQuery
7070
/**
7171
* Points to rcon class
7272
*
73-
* @var SourceRcon
73+
* @var SourceRcon|GoldSourceRcon|null
7474
*/
7575
private $Rcon;
7676

7777
/**
7878
* Points to socket class
7979
*
80-
* @var Socket
80+
* @var BaseSocket
8181
*/
8282
private $Socket;
8383

@@ -159,7 +159,7 @@ public function SetUseOldGetChallengeMethod( $Value )
159159
public function Disconnect( )
160160
{
161161
$this->Connected = false;
162-
$this->Challenge = 0;
162+
$this->Challenge = '';
163163

164164
$this->Socket->Close( );
165165

@@ -212,6 +212,7 @@ public function GetInfo( )
212212
$Buffer = $this->Socket->Read( );
213213

214214
$Type = $Buffer->GetByte( );
215+
$Server = [];
215216

216217
// Old GoldSource protocol, HLTV still uses it
217218
if( $Type === self::S2A_INFO_OLD && $this->Socket->Engine === self::GOLDSOURCE )
@@ -237,6 +238,7 @@ public function GetInfo( )
237238

238239
if( $Server[ 'IsMod' ] )
239240
{
241+
$Mod = [];
240242
$Mod[ 'Url' ] = $Buffer->GetString( );
241243
$Mod[ 'Download' ] = $Buffer->GetString( );
242244
$Buffer->Get( 1 ); // NULL byte
@@ -391,6 +393,7 @@ public function GetPlayers( )
391393

392394
while( $Count-- > 0 && $Buffer->Remaining( ) > 0 )
393395
{
396+
$Player = [];
394397
$Player[ 'Id' ] = $Buffer->GetByte( ); // PlayerID, is it just always 0?
395398
$Player[ 'Name' ] = $Buffer->GetString( );
396399
$Player[ 'Frags' ] = $Buffer->GetLong( );
@@ -527,6 +530,10 @@ public function SetRconPassword( $Password )
527530

528531
break;
529532
}
533+
default:
534+
{
535+
throw new SocketException( 'Unknown engine.', SocketException::INVALID_ENGINE );
536+
}
530537
}
531538

532539
$this->Rcon->Open( );

Tests/Tests.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function setUp()
7171
{
7272
$this->Socket = new TestableSocket();
7373
$this->SourceQuery = new SourceQuery( $this->Socket );
74-
$this->SourceQuery->Connect( 1, 2 );
74+
$this->SourceQuery->Connect( '', 2 );
7575
}
7676

7777
public function tearDown()
@@ -87,7 +87,7 @@ public function tearDown()
8787
public function testInvalidTimeout()
8888
{
8989
$SourceQuery = new SourceQuery( );
90-
$SourceQuery->Connect( 1, 2, -1 );
90+
$SourceQuery->Connect( '', 2, -1 );
9191
}
9292

9393
/**

0 commit comments

Comments
 (0)