Fixed HLTV GetPlayers/GetInfo

pull/13/head
xPaw 13 years ago
parent 011696a5e9
commit 3293f9a0d9

@ -22,7 +22,6 @@ class SourceQuery
// Packets Ending
const A2S_PING = 0x69;
const A2S_GETCHALLENGE = 0x57; // Doesn't work
const A2S_INFO = 0x54;
const A2S_PLAYER = 0x55;
const A2S_RULES = 0x56;
@ -218,12 +217,14 @@ class SourceQuery
public function GetPlayers( )
{
if( !$this->Connected || !$this->GetChallenge( ) )
if( !$this->Connected )
{
return false;
}
$this->Socket->Write( self :: A2S_PLAYER, $this->GetChallenge( ) );
if( $this->GetChallenge( self :: A2S_PLAYER, self :: S2A_PLAYER ) )
{
$this->Socket->Write( self :: A2S_PLAYER, $this->Challenge );
$this->Socket->Read( );
$Type = $this->Buffer->GetByte( );
@ -232,6 +233,7 @@ class SourceQuery
{
throw new SourceQueryException( 'GetPlayers: Packet header mismatch. (' . $Type . ')' );
}
}
$Players = Array( );
$Count = $this->Buffer->GetByte( );
@ -252,12 +254,14 @@ class SourceQuery
public function GetRules( )
{
if( !$this->Connected || !$this->GetChallenge( ) )
if( !$this->Connected )
{
return false;
}
$this->Socket->Write( self :: A2S_RULES, $this->GetChallenge( ) );
if( $this->GetChallenge( self :: A2S_RULES, self :: S2A_RULES ) )
{
$this->Socket->Write( self :: A2S_RULES, $this->Challenge );
$this->Socket->Read( );
$Type = $this->Buffer->GetByte( );
@ -266,6 +270,7 @@ class SourceQuery
{
throw new SourceQueryException( 'GetRules: Packet header mismatch. (' . $Type . ')' );
}
}
$Rules = Array( );
$Count = $this->Buffer->GetShort( );
@ -284,29 +289,41 @@ class SourceQuery
return $Rules;
}
private function GetChallenge( )
private function GetChallenge( $Header, $ExpectedResult )
{
if( $this->Challenge )
{
return $this->Challenge;
return true;
}
// A2S_GETCHALLENGE is broken
$this->Socket->Write( self :: A2S_PLAYER, 0xFFFFFFFF );
$this->Socket->Write( $Header, 0xFFFFFFFF );
$this->Socket->Read( );
$Type = $this->Buffer->GetByte( );
if( $Type != self :: S2A_CHALLENGE )
switch( $Type )
{
throw new SourceQueryException( 'GetChallenge: Packet header mismatch. (' . $Type . ')' );
}
case self :: S2A_CHALLENGE:
{
// All clear
// Let's keep it raw, instead of reading as long
$this->Challenge = $this->Buffer->Get( 4 );
return $this->Challenge;
return true;
}
case $ExpectedResult:
{
// Goldsource (HLTV)
return false;
}
default:
{
throw new SourceQueryException( 'GetChallenge: Packet header mismatch. (' . $Type . ')' );
}
}
return true;
}
public function SetRconPassword( $Password )

Loading…
Cancel
Save