diff --git a/build/server-phar.php b/build/server-phar.php index d99bf9943..95d725e4c 100644 --- a/build/server-phar.php +++ b/build/server-phar.php @@ -130,9 +130,13 @@ function main() : void{ exit(1); } - $opts = getopt("", ["out:"]); - $gitHash = Git::getRepositoryStatePretty(dirname(__DIR__)); - echo "Git hash detected as $gitHash" . PHP_EOL; + $opts = getopt("", ["out:", "git:"]); + if(isset($opts["git"])){ + $gitHash = $opts["git"]; + }else{ + $gitHash = Git::getRepositoryStatePretty(dirname(__DIR__)); + echo "Git hash detected as $gitHash" . PHP_EOL; + } foreach(buildPhar( $opts["out"] ?? getcwd() . DIRECTORY_SEPARATOR . "PocketMine-MP.phar", dirname(__DIR__) . DIRECTORY_SEPARATOR, diff --git a/composer.json b/composer.json index 5fc01e8d7..d3d05d0c8 100644 --- a/composer.json +++ b/composer.json @@ -31,8 +31,9 @@ "pocketmine/math": "^0.2.0", "pocketmine/snooze": "^0.1.0", "pocketmine/classloader": "^0.1.0", - "pocketmine/log": "^0.1.0", - "daverandom/callback-validator": "dev-master", + "pocketmine/log": "^0.2.0", + "pocketmine/log-pthreads": "^0.1.0", + "pocketmine/callback-validator": "^1.0.1", "adhocore/json-comment": "^0.1.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 4ff8a37c6..5bb800d84 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": "0a965a0cd39d5b3dd7b0ee1f0abe009b", + "content-hash": "6870d7b85559a32e2929692e0a0da169", "packages": [ { "name": "adhocore/json-comment", @@ -50,46 +50,6 @@ ], "time": "2020-01-03T13:51:23+00:00" }, - { - "name": "daverandom/callback-validator", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/DaveRandom/CallbackValidator.git", - "reference": "d87a08cddbc6099816ed01e50ce25cdfc43b542f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/DaveRandom/CallbackValidator/zipball/d87a08cddbc6099816ed01e50ce25cdfc43b542f", - "reference": "d87a08cddbc6099816ed01e50ce25cdfc43b542f", - "shasum": "" - }, - "require": { - "ext-reflection": "*", - "php": ">=7.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "DaveRandom\\CallbackValidator\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Chris Wright", - "email": "cw@daverandom.com" - } - ], - "description": "Tools for validating callback signatures", - "time": "2017-04-03T15:22:41+00:00" - }, { "name": "pocketmine/binaryutils", "version": "0.1.11", @@ -124,6 +84,49 @@ "description": "Classes and methods for conveniently handling binary data", "time": "2020-01-28T12:09:56+00:00" }, + { + "name": "pocketmine/callback-validator", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/pmmp/CallbackValidator.git", + "reference": "4aef6bb25f97d0b830ba0b4f66834b1a9c86fc9a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pmmp/CallbackValidator/zipball/4aef6bb25f97d0b830ba0b4f66834b1a9c86fc9a", + "reference": "4aef6bb25f97d0b830ba0b4f66834b1a9c86fc9a", + "shasum": "" + }, + "require": { + "ext-reflection": "*", + "php": ">=7.1" + }, + "replace": { + "daverandom/callback-validator": "*" + }, + "require-dev": { + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "DaveRandom\\CallbackValidator\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chris Wright", + "email": "cw@daverandom.com" + } + ], + "description": "Fork of daverandom/callback-validator - Tools for validating callback signatures", + "time": "2020-03-17T12:04:22+00:00" + }, { "name": "pocketmine/classloader", "version": "0.1.0", @@ -164,27 +167,27 @@ }, { "name": "pocketmine/log", - "version": "0.1.0", + "version": "0.2.0", "source": { "type": "git", "url": "https://github.com/pmmp/Log.git", - "reference": "62c1f0ea5a5c0ae4b308f9bd231fb11638ff866e" + "reference": "e59bedb5d4bbeb9a26647cb7c367cb2fa72addfa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/Log/zipball/62c1f0ea5a5c0ae4b308f9bd231fb11638ff866e", - "reference": "62c1f0ea5a5c0ae4b308f9bd231fb11638ff866e", + "url": "https://api.github.com/repos/pmmp/Log/zipball/e59bedb5d4bbeb9a26647cb7c367cb2fa72addfa", + "reference": "e59bedb5d4bbeb9a26647cb7c367cb2fa72addfa", "shasum": "" }, "require": { - "ext-pthreads": "~3.2.0", "php": ">=7.2" }, "conflict": { "pocketmine/spl": "<0.4" }, "require-dev": { - "phpstan/phpstan": "^0.12.8" + "phpstan/phpstan": "^0.12.8", + "phpstan/phpstan-strict-rules": "^0.12.2" }, "type": "library", "autoload": { @@ -197,7 +200,45 @@ "LGPL-3.0" ], "description": "Logging components used by PocketMine-MP and related projects", - "time": "2020-01-31T14:31:47+00:00" + "time": "2020-03-31T15:43:47+00:00" + }, + { + "name": "pocketmine/log-pthreads", + "version": "0.1.0", + "source": { + "type": "git", + "url": "https://github.com/pmmp/LogPthreads.git", + "reference": "9bbcef398b01487ab47c234a6a7054722abbe067" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pmmp/LogPthreads/zipball/9bbcef398b01487ab47c234a6a7054722abbe067", + "reference": "9bbcef398b01487ab47c234a6a7054722abbe067", + "shasum": "" + }, + "require": { + "ext-pthreads": "~3.2.0", + "php": ">=7.2", + "pocketmine/log": "^0.2.0" + }, + "conflict": { + "pocketmine/spl": "<0.4" + }, + "require-dev": { + "phpstan/phpstan": "^0.12.18" + }, + "type": "library", + "autoload": { + "classmap": [ + "./src" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "description": "Logging components specialized for pthreads used by PocketMine-MP and related projects", + "time": "2020-03-31T16:17:19+00:00" }, { "name": "pocketmine/math", @@ -272,31 +313,32 @@ }, { "name": "pocketmine/raklib", - "version": "0.12.7", + "version": "0.12.8", "source": { "type": "git", "url": "https://github.com/pmmp/RakLib.git", - "reference": "01abb4e78e2ef69a83d50037d558e0b274f8245b" + "reference": "9fea763ffc922db083e4528d4acd0b13d0ea83a4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/RakLib/zipball/01abb4e78e2ef69a83d50037d558e0b274f8245b", - "reference": "01abb4e78e2ef69a83d50037d558e0b274f8245b", + "url": "https://api.github.com/repos/pmmp/RakLib/zipball/9fea763ffc922db083e4528d4acd0b13d0ea83a4", + "reference": "9fea763ffc922db083e4528d4acd0b13d0ea83a4", "shasum": "" }, "require": { - "ext-bcmath": "*", "ext-pthreads": "~3.2.0", "ext-sockets": "*", "php": ">=7.2.0", "php-64bit": "*", "php-ipv6": "*", "pocketmine/binaryutils": "^0.1.9", - "pocketmine/log": "^0.1.0", + "pocketmine/log": "^0.2.0", + "pocketmine/log-pthreads": "^0.1.0", "pocketmine/snooze": "^0.1.0" }, "require-dev": { - "phpstan/phpstan": "^0.12.8" + "phpstan/phpstan": "^0.12.18", + "phpstan/phpstan-strict-rules": "^0.12.2" }, "type": "library", "autoload": { @@ -309,7 +351,7 @@ "GPL-3.0" ], "description": "A RakNet server implementation written in PHP", - "time": "2020-01-31T15:33:05+00:00" + "time": "2020-03-31T17:28:28+00:00" }, { "name": "pocketmine/snooze", @@ -382,11 +424,11 @@ "packages-dev": [ { "name": "irstea/phpunit-shim", - "version": "8.5.2", + "version": "8.5.3", "source": { "type": "git", "url": "https://gitlab.irstea.fr/pole-is/tools/phpunit-shim.git", - "reference": "8ec63f895972681271191821a36f9081c236b993" + "reference": "b55d058d7ad3cf516068f22138a5b8fb724605db" }, "require": { "ext-dom": "*", @@ -432,20 +474,20 @@ "testing", "xunit" ], - "time": "2020-01-23T13:39:47+00:00" + "time": "2020-04-01T02:21:12+00:00" }, { "name": "phpstan/phpstan", - "version": "0.12.14", + "version": "0.12.18", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "37bdd26a80235d0f9045b49f4151102b7831cbe2" + "reference": "1ce27fe29c8660a27926127d350d53d80c4d4286" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/37bdd26a80235d0f9045b49f4151102b7831cbe2", - "reference": "37bdd26a80235d0f9045b49f4151102b7831cbe2", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/1ce27fe29c8660a27926127d350d53d80c4d4286", + "reference": "1ce27fe29c8660a27926127d350d53d80c4d4286", "shasum": "" }, "require": { @@ -471,7 +513,7 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", - "time": "2020-03-02T22:29:43+00:00" + "time": "2020-03-22T16:51:47+00:00" }, { "name": "phpstan/phpstan-phpunit", @@ -583,9 +625,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "daverandom/callback-validator": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -609,6 +649,5 @@ "ext-zip": "*", "ext-zlib": ">=1.2.11" }, - "platform-dev": [], - "plugin-api-version": "1.1.0" + "platform-dev": [] } diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index acc08a5c2..c48de117b 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2535,6 +2535,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $cancelled = false; $heldItem = $this->inventory->getItemInHand(); + $oldItem = clone $heldItem; if(!$this->canInteract($target, 8)){ $cancelled = true; @@ -2594,7 +2595,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if($this->isAlive()){ //reactive damage like thorns might cause us to be killed by attacking another mob, which //would mean we'd already have dropped the inventory by the time we reached here - if($heldItem->onAttackEntity($target) and $this->isSurvival() and $heldItem->equalsExact($this->inventory->getItemInHand())){ //always fire the hook, even if we are survival + if($heldItem->onAttackEntity($target) and $this->isSurvival() and $oldItem->equalsExact($this->inventory->getItemInHand())){ //always fire the hook, even if we are survival $this->inventory->setItemInHand($heldItem); } diff --git a/src/pocketmine/entity/AttributeMap.php b/src/pocketmine/entity/AttributeMap.php index 930e90c14..73de5cbc9 100644 --- a/src/pocketmine/entity/AttributeMap.php +++ b/src/pocketmine/entity/AttributeMap.php @@ -71,10 +71,13 @@ class AttributeMap implements \ArrayAccess{ } /** - * @param int $offset - * @param float $value + * @param int|null $offset + * @param float $value */ public function offsetSet($offset, $value) : void{ + if($offset === null){ + throw new \InvalidArgumentException("Array push syntax is not supported"); + } $this->attributes[$offset]->setValue($value); } diff --git a/src/pocketmine/level/format/io/region/Anvil.php b/src/pocketmine/level/format/io/region/Anvil.php index d602fd8a2..6464269cf 100644 --- a/src/pocketmine/level/format/io/region/Anvil.php +++ b/src/pocketmine/level/format/io/region/Anvil.php @@ -33,6 +33,7 @@ use pocketmine\nbt\tag\ByteArrayTag; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntArrayTag; use pocketmine\nbt\tag\ListTag; +use function zlib_decode; class Anvil extends McRegion{ @@ -96,8 +97,12 @@ class Anvil extends McRegion{ } protected function nbtDeserialize(string $data) : Chunk{ + $data = @zlib_decode($data); + if($data === false){ + throw new CorruptedChunkException("Failed to decompress chunk data"); + } $nbt = new BigEndianNBTStream(); - $chunk = $nbt->readCompressed($data); + $chunk = $nbt->read($data); if(!($chunk instanceof CompoundTag) or !$chunk->hasTag("Level")){ throw new CorruptedChunkException("'Level' key is missing from chunk NBT"); } diff --git a/src/pocketmine/level/format/io/region/McRegion.php b/src/pocketmine/level/format/io/region/McRegion.php index 3516fc598..946ee5170 100644 --- a/src/pocketmine/level/format/io/region/McRegion.php +++ b/src/pocketmine/level/format/io/region/McRegion.php @@ -58,6 +58,7 @@ use function strrpos; use function substr; use function time; use function unpack; +use function zlib_decode; use const SCANDIR_SORT_NONE; class McRegion extends BaseLevelProvider{ @@ -125,8 +126,12 @@ class McRegion extends BaseLevelProvider{ * @throws CorruptedChunkException */ protected function nbtDeserialize(string $data) : Chunk{ + $data = @zlib_decode($data); + if($data === false){ + throw new CorruptedChunkException("Failed to decompress chunk data"); + } $nbt = new BigEndianNBTStream(); - $chunk = $nbt->readCompressed($data); + $chunk = $nbt->read($data); if(!($chunk instanceof CompoundTag) or !$chunk->hasTag("Level")){ throw new CorruptedChunkException("'Level' key is missing from chunk NBT"); } diff --git a/src/pocketmine/network/rcon/RCON.php b/src/pocketmine/network/rcon/RCON.php index 617f2ea9c..61a123e37 100644 --- a/src/pocketmine/network/rcon/RCON.php +++ b/src/pocketmine/network/rcon/RCON.php @@ -41,14 +41,17 @@ use function socket_getsockname; use function socket_last_error; use function socket_listen; use function socket_set_block; +use function socket_set_option; use function socket_strerror; use function socket_write; use function trim; use const AF_INET; use const AF_UNIX; +use const SO_REUSEADDR; use const SOCK_STREAM; use const SOCKET_ENOPROTOOPT; use const SOCKET_EPROTONOSUPPORT; +use const SOL_SOCKET; use const SOL_TCP; class RCON{ @@ -74,6 +77,10 @@ class RCON{ $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); + if(!socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR, 1)){ + throw new \RuntimeException("Unable to set option on socket: " . trim(socket_strerror(socket_last_error()))); + } + if($this->socket === false or !@socket_bind($this->socket, $interface, $port) or !@socket_listen($this->socket, 5)){ throw new \RuntimeException(trim(socket_strerror(socket_last_error()))); }