pocketmine\utils\BinaryStream::getString PHP Method

getString() public method

public getString ( )
    public function getString()
    {
        return $this->get($this->getShort());
    }

Usage Example

Ejemplo n.º 1
0
 public function processBatch(BatchPacket $packet, Player $p)
 {
     try {
         if (strlen($packet->payload) === 0) {
             //prevent zlib_decode errors for incorrectly-decoded packets
             throw new \InvalidArgumentException("BatchPacket payload is empty or packet decode error");
         }
         $str = zlib_decode($packet->payload, 1024 * 1024 * 64);
         //Max 64MB
         $len = strlen($str);
         if ($len === 0) {
             throw new \InvalidStateException("Decoded BatchPacket payload is empty");
         }
         $stream = new BinaryStream($str);
         while ($stream->offset < $len) {
             $buf = $stream->getString();
             if (($pk = $this->getPacket(ord($buf[0]))) !== null) {
                 if ($pk::NETWORK_ID === Info::BATCH_PACKET) {
                     throw new \InvalidStateException("Invalid BatchPacket inside BatchPacket");
                 }
                 $pk->setBuffer($buf, 1);
                 $pk->decode();
                 assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread in " . get_class($pk));
                 $p->handleDataPacket($pk);
             }
         }
     } catch (\Throwable $e) {
         if (\pocketmine\DEBUG > 1) {
             $logger = $this->server->getLogger();
             $logger->debug("BatchPacket " . " 0x" . bin2hex($packet->payload));
             $logger->logException($e);
         }
     }
 }
All Usage Examples Of pocketmine\utils\BinaryStream::getString