From 6854830b6e802cd4bce66107294e262a1a3fb8d5 Mon Sep 17 00:00:00 2001 From: zSALLAZAR <59490940+zSALLAZAR@users.noreply.github.com> Date: Mon, 13 Feb 2023 13:21:35 +0100 Subject: [PATCH 01/11] start.sh: Use -n instead of ! -z (#5567) See https://github.com/koalaman/shellcheck/wiki/SC2236 --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index 63a9a273b..74b24591a 100755 --- a/start.sh +++ b/start.sh @@ -23,7 +23,7 @@ if [ "$PHP_BINARY" == "" ]; then if [ -f ./bin/php7/bin/php ]; then export PHPRC="" PHP_BINARY="./bin/php7/bin/php" - elif [[ ! -z $(type php 2> /dev/null) ]]; then + elif [[ -n $(type php 2> /dev/null) ]]; then PHP_BINARY=$(type -p php) else echo "Couldn't find a PHP binary in system PATH or $PWD/bin/php7/bin" From 69155015c9cf53cd96e1df2b87cb340460f5c0e4 Mon Sep 17 00:00:00 2001 From: zSALLAZAR <59490940+zSALLAZAR@users.noreply.github.com> Date: Mon, 13 Feb 2023 13:24:47 +0100 Subject: [PATCH 02/11] Double quote array expansions to avoid re-splitting elements. (#5570) See: https://github.com/koalaman/shellcheck/wiki/SC2068 --- start.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index 74b24591a..0121f3887 100755 --- a/start.sh +++ b/start.sh @@ -51,12 +51,12 @@ if [ "$DO_LOOP" == "yes" ]; then if [ ${LOOPS} -gt 0 ]; then echo "Restarted $LOOPS times" fi - "$PHP_BINARY" "$POCKETMINE_FILE" $@ + "$PHP_BINARY" "$POCKETMINE_FILE" "$@" echo "To escape the loop, press CTRL+C now. Otherwise, wait 5 seconds for the server to restart." echo "" sleep 5 ((LOOPS++)) done else - exec "$PHP_BINARY" "$POCKETMINE_FILE" $@ + exec "$PHP_BINARY" "$POCKETMINE_FILE" "$@" fi From 2fd6e769e611b2cfe3501532c5b26394ddd1dd55 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 15 Feb 2023 14:59:05 +0000 Subject: [PATCH 03/11] NetworkSession: Improved packet budgeting this fixes players getting kicked during server lag spikes. closes #5532 --- src/network/mcpe/NetworkSession.php | 35 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index 0caccb53c..53fe430f9 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -361,12 +361,9 @@ class NetworkSession{ } if($this->incomingPacketBatchBudget <= 0){ - if(!function_exists('xdebug_is_debugger_active') || !xdebug_is_debugger_active()){ + $this->updatePacketBudget(); + if($this->incomingPacketBatchBudget <= 0){ throw new PacketHandlingException("Receiving packets too fast"); - }else{ - //when a debugging session is active, the server may halt at any point for an indefinite length of time, - //in which time the client will continue to send packets - $this->incomingPacketBatchBudget = self::INCOMING_PACKET_BATCH_MAX_BUDGET; } } $this->incomingPacketBatchBudget--; @@ -1143,6 +1140,23 @@ class NetworkSession{ $this->sendDataPacket(ToastRequestPacket::create($title, $body)); } + private function updatePacketBudget() : void{ + $nowNs = hrtime(true); + $timeSinceLastUpdateNs = $nowNs - $this->lastPacketBudgetUpdateTimeNs; + if($timeSinceLastUpdateNs > 50_000_000){ + $ticksSinceLastUpdate = intdiv($timeSinceLastUpdateNs, 50_000_000); + /* + * If the server takes an abnormally long time to process a tick, add the budget for time difference to + * compensate. This extra budget may be very large, but it will disappear the next time a normal update + * occurs. This ensures that backlogs during a large lag spike don't cause everyone to get kicked. + * As long as all the backlogged packets are processed before the next tick, everything should be OK for + * clients behaving normally. + */ + $this->incomingPacketBatchBudget = min($this->incomingPacketBatchBudget, self::INCOMING_PACKET_BATCH_MAX_BUDGET) + (self::INCOMING_PACKET_BATCH_PER_TICK * 2 * $ticksSinceLastUpdate); + $this->lastPacketBudgetUpdateTimeNs = $nowNs; + } + } + public function tick() : void{ if(!$this->isConnected()){ $this->dispose(); @@ -1170,16 +1184,5 @@ class NetworkSession{ } $this->flushSendBuffer(); - - $nowNs = hrtime(true); - $timeSinceLastUpdateNs = $nowNs - $this->lastPacketBudgetUpdateTimeNs; - if($timeSinceLastUpdateNs > 50_000_000){ - $ticksSinceLastUpdate = intdiv($timeSinceLastUpdateNs, 50_000_000); - $this->incomingPacketBatchBudget = min( - $this->incomingPacketBatchBudget + (self::INCOMING_PACKET_BATCH_PER_TICK * 2 * $ticksSinceLastUpdate), - self::INCOMING_PACKET_BATCH_MAX_BUDGET - ); - $this->lastPacketBudgetUpdateTimeNs = $nowNs; - } } } From 910c4c4b24510d422af0888a098a87cc40735abc Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 15 Feb 2023 15:02:00 +0000 Subject: [PATCH 04/11] Updated BedrockProtocol --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 74be1967b..04ec45376 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "fgrosse/phpasn1": "^2.3", "netresearch/jsonmapper": "^4.0", "pocketmine/bedrock-data": "~1.14.0+bedrock-1.19.60", - "pocketmine/bedrock-protocol": "~19.0.0+bedrock-1.19.60", + "pocketmine/bedrock-protocol": "~19.1.0+bedrock-1.19.60", "pocketmine/binaryutils": "^0.2.1", "pocketmine/callback-validator": "^1.0.2", "pocketmine/classloader": "^0.2.0", diff --git a/composer.lock b/composer.lock index 630320020..f87d2be11 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f4a0fb9a6731f083ef7e29fc3f527171", + "content-hash": "2121c9df1e7a2193339f5a4fc9f70f52", "packages": [ { "name": "adhocore/json-comment", @@ -276,16 +276,16 @@ }, { "name": "pocketmine/bedrock-protocol", - "version": "19.0.0+bedrock-1.19.60", + "version": "19.1.0+bedrock-1.19.60", "source": { "type": "git", "url": "https://github.com/pmmp/BedrockProtocol.git", - "reference": "3c8cf08d09b8b3fafc209d184e66e50d2e34c06c" + "reference": "b57d8145cb765110d599dd68241f2ebe68c80933" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/BedrockProtocol/zipball/3c8cf08d09b8b3fafc209d184e66e50d2e34c06c", - "reference": "3c8cf08d09b8b3fafc209d184e66e50d2e34c06c", + "url": "https://api.github.com/repos/pmmp/BedrockProtocol/zipball/b57d8145cb765110d599dd68241f2ebe68c80933", + "reference": "b57d8145cb765110d599dd68241f2ebe68c80933", "shasum": "" }, "require": { @@ -317,9 +317,9 @@ "description": "An implementation of the Minecraft: Bedrock Edition protocol in PHP", "support": { "issues": "https://github.com/pmmp/BedrockProtocol/issues", - "source": "https://github.com/pmmp/BedrockProtocol/tree/19.0.0+bedrock-1.19.60" + "source": "https://github.com/pmmp/BedrockProtocol/tree/19.1.0+bedrock-1.19.60" }, - "time": "2023-02-08T18:38:02+00:00" + "time": "2023-02-15T12:35:51+00:00" }, { "name": "pocketmine/binaryutils", From c5dcd268ad0c5f0932b1b6e27e264b9d8a8b36df Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 15 Feb 2023 15:04:41 +0000 Subject: [PATCH 05/11] CS --- src/network/mcpe/NetworkSession.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index 53fe430f9..ebc943960 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -129,7 +129,6 @@ use function array_values; use function base64_encode; use function bin2hex; use function count; -use function function_exists; use function get_class; use function hrtime; use function in_array; @@ -143,7 +142,6 @@ use function strtolower; use function substr; use function time; use function ucfirst; -use function xdebug_is_debugger_active; use const JSON_THROW_ON_ERROR; use const SORT_NUMERIC; From d7a0f5362e7d9617f239f02cb7f9c5e9d5b92407 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 15 Feb 2023 15:19:38 +0000 Subject: [PATCH 06/11] Release 4.14.1 --- changelogs/4.14.md | 7 +++++++ src/VersionInfo.php | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/changelogs/4.14.md b/changelogs/4.14.md index 206e99048..f266e8b01 100644 --- a/changelogs/4.14.md +++ b/changelogs/4.14.md @@ -12,3 +12,10 @@ Released 8th February 2023. ## General - Added support for Minecraft: Bedrock Edition 1.19.60. - Removed support for older versions. + +# 4.14.1 +Released 15th February 2023. + +## Fixes +- Fixed all players getting kicked with `Receiving packets too fast` if a server tick takes longer than 5 seconds (e.g. because of autosave or GC). +- Fixed players getting kicked when linking with entities. diff --git a/src/VersionInfo.php b/src/VersionInfo.php index 74aeaa19c..0847d4c37 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -32,7 +32,7 @@ use function str_repeat; final class VersionInfo{ public const NAME = "PocketMine-MP"; public const BASE_VERSION = "4.14.1"; - public const IS_DEVELOPMENT_BUILD = true; + public const IS_DEVELOPMENT_BUILD = false; public const BUILD_CHANNEL = "stable"; private function __construct(){ From 396d64c60bb5c9aefd625dff1dd7b5a6541e8402 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 15 Feb 2023 15:19:39 +0000 Subject: [PATCH 07/11] 4.14.2 is next --- src/VersionInfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VersionInfo.php b/src/VersionInfo.php index 0847d4c37..99a977fda 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -31,8 +31,8 @@ use function str_repeat; final class VersionInfo{ public const NAME = "PocketMine-MP"; - public const BASE_VERSION = "4.14.1"; - public const IS_DEVELOPMENT_BUILD = false; + public const BASE_VERSION = "4.14.2"; + public const IS_DEVELOPMENT_BUILD = true; public const BUILD_CHANNEL = "stable"; private function __construct(){ From 1e3b025916ad2c1ce5f33dbdca5bf1d6e013b44a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 17 Feb 2023 16:36:32 +0000 Subject: [PATCH 08/11] 1.19.62 --- composer.json | 2 +- composer.lock | 14 ++++++------- .../mcpe/handler/LoginPacketHandler.php | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 04ec45376..159e007be 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "fgrosse/phpasn1": "^2.3", "netresearch/jsonmapper": "^4.0", "pocketmine/bedrock-data": "~1.14.0+bedrock-1.19.60", - "pocketmine/bedrock-protocol": "~19.1.0+bedrock-1.19.60", + "pocketmine/bedrock-protocol": "~19.2.0+bedrock-1.19.62", "pocketmine/binaryutils": "^0.2.1", "pocketmine/callback-validator": "^1.0.2", "pocketmine/classloader": "^0.2.0", diff --git a/composer.lock b/composer.lock index f87d2be11..9bd452dca 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2121c9df1e7a2193339f5a4fc9f70f52", + "content-hash": "56a1e8facd8fd7d56d6c7d2eb390e842", "packages": [ { "name": "adhocore/json-comment", @@ -276,16 +276,16 @@ }, { "name": "pocketmine/bedrock-protocol", - "version": "19.1.0+bedrock-1.19.60", + "version": "19.2.0+bedrock-1.19.62", "source": { "type": "git", "url": "https://github.com/pmmp/BedrockProtocol.git", - "reference": "b57d8145cb765110d599dd68241f2ebe68c80933" + "reference": "a156db582d0b1a6c20c9d9cc9b1df7ef907efd0b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/BedrockProtocol/zipball/b57d8145cb765110d599dd68241f2ebe68c80933", - "reference": "b57d8145cb765110d599dd68241f2ebe68c80933", + "url": "https://api.github.com/repos/pmmp/BedrockProtocol/zipball/a156db582d0b1a6c20c9d9cc9b1df7ef907efd0b", + "reference": "a156db582d0b1a6c20c9d9cc9b1df7ef907efd0b", "shasum": "" }, "require": { @@ -317,9 +317,9 @@ "description": "An implementation of the Minecraft: Bedrock Edition protocol in PHP", "support": { "issues": "https://github.com/pmmp/BedrockProtocol/issues", - "source": "https://github.com/pmmp/BedrockProtocol/tree/19.1.0+bedrock-1.19.60" + "source": "https://github.com/pmmp/BedrockProtocol/tree/19.2.0+bedrock-1.19.62" }, - "time": "2023-02-15T12:35:51+00:00" + "time": "2023-02-17T16:32:49+00:00" }, { "name": "pocketmine/binaryutils", diff --git a/src/network/mcpe/handler/LoginPacketHandler.php b/src/network/mcpe/handler/LoginPacketHandler.php index 80f162697..6d896aba9 100644 --- a/src/network/mcpe/handler/LoginPacketHandler.php +++ b/src/network/mcpe/handler/LoginPacketHandler.php @@ -84,6 +84,27 @@ class LoginPacketHandler extends PacketHandler{ } $clientData = $this->parseClientData($packet->clientDataJwt); + + //TODO: REMOVE THIS + //Mojang forgot to bump the protocol version when they changed protocol in 1.19.62. Check the game version instead. + if(preg_match('/^(\d+)\.(\d+)\.(\d+)/', $clientData->GameVersion, $matches) !== 1){ + throw new PacketHandlingException("Invalid game version format, expected at least 3 digits"); + } + $major = (int) $matches[1]; + $minor = (int) $matches[2]; + $patch = (int) $matches[3]; + if($major === 1 && $minor === 19 && $patch < 62){ + $this->session->sendDataPacket(PlayStatusPacket::create(PlayStatusPacket::LOGIN_FAILED_CLIENT), true); + + //This pocketmine disconnect message will only be seen by the console (PlayStatusPacket causes the messages to be shown for the client) + $this->session->disconnect( + $this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_disconnect_incompatibleProtocol("$packet->protocol (< v1.19.62)")), + false + ); + + return true; + } + try{ $skin = SkinAdapterSingleton::get()->fromSkinData(ClientDataToSkinDataHelper::fromClientData($clientData)); }catch(\InvalidArgumentException | InvalidSkinException $e){ From 9a6d7b505cca3440228d276ce5363de26ce430a1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 17 Feb 2023 16:37:34 +0000 Subject: [PATCH 09/11] Release 4.15.0 --- changelogs/4.15.md | 14 ++++++++++++++ src/VersionInfo.php | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 changelogs/4.15.md diff --git a/changelogs/4.15.md b/changelogs/4.15.md new file mode 100644 index 000000000..b80115e88 --- /dev/null +++ b/changelogs/4.15.md @@ -0,0 +1,14 @@ +**For Minecraft: Bedrock Edition 1.19.62** + +### Note about API versions +Plugins which don't touch the protocol and compatible with any previous 4.x.y version will also run on these releases and do not need API bumps. +Plugin developers should **only** update their required API to this version if you need the changes in this build. + +**WARNING: If your plugin uses the protocol, you're not shielded by API change constraints.** You should consider using the `mcpe-protocol` directive in `plugin.yml` as a constraint if you do. + +# 4.15.0 +Released 17th February 2023. + +## General +- Added support for Minecraft: Bedrock Edition 1.19.62. +- Removed support for older versions. diff --git a/src/VersionInfo.php b/src/VersionInfo.php index 99a977fda..18cd74521 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -31,8 +31,8 @@ use function str_repeat; final class VersionInfo{ public const NAME = "PocketMine-MP"; - public const BASE_VERSION = "4.14.2"; - public const IS_DEVELOPMENT_BUILD = true; + public const BASE_VERSION = "4.15.0"; + public const IS_DEVELOPMENT_BUILD = false; public const BUILD_CHANNEL = "stable"; private function __construct(){ From 38828e2b424cd193e71e3fc9f1e06a5a02334ac5 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 17 Feb 2023 16:37:34 +0000 Subject: [PATCH 10/11] 4.15.1 is next --- src/VersionInfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VersionInfo.php b/src/VersionInfo.php index 18cd74521..a763bf070 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -31,8 +31,8 @@ use function str_repeat; final class VersionInfo{ public const NAME = "PocketMine-MP"; - public const BASE_VERSION = "4.15.0"; - public const IS_DEVELOPMENT_BUILD = false; + public const BASE_VERSION = "4.15.1"; + public const IS_DEVELOPMENT_BUILD = true; public const BUILD_CHANNEL = "stable"; private function __construct(){ From 71aad310c614453b8a2404a95994d04c15328c3d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 17 Feb 2023 16:39:46 +0000 Subject: [PATCH 11/11] stfu --- src/network/mcpe/handler/LoginPacketHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/network/mcpe/handler/LoginPacketHandler.php b/src/network/mcpe/handler/LoginPacketHandler.php index 6d896aba9..c2367454b 100644 --- a/src/network/mcpe/handler/LoginPacketHandler.php +++ b/src/network/mcpe/handler/LoginPacketHandler.php @@ -46,6 +46,7 @@ use pocketmine\player\XboxLivePlayerInfo; use pocketmine\Server; use Ramsey\Uuid\Uuid; use function is_array; +use function preg_match; /** * Handles the initial login phase of the session. This handler is used as the initial state.