diff --git a/system/pages/exp-stages.php b/system/pages/exp-stages.php index c5a14ef7..cd8d2b8e 100644 --- a/system/pages/exp-stages.php +++ b/system/pages/exp-stages.php @@ -11,20 +11,20 @@ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Experience Stages'; -if(file_exists($config['data_path'] . 'XML/stages.xml')) { - $stages = new DOMDocument(); - $stages->load($config['data_path'] . 'XML/stages.xml'); -} - -if(!isset($config['lua']['experienceStages']) || !getBoolean($config['lua']['experienceStages'])) -{ +if((!isset($config['lua']['experienceStages']) || !getBoolean($config['lua']['experienceStages'])) + && (!isset($config['lua']['rateUseStages']) || !getBoolean($config['lua']['rateUseStages'])) + ) { $enabled = false; - if(isset($stages)) { + if(file_exists($config['data_path'] . 'XML/stages.xml')) { + $stages = new DOMDocument(); + $stages->load($config['data_path'] . 'XML/stages.xml'); + foreach($stages->getElementsByTagName('config') as $node) { /** @var DOMElement $node */ - if($node->getAttribute('enabled')) + if($node->getAttribute('enabled')) { $enabled = true; + } } } @@ -42,21 +42,12 @@ if(!isset($config['lua']['experienceStages']) || !getBoolean($config['lua']['exp } } -if(!$stages) -{ - echo 'Error: cannot load stages.xml!'; +$stages = new MyAAC\Server\ExpStages(); +$stagesArray = $stages->get(); + +if (empty($stagesArray)) { + echo 'Error when loading experience stages.'; return; } -$stagesArray = []; -foreach($stages->getElementsByTagName('stage') as $stage) -{ - /** @var DOMElement $stage */ - $maxLevel = $stage->getAttribute('maxlevel'); - $stagesArray[] = [ - 'levels' => $stage->getAttribute('minlevel') . (isset($maxLevel[0]) ? '-' . $maxLevel : '+'), - 'multiplier' => $stage->getAttribute('multiplier') - ]; -} - $twig->display('experience_stages.html.twig', ['stages' => $stagesArray]); diff --git a/system/src/Server/ExpStages.php b/system/src/Server/ExpStages.php new file mode 100644 index 00000000..3b5cfd98 --- /dev/null +++ b/system/src/Server/ExpStages.php @@ -0,0 +1,35 @@ +load(); + + return $expStages->get(); + }); + } + + return self::$stages; + } +} diff --git a/system/src/Server/Lua/ExpStages.php b/system/src/Server/Lua/ExpStages.php new file mode 100644 index 00000000..aa8ec64b --- /dev/null +++ b/system/src/Server/Lua/ExpStages.php @@ -0,0 +1,46 @@ +eval($stagesContent); + } + catch (\Exception $e) { + error('Error: Cannot load stages.lua. More info in system/logs/error.log file.'); + log_append('error.log', "[" . __CLASS__ . "] Fatal error: Cannot load stages.lua - $file. Error: " . $e->getMessage()); + return; + } + + foreach ($stages as $stage) { + $this->stages[] = [ + 'levels' => $stage['minlevel'] . (isset($stage['maxlevel']) ? '-' . $stage['maxlevel'] : '+'), + 'multiplier' => $stage['multiplier'] + ]; + } + } + + public function get(): array { + return $this->stages; + } +} diff --git a/system/src/Server/TOML/Config.php b/system/src/Server/TOML/Config.php index 46f76576..2f4a7999 100644 --- a/system/src/Server/TOML/Config.php +++ b/system/src/Server/TOML/Config.php @@ -50,6 +50,7 @@ class Config $this->config['freePremium'] = $this->config['server']['accounts']['free_premium'] ?? false; $this->config['ip'] = $this->config['server']['network']['ip'] ?? '127.0.0.1'; $this->config['worldType'] = $this->config['server']['world']['type'] ?? 'unknown'; + $this->config['experienceStages'] = $this->config['stages']['config']['enabled'] ?? false; $this->config['houseRentPeriod'] = $this->config['server']['houses']['rent_period'] ?? 'never'; $this->config['pzLocked'] = $this->config['combat']['skull']['pz_locked'] ?? 60 * 1000; $this->config['url'] = $this->config['server']['identity']['url'] ?? 'http://localhost'; diff --git a/system/src/Server/TOML/ExpStages.php b/system/src/Server/TOML/ExpStages.php new file mode 100644 index 00000000..d742102d --- /dev/null +++ b/system/src/Server/TOML/ExpStages.php @@ -0,0 +1,44 @@ +getMessage()); + return; + } + + foreach ($stages['stage'] as $stage) { + $this->stages[] = [ + 'levels' => $stage['minlevel'] . (isset($stage['maxlevel']) ? '-' . $stage['maxlevel'] : '+'), + 'multiplier' => $stage['multiplier'] + ]; + } + + } + + public function get(): array { + return $this->stages; + } +} diff --git a/system/src/Server/XML/ExpStages.php b/system/src/Server/XML/ExpStages.php new file mode 100644 index 00000000..81e9b37c --- /dev/null +++ b/system/src/Server/XML/ExpStages.php @@ -0,0 +1,40 @@ +load($file)) { + error('Error: Cannot load stages.xml. More info in system/logs/error.log file.'); + log_append('error.log', "[" . __CLASS__ . "] Fatal error: Cannot load stages.xml - $file. Error: " . print_r(error_get_last(), true)); + return; + } + + foreach($xml->getElementsByTagName('stage') as $stage) + { + /** @var DOMElement $stage */ + $maxLevel = $stage->getAttribute('maxlevel'); + $this->stages[] = [ + 'levels' => $stage->getAttribute('minlevel') . (isset($maxLevel[0]) ? '-' . $maxLevel : '+'), + 'multiplier' => $stage->getAttribute('multiplier') + ]; + } + } + + public function get(): array { + return $this->stages; + } +}