diff --git a/src/Player.php b/src/Player.php index 9cf9bf66..96eef294 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1474,10 +1474,11 @@ class Player{ } public function makeInvisibleForAllPlayers(){ - foreach($this->server->api->player->getA as $player){ + foreach($this->server->api->player->getAll() as $player){ if($player->CID != $this->CID) $this->setInvisibleFor($player, true); } } + public function getGamemode(){ switch($this->gamemode){ case SURVIVAL: @@ -2803,8 +2804,37 @@ class Player{ break; } if($this->isSleeping) break; + + + //prevent crash caused by nan values + if(is_nan($packet->x) || is_nan($packet->y) || is_nan($packet->z)){ + ConsoleAPI::warn("{$this->username} Attempted to crash the server using NaN position!"); + $this->close("invalid position"); + break; + } + + if(is_infinite($packet->yaw) || is_infinite($packet->pitch) || is_infinite($packet->bodyYaw)){ + ConsoleAPI::warn("{$this->username} Attempted to crash other clients using INF rotation!"); + $this->close("invalid rotation"); + break; + } + + //doesnt crash anything but allows players to break their model rendering(make them/head invisible) + if(is_nan($packet->yaw) || is_nan($packet->pitch) || is_nan($packet->bodyYaw)){ + ConsoleAPI::warn("{$this->username} Attempted to break their model using NAN rotation!"); + $this->close("invalid rotation"); + break; + } + if(($this->entity instanceof Entity) && $packet->messageIndex > $this->lastMovement){ $this->lastMovement = $packet->messageIndex; + //prevent all movement this far - vanilla collisions break there + //farther distances(like inf) may cause client and server crash + if(abs($packet->x) >= 8388608 || abs($packet->y) >= 8388608 || abs($packet->z) >= 8388608){ + $this->addEntityMovementUpdateToQueue($this->entity); + break; + } + $newPos = new Vector3($packet->x, $packet->y, $packet->z); if($this->forceMovement instanceof Vector3){ if($this->forceMovement->distance($newPos) <= 0.7){ diff --git a/src/entity/Entity.php b/src/entity/Entity.php index e68a0d80..85e8d376 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -756,8 +756,8 @@ class Entity extends Position public function positionRider($dead){ if($this->rider != 0){ - $e = $this->level->entityList[$this->rider]; - if($e === false) return; + $e = $this->level->entityList[$this->rider] ?? false; + if(!($e instanceof Entity)) return; $v3 = $this->getRideHeight(); if($dead || $this->dead) $v3 = 0.01; @@ -918,7 +918,7 @@ class Entity extends Position } } - if($prevGroundState == $this->onGround && !$this->onGround && $this->player->isSleeping == false && !$this->dead){ //isSleeping may be a vector + if($prevGroundState == $this->onGround && !$this->onGround && $this->player->isSleeping == false && !$this->dead && $this->riding == 0){ //isSleeping may be a vector ++$this->notOnGroundTicks; }else if($this->onGround){ $this->notOnGroundTicks = 0; diff --git a/src/entity/ai/tasks/TaskEatTileGoal.php b/src/entity/ai/tasks/TaskEatTileGoal.php index a81ef6ca..23b1d63f 100644 --- a/src/entity/ai/tasks/TaskEatTileGoal.php +++ b/src/entity/ai/tasks/TaskEatTileGoal.php @@ -24,14 +24,14 @@ class TaskEatTileGoal extends TaskBase if (--$this->selfCounter == 4) { - $id = $ai->entity->level->level->getBlockID($ai->entity->x, $ai->entity->y, $ai->entity->z); - $idb = $ai->entity->level->level->getBlockID($ai->entity->x, $ai->entity->y - 1, $ai->entity->z); + $id = $ai->entity->level->level->getBlockID((int)$ai->entity->x, (int)$ai->entity->y, (int)$ai->entity->z); + $idb = $ai->entity->level->level->getBlockID((int)$ai->entity->x, (int)$ai->entity->y - 1, (int)$ai->entity->z); if($id === TALL_GRASS){ - $ai->entity->level->fastSetBlockUpdate($ai->entity->x, $ai->entity->y, $ai->entity->z, AIR, 0); + $ai->entity->level->fastSetBlockUpdate((int)$ai->entity->x, (int)$ai->entity->y, (int)$ai->entity->z, AIR, 0); $ai->entity->eatGrass(); }elseif($idb === GRASS){ - $ai->entity->level->fastSetBlockUpdate($ai->entity->x, $ai->entity->y - 1, $ai->entity->z, DIRT, 0); + $ai->entity->level->fastSetBlockUpdate((int)$ai->entity->x, (int)$ai->entity->y - 1, (int)$ai->entity->z, DIRT, 0); $ai->entity->eatGrass(); } } diff --git a/src/material/block/nonfull/SlabBlock.php b/src/material/block/nonfull/SlabBlock.php index 008a45a0..6d4256c4 100644 --- a/src/material/block/nonfull/SlabBlock.php +++ b/src/material/block/nonfull/SlabBlock.php @@ -29,7 +29,7 @@ class SlabBlock extends TransparentBlock{ [$id, $meta] = $level->level->getBlock($x, $y, $z); - if($meta & 0x08 == 0x08){ + if(($meta & 0x08) == 0x08){ StaticBlock::setBlockBounds($id, 0, 0, 0, 1, 1, 1); }else{ $bottom = (($meta ^ 8) >> 3) & 1; diff --git a/src/material/block/nonfull/WoodSlabBlock.php b/src/material/block/nonfull/WoodSlabBlock.php index 64ced90a..576bae2c 100644 --- a/src/material/block/nonfull/WoodSlabBlock.php +++ b/src/material/block/nonfull/WoodSlabBlock.php @@ -25,7 +25,7 @@ class WoodSlabBlock extends TransparentBlock{ [$id, $meta] = $level->level->getBlock($x, $y, $z); - if($meta & 0x08 == 0x08){ + if(($meta & 0x08) == 0x08){ StaticBlock::setBlockBounds($id, 0, 0, 0, 1, 1, 1); }else{ $bottom = (($meta ^ 8) >> 3) & 1; diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 0d03bd15..b86a0f28 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -663,9 +663,11 @@ class PMFLevel extends PMF{ }elseif($this->chunks[$index][$Y] === false){ $this->fillMiniChunk($X, $Z, $Y); } - $aX = $x - ($X << 4); - $aZ = $z - ($Z << 4); - $aY = $y - ($Y << 4); + + $aX = $x & 0xf; + $aZ = $z & 0xf; + $aY = $y & 0xf; + $bindex = (int) ($aY + ($aX << 5) + ($aZ << 9)); $mindex = (int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9)); $old_b = ord($this->chunks[$index][$Y][$bindex]);