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
This commit is contained in:
Sarjuuk
2021-10-24 17:12:05 +02:00
parent 56e70e22bb
commit 6b49aa6069
7 changed files with 71 additions and 56 deletions

View File

@@ -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);

View File

@@ -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'];

View File

@@ -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;

View File

@@ -431,6 +431,9 @@ function siteconfig() : void
$updScripts = [];
}
}
// actually load set constants
loadConfig(true);
}
?>

View File

@@ -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())
{

View File

@@ -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;
}

View File

@@ -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]];
}