public function broadcastPacketsCallback($data, array $identifiers, $channel = 0) { $pk = new BatchPacket(); $pk->setChannel($channel); $pk->payload = $data; $pk->encode(); $pk->isEncoded = \true; foreach ($identifiers as $i) { if (isset($this->players[$i])) { $this->players[$i]->dataPacket($pk); } } }
/** * @param $chunkX * @param $chunkZ * @param $payload * * @return DataPacket */ public static function getChunkCacheFromData($chunkX, $chunkZ, $payload) { $pk = new FullChunkDataPacket(); $pk->chunkX = $chunkX; $pk->chunkZ = $chunkZ; $pk->data = $payload; $pk->encode(); $batch = new BatchPacket(); $batch->payload = zlib_encode($pk->getBuffer(), ZLIB_ENCODING_DEFLATE, Server::getInstance()->networkCompressionLevel); $batch->setChannel(Network::CHANNEL_WORLD_CHUNKS); $batch->encode(); $batch->isEncoded = true; return $batch; }
public function sendChunks($data = array()) { if ($this->connected === \false) { return; } $bt = new BatchPacket(); $str = ""; foreach ($data as $set) { $x = $set["x"]; $z = $set["z"]; $payload = $set["payload"]; $this->usedChunks[Level::chunkHash($x, $z)] = true; $this->chunkLoadCount++; $pk = new FullChunkDataPacket(); $pk->chunkX = $x; $pk->chunkZ = $z; $pk->data = $payload; $pk->setChannel(Network::CHANNEL_WORLD_CHUNKS); $pk->encode(); $str .= $pk->buffer; } $bt->setChannel($this->spawned ? Network::CHANNEL_WORLD_CHUNKS : Network::CHANNEL_PRIORITY); $bt->payload = zlib_encode($str, ZLIB_ENCODING_DEFLATE, 6); $bt->encode(); $bt->isEncoded = true; $this->dataPacket($bt); foreach ($data as $set) { $x = $set["x"]; $z = $set["z"]; $payload = $set["payload"]; if ($this->spawned) { foreach ($this->level->getChunkEntities($x, $z) as $entity) { if ($entity !== $this and !$entity->closed and !$entity->dead) { $entity->spawnTo($this); } } } } }