diff --git a/src/Player.php b/src/Player.php index 117db768..4ad26a57 100755 --- a/src/Player.php +++ b/src/Player.php @@ -2423,8 +2423,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/config_post.php b/src/config_post.php index 21282731..b5a9a6c1 100644 --- a/src/config_post.php +++ b/src/config_post.php @@ -39,34 +39,70 @@ function parseOffset(string $offset) : string|false{ if(ini_get("date.timezone") == ""){ //No Timezone set date_default_timezone_set("GMT"); - if(str_contains(" " . strtoupper(php_uname("s")), " WIN")){ - - $regex = '/(UTC)(\+*\-*\d*\d*\:*\d*\d*)/'; + if(str_contains(" " . strtoupper(php_uname("s")), " WIN")){ //windows + $keyPath = 'HKLM\\SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation'; + $timezone = 'UTC'; //default /* - * wmic timezone get Caption - * Get the timezone offset + * Get the timezone offset through the registry * * Sample Output var_dump - * array(3) { - * [0] => - * string(7) "Caption" - * [1] => - * string(20) "(UTC+09:30) Adelaide" - * [2] => - * string(0) "" - * } + * array(13) { + * [0]=> + * string(0) "" + * [1]=> + * string(71) "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation" + * [2]=> + * string(35) " Bias REG_DWORD 0xfffffe20" + * [3]=> + * string(43) " DaylightBias REG_DWORD 0xffffffc4" + * [4]=> + * string(45) " DaylightName REG_SZ @tzres.dll,-571" + * [5]=> + * string(67) " DaylightStart REG_BINARY 00000000000000000000000000000000" + * [6]=> + * string(36) " StandardBias REG_DWORD 0x0" + * [7]=> + * string(45) " StandardName REG_SZ @tzres.dll,-572" + * [8]=> + * string(67) " StandardStart REG_BINARY 00000000000000000000000000000000" + * [9]=> + * string(52) " TimeZoneKeyName REG_SZ China Standard Time" + * [10]=> + * string(51) " DynamicDaylightTimeDisabled REG_DWORD 0x0" + * [11]=> + * string(45) " ActiveTimeBias REG_DWORD 0xfffffe20" + * [12]=> + * string(0) "" + * } */ - exec("wmic timezone get Caption", $output); + exec("reg query " . escapeshellarg($keyPath), $output); - $string = trim(implode("\n", $output)); + foreach($output as $line){ + if(preg_match('/ActiveTimeBias\s+REG_DWORD\s+0x([0-9a-fA-F]+)/', $line, $matches) > 0){ + $offsetMinutes = ((int) hexdec(trim($matches[1]))) << 32 >> 32; //sign int - //Detect the Time Zone string - preg_match($regex, $string, $matches); + if($offsetMinutes === 0){ + break; //UTC + } - if(!isset($matches[2]) or ($timezone = parseOffset($matches[2])) === false){ - $timezone = 'UTC'; + $sign = $offsetMinutes <= 0 ? '+' : '-'; //windows timezone + and - are opposite + $absMinutes = abs($offsetMinutes); + $hours = floor($absMinutes / 60); + $minutes = $absMinutes % 60; + + $offset = sprintf( + "%s%02d:%02d", + $sign, + $hours, + $minutes + ); + + $timezone = parseOffset($offset); + break; + } } + if(date_default_timezone_set($timezone)){ ini_set("date.timezone", $timezone); } diff --git a/src/material/block/attachable/SignPostBlock.php b/src/material/block/attachable/SignPostBlock.php index 8a1db4e2..eab861ba 100644 --- a/src/material/block/attachable/SignPostBlock.php +++ b/src/material/block/attachable/SignPostBlock.php @@ -21,7 +21,7 @@ class SignPostBlock extends TransparentBlock{ } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - if(($target->isSolid || $target->getID() === SIGN_POST || $target->getID() === WALL_SIGN) && $face !== 0){ + if(($target->isSolid || $target->getID() === SIGN_POST || $target->getID() === WALL_SIGN || $target->getID() === GLASS_PANE || $target->getID() === IRON_BARS || $target->getID() === STONE_WALL) && $face !== 0){ if(!isset(self::$faces[$face])){ $this->meta = floor((($player->entity->yaw + 180) * 16 / 360) + 0.5) & 0x0F; $this->level->setBlock($block, BlockAPI::get(SIGN_POST, $this->meta), true, false, true); diff --git a/src/material/block/attachable/WallSignBlock.php b/src/material/block/attachable/WallSignBlock.php index 5fe7179d..d92d67ba 100644 --- a/src/material/block/attachable/WallSignBlock.php +++ b/src/material/block/attachable/WallSignBlock.php @@ -23,7 +23,7 @@ class WallSignBlock extends SignPostBlock{ default => WALL_SIGN }; - if(!StaticBlock::getIsSolid($attached) && $attached != SIGN_POST && $attached != WALL_SIGN){ + if(!StaticBlock::getIsSolid($attached) && $attached != SIGN_POST && $attached != WALL_SIGN && $attached != GLASS_PANE && $attached != IRON_BARS && $attached != STONE_WALL){ $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, true); (ServerAPI::request())->api->entity->drop(new Position($x + 0.5, $y + 0.5, $z + 0.5, $level), BlockAPI::getItem(SIGN, 0, 1)); } diff --git a/src/material/item/generic/BucketItem.php b/src/material/item/generic/BucketItem.php index 79e9d765..a96ede89 100644 --- a/src/material/item/generic/BucketItem.php +++ b/src/material/item/generic/BucketItem.php @@ -39,7 +39,7 @@ class BucketItem extends Item{ return true; } }elseif($this->meta === WATER){ - if($block->getID() === AIR || $block instanceof LiquidBlock){ + if($block->getID() === AIR || $block->getID() === TORCH || $block instanceof LiquidBlock){ $water = new WaterBlock(); $level->setBlock($block, $water, true, false, true); //$water->place($this, $player, $block, $target, $face, $fx, $fy, $fz); @@ -54,7 +54,7 @@ class BucketItem extends Item{ return true; } }elseif($this->meta === LAVA){ - if($block->getID() === AIR || $block instanceof LiquidBlock){ + if($block->getID() === AIR || $block->getID() === TORCH || $block instanceof LiquidBlock){ $lava = new LavaBlock(); $level->setBlock($block, $lava, true, false, true); //$lava->place(clone $this, $player, $block, $target, $face, $fx, $fy, $fz);