当前位置: 首页>>代码示例>>PHP>>正文


PHP protocol\Packet类代码示例

本文整理汇总了PHP中raklib\protocol\Packet的典型用法代码示例。如果您正苦于以下问题:PHP Packet类的具体用法?PHP Packet怎么用?PHP Packet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Packet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendPacket

 public function sendPacket(Packet $packet, $dest, $port)
 {
     $packet->encode();
     $this->sendBytes += $this->socket->writePacket($packet->buffer, $dest, $port);
 }
开发者ID:kakichi,项目名称:ClearSky,代码行数:5,代码来源:SessionManager.php

示例2: handlePacket

 public function handlePacket(Packet $packet)
 {
     $this->isActive = \true;
     $this->lastUpdate = \microtime(\true);
     if ($this->state === self::STATE_CONNECTED or $this->state === self::STATE_CONNECTING_2) {
         if ($packet::$ID >= 0x80 and $packet::$ID <= 0x8f and $packet instanceof DataPacket) {
             //Data packet
             $packet->decode();
             if ($packet->seqNumber < $this->windowStart or $packet->seqNumber > $this->windowEnd or isset($this->receivedWindow[$packet->seqNumber])) {
                 return;
             }
             $diff = $packet->seqNumber - $this->lastSeqNumber;
             unset($this->NACKQueue[$packet->seqNumber]);
             $this->ACKQueue[$packet->seqNumber] = $packet->seqNumber;
             $this->receivedWindow[$packet->seqNumber] = $packet->seqNumber;
             if ($diff !== 1) {
                 for ($i = $this->lastSeqNumber + 1; $i < $packet->seqNumber; ++$i) {
                     if (!isset($this->receivedWindow[$i])) {
                         $this->NACKQueue[$i] = $i;
                     }
                 }
             }
             if ($diff >= 1) {
                 $this->lastSeqNumber = $packet->seqNumber;
                 $this->windowStart += $diff;
                 $this->windowEnd += $diff;
             }
             foreach ($packet->packets as $pk) {
                 $this->handleEncapsulatedPacket($pk);
             }
         } else {
             if ($packet instanceof ACK) {
                 $packet->decode();
                 foreach ($packet->packets as $seq) {
                     if (isset($this->recoveryQueue[$seq])) {
                         foreach ($this->recoveryQueue[$seq]->packets as $pk) {
                             if ($pk instanceof EncapsulatedPacket and $pk->needACK and $pk->messageIndex !== \null) {
                                 unset($this->needACK[$pk->identifierACK][$pk->messageIndex]);
                             }
                         }
                         unset($this->recoveryQueue[$seq]);
                     }
                 }
             } elseif ($packet instanceof NACK) {
                 $packet->decode();
                 foreach ($packet->packets as $seq) {
                     if (isset($this->recoveryQueue[$seq])) {
                         $pk = $this->recoveryQueue[$seq];
                         $pk->seqNumber = $this->sendSeqNumber++;
                         $this->packetToSend[] = $pk;
                         unset($this->recoveryQueue[$seq]);
                     }
                 }
             }
         }
     } elseif ($packet::$ID > 0x0 and $packet::$ID < 0x80) {
         //Not Data packet :)
         $packet->decode();
         if ($packet instanceof UNCONNECTED_PING) {
             $pk = new UNCONNECTED_PONG();
             $pk->serverID = $this->sessionManager->getID();
             $pk->pingID = $packet->pingID;
             $pk->serverName = $this->sessionManager->getName(true);
             $this->sendPacket($pk);
             $pk->serverName = $this->sessionManager->getName(false);
             $this->sendPacket($pk);
         } elseif ($packet instanceof OPEN_CONNECTION_REQUEST_1) {
             $packet->protocol;
             //TODO: check protocol number and refuse connections
             $pk = new OPEN_CONNECTION_REPLY_1();
             $pk->mtuSize = $packet->mtuSize;
             $pk->serverID = $this->sessionManager->getID();
             $this->sendPacket($pk);
             $this->state = self::STATE_CONNECTING_1;
         } elseif ($this->state === self::STATE_CONNECTING_1 and $packet instanceof OPEN_CONNECTION_REQUEST_2) {
             $this->id = $packet->clientID;
             if ($packet->serverPort === $this->sessionManager->getPort() or !$this->sessionManager->portChecking) {
                 $this->mtuSize = \min(\abs($packet->mtuSize), 1464);
                 //Max size, do not allow creating large buffers to fill server memory
                 $pk = new OPEN_CONNECTION_REPLY_2();
                 $pk->mtuSize = $this->mtuSize;
                 $pk->serverID = $this->sessionManager->getID();
                 $pk->clientAddress = $this->address;
                 $pk->clientPort = $this->port;
                 $this->sendPacket($pk);
                 $this->state = self::STATE_CONNECTING_2;
             }
         }
     }
 }
开发者ID:1455931078,项目名称:Genisys,代码行数:90,代码来源:Session.php

示例3: decode

 public function decode()
 {
     parent::decode();
     $this->clientID = Binary::readLong($this->get(8));
     $this->sendPing = Binary::readLong($this->get(8));
     $this->useSecurity = \ord($this->get(1)) > 0;
 }
开发者ID:xpyctum,项目名称:PocketMinePlusPlus,代码行数:7,代码来源:CLIENT_CONNECT_DataPacket__32bit.php

示例4: decode

 public function decode()
 {
     parent::decode();
     $this->clientID = Binary::readLong($this->get(8));
     $this->session = Binary::readLong($this->get(8));
     $this->unknown = $this->get(1);
 }
开发者ID:Hydreon,项目名称:PMSoft238,代码行数:7,代码来源:CLIENT_CONNECT_DataPacket.php

示例5: decode

 public function decode()
 {
     parent::decode();
     $this->offset += 16;
     //Magic
     $this->protocol = \ord($this->get(1));
     $this->mtuSize = \strlen($this->get(\true)) + 18;
 }
开发者ID:kakichi,项目名称:ClearSky,代码行数:8,代码来源:OPEN_CONNECTION_REQUEST_1.php

示例6: decode

 public function decode()
 {
     parent::decode();
     $this->offset += 16;
     //Magic
     $this->protocol = $this->getByte();
     $this->mtuSize = strlen($this->get(true)) + 18;
 }
开发者ID:NewDelion,项目名称:PocketMine-0.13.x,代码行数:8,代码来源:OPEN_CONNECTION_REQUEST_1.php

示例7: decode

 public function decode()
 {
     parent::decode();
     $this->pingID = $this->getLong();
     $this->serverID = $this->getLong();
     $this->offset += 16;
     //magic
     $this->serverName = $this->getString();
 }
开发者ID:NewDelion,项目名称:PocketMine-0.13.x,代码行数:9,代码来源:UNCONNECTED_PONG.php

示例8: decode

 public function decode()
 {
     parent::decode();
     $this->offset += 16;
     //Magic
     $this->getAddress($this->serverAddress, $this->serverPort);
     $this->mtuSize = \unpack("n", $this->get(2))[1];
     $this->clientID = Binary::readLong($this->get(8));
 }
开发者ID:xpyctum,项目名称:PocketMinePlusPlus,代码行数:9,代码来源:OPEN_CONNECTION_REQUEST_2__64bit.php

示例9: decode

 public function decode()
 {
     parent::decode();
     $this->offset += 16;
     //Magic
     $this->getAddress($this->serverAddress, $this->serverPort);
     $this->mtuSize = $this->getShort();
     $this->clientID = $this->getLong();
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:9,代码来源:OPEN_CONNECTION_REQUEST_2.php

示例10: decode

 public function decode()
 {
     parent::decode();
     $this->pingID = Binary::readLong($this->get(8));
     $this->serverID = Binary::readLong($this->get(8));
     $this->offset += 16;
     //magic
     $this->serverName = $this->getString();
 }
开发者ID:kakichi,项目名称:ClearSky,代码行数:9,代码来源:UNCONNECTED_PONG.php

示例11: decode

 public function decode()
 {
     parent::decode();
     $this->offset += 16;
     //Magic
     $this->serverID = Binary::readLong($this->get(8));
     $this->clientPort = unpack("n", $this->get(2))[1];
     $this->mtuSize = unpack("n", $this->get(2))[1];
     //server security
 }
开发者ID:Hydreon,项目名称:PMSoft238,代码行数:10,代码来源:OPEN_CONNECTION_REPLY_2.php

示例12: decode

 public function decode()
 {
     parent::decode();
     $this->offset += 16;
     //Magic
     $this->serverID = Binary::readLong($this->get(8));
     \ord($this->get(1));
     //security
     $this->mtuSize = \unpack("n", $this->get(2))[1];
 }
开发者ID:TylerAndrew,项目名称:Steadfast2,代码行数:10,代码来源:OPEN_CONNECTION_REPLY_1.php

示例13: decode

 public function decode()
 {
     parent::decode();
     $this->offset += 16;
     //Magic
     $this->serverID = $this->getLong();
     $this->clientPort = $this->getShort();
     $this->mtuSize = $this->getShort();
     //server security
 }
开发者ID:hlogeon,项目名称:PocketMineJs-MP,代码行数:10,代码来源:OPEN_CONNECTION_REPLY_2.php

示例14: decode

 public function decode()
 {
     parent::decode();
     $this->getAddress($this->address, $this->port);
     for ($i = 0; $i < 10; ++$i) {
         $this->getAddress($addr, $port, $version);
         $this->systemAddresses[$i] = [$addr, $port, $version];
     }
     $this->sendPing = Binary::readLong($this->get(8));
     $this->sendPong = Binary::readLong($this->get(8));
 }
开发者ID:TylerAndrew,项目名称:Steadfast2,代码行数:11,代码来源:CLIENT_HANDSHAKE_DataPacket.php

示例15: decode

 public function decode()
 {
     parent::decode();
     $this->cookie = $this->get(4);
     $this->security = $this->get(1);
     $this->port = unpack("n", $this->get(2))[1];
     $this->dataArray0 = $this->get(ord($this->get(1)));
     $this->dataArray = $this->getDataArray(9);
     $this->timestamp = $this->get(2);
     $this->session2 = Binary::readLong($this->get(8));
     $this->session = Binary::readLong($this->get(8));
 }
开发者ID:Hydreon,项目名称:PMSoft238,代码行数:12,代码来源:CLIENT_HANDSHAKE_DataPacket.php


注:本文中的raklib\protocol\Packet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。