From 3b7377370cd28a83f6ea4cd03cdbe3e7eb3f9be7 Mon Sep 17 00:00:00 2001 From: SOFe Date: Sun, 6 Nov 2016 11:46:39 +0800 Subject: [PATCH] Critical error upon missing submodules (#77) * Critical error upon missing SPL * Added checks for RakLib and PocketMine-Language * It actually throws ClassNotFoundException, not simply returns false :( Should I blame :shoghi:? --- src/pocketmine/PocketMine.php | 14 +++++++++ src/pocketmine/lang/BaseLang.php | 52 +++++++++++++++++++------------- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index e056bd217..4293cc77b 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -71,6 +71,7 @@ namespace pocketmine { use pocketmine\utils\Terminal; use pocketmine\utils\Utils; use pocketmine\wizard\Installer; + use raklib\RakLib; const VERSION = "1.6.1dev"; const API_VERSION = "2.1.0"; @@ -104,6 +105,11 @@ namespace pocketmine { } if(!class_exists("ClassLoader", false)){ + if(!is_file(\pocketmine\PATH . "src/spl/ClassLoader.php")){ + echo "[CRITICAL] Unable to find the PocketMine-SPL library." . PHP_EOL; + echo "[CRITICAL] Please use provided builds or clone the repository recursively." . PHP_EOL; + exit(1); + } require_once(\pocketmine\PATH . "src/spl/ClassLoader.php"); require_once(\pocketmine\PATH . "src/spl/BaseClassLoader.php"); require_once(\pocketmine\PATH . "src/pocketmine/CompatibleClassLoader.php"); @@ -114,6 +120,14 @@ namespace pocketmine { $autoloader->addPath(\pocketmine\PATH . "src" . DIRECTORY_SEPARATOR . "spl"); $autoloader->register(true); + try{ + if(!class_exists(RakLib::class)){ + throw new \Exception; + } + }catch(\Exception $e){ + echo "[CRITICAL] Unable to find the RakLib library." . PHP_EOL; + exit(1); + } set_time_limit(0); //Who set it to 30 seconds?!?! diff --git a/src/pocketmine/lang/BaseLang.php b/src/pocketmine/lang/BaseLang.php index ef079e700..5d4a78bce 100644 --- a/src/pocketmine/lang/BaseLang.php +++ b/src/pocketmine/lang/BaseLang.php @@ -23,6 +23,7 @@ namespace pocketmine\lang; use pocketmine\event\TextContainer; use pocketmine\event\TranslationContainer; +use pocketmine\Server; class BaseLang{ @@ -41,8 +42,12 @@ class BaseLang{ $path = \pocketmine\PATH . "src/pocketmine/lang/locale/"; } - $this->loadLang($path . $this->langName . ".ini", $this->lang); - $this->loadLang($path . $fallback . ".ini", $this->fallbackLang); + if(!$this->loadLang($file = $path . $this->langName . ".ini", $this->lang)){ + Server::getInstance()->getLogger()->error("Missing required language file $file"); + } + if(!$this->loadLang($file = $path . $fallback . ".ini", $this->fallbackLang)){ + Server::getInstance()->getLogger()->error("Missing required language file $file"); + } } public function getName(){ @@ -54,27 +59,32 @@ class BaseLang{ } protected function loadLang($path, array &$d){ - if(file_exists($path) and strlen($content = file_get_contents($path)) > 0){ - foreach(explode("\n", $content) as $line){ - $line = trim($line); - if($line === "" or $line{0} === "#"){ - continue; + if(file_exists($path)){ + if(strlen($content = file_get_contents($path)) > 0){ + foreach(explode("\n", $content) as $line){ + $line = trim($line); + if($line === "" or $line{0} === "#"){ + continue; + } + + $t = explode("=", $line, 2); + if(count($t) < 2){ + continue; + } + + $key = trim($t[0]); + $value = trim($t[1]); + + if($value === ""){ + continue; + } + + $d[$key] = $value; } - - $t = explode("=", $line, 2); - if(count($t) < 2){ - continue; - } - - $key = trim($t[0]); - $value = trim($t[1]); - - if($value === ""){ - continue; - } - - $d[$key] = $value; } + return true; + }else{ + return false; } }