diff --git a/BUILDING.md b/BUILDING.md index 369e57e63c..4a2b132b05 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -8,7 +8,7 @@ ## Custom PHP binaries Because PocketMine-MP requires several non-standard PHP extensions and configuration, PMMP provides scripts to build custom binaries for running PocketMine-MP, as well as prebuilt binaries. -- [Prebuilt binaries](https://jenkins.pmmp.io/job/PHP-7.3-Aggregate) +- [Prebuilt binaries](https://jenkins.pmmp.io/job/PHP-7.4-Aggregate) - [Compile scripts](https://github.com/pmmp/php-build-scripts) are provided as a submodule in the path `build/php` If you use a custom binary, you'll need to replace `composer` usages in this guide with `path/to/your/php path/to/your/composer.phar`. diff --git a/README.md b/README.md index bff7e31be2..3d1787e384 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ ## For developers * [Building and running from source](BUILDING.md) + * [Developer documentation](https://devdoc.pmmp.io) - General documentation for PocketMine-MP plugin developers * [Latest API documentation](https://jenkins.pmmp.io/job/PocketMine-MP-doc/doxygen/) - Doxygen documentation generated from development * [DevTools](https://github.com/pmmp/DevTools/) - Development tools plugin for creating plugins * [ExamplePlugin](https://github.com/pmmp/ExamplePlugin/) - Example plugin demonstrating some basic API features diff --git a/composer.json b/composer.json index 2f2e35a1ed..893b7c364c 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "respect/validation": "^2.0" }, "require-dev": { - "phpstan/phpstan": "0.12.81", + "phpstan/phpstan": "0.12.82", "phpstan/phpstan-phpunit": "^0.12.6", "phpstan/phpstan-strict-rules": "^0.12.2", "phpunit/phpunit": "^9.2" diff --git a/doxygen/index.md b/doxygen/index.md index 357c82504e..182bd9ecca 100644 --- a/doxygen/index.md +++ b/doxygen/index.md @@ -7,4 +7,4 @@ This site can be accessed via https://apidoc.pmmp.io. ### Additional developer resources - [DevTools](https://github.com/pmmp/DevTools/) - Development tools plugin for creating plugins - [ExamplePlugin](https://github.com/pmmp/ExamplePlugin/) - Example plugin demonstrating some basic API features - - [DeveloperDocs](https://github.com/pmmp/DeveloperDocs/) - Reference, guides and specifications for the PocketMine-MP API + - [DeveloperDocs](https://devdoc.pmmp.io) - General documentation for PocketMine-MP plugin developers diff --git a/src/command/CommandReader.php b/src/command/CommandReader.php index 20c0a5d751..ac74145ecb 100644 --- a/src/command/CommandReader.php +++ b/src/command/CommandReader.php @@ -114,37 +114,28 @@ class CommandReader extends Thread{ * @return bool if the main execution should continue reading lines */ private function readLine() : bool{ - $line = ""; - if(!is_resource(self::$stdin)){ $this->initStdin(); } - switch($this->type){ - /** @noinspection PhpMissingBreakStatementInspection */ - case self::TYPE_STREAM: - //stream_select doesn't work on piped streams for some reason - $r = [self::$stdin]; - $w = $e = null; - if(($count = stream_select($r, $w, $e, 0, 200000)) === 0){ //nothing changed in 200000 microseconds - return true; - }elseif($count === false){ //stream error - $this->initStdin(); - } - - case self::TYPE_PIPED: - if(($raw = fgets(self::$stdin)) === false){ //broken pipe or EOF - $this->initStdin(); - $this->synchronized(function() : void{ - $this->wait(200000); - }); //prevent CPU waste if it's end of pipe - return true; //loop back round - } - - $line = trim($raw); - break; + $r = [self::$stdin]; + $w = $e = null; + if(($count = stream_select($r, $w, $e, 0, 200000)) === 0){ //nothing changed in 200000 microseconds + return true; + }elseif($count === false){ //stream error + $this->initStdin(); } + if(($raw = fgets(self::$stdin)) === false){ //broken pipe or EOF + $this->initStdin(); + $this->synchronized(function() : void{ + $this->wait(200000); + }); //prevent CPU waste if it's end of pipe + return true; //loop back round + } + + $line = trim($raw); + if($line !== ""){ $this->buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", $line); if($this->notifier !== null){ diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index c3081eff77..c43bb5c589 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -98,6 +98,8 @@ use function base64_encode; use function count; use function fmod; use function implode; +use function is_infinite; +use function is_nan; use function json_decode; use function json_encode; use function json_last_error_msg; @@ -153,6 +155,14 @@ class InGamePacketHandler extends PacketHandler{ } public function handleMovePlayer(MovePlayerPacket $packet) : bool{ + $rawPos = $packet->position; + foreach([$rawPos->x, $rawPos->y, $rawPos->z, $packet->yaw, $packet->headYaw, $packet->pitch] as $float){ + if(is_infinite($float) || is_nan($float)){ + $this->session->getLogger()->debug("Invalid movement received, contains NAN/INF components"); + return false; + } + } + $yaw = fmod($packet->yaw, 360); $pitch = fmod($packet->pitch, 360); if($yaw < 0){ diff --git a/src/network/mcpe/protocol/AvailableCommandsPacket.php b/src/network/mcpe/protocol/AvailableCommandsPacket.php index aa0cb8d481..f9ad2186c9 100644 --- a/src/network/mcpe/protocol/AvailableCommandsPacket.php +++ b/src/network/mcpe/protocol/AvailableCommandsPacket.php @@ -49,25 +49,26 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ * ARG_FLAG_VALID | (type const) */ public const ARG_TYPE_INT = 0x01; - public const ARG_TYPE_FLOAT = 0x02; - public const ARG_TYPE_VALUE = 0x03; - public const ARG_TYPE_WILDCARD_INT = 0x04; - public const ARG_TYPE_OPERATOR = 0x05; - public const ARG_TYPE_TARGET = 0x06; + public const ARG_TYPE_FLOAT = 0x03; + public const ARG_TYPE_VALUE = 0x04; + public const ARG_TYPE_WILDCARD_INT = 0x05; + public const ARG_TYPE_OPERATOR = 0x06; + public const ARG_TYPE_TARGET = 0x07; + public const ARG_TYPE_WILDCARD_TARGET = 0x08; - public const ARG_TYPE_FILEPATH = 0x0e; + public const ARG_TYPE_FILEPATH = 0x10; - public const ARG_TYPE_STRING = 0x1d; + public const ARG_TYPE_STRING = 0x20; - public const ARG_TYPE_POSITION = 0x25; + public const ARG_TYPE_POSITION = 0x28; - public const ARG_TYPE_MESSAGE = 0x29; + public const ARG_TYPE_MESSAGE = 0x2c; - public const ARG_TYPE_RAWTEXT = 0x2b; + public const ARG_TYPE_RAWTEXT = 0x2e; - public const ARG_TYPE_JSON = 0x2f; + public const ARG_TYPE_JSON = 0x32; - public const ARG_TYPE_COMMAND = 0x36; + public const ARG_TYPE_COMMAND = 0x3f; /** * Enums are a little different: they are composed as follows: diff --git a/src/network/mcpe/protocol/CommandOutputPacket.php b/src/network/mcpe/protocol/CommandOutputPacket.php index 40470ba10a..6dc70acc8c 100644 --- a/src/network/mcpe/protocol/CommandOutputPacket.php +++ b/src/network/mcpe/protocol/CommandOutputPacket.php @@ -34,6 +34,11 @@ use function count; class CommandOutputPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::COMMAND_OUTPUT_PACKET; + public const TYPE_LAST = 1; + public const TYPE_SILENT = 2; + public const TYPE_ALL = 3; + public const TYPE_DATA_SET = 4; + /** @var CommandOriginData */ public $originData; /** @var int */ @@ -54,7 +59,7 @@ class CommandOutputPacket extends DataPacket implements ClientboundPacket{ $this->messages[] = $this->getCommandMessage($in); } - if($this->outputType === 4){ + if($this->outputType === self::TYPE_DATA_SET){ $this->unknownString = $in->getString(); } } @@ -85,7 +90,7 @@ class CommandOutputPacket extends DataPacket implements ClientboundPacket{ $this->putCommandMessage($message, $out); } - if($this->outputType === 4){ + if($this->outputType === self::TYPE_DATA_SET){ $out->putString($this->unknownString); } } diff --git a/src/network/mcpe/protocol/EventPacket.php b/src/network/mcpe/protocol/EventPacket.php index 924163f96e..581b02fc74 100644 --- a/src/network/mcpe/protocol/EventPacket.php +++ b/src/network/mcpe/protocol/EventPacket.php @@ -48,6 +48,13 @@ class EventPacket extends DataPacket implements ClientboundPacket{ public const TYPE_CAULDRON_BLOCK_USED = 15; public const TYPE_COMPOSTER_BLOCK_USED = 16; public const TYPE_BELL_BLOCK_USED = 17; + public const TYPE_ACTOR_DEFINITION = 18; + public const TYPE_RAID_UPDATE = 19; + public const TYPE_PLAYER_MOVEMENT_ANOMALY = 20; //anti cheat + public const TYPE_PLAYER_MOVEMENT_CORRECTED = 21; + public const TYPE_HONEY_HARVESTED = 22; + public const TYPE_TARGET_BLOCK_HIT = 23; + public const TYPE_PIGLIN_BARTER = 24; /** @var int */ public $playerRuntimeId; diff --git a/src/network/mcpe/protocol/PlayerAuthInputPacket.php b/src/network/mcpe/protocol/PlayerAuthInputPacket.php index 96442e3769..77fa3f5f9b 100644 --- a/src/network/mcpe/protocol/PlayerAuthInputPacket.php +++ b/src/network/mcpe/protocol/PlayerAuthInputPacket.php @@ -28,6 +28,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; use pocketmine\network\mcpe\protocol\types\InputMode; +use pocketmine\network\mcpe\protocol\types\PlayerAuthInputFlags; use pocketmine\network\mcpe\protocol\types\PlayMode; use function assert; @@ -60,6 +61,7 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{ private $delta; /** + * @param int $inputFlags @see InputFlags * @param int $inputMode @see InputMode * @param int $playMode @see PlayMode * @param Vector3|null $vrGazeDirection only used when PlayMode::VR @@ -111,6 +113,9 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{ return $this->moveVecZ; } + /** + * @see PlayerAuthInputFlags + */ public function getInputFlags() : int{ return $this->inputFlags; } diff --git a/src/network/mcpe/protocol/SetTitlePacket.php b/src/network/mcpe/protocol/SetTitlePacket.php index 58a6d7d332..989b9e9c5f 100644 --- a/src/network/mcpe/protocol/SetTitlePacket.php +++ b/src/network/mcpe/protocol/SetTitlePacket.php @@ -36,6 +36,9 @@ class SetTitlePacket extends DataPacket implements ClientboundPacket{ public const TYPE_SET_SUBTITLE = 3; public const TYPE_SET_ACTIONBAR_MESSAGE = 4; public const TYPE_SET_ANIMATION_TIMES = 5; + public const TYPE_SET_TITLE_JSON = 6; + public const TYPE_SET_SUBTITLE_JSON = 7; + public const TYPE_SET_ACTIONBAR_MESSAGE_JSON = 8; /** @var int */ public $type; diff --git a/src/network/mcpe/protocol/types/PlayerAuthInputFlags.php b/src/network/mcpe/protocol/types/PlayerAuthInputFlags.php new file mode 100644 index 0000000000..83104c88ed --- /dev/null +++ b/src/network/mcpe/protocol/types/PlayerAuthInputFlags.php @@ -0,0 +1,75 @@ +\\) does not accept key \\(int\\|string\\)\\.$#" count: 3