mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Setup/DBconfig
* test for known world db formats and throw appropriate errors * test for imported aowow db and throw error if missing * make DB connection reloadable
This commit is contained in:
@@ -26,7 +26,7 @@ Also, this project is not meant to be used for commercial puposes of any kind!
|
|||||||
+ [File Information](https://www.php.net/manual/en/book.fileinfo.php)
|
+ [File Information](https://www.php.net/manual/en/book.fileinfo.php)
|
||||||
+ [GNU Multiple Precision](https://www.php.net/manual/en/book.gmp.php) (When using TrinityCore as auth source)
|
+ [GNU Multiple Precision](https://www.php.net/manual/en/book.gmp.php) (When using TrinityCore as auth source)
|
||||||
+ MySQL ≥ 5.7.0 OR MariaDB ≥ 10.6.4 OR similar
|
+ MySQL ≥ 5.7.0 OR MariaDB ≥ 10.6.4 OR similar
|
||||||
+ [TDB 335.21101](https://github.com/TrinityCore/TrinityCore/releases/tag/TDB335.21101)
|
+ [TDB 335.21101](https://github.com/TrinityCore/TrinityCore/releases/tag/TDB335.21101) (no other other providers are supported at this time)
|
||||||
+ WIN: php.exe needs to be added to the `PATH` system variable, if it isn't already.
|
+ WIN: php.exe needs to be added to the `PATH` system variable, if it isn't already.
|
||||||
+ Tools require cmake: Please refer to the individual repositories for detailed information
|
+ Tools require cmake: Please refer to the individual repositories for detailed information
|
||||||
+ [MPQExtractor](https://github.com/Sarjuuk/MPQExtractor) / [FFmpeg](https://ffmpeg.org/download.html) / (optional: [BLPConverter](https://github.com/Sarjuuk/BLPConverter))
|
+ [MPQExtractor](https://github.com/Sarjuuk/MPQExtractor) / [FFmpeg](https://ffmpeg.org/download.html) / (optional: [BLPConverter](https://github.com/Sarjuuk/BLPConverter))
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ class DB
|
|||||||
public static function connect($idx)
|
public static function connect($idx)
|
||||||
{
|
{
|
||||||
if (self::isConnected($idx))
|
if (self::isConnected($idx))
|
||||||
return;
|
{
|
||||||
|
self::$interfaceCache[$idx]->link->close();
|
||||||
|
self::$interfaceCache[$idx] = null;
|
||||||
|
}
|
||||||
|
|
||||||
$options = &self::$optionsCache[$idx];
|
$options = &self::$optionsCache[$idx];
|
||||||
$interface = DbSimple_Generic::connect(self::createConnectSyntax($options));
|
$interface = DbSimple_Generic::connect(self::createConnectSyntax($options));
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ define('E_AOWOW', E_ALL & ~(E_DEPRECATED | E_USER_DEPRECATED | E
|
|||||||
define('JSON_AOWOW_POWER', JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
define('JSON_AOWOW_POWER', JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
define('FILTER_FLAG_STRIP_AOWOW', FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK);
|
define('FILTER_FLAG_STRIP_AOWOW', FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK);
|
||||||
|
|
||||||
|
define('TDB_WORLD_MINIMUM_VER', 21101);
|
||||||
|
define('TDB_WORLD_EXPECTED_VER', 24041);
|
||||||
|
|
||||||
// as of 01.01.2024 https://www.wowhead.com/wotlk/de/spell=40120/{seo}
|
// as of 01.01.2024 https://www.wowhead.com/wotlk/de/spell=40120/{seo}
|
||||||
// https://www.wowhead.com/wotlk/es/search=vuelo
|
// https://www.wowhead.com/wotlk/es/search=vuelo
|
||||||
define('WOWHEAD_LINK', 'https://www.wowhead.com/wotlk/%s/%s=%s');
|
define('WOWHEAD_LINK', 'https://www.wowhead.com/wotlk/%s/%s=%s');
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ function dbconfig() : void
|
|||||||
$databases = ['aowow', 'world', 'auth', 'characters'];
|
$databases = ['aowow', 'world', 'auth', 'characters'];
|
||||||
$AoWoWconf = [];
|
$AoWoWconf = [];
|
||||||
$dbFields = array(
|
$dbFields = array(
|
||||||
'host' => ['Server Host', false],
|
'host' => ['Hostname / IP', false],
|
||||||
'user' => ['User', false],
|
'user' => ['User', false],
|
||||||
'pass' => ['Password', true ],
|
'pass' => ['Password', true ],
|
||||||
'db' => ['Database Name', false],
|
'db' => ['Database Name', false],
|
||||||
@@ -28,12 +28,71 @@ function dbconfig() : void
|
|||||||
|
|
||||||
if ($dbInfo['host'])
|
if ($dbInfo['host'])
|
||||||
{
|
{
|
||||||
DB::test($dbInfo, $errStr);
|
$result = CLI::green('OK');
|
||||||
|
$note = '';
|
||||||
|
|
||||||
$buff[] = $errStr ? CLI::red('ERR') : CLI::green('OK');
|
if (DB::test($dbInfo, $note))
|
||||||
|
{
|
||||||
|
DB::load($idx, $dbInfo);
|
||||||
|
|
||||||
|
$ok = false;
|
||||||
|
switch ($idx)
|
||||||
|
{
|
||||||
|
case DB_AOWOW:
|
||||||
|
if (DB::Aowow()->selectCell('SHOW TABLES LIKE ?', 'aowow_dbversion'))
|
||||||
|
{
|
||||||
|
if ($date = DB::Aowow()->selectCell('SELECT `date` FROM ?_dbversion'))
|
||||||
|
{
|
||||||
|
$note = 'AoWoW DB version @ ' . date(Util::$dateFormatInternal, $date);
|
||||||
|
$ok = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$note = CLI::yellow('AoWoW DB version empty! Import of DB dump failed?');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$note = CLI::yellow('DB test failed to find dbversion table. setup/db_structure.sql not yet imported?');
|
||||||
|
break;
|
||||||
|
case DB_WORLD:
|
||||||
|
if (DB::World()->selectCell('SHOW TABLES LIKE ?', 'version'))
|
||||||
|
{
|
||||||
|
[$vString, $vNo] = DB::World()->selectRow('SELECT `db_version` AS "0", `cache_id` AS "1" FROM `version`');
|
||||||
|
if (strpos($vString, 'TDB') === 0)
|
||||||
|
{
|
||||||
|
if ($vNo < TDB_WORLD_MINIMUM_VER)
|
||||||
|
$note = CLI::yellow('DB test found TrinityDB version older than rev. ').CLI::bold(TDB_WORLD_MINIMUM_VER).CLI::yellow('. Please update to at least rev. ').CLI::bold(TDB_WORLD_MINIMUM_VER);
|
||||||
|
else if ($vNo > TDB_WORLD_EXPECTED_VER)
|
||||||
|
$note = CLI::yellow('DB test found TrinityDB version newer than rev. ').CLI::bold(TDB_WORLD_EXPECTED_VER).CLI::yellow('. Be advised! DB structure may diverge!');
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$note = 'TrinityDB version @ ' . $vString;
|
||||||
|
$ok = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (strpos($vString, 'ACDB') === 0)
|
||||||
|
$note = CLI::yellow('DB test found AzerothCore DB version. AzerothCore DB structure is not supported!');
|
||||||
|
else
|
||||||
|
$note = CLI::yellow('DB test found unexpected vendor in expected version table. Uhh.. Good Luck..!?');
|
||||||
|
}
|
||||||
|
else if (DB::World()->selectCell('SHOW TABLES LIKE ?', 'db_version'))
|
||||||
|
$note = CLI::yellow('DB test found MaNGOS styled version table. MaNGOS DB structure is not supported!');
|
||||||
|
else
|
||||||
|
$note = CLI::yellow('DB test failed to find version table. TrinityDB world not yet imported?');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$ok = true; // no tests right now
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$ok)
|
||||||
|
$result = CLI::yellow('WARN');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$result = CLI::red('ERR');
|
||||||
|
|
||||||
|
$buff[] = $result;
|
||||||
$buff[] = 'mysqli://'.$dbInfo['user'].':'.($dbInfo['pass'] ? '**********' : '').'@'.$dbInfo['host'].'/'.$dbInfo['db'];
|
$buff[] = 'mysqli://'.$dbInfo['user'].':'.($dbInfo['pass'] ? '**********' : '').'@'.$dbInfo['host'].'/'.$dbInfo['db'];
|
||||||
$buff[] = $dbInfo['prefix'] ? 'table prefix: '.$dbInfo['prefix'] : '';
|
$buff[] = $dbInfo['prefix'] ? 'table prefix: '.$dbInfo['prefix'] : '';
|
||||||
$buff[] = $errStr;
|
$buff[] = $note;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$buff[] = CLI::bold('<empty>');
|
$buff[] = CLI::bold('<empty>');
|
||||||
@@ -50,65 +109,65 @@ function dbconfig() : void
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
CLI::write("select a numerical index to use the corresponding entry");
|
CLI::write('select an index to use the corresponding entry');
|
||||||
|
|
||||||
$nCharDBs = 0;
|
$nCharDBs = 0;
|
||||||
$tblRows = [];
|
$tblRows = [];
|
||||||
foreach ($databases as $idx => $name)
|
foreach ($databases as $idx => $name)
|
||||||
{
|
{
|
||||||
if ($idx != 3)
|
if ($idx != DB_CHARACTERS)
|
||||||
$tblRows[] = $testDB($idx, $name, $AoWoWconf[$name]);
|
$tblRows[] = $testDB($idx, $name, $AoWoWconf[$name]);
|
||||||
else if (!empty($AoWoWconf[$name]))
|
else if (!empty($AoWoWconf[$name]))
|
||||||
foreach ($AoWoWconf[$name] as $charIdx => $dbInfo)
|
foreach ($AoWoWconf[$name] as $charIdx => $dbInfo)
|
||||||
$tblRows[] = $testDB($idx + $nCharDBs++, $name.' ['.$charIdx.']', $AoWoWconf[$name][$charIdx]);
|
$tblRows[] = $testDB($idx + $nCharDBs++, $name.' ['.$charIdx.']', $AoWoWconf[$name][$charIdx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$tblRows[] = ['['.CLI::bold(3 + $nCharDBs).']', 'add new character DB'];
|
$tblRows[] = ['['.CLI::bold('N').']', 'new characters DB'];
|
||||||
|
$tblRows[] = ['['.CLI::bold('R').']', 'retest / reload DBs'];
|
||||||
CLI::writeTable($tblRows, true);
|
CLI::writeTable($tblRows, true);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
$inp = ['idx' => ['', true, '/\d/']];
|
$inp = ['idx' => ['', true, '/\d|R|N/i']];
|
||||||
if (CLI::read($inp, true) && $inp)
|
if (CLI::read($inp, true) && $inp)
|
||||||
{
|
{
|
||||||
if ($inp['idx'] >= 0 && $inp['idx'] <= (3 + $nCharDBs))
|
if (strtoupper($inp['idx']) == 'R')
|
||||||
|
continue 2;
|
||||||
|
else if (($inp['idx'] >= DB_AOWOW && $inp['idx'] < (DB_CHARACTERS + $nCharDBs)) || strtoupper($inp['idx']) == 'N')
|
||||||
{
|
{
|
||||||
$curFields = $inp['idx'] ? $dbFields : array_slice($dbFields, 0, 4);
|
$curFields = $inp['idx'] ? $dbFields : array_slice($dbFields, 0, 4);
|
||||||
|
|
||||||
if ($inp['idx'] == 3 + $nCharDBs) // add new realmDB
|
if (strtoupper($inp['idx']) == 'N') // add new characters DB
|
||||||
$curFields['realmId'] = ['Realm Id', false, '/[1-9][0-9]*/'];
|
$curFields['realmId'] = ['Realm Id', false, '/\d{1,3}/'];
|
||||||
|
|
||||||
if (CLI::read($curFields))
|
if (CLI::read($curFields))
|
||||||
{
|
{
|
||||||
if ($inp['idx'] == 0 && $curFields)
|
if ($inp['idx'] == DB_AOWOW && $curFields)
|
||||||
$curFields['prefix'] = 'aowow_';
|
$curFields['prefix'] = 'aowow_';
|
||||||
|
|
||||||
// auth, world or aowow
|
if (strtoupper($inp['idx']) == 'N') // new char DB
|
||||||
if ($inp['idx'] < 3)
|
|
||||||
$AoWoWconf[$databases[$inp['idx']]] = $curFields ?: array_combine(array_keys($dbFields), ['', '', '', '', '']);
|
|
||||||
// new char DB
|
|
||||||
else if ($inp['idx'] == 3 + $nCharDBs)
|
|
||||||
{
|
{
|
||||||
if ($curFields)
|
if ($curFields)
|
||||||
{
|
{
|
||||||
$_ = $curFields['realmId'];
|
$_ = $curFields['realmId'];
|
||||||
unset($curFields['realmId']);
|
unset($curFields['realmId']);
|
||||||
$AoWoWconf[$databases[3]][$_] = $curFields;
|
$AoWoWconf[$databases[DB_CHARACTERS]][$_] = $curFields;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// existing char DB
|
else if ($inp['idx'] < DB_CHARACTERS) // auth, world or aowow
|
||||||
else
|
$AoWoWconf[$databases[$inp['idx']]] = $curFields ?: array_combine(array_keys($dbFields), ['', '', '', '', '']);
|
||||||
|
else // existing char DB
|
||||||
{
|
{
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($AoWoWconf[$databases[3]] as $realmId => &$dbInfo)
|
foreach ($AoWoWconf[$databases[DB_CHARACTERS]] as $realmId => &$dbInfo)
|
||||||
{
|
{
|
||||||
if ($inp['idx'] - 3 != $i++)
|
if ($inp['idx'] - DB_CHARACTERS != $i++)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ($curFields)
|
if ($curFields)
|
||||||
$dbInfo = $curFields;
|
$dbInfo = $curFields;
|
||||||
else
|
else
|
||||||
unset($AoWoWconf[$databases[3]][$realmId]);
|
unset($AoWoWconf[$databases[DB_CHARACTERS]][$realmId]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,8 +132,23 @@ function setup() : void
|
|||||||
if (DB::test($AoWoWconf[$what], $err))
|
if (DB::test($AoWoWconf[$what], $err))
|
||||||
{
|
{
|
||||||
DB::load($idx, $AoWoWconf[$what]);
|
DB::load($idx, $AoWoWconf[$what]);
|
||||||
if ($idx == DB_AOWOW)
|
switch ($idx)
|
||||||
Cfg::load(); // first time load after successful db setup
|
{
|
||||||
|
case DB_AOWOW:
|
||||||
|
if (DB::Aowow()->selectCell('SHOW TABLES LIKE ?', 'aowow_dbversion'))
|
||||||
|
Cfg::load(); // first time load after successful db setup
|
||||||
|
else
|
||||||
|
$error[] = ' * '.$what.': doesn\'t seem to contain aowow tables!';
|
||||||
|
break;
|
||||||
|
case DB_WORLD:
|
||||||
|
if (!DB::Aowow()->selectCell('SHOW TABLES LIKE ?', 'version'))
|
||||||
|
$error[] = ' * '.$what.': doesn\'t seem to contain TrinityCore world tables!';
|
||||||
|
else if (DB::Aowow()->selectCell('SELECT `cache_id` FROM `version`') < TDB_WORLD_MINIMUM_VER)
|
||||||
|
$error[] = ' * '.$what.': TCDB world db is structurally outdated! (min rev.: '.CLI::bold(TDB_WORLD_MINIMUM_VER).')';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// no further checks at this time
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$error[] = ' * '.$what.': '.$err;
|
$error[] = ' * '.$what.': '.$err;
|
||||||
|
|||||||
Reference in New Issue
Block a user