From 6b49aa606931451218683b6f2e252d87d19a9fbe Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Sun, 24 Oct 2021 17:12:05 +0200 Subject: [PATCH] Setup/Misc * fix some outdated array indizes during setup * fix indexing when connecting to DB for first time * add initial loading of config strings during setup --- includes/kernel.php | 69 +++++++++++++----------- setup/tools/CLISetup.class.php | 6 +-- setup/tools/clisetup/setup.func.php | 2 +- setup/tools/clisetup/siteconfig.func.php | 3 ++ setup/tools/dbc.class.php | 5 +- setup/tools/fileGen.class.php | 40 +++++++------- setup/tools/sqlgen/spawns.func.php | 2 +- 7 files changed, 71 insertions(+), 56 deletions(-) diff --git a/includes/kernel.php b/includes/kernel.php index 79a92b22..ca76e493 100644 --- a/includes/kernel.php +++ b/includes/kernel.php @@ -93,43 +93,48 @@ if (!empty($AoWoWconf['characters'])) // load config to constants -$sets = DB::isConnectable(DB_AOWOW) ? DB::Aowow()->select('SELECT `key` AS ARRAY_KEY, `value`, `flags` FROM ?_config') : []; -foreach ($sets as $k => $v) +function loadConfig(bool $noPHP = false) : void { - $php = $v['flags'] & CON_FLAG_PHP; - - // this should not have been possible - if (!strlen($v['value']) && !($v['flags'] & CON_FLAG_TYPE_STRING) && !$php) + $sets = DB::isConnectable(DB_AOWOW) ? DB::Aowow()->select('SELECT `key` AS ARRAY_KEY, `value`, `flags` FROM ?_config') : []; + foreach ($sets as $k => $v) { - trigger_error('Aowow config value CFG_'.strtoupper($k).' is empty - config will not be used!', E_USER_ERROR); - continue; - } + $php = $v['flags'] & CON_FLAG_PHP; + if ($php && $noPHP) + continue; - if ($v['flags'] & CON_FLAG_TYPE_INT) - $val = intVal($v['value']); - else if ($v['flags'] & CON_FLAG_TYPE_FLOAT) - $val = floatVal($v['value']); - else if ($v['flags'] & CON_FLAG_TYPE_BOOL) - $val = (bool)$v['value']; - else if ($v['flags'] & CON_FLAG_TYPE_STRING) - $val = preg_replace("/[\p{C}]/ui", '', $v['value']); - else if ($php) - { - trigger_error('PHP config value '.strtolower($k).' has no type set - config will not be used!', E_USER_ERROR); - continue; - } - else // if (!$php) - { - trigger_error('Aowow config value CFG_'.strtoupper($k).' has no type set - value forced to 0!', E_USER_ERROR); - $val = 0; - } + // this should not have been possible + if (!strlen($v['value']) && !($v['flags'] & CON_FLAG_TYPE_STRING) && !$php) + { + trigger_error('Aowow config value CFG_'.strtoupper($k).' is empty - config will not be used!', E_USER_ERROR); + continue; + } - if ($php) - ini_set(strtolower($k), $val); - else - define('CFG_'.strtoupper($k), $val); + if ($v['flags'] & CON_FLAG_TYPE_INT) + $val = intVal($v['value']); + else if ($v['flags'] & CON_FLAG_TYPE_FLOAT) + $val = floatVal($v['value']); + else if ($v['flags'] & CON_FLAG_TYPE_BOOL) + $val = (bool)$v['value']; + else if ($v['flags'] & CON_FLAG_TYPE_STRING) + $val = preg_replace("/[\p{C}]/ui", '', $v['value']); + else if ($php) + { + trigger_error('PHP config value '.strtolower($k).' has no type set - config will not be used!', E_USER_ERROR); + continue; + } + else // if (!$php) + { + trigger_error('Aowow config value CFG_'.strtoupper($k).' has no type set - value forced to 0!', E_USER_ERROR); + $val = 0; + } + + if ($php) + ini_set(strtolower($k), $val); + else + define('CFG_'.strtoupper($k), $val); + } } - +loadConfig(); // handle non-fatal errors and notices error_reporting(!empty($AoWoWconf['aowow']) && CFG_DEBUG ? E_AOWOW : 0); diff --git a/setup/tools/CLISetup.class.php b/setup/tools/CLISetup.class.php index 7406c386..b9e8cf4f 100644 --- a/setup/tools/CLISetup.class.php +++ b/setup/tools/CLISetup.class.php @@ -104,15 +104,15 @@ class CLISetup self::$opts[$alias[$o] ?? $o] = (self::$optDefs[$alias[$o] ?? $o][2] & self::ARGV_ARRAY) ? ($v ? explode(',', $v) : []) : ($v ?: true); // optional logging - if (self::$opts['log']) + if (isset(self::$opts['log'])) CLI::initLogFile(trim(self::$opts['log'])); // alternative data source (no quotes, use forward slash) - if (self::$opts['mpqDataDir']) + if (isset(self::$opts['mpqDataDir'])) self::$srcDir = CLI::nicePath($self::$opts['mpqDataDir']); // optional limit handled locales - if (self::$opts['locales']) + if (isset(self::$opts['locales'])) { // engb and enus are identical for all intents and purposes $from = ['engb', 'esmx', 'encn']; diff --git a/setup/tools/clisetup/setup.func.php b/setup/tools/clisetup/setup.func.php index ad6dcb8b..18173bd4 100644 --- a/setup/tools/clisetup/setup.func.php +++ b/setup/tools/clisetup/setup.func.php @@ -118,7 +118,7 @@ function setup() : void require 'config/config.php'; $error = []; - foreach (['world', 'aowow', 'auth'] as $idx => $what) + foreach (['aowow', 'world', 'auth'] as $idx => $what) { if ($what == 'auth' && (empty($AoWoWconf['auth']) || empty($AoWoWconf['auth']['host']))) continue; diff --git a/setup/tools/clisetup/siteconfig.func.php b/setup/tools/clisetup/siteconfig.func.php index 803dbe74..12ed36cd 100644 --- a/setup/tools/clisetup/siteconfig.func.php +++ b/setup/tools/clisetup/siteconfig.func.php @@ -431,6 +431,9 @@ function siteconfig() : void $updScripts = []; } } + + // actually load set constants + loadConfig(true); } ?> diff --git a/setup/tools/dbc.class.php b/setup/tools/dbc.class.php index 64200e70..b2e67dae 100644 --- a/setup/tools/dbc.class.php +++ b/setup/tools/dbc.class.php @@ -349,7 +349,10 @@ class DBC $this->createTable(); - CLI::write(' - reading '.($this->localized ? 'and merging ' : '').$this->file.'.dbc for locales '.implode(', ', array_keys($this->fileRefs))); + if ($this->localized) + CLI::write(' - reading and merging '.$this->file.'.dbc for locales '.implode(', ', array_keys($this->fileRefs))); + else + CLI::write(' - reading '.$this->file.'.dbc'); if (!$this->read()) { diff --git a/setup/tools/fileGen.class.php b/setup/tools/fileGen.class.php index b138da95..03d87202 100644 --- a/setup/tools/fileGen.class.php +++ b/setup/tools/fileGen.class.php @@ -58,11 +58,11 @@ class FileGen 'static/wowsounds/' ); - public static $txtConstants = array( - 'CFG_NAME' => CFG_NAME, - 'CFG_NAME_SHORT' => CFG_NAME_SHORT, - 'HOST_URL' => HOST_URL, - 'STATIC_URL' => STATIC_URL + private static $txtConstants = array( + 'CFG_NAME' => '', + 'CFG_NAME_SHORT' => '', + 'HOST_URL' => '', + 'STATIC_URL' => '' ); public static function init(int $mode = self::MODE_NORMAL, array $updScripts = []) : bool @@ -76,15 +76,6 @@ class FileGen return false; } - // handle command prompts - if (!self::handleCLIOpts($doScripts)) - return false; - - // check passed subscript names; limit to real scriptNames - self::$subScripts = array_merge(array_keys(self::$tplFiles), array_keys(self::$datasets)); - if ($doScripts || $updScripts) - self::$subScripts = array_intersect($doScripts ?: $updScripts, self::$subScripts); - // create directory structure CLI::write('FileGen::init() - creating required directories'); $pathOk = 0; @@ -95,6 +86,15 @@ class FileGen CLI::write('created '.$pathOk.' extra paths'.($pathOk == count(self::$reqDirs) ? '' : ' with errors')); CLI::write(); + // handle command prompts + if (!self::handleCLIOpts($doScripts)) + return false; + + // check passed subscript names; limit to real scriptNames + self::$subScripts = array_merge(array_keys(self::$tplFiles), array_keys(self::$datasets)); + if ($doScripts || $updScripts) + self::$subScripts = array_intersect($doScripts ?: $updScripts, self::$subScripts); + return true; } @@ -183,10 +183,14 @@ class FileGen { [$file, $destPath, $deps] = self::$tplFiles[$key]; - if ($content = file_get_contents(FileGen::$tplPath.$file.'.in')) + foreach (self::$txtConstants as $n => &$c) + if (!$c && defined($n)) + $c = constant($n); + + if ($content = file_get_contents(self::$tplPath.$file.'.in')) { // replace constants - $content = strtr($content, FileGen::$txtConstants); + $content = strtr($content, self::$txtConstants); // check for required auxiliary DBC files foreach ($reqDBC as $req) @@ -217,7 +221,7 @@ class FileGen $success = true; } else - CLI::write(sprintf(ERR_READ_FILE, CLI::bold(FileGen::$tplPath.$file.'.in')), CLI::LOG_ERROR); + CLI::write(sprintf(ERR_READ_FILE, CLI::bold(self::$tplPath.$file.'.in')), CLI::LOG_ERROR); } else if (!empty(self::$datasets[$key])) { @@ -234,7 +238,7 @@ class FileGen CLI::write(' - subscript \''.$key.'\' not defined in included file', CLI::LOG_ERROR); } - set_time_limit(FileGen::$defaultExecTime); // reset to default for the next script + set_time_limit(self::$defaultExecTime); // reset to default for the next script return $success; } diff --git a/setup/tools/sqlgen/spawns.func.php b/setup/tools/sqlgen/spawns.func.php index e301db19..bf73fc2a 100644 --- a/setup/tools/sqlgen/spawns.func.php +++ b/setup/tools/sqlgen/spawns.func.php @@ -103,7 +103,7 @@ SqlGen::register(new class extends SetupScript // spawn does not really match on a map, but we need at least one result if (!$result) { - usort($points, function ($a, $b) { return ($a['quality'] < $b['quality']) ? -1 : 1; }); + usort($points, function ($a, $b) { return ($a['dist'] < $b['dist']) ? -1 : 1; }); $result = [1.0, $points[0]]; }