mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 16:49:53 +00:00
InGamePacketHandler: check the validity of facing values given by the client
This commit is contained in:
parent
d34f4b28b3
commit
f126479c37
@ -39,6 +39,7 @@ use pocketmine\item\VanillaItems;
|
|||||||
use pocketmine\item\WritableBook;
|
use pocketmine\item\WritableBook;
|
||||||
use pocketmine\item\WritableBookPage;
|
use pocketmine\item\WritableBookPage;
|
||||||
use pocketmine\item\WrittenBook;
|
use pocketmine\item\WrittenBook;
|
||||||
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
@ -104,6 +105,7 @@ use function base64_encode;
|
|||||||
use function count;
|
use function count;
|
||||||
use function fmod;
|
use function fmod;
|
||||||
use function implode;
|
use function implode;
|
||||||
|
use function in_array;
|
||||||
use function is_infinite;
|
use function is_infinite;
|
||||||
use function is_nan;
|
use function is_nan;
|
||||||
use function json_decode;
|
use function json_decode;
|
||||||
@ -361,6 +363,8 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
}
|
}
|
||||||
//TODO: end hack for client spam bug
|
//TODO: end hack for client spam bug
|
||||||
|
|
||||||
|
self::validateFacing($data->getFace());
|
||||||
|
|
||||||
$blockPos = $data->getBlockPosition();
|
$blockPos = $data->getBlockPosition();
|
||||||
$vBlockPos = new Vector3($blockPos->getX(), $blockPos->getY(), $blockPos->getZ());
|
$vBlockPos = new Vector3($blockPos->getX(), $blockPos->getY(), $blockPos->getZ());
|
||||||
if(!$this->player->interactBlock($vBlockPos, $data->getFace(), $clickPos)){
|
if(!$this->player->interactBlock($vBlockPos, $data->getFace(), $clickPos)){
|
||||||
@ -392,6 +396,15 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws PacketHandlingException
|
||||||
|
*/
|
||||||
|
private static function validateFacing(int $facing) : void{
|
||||||
|
if(!in_array($facing, Facing::ALL, true)){
|
||||||
|
throw new PacketHandlingException("Invalid facing value $facing");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal function used to execute rollbacks when an action fails on a block.
|
* Internal function used to execute rollbacks when an action fails on a block.
|
||||||
*/
|
*/
|
||||||
@ -504,6 +517,7 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
|
|
||||||
switch($packet->action){
|
switch($packet->action){
|
||||||
case PlayerAction::START_BREAK:
|
case PlayerAction::START_BREAK:
|
||||||
|
self::validateFacing($packet->face);
|
||||||
if(!$this->player->attackBlock($pos, $packet->face)){
|
if(!$this->player->attackBlock($pos, $packet->face)){
|
||||||
$this->onFailedBlockAction($pos, $packet->face);
|
$this->onFailedBlockAction($pos, $packet->face);
|
||||||
}
|
}
|
||||||
@ -547,6 +561,7 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
case PlayerAction::STOP_GLIDE:
|
case PlayerAction::STOP_GLIDE:
|
||||||
break; //TODO
|
break; //TODO
|
||||||
case PlayerAction::CRACK_BREAK:
|
case PlayerAction::CRACK_BREAK:
|
||||||
|
self::validateFacing($packet->face);
|
||||||
$this->player->continueBreakBlock($pos, $packet->face);
|
$this->player->continueBreakBlock($pos, $packet->face);
|
||||||
break;
|
break;
|
||||||
case PlayerAction::START_SWIMMING:
|
case PlayerAction::START_SWIMMING:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user