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; }
/** * Get players on the server * * @throws SourceQueryException * * @return bool|array Returns array with players on success, false on failure */ public function GetPlayers() { if (!$this->Connected) { return false; } switch ($this->GetChallenge(self::A2S_PLAYER, self::S2A_PLAYER)) { case self::GETCHALLENGE_FAILED: return false; case self::GETCHALLENGE_ALL_CLEAR: $this->Socket->Write(self::A2S_PLAYER, $this->Challenge); $this->Socket->Read(); $Type = $this->Buffer->GetByte(); if ($Type == 0) { return false; } else { if ($Type != self::S2A_PLAYER) { throw new SourceQueryException('GetPlayers: Packet header mismatch. (0x' . DecHex($Type) . ')'); } } break; } $Players = array(); $Count = $this->Buffer->GetByte(); while ($Count-- > 0 && $this->Buffer->Remaining() > 0) { $Player['Id'] = $this->Buffer->GetByte(); // PlayerID, is it just always 0? $Player['Name'] = $this->Buffer->GetString(); $Player['Frags'] = $this->Buffer->GetLong(); $Player['Time'] = (int) $this->Buffer->GetFloat(); $Player['TimeF'] = GMDate($Player['Time'] > 3600 ? "H:i:s" : "i:s", $Player['Time']); $Players[] = $Player; } return $Players; }
private function Sherlock($Length) { $Data = FRead($this->Socket, $Length); if (StrLen($Data) < 4) { return false; } $this->Buffer->Set($Data); return $this->Buffer->GetLong() === -2; }
public function Authorize($Password) { $this->Write(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 === SourceQuery::SERVERDATA_RESPONSE_VALUE) { $this->Read(); $RequestID = $this->Buffer->GetLong(); $Type = $this->Buffer->GetLong(); } if ($RequestID === -1 || $Type !== SourceQuery::SERVERDATA_AUTH_RESPONSE) { throw new AuthenticationException('RCON authorization failed.', AuthenticationException::BAD_PASSWORD); } return true; }
/** * Get players on the server * * @throws InvalidPacketException * * @return bool|array Returns array with players on success, false on failure */ public function GetPlayers() { if (!$this->Connected) { return false; } switch ($this->GetChallenge(self::A2S_PLAYER, self::S2A_PLAYER)) { case self::GETCHALLENGE_FAILED: return false; case self::GETCHALLENGE_ALL_CLEAR: $this->Socket->Write(self::A2S_PLAYER, $this->Challenge); $this->Socket->Read(14000); // Moronic Arma 3 developers do not split their packets, so we have to read more data // This violates the protocol spec, and they probably should fix it: https://developer.valvesoftware.com/wiki/Server_queries#Protocol $Type = $this->Buffer->GetByte(); if ($Type === 0) { return false; } else { if ($Type !== self::S2A_PLAYER) { throw new InvalidPacketException('GetPlayers: Packet header mismatch. (0x' . DecHex($Type) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH); } } break; } $Players = array(); $Count = $this->Buffer->GetByte(); while ($Count-- > 0 && $this->Buffer->Remaining() > 0) { $Player['Id'] = $this->Buffer->GetByte(); // PlayerID, is it just always 0? $Player['Name'] = $this->Buffer->GetString(); $Player['Frags'] = $this->Buffer->GetLong(); $Player['Time'] = (int) $this->Buffer->GetFloat(); $Player['TimeF'] = GMDate($Player['Time'] > 3600 ? "H:i:s" : "i:s", $Player['Time']); $Players[] = $Player; } return $Players; }