mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
PluginManager: account for possible invalid format of API version
we're seeing a lot of crashes because of this.
This commit is contained in:
parent
0ad663ff50
commit
7d06b76aaf
@ -1 +1 @@
|
||||
Subproject commit cb47518ae37ce834b612b2efe2df841852d07a31
|
||||
Subproject commit cf184a00f886a49dd91c2acb69384c630d3ac102
|
@ -1734,6 +1734,12 @@ final class KnownTranslationFactory{
|
||||
]);
|
||||
}
|
||||
|
||||
public static function pocketmine_plugin_invalidAPI(Translatable|string $apiVersion) : Translatable{
|
||||
return new Translatable(KnownTranslationKeys::POCKETMINE_PLUGIN_INVALIDAPI, [
|
||||
"apiVersion" => $apiVersion,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function pocketmine_plugin_load(Translatable|string $param0) : Translatable{
|
||||
return new Translatable(KnownTranslationKeys::POCKETMINE_PLUGIN_LOAD, [
|
||||
0 => $param0,
|
||||
|
@ -362,6 +362,7 @@ final class KnownTranslationKeys{
|
||||
public const POCKETMINE_PLUGIN_INCOMPATIBLEOS = "pocketmine.plugin.incompatibleOS";
|
||||
public const POCKETMINE_PLUGIN_INCOMPATIBLEPHPVERSION = "pocketmine.plugin.incompatiblePhpVersion";
|
||||
public const POCKETMINE_PLUGIN_INCOMPATIBLEPROTOCOL = "pocketmine.plugin.incompatibleProtocol";
|
||||
public const POCKETMINE_PLUGIN_INVALIDAPI = "pocketmine.plugin.invalidAPI";
|
||||
public const POCKETMINE_PLUGIN_LOAD = "pocketmine.plugin.load";
|
||||
public const POCKETMINE_PLUGIN_LOADERROR = "pocketmine.plugin.loadError";
|
||||
public const POCKETMINE_PLUGIN_RESTRICTEDNAME = "pocketmine.plugin.restrictedName";
|
||||
|
@ -40,6 +40,7 @@ use pocketmine\Server;
|
||||
use pocketmine\timings\TimingsHandler;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
use pocketmine\utils\Utils;
|
||||
use pocketmine\utils\VersionString;
|
||||
use Webmozart\PathUtil\Path;
|
||||
use function array_intersect;
|
||||
use function array_merge;
|
||||
@ -268,6 +269,16 @@ class PluginManager{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach($description->getCompatibleApis() as $api){
|
||||
if(!VersionString::isValidBaseVersion($api)){
|
||||
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
|
||||
$name,
|
||||
KnownTranslationFactory::pocketmine_plugin_invalidAPI($api)
|
||||
)));
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
if(!ApiVersion::isCompatible($this->server->getApiVersion(), $description->getCompatibleApis())){
|
||||
$this->server->getLogger()->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_loadError(
|
||||
$name,
|
||||
|
@ -63,6 +63,10 @@ class VersionString{
|
||||
$this->suffix = $matches[4] ?? "";
|
||||
}
|
||||
|
||||
public static function isValidBaseVersion(string $baseVersion) : bool{
|
||||
return preg_match('/^\d+\.\d+\.\d+(?:-(.*))?$/', $baseVersion, $matches) === 1;
|
||||
}
|
||||
|
||||
public function getNumber() : int{
|
||||
return (($this->major << 9) | ($this->minor << 5) | $this->patch);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user