encode() abstract public method

abstract public encode ( )
Ejemplo n.º 1
0
 public function putPacket(Player $player, DataPacket $packet, $needACK = false, $immediate = true)
 {
     $packet->encode();
     $pk = new RedirectPacket();
     $pk->uuid = $player->getUniqueId();
     $pk->direct = $immediate;
     $pk->mcpeBuffer = $packet->buffer;
     $this->synapseInterface->putPacket($pk);
 }
Ejemplo n.º 2
0
 /**
  * Broadcasts a Minecraft packet to a list of players
  *
  * @param Player[]   $players
  * @param DataPacket $packet
  */
 public static function broadcastPacket(array $players, DataPacket $packet)
 {
     $packet->encode();
     $packet->isEncoded = true;
     if (Network::$BATCH_THRESHOLD >= 0 and strlen($packet->buffer) >= Network::$BATCH_THRESHOLD) {
         Server::getInstance()->batchPackets($players, [$packet->buffer], false, $packet->getChannel());
         return;
     }
     foreach ($players as $player) {
         $player->dataPacket($packet);
     }
     if (isset($packet->__encapsulatedPacket)) {
         unset($packet->__encapsulatedPacket);
     }
 }
Ejemplo n.º 3
0
 public function putPacket(Player $player, DataPacket $packet, $needACK = \false, $immediate = \false)
 {
     if (isset($this->identifiers[$player])) {
         $identifier = $this->identifiers[$player];
         $pk = \null;
         if (!$packet->isEncoded) {
             $packet->encode();
         } elseif (!$needACK) {
             if (!isset($packet->__encapsulatedPacket)) {
                 $packet->__encapsulatedPacket = new CachedEncapsulatedPacket();
                 $packet->__encapsulatedPacket->identifierACK = \null;
                 $packet->__encapsulatedPacket->buffer = $packet->buffer;
                 if ($packet->getChannel() !== 0) {
                     $packet->__encapsulatedPacket->reliability = 3;
                     $packet->__encapsulatedPacket->orderChannel = $packet->getChannel();
                     $packet->__encapsulatedPacket->orderIndex = 0;
                 } else {
                     $packet->__encapsulatedPacket->reliability = 2;
                 }
             }
             $pk = $packet->__encapsulatedPacket;
         }
         if (!$immediate and !$needACK and $packet->pid() !== ProtocolInfo::BATCH_PACKET and Network::$BATCH_THRESHOLD >= 0 and \strlen($packet->buffer) >= Network::$BATCH_THRESHOLD) {
             $this->server->batchPackets([$player], [$packet], \true, $packet->getChannel());
             return \null;
         }
         if ($pk === \null) {
             $pk = new EncapsulatedPacket();
             $pk->buffer = $packet->buffer;
             if ($packet->getChannel() !== 0) {
                 $packet->reliability = 3;
                 $packet->orderChannel = $packet->getChannel();
                 $packet->orderIndex = 0;
             } else {
                 $packet->reliability = 2;
             }
             if ($needACK === \true) {
                 $pk->identifierACK = $this->identifiersACK[$identifier]++;
             }
         }
         $this->interface->sendEncapsulated($identifier, $pk, ($needACK === \true ? RakLib::FLAG_NEED_ACK : 0) | ($immediate === \true ? RakLib::PRIORITY_IMMEDIATE : RakLib::PRIORITY_NORMAL));
         return $pk->identifierACK;
     }
     return \null;
 }
Ejemplo n.º 4
0
 public function putPacket(Player $player, DataPacket $packet, $needACK = false, $immediate = false)
 {
     if (isset($this->identifiers[$h = spl_object_hash($player)])) {
         $identifier = $this->identifiers[$h];
         $pk = null;
         if (!$packet->isEncoded) {
             $packet->encode();
         } elseif (!$needACK) {
             if (!isset($packet->__encapsulatedPacket)) {
                 $packet->__encapsulatedPacket = new CachedEncapsulatedPacket();
                 $packet->__encapsulatedPacket->identifierACK = null;
                 $packet->__encapsulatedPacket->buffer = chr(0xfe) . $packet->buffer;
                 // #blameshoghi
                 $packet->__encapsulatedPacket->reliability = 3;
                 $packet->__encapsulatedPacket->orderChannel = 0;
             }
             $pk = $packet->__encapsulatedPacket;
         }
         if (!$immediate and !$needACK and $packet::NETWORK_ID !== ProtocolInfo::BATCH_PACKET and Network::$BATCH_THRESHOLD >= 0 and strlen($packet->buffer) >= Network::$BATCH_THRESHOLD) {
             $this->server->batchPackets([$player], [$packet], true);
             return null;
         }
         if ($pk === null) {
             $pk = new EncapsulatedPacket();
             $pk->buffer = chr(0xfe) . $packet->buffer;
             // #blameshoghi
             $packet->reliability = 3;
             $packet->orderChannel = 0;
             if ($needACK === true) {
                 $pk->identifierACK = $this->identifiersACK[$identifier]++;
             }
         }
         $this->interface->sendEncapsulated($identifier, $pk, ($needACK === true ? RakLib::FLAG_NEED_ACK : 0) | ($immediate === true ? RakLib::PRIORITY_IMMEDIATE : RakLib::PRIORITY_NORMAL));
         return $pk->identifierACK;
     }
     return null;
 }
Ejemplo n.º 5
0
 /**
  * Broadcasts a Minecraft packet to a list of players
  *
  * @param Player[]   $players
  * @param DataPacket $packet
  */
 public static function broadcastPacket(array $players, DataPacket $packet)
 {
     $packet->encode();
     $packet->isEncoded = true;
     foreach ($players as $player) {
         $player->dataPacket($packet);
     }
     if (isset($packet->__encapsulatedPacket)) {
         unset($packet->__encapsulatedPacket);
     }
 }
Ejemplo n.º 6
0
 /**
  * Batch a Data packet
  *
  * @param DataPacket $packet
  *
  * @return bool
  */
 public function batchDataPacket(DataPacket $packet)
 {
     $str = "";
     if ($packet instanceof DataPacket) {
         if (!$packet->isEncoded) {
             $packet->encode();
         }
         $str .= Binary::writeInt(strlen($packet->buffer)) . $packet->buffer;
     } else {
         $str .= Binary::writeInt(strlen($packet)) . $packet;
     }
     $pk = new BatchPacket();
     $pk->payload = zlib_encode($str, ZLIB_ENCODING_DEFLATE, 7);
     $pk->encode();
     $pk->isEncoded = true;
     $this->dataPacket($pk);
 }
Ejemplo n.º 7
0
 public function putPacket(Player $player, DataPacket $packet, $needACK = false, $immediate = false)
 {
     if (isset($this->identifiers[$player])) {
         $identifier = $this->identifiers[$player];
         $pk = null;
         if (!$packet->isEncoded) {
             $packet->encode();
         } elseif (!$needACK) {
             if (!isset($packet->__encapsulatedPacket)) {
                 $packet->__encapsulatedPacket = new CachedEncapsulatedPacket();
                 $packet->__encapsulatedPacket->identifierACK = null;
                 $packet->__encapsulatedPacket->buffer = $packet->buffer;
                 $packet->__encapsulatedPacket->reliability = 2;
             }
             $pk = $packet->__encapsulatedPacket;
         }
         if ($pk === null) {
             $pk = new EncapsulatedPacket();
             $pk->buffer = $packet->buffer;
             $pk->reliability = 2;
             if ($needACK === true) {
                 $pk->identifierACK = $this->identifiersACK[$identifier]++;
             }
         }
         $this->interface->sendEncapsulated($identifier, $pk, ($needACK === true ? RakLib::FLAG_NEED_ACK : 0) | ($immediate === true ? RakLib::PRIORITY_IMMEDIATE : RakLib::PRIORITY_NORMAL));
         return $pk->identifierACK;
     }
     return null;
 }