public function getReply() { if ($this->receivePacket(1440) == 0) { throw new RCONBanException(); } $packetData = substr($this->buffer->_array(), 0, $this->buffer->limit()); $packetSize = $this->buffer->getLong() + 4; if ($packetSize > 1440) { $remainingBytes = $packetSize - $this->buffer->limit(); do { if ($remainingBytes < 1440) { $this->receivePacket($remainingBytes); } else { $this->receivePacket(1440); } $packetData .= substr($this->buffer->_array(), 0, $this->buffer->limit()); $remainingBytes -= $this->buffer->limit(); } while ($remainingBytes > 0); } return RCONPacketFactory::getPacketFromData($packetData); }
/** * Reads a packet from the socket * * The Source RCON protocol allows packets of an arbitrary sice transmitted * using multiple TCP packets. The data is received in chunks and * concatenated into a single response packet. * * @return SteamPacket The packet replied from the server or * <var>null</var> if the connection has been closed by the server */ public function getReply() { try { if ($this->receivePacket(4) == 0) { $this->socket->close(); return null; } } catch (ConnectionResetException $e) { $this->socket->close(); return null; } $packetSize = $this->buffer->getLong(); $remainingBytes = $packetSize; $packetData = ''; do { $receivedBytes = $this->receivePacket($remainingBytes); $remainingBytes -= $receivedBytes; $packetData .= $this->buffer->get(); } while ($remainingBytes > 0); $packet = RCONPacketFactory::getPacketFromData($packetData); trigger_error('Received packet of type ' . get_class($packet)); return $packet; }