public function Authorize($Password) { $this->RconPassword = $Password; switch ($this->Socket->Engine) { case CI_SourceQuery::GOLDSOURCE: $this->Write(0, 'challenge rcon'); $this->Socket->Read(); if ($this->Buffer->Get(14) != 'challenge rcon') { return false; } $this->RconChallenge = Trim($this->Buffer->Get()); break; case CI_SourceQuery::SOURCE: $this->Write(CI_SourceQuery::SERVERDATA_AUTH, $Password); $this->Read(); $RequestID = $this->Buffer->GetLong(); $Type = $this->Buffer->GetLong(); // If we receive SERVERDATA_RESPONSE_VALUE, then we need to read again // More info: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Additional_Comments if ($Type == CI_SourceQuery::SERVERDATA_RESPONSE_VALUE) { $this->Read(); $RequestID = $this->Buffer->GetLong(); $Type = $this->Buffer->GetLong(); } if ($RequestID == -1 || $Type != CI_SourceQuery::SERVERDATA_AUTH_RESPONSE) { throw new CI_SourceQueryException('RCON authorization failed.'); } $this->RconChallenge = 1; break; } return true; }
public function Authorize($Password) { $this->RconPassword = $Password; $this->Write(0, 'challenge rcon'); $this->Socket->Read(); if ($this->Buffer->Get(14) !== 'challenge rcon') { return false; } $this->RconChallenge = Trim($this->Buffer->Get()); return true; }
/** * Get challenge (used for players/rules packets) * * @return bool True if all went well, false if server uses old GoldSource protocol, and it already contains answer */ private function GetChallenge($Header, $ExpectedResult) { if ($this->Challenge) { return self::GETCHALLENGE_ALL_CLEAR; } $this->Socket->Write($Header, 0xffffffff); $this->Socket->Read(); $Type = $this->Buffer->GetByte(); switch ($Type) { case self::S2A_CHALLENGE: $this->Challenge = $this->Buffer->Get(4); return self::GETCHALLENGE_ALL_CLEAR; case $ExpectedResult: // Goldsource (HLTV) return self::GETCHALLENGE_CONTAINS_ANSWER; case 0: return self::GETCHALLENGE_FAILED; default: throw new SourceQueryException('GetChallenge: Packet header mismatch. (0x' . DecHex($Type) . ')'); } }
/** * Get challenge (used for players/rules packets) * * @param $Header * @param $ExpectedResult * @throws InvalidPacketException * @return bool True if all went well, false if server uses old GoldSource protocol, and it already contains answer */ private function GetChallenge($Header, $ExpectedResult) { if ($this->Challenge) { return self::GETCHALLENGE_ALL_CLEAR; } if ($this->UseOldGetChallengeMethod) { $Header = self::A2S_SERVERQUERY_GETCHALLENGE; } $this->Socket->Write($Header, 0xffffffff); $this->Socket->Read(); $Type = $this->Buffer->GetByte(); switch ($Type) { case self::S2A_CHALLENGE: $this->Challenge = $this->Buffer->Get(4); return self::GETCHALLENGE_ALL_CLEAR; case $ExpectedResult: // Goldsource (HLTV) return self::GETCHALLENGE_CONTAINS_ANSWER; case 0: return self::GETCHALLENGE_FAILED; default: throw new InvalidPacketException('GetChallenge: Packet header mismatch. (0x' . DecHex($Type) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH); } }