Fix gold source query not working

Closes #95
pull/124/head
Pavel Djundik 9 years ago
parent ccda8686ae
commit d4ae8c631d

@ -69,45 +69,50 @@
// GoldSource RCON has same structure as Query // GoldSource RCON has same structure as Query
$Buffer = $this->Socket->Read( ); $Buffer = $this->Socket->Read( );
if( $Buffer->GetByte( ) !== SourceQuery::S2A_RCON ) $StringBuffer = '';
{
throw new InvalidPacketException( 'Invalid rcon response.', InvalidPacketException::PACKET_HEADER_MISMATCH );
}
$Buffer = $Buffer->Get( );
$Trimmed = Trim( $Buffer );
if( $Trimmed === 'Bad rcon_password.' )
{
throw new AuthenticationException( $Trimmed, AuthenticationException::BAD_PASSWORD );
}
else if( $Trimmed === 'You have been banned from this server.' )
{
throw new AuthenticationException( $Trimmed, AuthenticationException::BANNED );
}
$ReadMore = false; $ReadMore = false;
// There is no indentifier of the end, so we just need to continue reading // There is no indentifier of the end, so we just need to continue reading
// TODO: Needs to be looked again, it causes timeouts
do do
{ {
$this->Socket->Read( ); $ReadMore = $Buffer->Remaining( ) > 0;
$ReadMore = $Buffer->Remaining( ) > 0 && $Buffer->GetByte( ) === SourceQuery::S2A_RCON;
if( $ReadMore ) if( $ReadMore )
{ {
$Packet = $Buffer->Get( ); if( $Buffer->GetByte( ) !== SourceQuery::S2A_RCON )
$Buffer .= SubStr( $Packet, 0, -2 ); {
throw new InvalidPacketException( 'Invalid rcon response.', InvalidPacketException::PACKET_HEADER_MISMATCH );
}
$Packet = $Buffer->Get( );
$StringBuffer .= $Packet;
//$StringBuffer .= SubStr( $Packet, 0, -2 );
// Let's assume if this packet is not long enough, there are no more after this one // Let's assume if this packet is not long enough, there are no more after this one
$ReadMore = StrLen( $Packet ) > 1000; // use 1300? $ReadMore = StrLen( $Packet ) > 1000; // use 1300?
if( $ReadMore )
{
$Buffer = $this->Socket->Read( );
}
} }
} }
while( $ReadMore ); while( $ReadMore );
$Buffer->Set( Trim( $Buffer ) ); $Trimmed = trim( $StringBuffer );
if( $Trimmed === 'Bad rcon_password.' )
{
throw new AuthenticationException( $Trimmed, AuthenticationException::BAD_PASSWORD );
}
else if( $Trimmed === 'You have been banned from this server.' )
{
throw new AuthenticationException( $Trimmed, AuthenticationException::BANNED );
}
$Buffer->Set( $Trimmed );
return $Buffer;
} }
public function Command( $Command ) public function Command( $Command )

Loading…
Cancel
Save