mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
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:
@@ -93,10 +93,14 @@ if (!empty($AoWoWconf['characters']))
|
|||||||
|
|
||||||
|
|
||||||
// load config to constants
|
// load config to constants
|
||||||
|
function loadConfig(bool $noPHP = false) : void
|
||||||
|
{
|
||||||
$sets = DB::isConnectable(DB_AOWOW) ? DB::Aowow()->select('SELECT `key` AS ARRAY_KEY, `value`, `flags` FROM ?_config') : [];
|
$sets = DB::isConnectable(DB_AOWOW) ? DB::Aowow()->select('SELECT `key` AS ARRAY_KEY, `value`, `flags` FROM ?_config') : [];
|
||||||
foreach ($sets as $k => $v)
|
foreach ($sets as $k => $v)
|
||||||
{
|
{
|
||||||
$php = $v['flags'] & CON_FLAG_PHP;
|
$php = $v['flags'] & CON_FLAG_PHP;
|
||||||
|
if ($php && $noPHP)
|
||||||
|
continue;
|
||||||
|
|
||||||
// this should not have been possible
|
// this should not have been possible
|
||||||
if (!strlen($v['value']) && !($v['flags'] & CON_FLAG_TYPE_STRING) && !$php)
|
if (!strlen($v['value']) && !($v['flags'] & CON_FLAG_TYPE_STRING) && !$php)
|
||||||
@@ -129,7 +133,8 @@ foreach ($sets as $k => $v)
|
|||||||
else
|
else
|
||||||
define('CFG_'.strtoupper($k), $val);
|
define('CFG_'.strtoupper($k), $val);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
loadConfig();
|
||||||
|
|
||||||
// handle non-fatal errors and notices
|
// handle non-fatal errors and notices
|
||||||
error_reporting(!empty($AoWoWconf['aowow']) && CFG_DEBUG ? E_AOWOW : 0);
|
error_reporting(!empty($AoWoWconf['aowow']) && CFG_DEBUG ? E_AOWOW : 0);
|
||||||
|
|||||||
@@ -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);
|
self::$opts[$alias[$o] ?? $o] = (self::$optDefs[$alias[$o] ?? $o][2] & self::ARGV_ARRAY) ? ($v ? explode(',', $v) : []) : ($v ?: true);
|
||||||
|
|
||||||
// optional logging
|
// optional logging
|
||||||
if (self::$opts['log'])
|
if (isset(self::$opts['log']))
|
||||||
CLI::initLogFile(trim(self::$opts['log']));
|
CLI::initLogFile(trim(self::$opts['log']));
|
||||||
|
|
||||||
// alternative data source (no quotes, use forward slash)
|
// alternative data source (no quotes, use forward slash)
|
||||||
if (self::$opts['mpqDataDir'])
|
if (isset(self::$opts['mpqDataDir']))
|
||||||
self::$srcDir = CLI::nicePath($self::$opts['mpqDataDir']);
|
self::$srcDir = CLI::nicePath($self::$opts['mpqDataDir']);
|
||||||
|
|
||||||
// optional limit handled locales
|
// optional limit handled locales
|
||||||
if (self::$opts['locales'])
|
if (isset(self::$opts['locales']))
|
||||||
{
|
{
|
||||||
// engb and enus are identical for all intents and purposes
|
// engb and enus are identical for all intents and purposes
|
||||||
$from = ['engb', 'esmx', 'encn'];
|
$from = ['engb', 'esmx', 'encn'];
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ function setup() : void
|
|||||||
require 'config/config.php';
|
require 'config/config.php';
|
||||||
|
|
||||||
$error = [];
|
$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'])))
|
if ($what == 'auth' && (empty($AoWoWconf['auth']) || empty($AoWoWconf['auth']['host'])))
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -431,6 +431,9 @@ function siteconfig() : void
|
|||||||
$updScripts = [];
|
$updScripts = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// actually load set constants
|
||||||
|
loadConfig(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -349,7 +349,10 @@ class DBC
|
|||||||
|
|
||||||
$this->createTable();
|
$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())
|
if (!$this->read())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,11 +58,11 @@ class FileGen
|
|||||||
'static/wowsounds/'
|
'static/wowsounds/'
|
||||||
);
|
);
|
||||||
|
|
||||||
public static $txtConstants = array(
|
private static $txtConstants = array(
|
||||||
'CFG_NAME' => CFG_NAME,
|
'CFG_NAME' => '',
|
||||||
'CFG_NAME_SHORT' => CFG_NAME_SHORT,
|
'CFG_NAME_SHORT' => '',
|
||||||
'HOST_URL' => HOST_URL,
|
'HOST_URL' => '',
|
||||||
'STATIC_URL' => STATIC_URL
|
'STATIC_URL' => ''
|
||||||
);
|
);
|
||||||
|
|
||||||
public static function init(int $mode = self::MODE_NORMAL, array $updScripts = []) : bool
|
public static function init(int $mode = self::MODE_NORMAL, array $updScripts = []) : bool
|
||||||
@@ -76,15 +76,6 @@ class FileGen
|
|||||||
return false;
|
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
|
// create directory structure
|
||||||
CLI::write('FileGen::init() - creating required directories');
|
CLI::write('FileGen::init() - creating required directories');
|
||||||
$pathOk = 0;
|
$pathOk = 0;
|
||||||
@@ -95,6 +86,15 @@ class FileGen
|
|||||||
CLI::write('created '.$pathOk.' extra paths'.($pathOk == count(self::$reqDirs) ? '' : ' with errors'));
|
CLI::write('created '.$pathOk.' extra paths'.($pathOk == count(self::$reqDirs) ? '' : ' with errors'));
|
||||||
CLI::write();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,10 +183,14 @@ class FileGen
|
|||||||
{
|
{
|
||||||
[$file, $destPath, $deps] = self::$tplFiles[$key];
|
[$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
|
// replace constants
|
||||||
$content = strtr($content, FileGen::$txtConstants);
|
$content = strtr($content, self::$txtConstants);
|
||||||
|
|
||||||
// check for required auxiliary DBC files
|
// check for required auxiliary DBC files
|
||||||
foreach ($reqDBC as $req)
|
foreach ($reqDBC as $req)
|
||||||
@@ -217,7 +221,7 @@ class FileGen
|
|||||||
$success = true;
|
$success = true;
|
||||||
}
|
}
|
||||||
else
|
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]))
|
else if (!empty(self::$datasets[$key]))
|
||||||
{
|
{
|
||||||
@@ -234,7 +238,7 @@ class FileGen
|
|||||||
CLI::write(' - subscript \''.$key.'\' not defined in included file', CLI::LOG_ERROR);
|
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;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
// spawn does not really match on a map, but we need at least one result
|
||||||
if (!$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]];
|
$result = [1.0, $points[0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user