/** * @param int $Length * @throws AuthenticationException */ public function Read($Length = 1400) { // GoldSource RCON has same structure as Query $this->Socket->Read(); if ($this->Buffer->GetByte() !== SourceQuery::S2A_RCON) { return false; } $Buffer = $this->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; // There is no indentifier of the end, so we just need to continue reading // TODO: Needs to be looked again, it causes timeouts do { $this->Socket->Read(); $ReadMore = $this->Buffer->Remaining() > 0 && $this->Buffer->GetByte() === SourceQuery::S2A_RCON; if ($ReadMore) { $Packet = $this->Buffer->Get(); $Buffer .= SubStr($Packet, 0, -2); // Let's assume if this packet is not long enough, there are no more after this one $ReadMore = StrLen($Packet) > 1000; // use 1300? } } while ($ReadMore); $this->Buffer->Set(Trim($Buffer)); }
public function Read($Length = 1400) { $this->Buffer->Set(FRead($this->RconSocket, $Length)); if ($this->Buffer->Remaining() < 4) { throw new InvalidPacketException('Rcon read: Failed to read any data from socket', InvalidPacketException::BUFFER_EMPTY); } $PacketSize = $this->Buffer->GetLong(); $Buffer = $this->Buffer->Get(); $Remaining = $PacketSize - StrLen($Buffer); while ($Remaining > 0) { $Buffer2 = FRead($this->RconSocket, $Length); $Buffer .= $Buffer2; $Remaining -= StrLen($Buffer2); } $this->Buffer->Set($Buffer); }
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 Read() { $this->Buffer->Set(FRead($this->RconSocket, 4)); if ($this->Buffer->Remaining() < 4) { throw new InvalidPacketException('Rcon read: Failed to read any data from socket', InvalidPacketException::BUFFER_EMPTY); } $PacketSize = $this->Buffer->GetLong(); $this->Buffer->Set(FRead($this->RconSocket, $PacketSize)); $Buffer = $this->Buffer->Get(); $Remaining = $PacketSize - StrLen($Buffer); while ($Remaining > 0) { $Buffer2 = FRead($this->RconSocket, $Remaining); $PacketSize = StrLen($Buffer2); if ($PacketSize === 0) { throw new InvalidPacketException('Read ' . strlen($Buffer) . ' bytes from socket, ' . $Remaining . ' remaining', InvalidPacketException::BUFFER_EMPTY); break; } $Buffer .= $Buffer2; $Remaining -= $PacketSize; } $this->Buffer->Set($Buffer); }
public function Read($Length = 1400) { switch ($this->Socket->Engine) { case CI_SourceQuery::GOLDSOURCE: // GoldSource RCON has same structure as Query $this->Socket->Read(); if ($this->Buffer->GetByte() != SourceQuery::S2A_RCON) { return false; } $Buffer = $this->Buffer->Get(); $Trimmed = Trim($Buffer); if ($Trimmed == 'Bad rcon_password.' || $Trimmed == 'You have been banned from this server.') { throw new SourceQueryException($Trimmed); } $ReadMore = false; // There is no indentifier of the end, so we just need to continue reading // TODO: Needs to be looked again, it causes timeouts do { $this->Socket->Read(); $ReadMore = $this->Buffer->Remaining() > 0 && $this->Buffer->GetByte() == SourceQuery::S2A_RCON; if ($ReadMore) { $Packet = $this->Buffer->Get(); $Buffer .= SubStr($Packet, 0, -2); // Let's assume if this packet is not long enough, there are no more after this one $ReadMore = StrLen($Packet) > 1000; // use 1300? } } while ($ReadMore); $this->Buffer->Set(Trim($Buffer)); break; case CI_SourceQuery::SOURCE: $this->Buffer->Set(FRead($this->RconSocket, $Length)); $Buffer = ""; $PacketSize = $this->Buffer->GetLong(); $Buffer .= $this->Buffer->Get(); // TODO: multi packet reading $this->Buffer->Set($Buffer); break; } }
public function Read($Length = 1400) { $this->Buffer->Set(FRead($this->RconSocket, $Length)); $PacketSize = $this->Buffer->GetLong(); $Buffer = $this->Buffer->Get(); $Remaining = $PacketSize - StrLen($Buffer); while ($Remaining > 0) { $Buffer2 = FRead($this->RconSocket, $Length); $Buffer .= $Buffer2; $Remaining -= StrLen($Buffer2); } $this->Buffer->Set($Buffer); }