/**
  * Reads a packet from the socket
  *
  * The Source query protocol specifies a maximum packet size of 1,400
  * bytes. Bigger packets will be split over several UDP packets. This
  * method reassembles split packets into single packet objects.
  *
  * @return \SteamCondenser\Servers\Packets\SteamPacket The packet replied
  *         from the server
  */
 public function getReply()
 {
     $bytesRead = $this->receivePacket(1400);
     if ($this->buffer->getLong() == -2) {
         do {
             $requestId = $this->buffer->getLong();
             $packetCountAndNumber = $this->buffer->getByte();
             $packetCount = $packetCountAndNumber & 0xf;
             $packetNumber = ($packetCountAndNumber >> 4) + 1;
             $splitPackets[$packetNumber - 1] = $this->buffer->get();
             $this->logger->debug("Received packet {$packetNumber} of {$packetCount} for request #{$requestId}");
             if (sizeof($splitPackets) < $packetCount) {
                 try {
                     $bytesRead = $this->receivePacket();
                 } catch (\SteamCondenser\Exceptions\TimeoutException $e) {
                     $bytesRead = 0;
                 }
             } else {
                 $bytesRead = 0;
             }
         } while ($bytesRead > 0 && $this->buffer->getLong() == -2);
         $packet = SteamPacketFactory::reassemblePacket($splitPackets);
     } else {
         $packet = SteamPacketFactory::getPacketFromData($this->buffer->get());
     }
     $this->logger->debug("Received packet of type \"" . get_class($packet) . "\"");
     return $packet;
 }
 /**
  * Reads a single packet from the socket
  *
  * @return SteamPacket The packet replied from the server
  * @throws PacketFormatException if the packet has the wrong format
  */
 public function getReply()
 {
     $this->receivePacket(1500);
     if ($this->buffer->getLong() != -1) {
         throw new PacketFormatException("Master query response has wrong packet header.");
     }
     $packet = SteamPacketFactory::getPacketFromData($this->buffer->get());
     $this->logger->debug("Received reply of type \"" . get_class($packet) . "\"");
     return $packet;
 }
 /**
  * Reads a packet from the socket
  *
  * The Source query protocol specifies a maximum packet size of 1,400
  * bytes. Bigger packets will be split over several UDP packets. This
  * method reassembles split packets into single packet objects.
  * Additionally Source may compress big packets using bzip2. Those packets
  * will be compressed.
  *
  * @return SteamPacket The packet replied from the server
  */
 public function getReply()
 {
     $this->receivePacket(1400);
     $isCompressed = false;
     if ($this->buffer->getLong() == -2) {
         do {
             $requestId = $this->buffer->getLong();
             $isCompressed = ($requestId & 0x80000000) != 0;
             $packetCount = $this->buffer->getByte();
             $packetNumber = $this->buffer->getByte() + 1;
             if ($isCompressed) {
                 $splitSize = $this->buffer->getLong();
                 $packetChecksum = $this->buffer->getUnsignedLong();
             } else {
                 $splitSize = $this->buffer->getShort();
             }
             $splitPackets[$packetNumber] = $this->buffer->get();
             $this->logger->debug("Received packet {$packetNumber} of {$packetCount} for request #{$requestId}");
             if (sizeof($splitPackets) < $packetCount) {
                 try {
                     $bytesRead = $this->receivePacket();
                 } catch (TimeoutException $e) {
                     $bytesRead = 0;
                 }
             } else {
                 $bytesRead = 0;
             }
         } while ($bytesRead > 0 && $this->buffer->getLong() == -2);
         if ($isCompressed) {
             $packet = SteamPacketFactory::reassemblePacket($splitPackets, true, $packetChecksum);
         } else {
             $packet = SteamPacketFactory::reassemblePacket($splitPackets);
         }
     } else {
         $packet = SteamPacketFactory::getPacketFromData($this->buffer->get());
     }
     if ($isCompressed) {
         $this->logger->debug("Received compressed reply of type \"" . get_class($packet) . "\"");
     } else {
         $this->logger->debug("Received reply of type \"" . get_class($packet) . "\"");
     }
     return $packet;
 }