From 0f174f76050f81909f725aff46a4210d378d0307 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 18 May 2017 15:58:09 +0100 Subject: [PATCH 1/9] Fixed ServerKiller always killing on shutdown on single-core machines, close #170 --- src/pocketmine/PocketMine.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 29317e941..5503c9c22 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -491,6 +491,7 @@ namespace pocketmine { $killer = new ServerKiller(8); $killer->start(); + usleep(10000); //Fixes ServerKiller not being able to start on single-core machines $erroredThreads = 0; foreach(ThreadManager::getInstance()->getAll() as $id => $thread){ From 0207b221105535c6df15f0416aea7487b33af568 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 21 May 2017 12:44:42 +0100 Subject: [PATCH 2/9] Fixed Mojang world converters barfing on PocketMine-MP generated McRegion worlds blame @shoghicp --- src/pocketmine/level/format/io/region/Anvil.php | 4 ++++ src/pocketmine/level/format/io/region/McRegion.php | 10 +++++++++- src/pocketmine/level/format/io/region/PMAnvil.php | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/level/format/io/region/Anvil.php b/src/pocketmine/level/format/io/region/Anvil.php index 084126b5f..7bb36b24b 100644 --- a/src/pocketmine/level/format/io/region/Anvil.php +++ b/src/pocketmine/level/format/io/region/Anvil.php @@ -156,6 +156,10 @@ class Anvil extends McRegion{ return "anvil"; } + public static function getPcWorldFormatVersion() : int{ + return 19133; //anvil + } + public function getWorldHeight() : int{ //TODO: add world height options return 256; diff --git a/src/pocketmine/level/format/io/region/McRegion.php b/src/pocketmine/level/format/io/region/McRegion.php index 5d9e29758..8f893abca 100644 --- a/src/pocketmine/level/format/io/region/McRegion.php +++ b/src/pocketmine/level/format/io/region/McRegion.php @@ -210,6 +210,14 @@ class McRegion extends BaseLevelProvider{ return "mcregion"; } + /** + * Returns the storage version as per Minecraft PC world formats. + * @return int + */ + public static function getPcWorldFormatVersion() : int{ + return 19132; //mcregion + } + public function getWorldHeight() : int{ //TODO: add world height options return 128; @@ -251,7 +259,7 @@ class McRegion extends BaseLevelProvider{ "SpawnX" => new IntTag("SpawnX", 256), "SpawnY" => new IntTag("SpawnY", 70), "SpawnZ" => new IntTag("SpawnZ", 256), - "version" => new IntTag("version", 19133), + "version" => new IntTag("version", static::getPcWorldFormatVersion()), "DayTime" => new IntTag("DayTime", 0), "LastPlayed" => new LongTag("LastPlayed", microtime(true) * 1000), "RandomSeed" => new LongTag("RandomSeed", $seed), diff --git a/src/pocketmine/level/format/io/region/PMAnvil.php b/src/pocketmine/level/format/io/region/PMAnvil.php index 9ec30c203..64a62b1d3 100644 --- a/src/pocketmine/level/format/io/region/PMAnvil.php +++ b/src/pocketmine/level/format/io/region/PMAnvil.php @@ -150,4 +150,8 @@ class PMAnvil extends Anvil{ public static function getProviderName() : string{ return "pmanvil"; } + + public static function getPcWorldFormatVersion() : int{ + return -1; //Not a PC format, only PocketMine-MP + } } \ No newline at end of file From aecff7c782f9700beaace01b62c18ed974b0e40b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 21 May 2017 13:27:27 +0100 Subject: [PATCH 3/9] Revert "Improved handling of incompatible protocols" This reverts commit 576702ffa97e16b1ca4cdee7d94460c661347ca7. This crippled plugins which use data fromm LoginPacket :S --- src/pocketmine/Player.php | 27 +++++++------------ .../network/mcpe/protocol/LoginPacket.php | 7 +++-- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b4ffe0c1f..b9809f763 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1907,6 +1907,15 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return false; } + $this->username = TextFormat::clean($packet->username); + $this->displayName = $this->username; + $this->iusername = strtolower($this->username); + $this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $this->username, false); + + if(count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)){ + return true; + } + if($packet->protocol !== ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol < ProtocolInfo::CURRENT_PROTOCOL){ $message = "disconnectionScreen.outdatedClient"; @@ -1920,19 +1929,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return true; } - $packet->decodeAdditional(); - - //TODO: check MCEE - - $this->username = TextFormat::clean($packet->username); - $this->displayName = $this->username; - $this->iusername = strtolower($this->username); - $this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $this->username, false); - - if(count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)){ - return true; - } - $this->randomClientId = $packet->clientId; $this->uuid = UUID::fromString($packet->clientUUID); @@ -3369,16 +3365,13 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $timings->startTiming(); $packet->decode(); + assert($packet->feof(), "Still " . strlen(substr($packet->buffer, $packet->offset)) . " bytes unread in " . get_class($packet)); $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet)); if(!$ev->isCancelled() and !$packet->handle($this)){ $this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->getName() . ": 0x" . bin2hex($packet->buffer)); } - if(!$packet->feof()){ - $this->server->getLogger()->debug("Still " . strlen(substr($packet->buffer, $packet->offset)) . " bytes unread in " . get_class($packet) . " from " . $this->getName() . ": " . bin2hex($packet->get(true))); - } - $timings->stopTiming(); } diff --git a/src/pocketmine/network/mcpe/protocol/LoginPacket.php b/src/pocketmine/network/mcpe/protocol/LoginPacket.php index be249eb03..b8a596475 100644 --- a/src/pocketmine/network/mcpe/protocol/LoginPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LoginPacket.php @@ -54,9 +54,12 @@ class LoginPacket extends DataPacket{ public function decode(){ $this->protocol = $this->getInt(); - } - public function decodeAdditional(){ + if($this->protocol !== ProtocolInfo::CURRENT_PROTOCOL){ + $this->buffer = null; + return; //Do not attempt to decode for non-accepted protocols + } + $this->gameEdition = $this->getByte(); $str = zlib_decode($this->getString(), 1024 * 1024 * 64); From c5527db4248604cb6ed5154e8d9632c8ab583ea2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 21 May 2017 13:58:01 +0100 Subject: [PATCH 4/9] Be more clear about ProtocolInfo being automatically generated and add notice to not bother submitting PRs for changing version numbers (#931) --- .../network/mcpe/protocol/ProtocolInfo.php | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php b/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php index e789512ff..2a829ddb5 100644 --- a/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php +++ b/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php @@ -16,23 +16,35 @@ * @author PocketMine Team * @link http://www.pocketmine.net/ * - * This file is generated automatically, do not edit it manually. * */ -/** - * Minecraft: PE multiplayer protocol implementation - */ namespace pocketmine\network\mcpe\protocol; - +/** + * Version numbers and packet IDs for the current Minecraft PE protocol + */ interface ProtocolInfo{ + /** + * NOTE TO DEVELOPERS + * Do not waste your time or ours submitting pull requests changing game and/or protocol version numbers. + * Pull requests changing game and/or protocol version numbers will be closed. + * + * This file is generated automatically, do not edit it manually. + */ + /** * Actual Minecraft: PE protocol version */ const CURRENT_PROTOCOL = 107; + /** + * Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. + */ const MINECRAFT_VERSION = 'v1.0.7.0'; + /** + * Version number sent to clients in ping responses. + */ const MINECRAFT_VERSION_NETWORK = '1.0.7.0'; const LOGIN_PACKET = 0x01; From 4e381ab03321ff9dd42e94a40c2adb20a7a6c1b7 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 21 May 2017 14:40:36 +0100 Subject: [PATCH 5/9] Added DATA_COLOR alias --- src/pocketmine/entity/Entity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 0a92b237e..60c6f4469 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -76,7 +76,7 @@ abstract class Entity extends Location implements Metadatable{ const DATA_FLAGS = 0; //1 (int) const DATA_VARIANT = 2; //int - const DATA_COLOUR = 3; //byte + const DATA_COLOR = 3, DATA_COLOUR = 3; //byte const DATA_NAMETAG = 4; //string const DATA_OWNER_EID = 5; //long From 674394c4f5fb62daf491fdf04ce47c79a8c5bbb3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 22 May 2017 06:53:57 +0100 Subject: [PATCH 6/9] Fixed undefined offset when retrieving something from the thread store that doesn't exist (#919) --- src/pocketmine/scheduler/AsyncTask.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/scheduler/AsyncTask.php b/src/pocketmine/scheduler/AsyncTask.php index cd50ac11e..3c531f206 100644 --- a/src/pocketmine/scheduler/AsyncTask.php +++ b/src/pocketmine/scheduler/AsyncTask.php @@ -139,7 +139,7 @@ abstract class AsyncTask extends Collectable{ */ public function getFromThreadStore($identifier){ global $store; - return $this->isGarbage() ? null : $store[$identifier]; + return ($this->isGarbage() or !isset($store[$identifier])) ? null : $store[$identifier]; } /** From 23ed3334c29b885a6293dbb70400e739670ddfd3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 23 May 2017 16:26:29 +0100 Subject: [PATCH 7/9] added creative mode check for block picking --- src/pocketmine/Player.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b9809f763..14f1c4c10 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2416,18 +2416,21 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ - $tile = $this->getLevel()->getTile($this->temporalVector->setComponents($packet->tileX, $packet->tileY, $packet->tileZ)); - if($tile instanceof Tile){ //TODO: check if the held item matches the target tile - $nbt = $tile->getCleanedNBT(); - if($nbt instanceof CompoundTag){ - $item = $this->inventory->getItemInHand(); - $item->setCustomBlockData($nbt); - $item->setLore(["+(DATA)"]); - $this->inventory->setItemInHand($item); - } + if($this->isCreative()){ + $tile = $this->getLevel()->getTile($this->temporalVector->setComponents($packet->tileX, $packet->tileY, $packet->tileZ)); + if($tile instanceof Tile){ //TODO: check if the held item matches the target tile + $nbt = $tile->getCleanedNBT(); + if($nbt instanceof CompoundTag){ + $item = $this->inventory->getItemInHand(); + $item->setCustomBlockData($nbt); + $item->setLore(["+(DATA)"]); + $this->inventory->setItemInHand($item); + } - return true; + return true; + } } + return false; } From 5c8297f4a16e0c25a5d12ec8e76e451dc4673875 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 23 May 2017 19:48:49 +0100 Subject: [PATCH 8/9] Fixed some logic issues with falling blocks, fix #897 #899 #935 --- src/pocketmine/entity/FallingSand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index 945892eb4..2ff81d4e7 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -121,7 +121,8 @@ class FallingSand extends Entity{ if($this->onGround){ $this->kill(); $block = $this->level->getBlock($pos); - if($block->getId() > 0 and !$block->isSolid() and !($block instanceof Liquid)){ + if($block->getId() > 0 and $block->isTransparent() and !$block->canBeReplaced()){ + //FIXME: falling blocks are supposed to be destroyed by glass blocks, and anvils are supposed to destroy torches $this->getLevel()->dropItem($this, ItemItem::get($this->getBlock(), $this->getDamage(), 1)); }else{ $this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), $this->getDamage()))); From 92281da5147e068c667c75aebf903ad854413b37 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 23 May 2017 20:02:23 +0100 Subject: [PATCH 9/9] Fix wrong comment in FallingSand This is actually a bug in MCPE --- src/pocketmine/entity/FallingSand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index 2ff81d4e7..6d1d526d4 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -122,7 +122,7 @@ class FallingSand extends Entity{ $this->kill(); $block = $this->level->getBlock($pos); if($block->getId() > 0 and $block->isTransparent() and !$block->canBeReplaced()){ - //FIXME: falling blocks are supposed to be destroyed by glass blocks, and anvils are supposed to destroy torches + //FIXME: anvils are supposed to destroy torches $this->getLevel()->dropItem($this, ItemItem::get($this->getBlock(), $this->getDamage(), 1)); }else{ $this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), $this->getDamage())));