當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DataPacket::encode方法代碼示例

本文整理匯總了PHP中pocketmine\network\protocol\DataPacket::encode方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataPacket::encode方法的具體用法?PHP DataPacket::encode怎麽用?PHP DataPacket::encode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pocketmine\network\protocol\DataPacket的用法示例。


在下文中一共展示了DataPacket::encode方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: putPacket

 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);
 }
開發者ID:iTXTech,項目名稱:Genisys,代碼行數:9,代碼來源:SynLibInterface.php

示例2: broadcastPacket

 /**
  * 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);
     }
 }
開發者ID:ZenaGamingsky,項目名稱:PocketBox,代碼行數:21,代碼來源:Server.php

示例3: putPacket

 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;
 }
開發者ID:Edwardthedog2,項目名稱:Steadfast2,代碼行數:45,代碼來源:RakLibInterface.php

示例4: putPacket

 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;
 }
開發者ID:xxFlare,項目名稱:PocketMine-MP,代碼行數:37,代碼來源:RakLibInterface.php

示例5: broadcastPacket

 /**
  * 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);
     }
 }
開發者ID:hlogeon,項目名稱:PocketMineJs-MP,代碼行數:17,代碼來源:Server.php

示例6: batchDataPacket

 /**
  * 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);
 }
開發者ID:WonderlandPE,項目名稱:Steadfast2,代碼行數:24,代碼來源:Player.php

示例7: putPacket

 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;
 }
開發者ID:hlogeon,項目名稱:PocketMineJs-MP,代碼行數:29,代碼來源:RakLibInterface.php


注:本文中的pocketmine\network\protocol\DataPacket::encode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。