Skip to content

Commit 4b900d3

Browse files
committed
Make the max fread length a const
1 parent fd187f0 commit 4b900d3

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

SourceQuery/BaseSocket.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public function __destruct( )
4141
abstract public function Close( ) : void;
4242
abstract public function Open( string $Address, int $Port, int $Timeout, int $Engine ) : void;
4343
abstract public function Write( int $Header, string $String = '' ) : bool;
44-
abstract public function Read( int $Length = 1400 ) : Buffer;
44+
abstract public function Read( ) : Buffer;
4545

46-
protected function ReadInternal( Buffer $Buffer, int $Length, callable $SherlockFunction ) : Buffer
46+
protected function ReadInternal( Buffer $Buffer, callable $SherlockFunction ) : Buffer
4747
{
4848
if( $Buffer->Remaining( ) === 0 )
4949
{
@@ -106,7 +106,7 @@ protected function ReadInternal( Buffer $Buffer, int $Length, callable $Sherlock
106106

107107
$ReadMore = $PacketCount > sizeof( $Packets );
108108
}
109-
while( $ReadMore && $SherlockFunction( $Buffer, $Length ) );
109+
while( $ReadMore && $SherlockFunction( $Buffer ) );
110110

111111
$Data = implode( $Packets );
112112

SourceQuery/Socket.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public function Write( int $Header, string $String = '' ) : bool
6161

6262
return $Length === fwrite( $this->Socket, $Command, $Length );
6363
}
64+
65+
private const MaxPacketLength = 1 << 16;
6466

6567
/**
6668
* Reads from socket and returns Buffer.
@@ -69,19 +71,19 @@ public function Write( int $Header, string $String = '' ) : bool
6971
*
7072
* @return Buffer Buffer
7173
*/
72-
public function Read( int $Length = 1400 ) : Buffer
74+
public function Read( ) : Buffer
7375
{
7476
$Buffer = new Buffer( );
75-
$Buffer->Set( fread( $this->Socket, $Length ) );
77+
$Buffer->Set( fread( $this->Socket, self::MaxPacketLength ) );
7678

77-
$this->ReadInternal( $Buffer, $Length, [ $this, 'Sherlock' ] );
79+
$this->ReadInternal( $Buffer, [ $this, 'Sherlock' ] );
7880

7981
return $Buffer;
8082
}
8183

82-
public function Sherlock( Buffer $Buffer, int $Length ) : bool
84+
public function Sherlock( Buffer $Buffer ) : bool
8385
{
84-
$Data = fread( $this->Socket, $Length );
86+
$Data = fread( $this->Socket, self::MaxPacketLength );
8587

8688
if( strlen( $Data ) < 4 )
8789
{

SourceQuery/SourceQuery.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,7 @@ public function GetPlayers( ) : array
383383
$this->GetChallenge( self::A2S_PLAYER, self::S2A_PLAYER );
384384

385385
$this->Socket->Write( self::A2S_PLAYER, $this->Challenge );
386-
$Buffer = $this->Socket->Read( 14000 ); // Arma 3 developers do not split their packets, so we have to read more data
387-
// This violates the protocol spec, and they probably should fix it: https://developer.valvesoftware.com/wiki/Server_queries#Protocol
386+
$Buffer = $this->Socket->Read( );
388387

389388
$Type = $Buffer->GetByte( );
390389

@@ -429,7 +428,7 @@ public function GetRules( ) : array
429428
$this->GetChallenge( self::A2S_RULES, self::S2A_RULES );
430429

431430
$this->Socket->Write( self::A2S_RULES, $this->Challenge );
432-
$Buffer = $this->Socket->Read( 14000 ); // fix Rust long desc
431+
$Buffer = $this->Socket->Read( );
433432

434433
$Type = $Buffer->GetByte( );
435434

Tests/Tests.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ public function Write( int $Header, string $String = '' ) : bool
3939
return true;
4040
}
4141

42-
public function Read( int $Length = 1400 ) : Buffer
42+
public function Read( ) : Buffer
4343
{
4444
$Buffer = new Buffer( );
4545
$Buffer->Set( $this->PacketQueue->shift() );
4646

47-
$this->ReadInternal( $Buffer, $Length, [ $this, 'Sherlock' ] );
47+
$this->ReadInternal( $Buffer, [ $this, 'Sherlock' ] );
4848

4949
return $Buffer;
5050
}
5151

52-
public function Sherlock( Buffer $Buffer, int $Length ) : bool
52+
public function Sherlock( Buffer $Buffer ) : bool
5353
{
5454
if( $this->PacketQueue->isEmpty() )
5555
{

0 commit comments

Comments
 (0)