mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-19 04:15:04 +00:00
Fixed remaining cases of undefined behaviour on ambiguous world format
It was still possible to produce undefined behaviour by creating a db folder in a region-based world, or adding regions to a leveldb world. This now solves the problem completely by refusing to load the world if multiple formats match the world.
This commit is contained in:
@@ -87,17 +87,17 @@ abstract class LevelProviderManager{
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return string|null
|
||||
* @return string[]|LevelProvider[]
|
||||
*/
|
||||
public static function getProvider(string $path){
|
||||
foreach(self::$providers as $provider){
|
||||
/** @var $provider LevelProvider */
|
||||
public static function getMatchingProviders(string $path) : array{
|
||||
$result = [];
|
||||
foreach(self::$providers as $alias => $provider){
|
||||
/** @var LevelProvider|string $provider */
|
||||
if($provider::isValid($path)){
|
||||
return $provider;
|
||||
$result[$alias] = $provider;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -45,23 +45,16 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
|
||||
abstract protected static function getPcWorldFormatVersion() : int;
|
||||
|
||||
public static function isValid(string $path) : bool{
|
||||
$isValid = (file_exists($path . "/level.dat") and is_dir($path . "/region/"));
|
||||
|
||||
if($isValid){
|
||||
$files = array_filter(scandir($path . "/region/", SCANDIR_SORT_NONE), function($file){
|
||||
return substr($file, strrpos($file, ".") + 1, 2) === "mc"; //region file
|
||||
});
|
||||
|
||||
$ext = static::getRegionFileExtension();
|
||||
foreach($files as $f){
|
||||
if(substr($f, strrpos($f, ".") + 1) !== $ext){
|
||||
$isValid = false;
|
||||
break;
|
||||
if(file_exists($path . "/level.dat") and is_dir($path . "/region/")){
|
||||
foreach(scandir($path . "/region/", SCANDIR_SORT_NONE) as $file){
|
||||
if(substr($file, strrpos($file, ".") + 1) === static::getRegionFileExtension()){
|
||||
//we don't care if other region types exist, we only care if this format is possible
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []){
|
||||
|
Reference in New Issue
Block a user