Stop the server if generators specified for new worlds are not valid

I thought I did this already in eff856d8e513a1f01eca16ab55bacf6e83399527, but it looks like my brain slipped a gear.

Without this change, it's possible to crash the server by specifying an invalid generator for the default world if it doesn't yet exist.
This commit is contained in:
Dylan K. Taylor 2022-05-11 14:35:20 +01:00
parent 9ff1bf6deb
commit db6abfb227
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -1097,6 +1097,7 @@ class Server{
$generatorClass = $getGenerator($generatorName, $generatorOptions, $name); $generatorClass = $getGenerator($generatorName, $generatorOptions, $name);
if($generatorClass === null){ if($generatorClass === null){
$anyWorldFailedToLoad = true;
continue; continue;
} }
$creationOptions->setGeneratorClass($generatorClass); $creationOptions->setGeneratorClass($generatorClass);
@ -1133,7 +1134,11 @@ class Server{
$generatorName = $this->configGroup->getConfigString("level-type"); $generatorName = $this->configGroup->getConfigString("level-type");
$generatorOptions = $this->configGroup->getConfigString("generator-settings"); $generatorOptions = $this->configGroup->getConfigString("generator-settings");
$generatorClass = $getGenerator($generatorName, $generatorOptions, $default); $generatorClass = $getGenerator($generatorName, $generatorOptions, $default);
if($generatorClass !== null){
if($generatorClass === null){
$this->getLogger()->emergency($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_defaultError()));
return false;
}
$creationOptions = WorldCreationOptions::create() $creationOptions = WorldCreationOptions::create()
->setGeneratorClass($generatorClass) ->setGeneratorClass($generatorClass)
->setGeneratorOptions($generatorOptions); ->setGeneratorOptions($generatorOptions);
@ -1143,7 +1148,6 @@ class Server{
} }
$this->worldManager->generateWorld($default, $creationOptions); $this->worldManager->generateWorld($default, $creationOptions);
} }
}
$world = $this->worldManager->getWorldByName($default); $world = $this->worldManager->getWorldByName($default);
if($world === null){ if($world === null){