From 660d42e8d1b1571fc829468001a0b9d361115da4 Mon Sep 17 00:00:00 2001 From: Dylan T Date: Thu, 13 Dec 2018 20:07:17 +0000 Subject: [PATCH 1/7] Backport usage of SetLocalPlayerAsInitializedPacket to 3.4 (#2558) This fixes various problems, such as forms not working on PlayerJoinEvent. --- src/pocketmine/Player.php | 16 ++++++++-------- .../network/mcpe/PlayerNetworkSessionAdapter.php | 6 ++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b2df4f827..0373872fb 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -276,7 +276,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** @var int */ protected $spawnThreshold; /** @var int */ - protected $chunkLoadCount = 0; + protected $spawnChunkLoadCount = 0; /** @var int */ protected $chunksPerTick; @@ -962,8 +962,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } $this->usedChunks[Level::chunkHash($x, $z)] = true; - $this->chunkLoadCount++; - $this->dataPacket($payload); if($this->spawned){ @@ -974,8 +972,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - if($this->chunkLoadCount >= $this->spawnThreshold and !$this->spawned){ - $this->doFirstSpawn(); + if($this->spawnChunkLoadCount !== -1 and ++$this->spawnChunkLoadCount >= $this->spawnThreshold){ + $this->sendPlayStatus(PlayStatusPacket::PLAYER_SPAWN); + $this->spawnChunkLoadCount = -1; } } @@ -1013,11 +1012,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ Timings::$playerChunkSendTimer->stopTiming(); } - protected function doFirstSpawn(){ + public function doFirstSpawn(){ + if($this->spawned){ + return; //avoid player spawning twice (this can only happen on 3.x with a custom malicious client) + } $this->spawned = true; - $this->sendPlayStatus(PlayStatusPacket::PLAYER_SPAWN); - if($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)){ PermissionManager::getInstance()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this); } diff --git a/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php b/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php index adecfab3d..44b245b94 100644 --- a/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php +++ b/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php @@ -58,6 +58,7 @@ use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket; use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket; use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket; use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket; +use pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket; use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket; use pocketmine\network\mcpe\protocol\ShowCreditsPacket; use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket; @@ -280,4 +281,9 @@ class PlayerNetworkSessionAdapter extends NetworkSession{ public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{ return false; //TODO: GUI stuff } + + public function handleSetLocalPlayerAsInitialized(SetLocalPlayerAsInitializedPacket $packet) : bool{ + $this->player->doFirstSpawn(); + return true; + } } From cbb9c4f2989740ca5c1db5445c2f0b7bc0f40410 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 13 Dec 2018 17:54:15 +0000 Subject: [PATCH 2/7] Entity: require scale > 0 in setScale(), fixes #2563 --- src/pocketmine/entity/Entity.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 02bdfba10..e080c8874 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -637,6 +637,9 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ * @param float $value */ public function setScale(float $value) : void{ + if($value <= 0){ + throw new \InvalidArgumentException("Scale must be greater than 0"); + } $multiplier = $value / $this->getScale(); $this->width *= $multiplier; From ed88684e7120caebb4795d55842b6da95c1a8d5d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 13 Dec 2018 18:20:30 +0000 Subject: [PATCH 3/7] Fixed invisible FloatingTextParticle crashing the server, closes #2560 --- src/pocketmine/level/Level.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 38ea07f37..a651de3c6 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -450,13 +450,14 @@ class Level implements ChunkManager, Metadatable{ if(!is_array($pk)){ $pk = [$pk]; } - - if($players === null){ - foreach($pk as $e){ - $this->broadcastPacketToViewers($sound, $e); + if(!empty($pk)){ + if($players === null){ + foreach($pk as $e){ + $this->broadcastPacketToViewers($sound, $e); + } + }else{ + $this->server->batchPackets($players, $pk, false); } - }else{ - $this->server->batchPackets($players, $pk, false); } } @@ -465,13 +466,14 @@ class Level implements ChunkManager, Metadatable{ if(!is_array($pk)){ $pk = [$pk]; } - - if($players === null){ - foreach($pk as $e){ - $this->broadcastPacketToViewers($particle, $e); + if(!empty($pk)){ + if($players === null){ + foreach($pk as $e){ + $this->broadcastPacketToViewers($particle, $e); + } + }else{ + $this->server->batchPackets($players, $pk, false); } - }else{ - $this->server->batchPackets($players, $pk, false); } } From 9b2653fb6ff2a5d83f5b7f6c35ec30bbe512a18d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 14 Dec 2018 09:29:59 +0000 Subject: [PATCH 4/7] Release 3.4.2 --- src/pocketmine/PocketMine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index f414f3b09..06df5b2fa 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -38,7 +38,7 @@ namespace pocketmine { const NAME = "PocketMine-MP"; const BASE_VERSION = "3.4.2"; - const IS_DEVELOPMENT_BUILD = true; + const IS_DEVELOPMENT_BUILD = false; const BUILD_NUMBER = 0; const MIN_PHP_VERSION = "7.2.0"; From d4fe1b8ece830c06d1565b31219f54daf32012c7 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 14 Dec 2018 09:30:44 +0000 Subject: [PATCH 5/7] 3.4.3 is next --- src/pocketmine/PocketMine.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 06df5b2fa..c120b7714 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -37,8 +37,8 @@ namespace pocketmine { use pocketmine\wizard\SetupWizard; const NAME = "PocketMine-MP"; - const BASE_VERSION = "3.4.2"; - const IS_DEVELOPMENT_BUILD = false; + const BASE_VERSION = "3.4.3"; + const IS_DEVELOPMENT_BUILD = true; const BUILD_NUMBER = 0; const MIN_PHP_VERSION = "7.2.0"; From b42132a7c36903608008697b38d96ed026db3ab3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 14 Dec 2018 09:45:47 +0000 Subject: [PATCH 6/7] Release 3.5.1 --- src/pocketmine/PocketMine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 3051f9b5c..191d77519 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -38,7 +38,7 @@ namespace pocketmine { const NAME = "PocketMine-MP"; const BASE_VERSION = "3.5.1"; - const IS_DEVELOPMENT_BUILD = true; + const IS_DEVELOPMENT_BUILD = false; const BUILD_NUMBER = 0; const MIN_PHP_VERSION = "7.2.0"; From 5934399a0d33e7fceab76abccfebdcb19ba0cf79 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 14 Dec 2018 09:46:12 +0000 Subject: [PATCH 7/7] 3.5.2 is next --- src/pocketmine/PocketMine.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 191d77519..92909c8ac 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -37,8 +37,8 @@ namespace pocketmine { use pocketmine\wizard\SetupWizard; const NAME = "PocketMine-MP"; - const BASE_VERSION = "3.5.1"; - const IS_DEVELOPMENT_BUILD = false; + const BASE_VERSION = "3.5.2"; + const IS_DEVELOPMENT_BUILD = true; const BUILD_NUMBER = 0; const MIN_PHP_VERSION = "7.2.0";