PocketMine-MP/src/pocketmine/network/CompressBatchedTask.php
Dylan K. Taylor f903dbfe00 Server: Removed identifiers array
This is completely unnecessary and adds extra complexity for no good reason. Maybe it was used historically, but nowadays it is only used to identify players to send async-prepared batch packets to.

There are two alternative ways to do that:
1. use spl_object_hash() as the targets array in CompressBatchedTask
2. use ServerScheduler's object storage to retain references to the Player[] array.

I've opted for the second method.

Removing these identifiers allows great code simplification in removePlayer() and removes the need for those old stupid hacks.

This also includes a backwards-compatibility break by removing the $identifier parameter of Server->addPlayer().
2018-02-27 11:43:02 +00:00

67 lines
1.7 KiB
PHP

<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network;
use pocketmine\network\mcpe\protocol\BatchPacket;
use pocketmine\Player;
use pocketmine\scheduler\AsyncTask;
use pocketmine\Server;
class CompressBatchedTask extends AsyncTask{
public $level = 7;
public $data;
/**
* @param BatchPacket $batch
* @param string[] $targets
*/
public function __construct(BatchPacket $batch, array $targets){
$this->data = $batch->payload;
$this->level = $batch->getCompressionLevel();
$this->storeLocal($targets);
}
public function onRun(){
$batch = new BatchPacket();
$batch->payload = $this->data;
$this->data = null;
$batch->setCompressionLevel($this->level);
$batch->encode();
$this->setResult($batch->buffer, false);
}
public function onCompletion(Server $server){
$pk = new BatchPacket($this->getResult());
$pk->isEncoded = true;
/** @var Player[] $targets */
$targets = $this->fetchLocal();
$server->broadcastPacketsCallback($pk, $targets);
}
}