Skip to content

Commit

Permalink
Partial fix for multi-packet source rcon
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Feb 20, 2015
1 parent 5072999 commit 00c5a9f
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions SourceQuery/SourceRcon.class.php
Expand Up @@ -75,9 +75,9 @@ public function Write( $Header, $String = '' )
return $Length === FWrite( $this->RconSocket, $Command, $Length );
}

public function Read( $Length = 1400 )
public function Read( )
{
$this->Buffer->Set( FRead( $this->RconSocket, $Length ) );
$this->Buffer->Set( FRead( $this->RconSocket, 4 ) );

if( $this->Buffer->Remaining( ) < 4 )
{
Expand All @@ -86,16 +86,27 @@ public function Read( $Length = 1400 )

$PacketSize = $this->Buffer->GetLong( );

$this->Buffer->Set( FRead( $this->RconSocket, $PacketSize ) );

$Buffer = $this->Buffer->Get( );

$Remaining = $PacketSize - StrLen( $Buffer );

while( $Remaining > 0 )
{
$Buffer2 = FRead( $this->RconSocket, $Length );
$Buffer .= $Buffer2;
$Buffer2 = FRead( $this->RconSocket, $Remaining );

$PacketSize = StrLen( $Buffer2 );

if( $PacketSize === 0 )
{
throw new InvalidPacketException( 'Read ' . strlen( $Buffer ) . ' bytes from socket, ' . $Remaining . ' remaining', InvalidPacketException::BUFFER_EMPTY );

break;
}

$Remaining -= StrLen( $Buffer2 );
$Buffer .= $Buffer2;
$Remaining -= $PacketSize;
}

$this->Buffer->Set( $Buffer );
Expand Down Expand Up @@ -139,9 +150,16 @@ public function Command( $Command )
break;
}

$Buffer .= $this->Buffer->Get( );
$Buffer2 = $this->Buffer->Get( );

if( $Buffer2 === "\x00\x01\x00\x00\x00\x00" )
{
break;
}

$Buffer .= $Buffer2;
}
while( false ); // TODO: This is so broken that we don't even try to read multiple times, needs to be revised
while( true );
}

// TODO: It should use GetString, but there are no null bytes at the end, why?
Expand Down

0 comments on commit 00c5a9f

Please sign in to comment.