本文整理汇总了PHP中pocketmine\Server::batchPackets方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::batchPackets方法的具体用法?PHP Server::batchPackets怎么用?PHP Server::batchPackets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\Server
的用法示例。
在下文中一共展示了Server::batchPackets方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
$packet->__encapsulatedPacket->reliability = PacketReliability::RELIABLE_ORDERED;
$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;
$packet->reliability = PacketReliability::RELIABLE_ORDERED;
$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;
}
示例2: putPacket
public function putPacket(Player $player, DataPacket $packet, $needACK = false, $immediate = false)
{
if (isset($this->identifiers[$h = spl_object_hash($player)])) {
if (\pocketmine\DEBUG > 2) {
echo "SendDataPacket: 0x" . bin2hex(chr($packet::NETWORK_ID)) . "\n";
}
$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 = $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::NETWORK_ID !== 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;
}
示例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;
}
示例4: addParticle
public function addParticle(Particle $particle, array $players = null)
{
$pk = $particle->encode();
if ($players === null) {
$players = $this->getUsingChunk($particle->x >> 4, $particle->z >> 4);
}
if ($pk !== null) {
if (!is_array($pk)) {
Server::broadcastPacket($players, $pk);
} else {
$this->server->batchPackets($players, $pk, false);
}
}
}
示例5: addParticle
public function addParticle(Particle $particle, array $players = null)
{
$pk = $particle->encode();
if ($players === null) {
$players = $this->getUsingChunk($particle->x >> 4, $particle->z >> 4);
}
if ($pk !== null) {
if (!is_array($pk)) {
Server::broadcastPacket($players, $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
} else {
$this->server->batchPackets($players, $pk, false, Network::CHANNEL_WORLD_EVENTS);
}
}
}
示例6: addParticle
public function addParticle(Particle $particle, array $players = \null)
{
$pk = $particle->encode();
if ($players === \null) {
if ($pk !== \null) {
if (!\is_array($pk)) {
$this->addChunkPacket($particle->x >> 4, $particle->z >> 4, $pk);
} else {
foreach ($pk as $e) {
$this->addChunkPacket($particle->x >> 4, $particle->z >> 4, $e);
}
}
}
} else {
if ($pk !== \null) {
if (!\is_array($pk)) {
Server::broadcastPacket($players, $pk);
} else {
$this->server->batchPackets($players, $pk, \false);
}
}
}
}
示例7: sendBlocks
/**
* @param Player[] $target
* @param Block[] $blocks
* @param int $flags
* @param bool $optimizeRebuilds
*/
public function sendBlocks(array $target, array $blocks, $flags = UpdateBlockPacket::FLAG_NONE, $optimizeRebuilds = false)
{
$batchPacketList = [];
$top = -1;
if ($optimizeRebuilds) {
$chunks = [];
foreach ($blocks as $b) {
if ($b === null) {
continue;
}
++$top;
$batchPacketList[$top] = new UpdateBlockPacket();
$first = false;
if (!isset($chunks[$index = Level::chunkHash($b->x >> 4, $b->z >> 4)])) {
$chunks[$index] = true;
$first = true;
}
if ($b instanceof Block) {
$batchPacketList[$top]->records[] = [$b->x, $b->z, $b->y, $b->getId(), $b->getDamage(), $first ? $flags : UpdateBlockPacket::FLAG_NONE];
} else {
$fullBlock = $this->getFullBlock($b->x, $b->y, $b->z);
$batchPacketList[$top]->records[] = [$b->x, $b->z, $b->y, $fullBlock >> 4, $fullBlock & 0xf, $first ? $flags : UpdateBlockPacket::FLAG_NONE];
}
}
} else {
foreach ($blocks as $b) {
if ($b === null) {
continue;
}
++$top;
$batchPacketList[$top] = new UpdateBlockPacket();
if ($b instanceof Block) {
$batchPacketList[$top]->records[] = [$b->x, $b->z, $b->y, $b->getId(), $b->getDamage(), $flags];
} else {
$fullBlock = $this->getFullBlock($b->x, $b->y, $b->z);
$batchPacketList[$top]->records[] = [$b->x, $b->z, $b->y, $fullBlock >> 4, $fullBlock & 0xf, $flags];
}
}
}
$this->server->batchPackets($target, $batchPacketList);
}
示例8: addSound
public function addSound(Sound $sound, array $players = null)
{
$pk = $sound->encode();
if ($players === null) {
if ($pk !== null) {
if (!is_array($pk)) {
$this->addChunkPacket($sound->x >> 4, $sound->z >> 4, $pk);
} else {
foreach ($pk as $e) {
$this->addChunkPacket($sound->x >> 4, $sound->z >> 4, $e);
}
}
}
} else {
if ($pk !== null) {
if (!is_array($pk)) {
Server::broadcastPacket($players, $pk);
} else {
$this->server->batchPackets($players, $pk, false);
}
}
}
}