fixed unsupported leveldb format versions crashing the server

This commit is contained in:
Dylan K. Taylor 2018-10-07 15:42:59 +01:00
parent e13764832d
commit 8d1400115e
4 changed files with 43 additions and 9 deletions

View File

@ -50,6 +50,7 @@ use pocketmine\lang\Language;
use pocketmine\lang\LanguageNotFoundException;
use pocketmine\lang\TextContainer;
use pocketmine\level\biome\Biome;
use pocketmine\level\format\io\exception\UnsupportedLevelFormatException;
use pocketmine\level\format\io\LevelProvider;
use pocketmine\level\format\io\LevelProviderManager;
use pocketmine\level\generator\Generator;
@ -1044,8 +1045,13 @@ class Server{
}
$providerClass = array_shift($providers);
/** @see LevelProvider::__construct() */
$level = new Level($this, $name, new $providerClass($path));
try{
/** @see LevelProvider::__construct() */
$level = new Level($this, $name, new $providerClass($path));
}catch(UnsupportedLevelFormatException $e){
$this->logger->error($this->language->translateString("pocketmine.level.loadError", [$name, $e->getMessage()]));
return false;
}
$this->levels[$level->getId()] = $level;

View File

@ -23,10 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\format\io\data;
use pocketmine\level\format\io\exception\UnsupportedLevelFormatException;
use pocketmine\level\generator\Flat;
use pocketmine\level\generator\GeneratorManager;
use pocketmine\level\Level;
use pocketmine\level\LevelException;
use pocketmine\nbt\LittleEndianNBTStream;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
@ -103,7 +103,7 @@ class BedrockLevelData extends BaseNbtLevelData{
if($levelData instanceof CompoundTag){
$version = $levelData->getInt("StorageVersion", INT32_MAX, true);
if($version > self::CURRENT_STORAGE_VERSION){
throw new LevelException("Specified LevelDB world format version ($version) is not supported by " . \pocketmine\NAME);
throw new UnsupportedLevelFormatException("Specified LevelDB world format version ($version) is not supported by " . \pocketmine\NAME);
}
return $levelData;
@ -125,9 +125,9 @@ class BedrockLevelData extends BaseNbtLevelData{
$this->compoundTag->setString("generatorOptions", "");
break;
case self::GENERATOR_LIMITED:
throw new LevelException("Limited worlds are not currently supported");
throw new UnsupportedLevelFormatException("Limited worlds are not currently supported");
default:
throw new LevelException("Unknown LevelDB world format type, this level cannot be loaded");
throw new UnsupportedLevelFormatException("Unknown LevelDB world format type, this level cannot be loaded");
}
}else{
$this->compoundTag->setString("generatorName", "default");

View File

@ -0,0 +1,28 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\level\format\io\exception;
class UnsupportedLevelFormatException extends \RuntimeException{
}

View File

@ -28,9 +28,9 @@ use pocketmine\level\format\io\BaseLevelProvider;
use pocketmine\level\format\io\ChunkUtils;
use pocketmine\level\format\io\data\BedrockLevelData;
use pocketmine\level\format\io\exception\UnsupportedChunkFormatException;
use pocketmine\level\format\io\exception\UnsupportedLevelFormatException;
use pocketmine\level\format\io\LevelData;
use pocketmine\level\format\SubChunk;
use pocketmine\level\LevelException;
use pocketmine\nbt\LittleEndianNBTStream;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
@ -70,11 +70,11 @@ class LevelDB extends BaseLevelProvider{
private static function checkForLevelDBExtension() : void{
if(!extension_loaded('leveldb')){
throw new LevelException("The leveldb PHP extension is required to use this world format");
throw new UnsupportedLevelFormatException("The leveldb PHP extension is required to use this world format");
}
if(!defined('LEVELDB_ZLIB_RAW_COMPRESSION')){
throw new LevelException("Given version of php-leveldb doesn't support zlib raw compression");
throw new UnsupportedLevelFormatException("Given version of php-leveldb doesn't support zlib raw compression");
}
}