mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 02:38:54 +00:00
Server->batchPackets() now only accepts DataPacket objects, fixed players receiving double PlayerListPackets with their own data
This commit is contained in:
parent
15b47fcb2f
commit
fe8cb8cd86
@ -1750,7 +1750,7 @@ class Server{
|
|||||||
$packet->encode();
|
$packet->encode();
|
||||||
$packet->isEncoded = true;
|
$packet->isEncoded = true;
|
||||||
if(Network::$BATCH_THRESHOLD >= 0 and strlen($packet->buffer) >= Network::$BATCH_THRESHOLD){
|
if(Network::$BATCH_THRESHOLD >= 0 and strlen($packet->buffer) >= Network::$BATCH_THRESHOLD){
|
||||||
$this->batchPackets($players, [$packet->buffer], false);
|
$this->batchPackets($players, [$packet], false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1766,19 +1766,13 @@ class Server{
|
|||||||
* Broadcasts a list of packets in a batch to a list of players
|
* Broadcasts a list of packets in a batch to a list of players
|
||||||
*
|
*
|
||||||
* @param Player[] $players
|
* @param Player[] $players
|
||||||
* @param DataPacket[]|string $packets
|
* @param DataPacket[] $packets
|
||||||
* @param bool $forceSync
|
* @param bool $forceSync
|
||||||
* @param bool $immediate
|
* @param bool $immediate
|
||||||
*/
|
*/
|
||||||
public function batchPackets(array $players, array $packets, $forceSync = false, bool $immediate = false){
|
public function batchPackets(array $players, array $packets, $forceSync = false, bool $immediate = false){
|
||||||
Timings::$playerNetworkTimer->startTiming();
|
Timings::$playerNetworkTimer->startTiming();
|
||||||
|
|
||||||
$pk = new BatchPacket();
|
|
||||||
|
|
||||||
foreach($packets as $p){
|
|
||||||
$pk->addPacket($p);
|
|
||||||
}
|
|
||||||
|
|
||||||
$targets = [];
|
$targets = [];
|
||||||
foreach($players as $p){
|
foreach($players as $p){
|
||||||
if($p->isConnected()){
|
if($p->isConnected()){
|
||||||
@ -1786,6 +1780,13 @@ class Server{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(count($targets) > 0){
|
||||||
|
$pk = new BatchPacket();
|
||||||
|
|
||||||
|
foreach($packets as $p){
|
||||||
|
$pk->addPacket($p);
|
||||||
|
}
|
||||||
|
|
||||||
if(!$forceSync and $this->networkCompressionAsync){
|
if(!$forceSync and $this->networkCompressionAsync){
|
||||||
$task = new CompressBatchedTask($pk, $targets, $this->networkCompressionLevel, $immediate);
|
$task = new CompressBatchedTask($pk, $targets, $this->networkCompressionLevel, $immediate);
|
||||||
$this->getScheduler()->scheduleAsyncTask($task);
|
$this->getScheduler()->scheduleAsyncTask($task);
|
||||||
@ -1793,6 +1794,7 @@ class Server{
|
|||||||
$pk->compress($this->networkCompressionLevel);
|
$pk->compress($this->networkCompressionLevel);
|
||||||
$this->broadcastPacketsCallback($pk, $targets, $immediate);
|
$this->broadcastPacketsCallback($pk, $targets, $immediate);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Timings::$playerNetworkTimer->stopTiming();
|
Timings::$playerNetworkTimer->stopTiming();
|
||||||
}
|
}
|
||||||
@ -2168,9 +2170,9 @@ class Server{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function addOnlinePlayer(Player $player){
|
public function addOnlinePlayer(Player $player){
|
||||||
$this->playerList[$player->getRawUniqueId()] = $player;
|
|
||||||
|
|
||||||
$this->updatePlayerListData($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinId(), $player->getSkinData());
|
$this->updatePlayerListData($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkinId(), $player->getSkinData());
|
||||||
|
|
||||||
|
$this->playerList[$player->getRawUniqueId()] = $player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeOnlinePlayer(Player $player){
|
public function removeOnlinePlayer(Player $player){
|
||||||
|
@ -54,20 +54,17 @@ class BatchPacket extends DataPacket{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param DataPacket|string $packet
|
* @param DataPacket $packet
|
||||||
*/
|
*/
|
||||||
public function addPacket($packet){
|
public function addPacket(DataPacket $packet){
|
||||||
if($packet instanceof DataPacket){
|
|
||||||
if(!$packet->canBeBatched()){
|
if(!$packet->canBeBatched()){
|
||||||
throw new \InvalidArgumentException(get_class($packet) . " cannot be put inside a BatchPacket");
|
throw new \InvalidArgumentException(get_class($packet) . " cannot be put inside a BatchPacket");
|
||||||
}
|
}
|
||||||
if(!$packet->isEncoded){
|
if(!$packet->isEncoded){
|
||||||
$packet->encode();
|
$packet->encode();
|
||||||
}
|
}
|
||||||
$packet = $packet->buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->payload .= Binary::writeUnsignedVarInt(strlen($packet)) . $packet;
|
$this->payload .= Binary::writeUnsignedVarInt(strlen($packet->buffer)) . $packet->buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compress(int $level = 7){
|
public function compress(int $level = 7){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user