mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
- setup can now be run from CLI. Use "> php index.php --help" to start off - updated logging for use with CLI - added generators for client imagery (icons, maps, talents, ect) DBC: - parsed DBCs are now expected in the Aowow-DB, prefixed with dbc_* (they are joined with these tables, so its easier to have them here altogether) - setup/db_setup_3.zip may be reapplied (optionally) - alternatively aowow will now extract you own DBCs alongside your textures. They will be parsed and saved to DB, as needed. Misc: * HOST_URL and STATIC_URL will now be determined automaticly once and * then saved to ?_config (setup by CLI requires these to be set) Spell: * added glyph-symbol to infobox for glyph-related spells
124 lines
2.7 KiB
PHP
124 lines
2.7 KiB
PHP
<?php
|
|
|
|
if (!defined('AOWOW_REVISION'))
|
|
die('illegal access');
|
|
|
|
/*
|
|
Class designed by LordJZ for Aowow3
|
|
|
|
https://github.com/LordJZ/aowow3/
|
|
*/
|
|
|
|
class DB
|
|
{
|
|
private static $interfaceCache = [];
|
|
private static $optionsCache = [];
|
|
private static $connectionCache = [];
|
|
|
|
private static function createConnectSyntax(&$options)
|
|
{
|
|
return 'mysqli://'.$options['user'].':'.$options['pass'].'@'.$options['host'].'/'.$options['db'];
|
|
}
|
|
|
|
public static function connect($idx)
|
|
{
|
|
if (self::isConnected($idx))
|
|
return;
|
|
|
|
$options = &self::$optionsCache[$idx];
|
|
$interface = DbSimple_Generic::connect(self::createConnectSyntax($options));
|
|
|
|
$interface->setErrorHandler(['DB', 'errorHandler']);
|
|
|
|
if ($interface->error)
|
|
die('Failed to connect to database.');
|
|
|
|
$interface->query('SET NAMES ?', 'utf8');
|
|
if ($options['prefix'])
|
|
$interface->setIdentPrefix($options['prefix']);
|
|
|
|
self::$interfaceCache[$idx] = &$interface;
|
|
self::$connectionCache[$idx] = true;
|
|
}
|
|
|
|
public static function errorHandler($message, $data)
|
|
{
|
|
if (!error_reporting())
|
|
return;
|
|
|
|
$error = "DB ERROR:<br /><br />\n\n<pre>".print_r($data, true)."</pre>";
|
|
|
|
echo CLI ? strip_tags($error) : $error;
|
|
exit;
|
|
}
|
|
|
|
public static function getDB($idx)
|
|
{
|
|
return self::$interfaceCache[$idx];
|
|
}
|
|
|
|
public static function isConnected($idx)
|
|
{
|
|
return isset(self::$connectionCache[$idx]);
|
|
}
|
|
|
|
public static function isConnectable($idx)
|
|
{
|
|
return isset(self::$optionsCache[$idx]);
|
|
}
|
|
|
|
private static function safeGetDB($idx)
|
|
{
|
|
if (!self::isConnected($idx))
|
|
self::connect($idx);
|
|
|
|
return self::getDB($idx);
|
|
}
|
|
|
|
/**
|
|
* @static
|
|
* @return DbSimple_Mysql
|
|
*/
|
|
public static function Characters($realm)
|
|
{
|
|
if (!isset(self::$optionsCache[DB_CHARACTERS.$realm]))
|
|
die('Connection info not found for live database of realm #'.$realm.'. Aborted.');
|
|
|
|
return self::safeGetDB(DB_CHARACTERS.$realm);
|
|
}
|
|
|
|
/**
|
|
* @static
|
|
* @return DbSimple_Mysql
|
|
*/
|
|
public static function Auth()
|
|
{
|
|
return self::safeGetDB(DB_AUTH);
|
|
}
|
|
|
|
/**
|
|
* @static
|
|
* @return DbSimple_Mysql
|
|
*/
|
|
public static function World()
|
|
{
|
|
return self::safeGetDB(DB_WORLD);
|
|
}
|
|
|
|
/**
|
|
* @static
|
|
* @return DbSimple_Mysql
|
|
*/
|
|
public static function Aowow()
|
|
{
|
|
return self::safeGetDB(DB_AOWOW);
|
|
}
|
|
|
|
public static function load($idx, $config)
|
|
{
|
|
self::$optionsCache[$idx] = $config;
|
|
}
|
|
}
|
|
|
|
?>
|