public function Authorize($Password) { $this->RconPassword = $Password; $this->Write(0, 'challenge rcon'); $Buffer = $this->Socket->Read(); if ($Buffer->Get(14) !== 'challenge rcon') { throw new AuthenticationException('Failed to get RCON challenge.', AuthenticationException::BAD_PASSWORD); } $this->RconChallenge = Trim($Buffer->Get()); }
/** * Get challenge (used for players/rules packets) * * @param $Header * @param $ExpectedResult * * @throws InvalidPacketException */ private function GetChallenge($Header, $ExpectedResult) { if ($this->Challenge) { return; } if ($this->UseOldGetChallengeMethod) { $Header = self::A2S_SERVERQUERY_GETCHALLENGE; } $this->Socket->Write($Header, 0xffffffff); $Buffer = $this->Socket->Read(); $Type = $Buffer->GetByte(); switch ($Type) { case self::S2A_CHALLENGE: $this->Challenge = $Buffer->Get(4); return; case $ExpectedResult: // Goldsource (HLTV) return; case 0: throw new InvalidPacketException('GetChallenge: Failed to get challenge.'); default: throw new InvalidPacketException('GetChallenge: Packet header mismatch. (0x' . DecHex($Type) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH); } }