本文整理汇总了PHP中pocketmine\Player::handleDataPacket方法的典型用法代码示例。如果您正苦于以下问题:PHP Player::handleDataPacket方法的具体用法?PHP Player::handleDataPacket怎么用?PHP Player::handleDataPacket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\Player
的用法示例。
在下文中一共展示了Player::handleDataPacket方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processBatch
public function processBatch(BatchPacket $packet, Player $p)
{
$str = zlib_decode($packet->payload, 1024 * 1024 * 64);
//Max 64MB
$len = strlen($str);
$offset = 0;
try {
while ($offset < $len) {
$pkLen = Binary::readInt(substr($str, $offset, 4));
$offset += 4;
$buf = substr($str, $offset, $pkLen);
$offset += $pkLen;
if (($pk = $this->getPacket(ord($buf[1]))) !== null) {
if ($pk::NETWORK_ID === Info::BATCH_PACKET) {
throw new \InvalidStateException("Invalid BatchPacket inside BatchPacket");
}
$pk->setBuffer($buf, 2);
$pk->decode();
$p->handleDataPacket($pk);
if ($pk->getOffset() <= 0) {
return;
}
}
}
} catch (\Throwable $e) {
if (\pocketmine\DEBUG > 1) {
$logger = $this->server->getLogger();
if ($logger instanceof MainLogger) {
$logger->debug("BatchPacket " . " 0x" . bin2hex($packet->payload));
$logger->logException($e);
}
}
}
}
示例2: processBatch
public function processBatch(BatchPacket $packet, Player $p)
{
$str = \zlib_decode($packet->payload, 1024 * 1024 * 64);
//Max 64MB
$len = \strlen($str);
$offset = 0;
try {
while ($offset < $len) {
$pkLen = \PHP_INT_SIZE === 8 ? \unpack("N", \substr($str, $offset, 4))[1] << 32 >> 32 : \unpack("N", \substr($str, $offset, 4))[1];
$offset += 4;
$buf = \substr($str, $offset, $pkLen);
$offset += $pkLen;
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();
$p->handleDataPacket($pk);
if ($pk->getOffset() <= 0) {
return;
}
}
}
} catch (\Exception $e) {
if (\pocketmine\DEBUG > 1) {
$logger = $this->server->getLogger();
if ($logger instanceof MainLogger) {
$logger->debug("BatchPacket " . " 0x" . \bin2hex($packet->payload));
$logger->logException($e);
}
}
}
}
示例3: handleDataPacket
public function handleDataPacket(DataPacket $packet)
{
$this->lastPacketTime = microtime(true);
return parent::handleDataPacket($packet);
}
示例4: processBatch
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);
}
}
}
示例5: processBatch
public function processBatch(BatchPacket $packet, Player $p)
{
$str = \zlib_decode($packet->payload, 1024 * 1024 * 64);
//Max 64MB
$len = \strlen($str);
$offset = 0;
try {
while ($offset < $len) {
if (($pk = $this->getPacket(\ord($str[$offset++]))) !== \null) {
if ($pk->pid() === Info::BATCH_PACKET) {
throw new \InvalidStateException("Invalid BatchPacket inside BatchPacket");
}
$pk->setBuffer($str, $offset);
$pk->decode();
$p->handleDataPacket($pk);
$offset += $pk->getOffset();
if ($pk->getOffset() <= 0) {
return;
}
}
}
} catch (\Exception $e) {
if (\pocketmine\DEBUG > 1) {
$logger = $this->server->getLogger();
if ($logger instanceof MainLogger) {
$logger->debug("BatchPacket " . " 0x" . \bin2hex($packet->payload));
$logger->logException($e);
}
}
}
}
示例6: handleDataPacket
public function handleDataPacket(DataPacket $packet)
{
parent::handleDataPacket($packet);
}