Some fixes

* more info displayed when cannot connect to database
* added Cache:delete($key) function
* added support for OTHire 0.0.3
* deleted unused ODBC and PostgreSQL files
* fixed support for Gesior layouts
This commit is contained in:
slawkens1 2017-05-02 21:34:41 +02:00
parent d3395e2eaf
commit 769c2942a4
15 changed files with 61 additions and 232 deletions

File diff suppressed because one or more lines are too long

View File

@ -234,7 +234,7 @@ if(!$error) {
$account_db->save(); $account_db->save();
} }
else { else {
$new_account = $ots->createObject('Account'); $new_account = new OTS_Account();
$new_account->create('dummy_account', 1); $new_account->create('dummy_account', 1);
$account_db->setPassword('for sample characters. ' . generateRandomString(10)); $account_db->setPassword('for sample characters. ' . generateRandomString(10));
} }

View File

@ -3,14 +3,14 @@
* *
* @param string $name * @param string $name
* @param boolean $ok * @param boolean $ok
* @param mixed $version * @param mixed $info
*/ */
function version_check($name, $ok, $version = '', $warning = false) function version_check($name, $ok, $info = '', $warning = false)
{ {
global $failed; global $failed;
echo '<p class="' . ($ok ? 'success' : ($warning ? 'warning' : 'error')) . '">' . $name; echo '<p class="' . ($ok ? 'success' : ($warning ? 'warning' : 'error')) . '">' . $name;
if(!empty($version)) if(!empty($info))
echo ': <b>' . $version . '</b>'; echo ': <b>' . $info . '</b>';
echo '</p>'; echo '</p>';
if(!$ok && !$warning) if(!$ok && !$warning)
@ -33,8 +33,9 @@ version_check('register_long_arrays', !$ini_register_globals, $ini_register_glob
$ini_safe_mode = ini_get_bool('safe_mode'); $ini_safe_mode = ini_get_bool('safe_mode');
version_check('safe_mode', !$ini_safe_mode, $ini_safe_mode ? $locale['on'] : $locale['off'], true); version_check('safe_mode', !$ini_safe_mode, $ini_safe_mode ? $locale['on'] : $locale['off'], true);
version_check('PDO extension loaded', extension_loaded('pdo'), '', false); version_check(str_replace('$EXTENSION$', 'PDO', $locale['step_requirements_extension']) , extension_loaded('pdo'), extension_loaded('pdo') ? $locale['loaded'] : $locale['not_loaded']);
version_check('zip extension loaded', extension_loaded('zip'), '', false); version_check(str_replace('$EXTENSION$', 'XML', $locale['step_requirements_extension']), extension_loaded('xml'), extension_loaded('xml') ? $locale['loaded'] : $locale['not_loaded']);
version_check(str_replace('$EXTENSION$', 'ZIP', $locale['step_requirements_extension']), extension_loaded('zip'), extension_loaded('zip') ? $locale['loaded'] : $locale['not_loaded']);
if($failed) if($failed)
{ {

View File

@ -65,12 +65,16 @@ defined('MYAAC') or die('Direct access not allowed!');
); );
} }
catch(PDOException $error) { catch(PDOException $error) {
if($cache->enabled()) {
$cache->delete('config_lua');
}
die('ERROR: Cannot connect to MySQL database.<br/>' . die('ERROR: Cannot connect to MySQL database.<br/>' .
'Possible reasons:' . 'Possible reasons:' .
'<ul>' . '<ul>' .
'<li>MySQL is not configured propertly in <i>config.lua</i>.</li>' . '<li>MySQL is not configured propertly in <i>config.lua</i>.</li>' .
'<li>MySQL server is not running.</li>' . '<li>MySQL server is not running.</li>' .
'</ul>'); '</ul>' . $error);
} }
$db = POT::getInstance()->getDBHandle(); $db = POT::getInstance()->getDBHandle();
?> ?>

View File

@ -381,6 +381,8 @@ function delete_guild($id)
foreach($rank_list as $rank_in_guild) { foreach($rank_list as $rank_in_guild) {
if(fieldExist('rank_id', 'players')) if(fieldExist('rank_id', 'players'))
$players_with_rank = $db->query('SELECT `id`, `rank_id` FROM `players` WHERE `rank_id` = ' . $rank->getId() . ' AND `deleted` = 0;'); $players_with_rank = $db->query('SELECT `id`, `rank_id` FROM `players` WHERE `rank_id` = ' . $rank->getId() . ' AND `deleted` = 0;');
else if(tableExist('guild_members'))
$players_with_rank = $db->query('SELECT `players`.`id` as `id`, `guild_members`.`rank_id` as `rank_id` FROM `players`, `guild_members` WHERE `guild_members`.`rank_id` = ' . $rank_in_guild->getId() . ' AND `players`.`id` = `guild_members`.`player_id` ORDER BY `name`;');
else else
$players_with_rank = $db->query('SELECT `players`.`id` as `id`, `guild_membership`.`rank_id` as `rank_id` FROM `players`, `guild_membership` WHERE `guild_membership`.`rank_id` = ' . $rank_in_guild->getId() . ' AND `players`.`id` = `guild_membership`.`player_id` ORDER BY `name`;'); $players_with_rank = $db->query('SELECT `players`.`id` as `id`, `guild_membership`.`rank_id` as `rank_id` FROM `players`, `guild_membership` WHERE `guild_membership`.`rank_id` = ' . $rank_in_guild->getId() . ' AND `players`.`id` = `guild_membership`.`player_id` ORDER BY `name`;');

View File

@ -91,6 +91,15 @@ else if(isset($config['lua']['data_directory'][0]))
if($tmp[strlen($tmp) - 1] != '/') // do not forget about trailing slash if($tmp[strlen($tmp) - 1] != '/') // do not forget about trailing slash
$tmp .= '/'; $tmp .= '/';
} }
else if(isset($config['lua']['datadir'][0]))
{
$tmp = $config['lua']['datadir'];
if($tmp[0] != '/')
$tmp = $config['server_path'] . $tmp;
if($tmp[strlen($tmp) - 1] != '/') // do not forget about trailing slash
$tmp .= '/';
}
else else
$tmp = $config['server_path'] . 'data/'; $tmp = $config['server_path'] . 'data/';

View File

@ -42,6 +42,10 @@ class Cache_APC
return ($var = apc_fetch($this->prefix . $key)) !== false; return ($var = apc_fetch($this->prefix . $key)) !== false;
} }
public function delete($key) {
apc_delete($key);
}
public function enabled() { public function enabled() {
return $this->enabled; return $this->enabled;
} }

View File

@ -41,6 +41,10 @@ class Cache_eAccelerator
return ($var = eaccelerator_get($this->prefix . $key)) !== null; return ($var = eaccelerator_get($this->prefix . $key)) !== null;
} }
public function delete($key) {
eaccelerator_rm($key);
}
public function enabled() { public function enabled() {
return $this->enabled; return $this->enabled;
} }

View File

@ -51,6 +51,13 @@ class Cache_File
return true; return true;
} }
public function delete($key)
{
$file = $this->_name($key);
if(file_exists($file))
unlink($file);
}
public function enabled() { public function enabled() {
return $this->enabled; return $this->enabled;
} }

View File

@ -47,6 +47,10 @@ class Cache_XCache
return true; return true;
} }
public function delete($key) {
xcache_unset($key);
}
public function enabled() { public function enabled() {
return $this->enabled; return $this->enabled;
} }

View File

@ -1,110 +0,0 @@
<?php
/**#@+
* @version 0.0.4
* @since 0.0.4
*/
/**
* @package POT
* @version 0.1.3
* @author Wrzasq <wrzasq@gmail.com>
* @copyright 2007 - 2008 (C) by Wrzasq
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3
*/
/**
* ODBC connection interface.
*
* <p>
* At all everything that you really need to read from this class documentation is list of parameters for driver's constructor.
* </p>
*
* @package POT
* @version 0.1.3
*/
class OTS_DB_ODBC extends OTS_Base_DB
{
/**
* Creates database connection.
*
* <p>
* Connects to ODBC data source on given arguments.
* </p>
*
* <p>
* List of parameters for this drivers:
* </p>
*
* <ul>
* <li><var>host</var> - database host.</li>
* <li><var>port</var> - ODBC driver.</li>
* <li><var>database</var> - database name.</li>
* <li><var>user</var> - user login.</li>
* <li><var>password</var> - user password.</li>
* <li><var>source</var> - ODBC data source.</li>
* </ul>
*
* <p>
* Note: Since 0.1.3 version <var>source</var> parameter was added.
* </p>
*
* @version 0.1.3
* @param array $params Connection parameters.
* @throws PDOException On PDO operation error.
*/
public function __construct($params)
{
$user = null;
$password = null;
$dns = array();
if( isset($params['host']) )
{
$dns[] = 'HOSTNAME={' . $params['host'] . '}';
}
if( isset($params['port']) )
{
$dns[] = 'DRIVER={' . $params['port'] . '}';
}
if( isset($params['database']) )
{
$dns[] = 'DATABASE={' . $params['database'] . '}';
}
if( isset($params['user']) )
{
$user = $params['user'];
$dns[] = 'UID={' . $user . '}';
}
if( isset($params['password']) )
{
$password = $params['password'];
$dns[] = 'PWD={' . $user . '}';
}
if( isset($params['prefix']) )
{
$this->prefix = $params['prefix'];
}
// composes DNS
$dns = implode(';', $dns);
// source parameter overwrites all other params
if( isset($params['source']) )
{
$dns = $params['source'];
}
// PDO constructor
parent::__construct('odbc:' . $dns, $user, $password);
}
}
/**#@-*/
?>

View File

@ -1,103 +0,0 @@
<?php
/**#@+
* @version 0.0.4
* @since 0.0.4
*/
/**
* @package POT
* @version 0.1.3
* @author Wrzasq <wrzasq@gmail.com>
* @copyright 2007 (C) by Wrzasq
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3
*/
/**
* PostgreSQL connection interface.
*
* <p>
* At all everything that you really need to read from this class documentation is list of parameters for driver's constructor.
* </p>
*
* @package POT
* @version 0.1.3
*/
class OTS_DB_PostgreSQL extends OTS_Base_DB
{
/**
* Creates database connection.
*
* <p>
* Connects to PgSQL (PostgreSQL) database on given arguments.
* </p>
*
* <p>
* List of parameters for this drivers:
* </p>
*
* <ul>
* <li><var>host</var> - database server.</li>
* <li><var>port</var> - port (optional, also it is possible to use host:port in <var>host</var> parameter).</li>
* <li><var>database</var> - database name.</li>
* <li><var>user</var> - user login.</li>
* <li><var>password</var> - user password.</li>
* </ul>
*
* @version 0.0.6
* @param array $params Connection parameters.
* @throws PDOException On PDO operation error.
*/
public function __construct($params)
{
$user = null;
$password = null;
$dns = array();
// host:port support
if( strpos(':', $params['host']) !== false)
{
$host = explode(':', $params['host'], 2);
$params['host'] = $host[0];
$params['port'] = $host[1];
}
if( isset($params['host']) )
{
$dns[] = 'host=' . $params['host'];
}
if( isset($params['port']) )
{
$dns[] = 'port=' . $params['port'];
}
if( isset($params['database']) )
{
$dns[] = 'dbname=' . $params['database'];
}
if( isset($params['user']) )
{
$user = $params['user'];
}
if( isset($params['password']) )
{
$password = $params['password'];
}
if( isset($params['prefix']) )
{
$this->prefix = $params['prefix'];
}
// PDO constructor
parent::__construct('pgsql:' . implode(' ', $dns), $user, $password);
}
}
/**#@-*/
?>

View File

@ -12,6 +12,11 @@
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$title = 'Guilds'; $title = 'Guilds';
if(tableExist('guild_members'))
define('GUILD_MEMBERS_TABLE', 'guild_members');
else
define('GUILD_MEMBERS_TABLE', 'guild_membership');
if($action == 'login') if($action == 'login')
{ {
if(check_guild_name($_REQUEST['guild'])) if(check_guild_name($_REQUEST['guild']))
@ -261,7 +266,7 @@ if($action == 'show')
if(fieldExist('rank_id', 'players')) if(fieldExist('rank_id', 'players'))
$players_with_rank = $db->query('SELECT `id`, `rank_id` FROM `players` WHERE `rank_id` = ' . $rank->getId() . ' AND `deleted` = 0;'); $players_with_rank = $db->query('SELECT `id`, `rank_id` FROM `players` WHERE `rank_id` = ' . $rank->getId() . ' AND `deleted` = 0;');
else else
$players_with_rank = $db->query('SELECT `players`.`id` as `id`, `guild_membership`.`rank_id` as `rank_id` FROM `players`, `guild_membership` WHERE `guild_membership`.`rank_id` = ' . $rank->getId() . ' AND `players`.`id` = `guild_membership`.`player_id` ORDER BY `name`;'); $players_with_rank = $db->query('SELECT `players`.`id` as `id`, `' . GUILD_MEMBERS_TABLE . '`.`rank_id` as `rank_id` FROM `players`, `' . GUILD_MEMBERS_TABLE . '` WHERE `' . GUILD_MEMBERS_TABLE . '`.`rank_id` = ' . $rank->getId() . ' AND `players`.`id` = `' . GUILD_MEMBERS_TABLE . '`.`player_id` ORDER BY `name`;');
$players_with_rank_number = $players_with_rank->rowCount(); $players_with_rank_number = $players_with_rank->rowCount();
if($players_with_rank_number > 0) if($players_with_rank_number > 0)
@ -491,7 +496,7 @@ if($action == 'changerank')
if(fieldExist('rank_id', 'players')) if(fieldExist('rank_id', 'players'))
$players_with_rank = $db->query('SELECT `id`, `rank_id` FROM `players` WHERE `rank_id` = ' . $rank->getId() . ' AND `deleted` = 0;'); $players_with_rank = $db->query('SELECT `id`, `rank_id` FROM `players` WHERE `rank_id` = ' . $rank->getId() . ' AND `deleted` = 0;');
else else
$players_with_rank = $db->query('SELECT `players`.`id` as `id`, `guild_membership`.`rank_id` as `rank_id` FROM `players`, `guild_membership` WHERE `guild_membership`.`rank_id` = ' . $rank->getId() . ' AND `players`.`id` = `guild_membership`.`player_id` ORDER BY `name`;'); $players_with_rank = $db->query('SELECT `players`.`id` as `id`, `' . GUILD_MEMBERS_TABLE . '`.`rank_id` as `rank_id` FROM `players`, `' . GUILD_MEMBERS_TABLE . '` WHERE `' . GUILD_MEMBERS_TABLE . '`.`rank_id` = ' . $rank->getId() . ' AND `players`.`id` = `' . GUILD_MEMBERS_TABLE . '`.`player_id` ORDER BY `name`;');
$players_with_rank_number = $players_with_rank->rowCount(); $players_with_rank_number = $players_with_rank->rowCount();
if(count($players_with_rank) > 0) if(count($players_with_rank) > 0)
@ -573,7 +578,7 @@ if($action == 'changerank')
if(fieldExist('rank_id', 'players')) if(fieldExist('rank_id', 'players'))
$players_with_rank = $db->query('SELECT `id`, `rank_id` FROM `players` WHERE `rank_id` = ' . $rank->getId() . ' AND `deleted` = 0;'); $players_with_rank = $db->query('SELECT `id`, `rank_id` FROM `players` WHERE `rank_id` = ' . $rank->getId() . ' AND `deleted` = 0;');
else else
$players_with_rank = $db->query('SELECT `players`.`id` as `id`, `guild_membership`.`rank_id` as `rank_id` FROM `players`, `guild_membership` WHERE `guild_membership`.`rank_id` = ' . $rank->getId() . ' AND `players`.`id` = `guild_membership`.`player_id` ORDER BY `name`;'); $players_with_rank = $db->query('SELECT `players`.`id` as `id`, `' . GUILD_MEMBERS_TABLE . '`.`rank_id` as `rank_id` FROM `players`, `' . GUILD_MEMBERS_TABLE . '` WHERE `' . GUILD_MEMBERS_TABLE . '`.`rank_id` = ' . $rank->getId() . ' AND `players`.`id` = `' . GUILD_MEMBERS_TABLE . '`.`player_id` ORDER BY `name`;');
$players_with_rank_number = $players_with_rank->rowCount(); $players_with_rank_number = $players_with_rank->rowCount();
if(count($players_with_rank) > 0) if(count($players_with_rank) > 0)
@ -1598,7 +1603,7 @@ else
if(fieldExist('rank_id', 'players')) if(fieldExist('rank_id', 'players'))
$players_with_rank = $db->query('SELECT `id`, `rank_id` FROM `players` WHERE `rank_id` = ' . $rank->getId() . ' AND `deleted` = 0;'); $players_with_rank = $db->query('SELECT `id`, `rank_id` FROM `players` WHERE `rank_id` = ' . $rank->getId() . ' AND `deleted` = 0;');
else else
$players_with_rank = $db->query('SELECT `players`.`id` as `id`, `guild_membership`.`rank_id` as `rank_id` FROM `players`, `guild_membership` WHERE `guild_membership`.`rank_id` = ' . $rank->getId() . ' AND `players`.`id` = `guild_membership`.`player_id` ORDER BY `name`;'); $players_with_rank = $db->query('SELECT `players`.`id` as `id`, `' . GUILD_MEMBERS_TABLE . '`.`rank_id` as `rank_id` FROM `players`, `' . GUILD_MEMBERS_TABLE . '` WHERE `' . GUILD_MEMBERS_TABLE . '`.`rank_id` = ' . $rank->getId() . ' AND `players`.`id` = `' . GUILD_MEMBERS_TABLE . '`.`player_id` ORDER BY `name`;');
$players_with_rank_number = $players_with_rank->rowCount(); $players_with_rank_number = $players_with_rank->rowCount();
if($players_with_rank_number > 0) { if($players_with_rank_number > 0) {

View File

@ -36,7 +36,9 @@ if($config['template_allow_change'])
} }
$template_path = 'templates/' . $template_name; $template_path = 'templates/' . $template_name;
if(!file_exists($template_path . '/config.php')) if(!file_exists($template_path . '/index.php') &&
!file_exists($template_path . '/template.php') &&
!file_exists($template_path . '/layout.php'))
{ {
$template_name = 'kathrine'; $template_name = 'kathrine';
$template_path = 'templates/' . $template_name; $template_path = 'templates/' . $template_name;
@ -66,7 +68,7 @@ if($exists || ($config['backward_support'] && file_exists($template_path . '/lay
foreach($template_ini as $key => $value) foreach($template_ini as $key => $value)
$config[$key] = $value; $config[$key] = $value;
} }
else else if(file_exists($template_path . '/config.php'))
require($template_path . '/config.php'); require($template_path . '/config.php');
$template = array(); $template = array();
@ -76,7 +78,7 @@ $template['link_account_lost'] = internalLayoutLink(($config['friendly_urls'] ?
$template['link_account_logout'] = internalLayoutLink(($config['friendly_urls'] ? 'account' : 'accountmanagement'), 'logout'); $template['link_account_logout'] = internalLayoutLink(($config['friendly_urls'] ? 'account' : 'accountmanagement'), 'logout');
$template['link_news'] = internalLayoutLink('news'); $template['link_news'] = internalLayoutLink('news');
$template['link_news_archive'] = internalLayoutLink('news' . ($config['friendly_urls'] ? '' : '') . 'archive'); $template['link_news_archive'] = internalLayoutLink('news' . ($config['friendly_urls'] ? '/' : '') . 'archive');
$template['link_changelog'] = internalLayoutLink('changelog'); $template['link_changelog'] = internalLayoutLink('changelog');
$template['link_rules'] = internalLayoutLink('rules'); $template['link_rules'] = internalLayoutLink('rules');
$template['link_downloads'] = internalLayoutLink('downloads'); $template['link_downloads'] = internalLayoutLink('downloads');

View File

@ -51,9 +51,9 @@
<div id="mainsubmenu"> <div id="mainsubmenu">
<div id="news-submenu"> <div id="news-submenu">
<a href="<?php echo internalLayoutLink('news'); ?>">Latest News</a> <a href="<?php echo $template['link_news']; ?>">Latest News</a>
<span class="separator"></span> <span class="separator"></span>
<a href="<?php echo internalLayoutLink('news' . ($config['friendly_urls'] ? '' : '') . 'archive')?>">News Archives</a> <a href="<?php echo $template['link_news_archive']; ?>">News Archives</a>
</div> </div>
<div id="account-submenu"> <div id="account-submenu">
@ -159,7 +159,7 @@
<div id="margins"> <div id="margins">
<table cellpadding="0" cellspacing="0" border="0" width="100%"> <table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr> <tr>
<td><a href="<?php echo internalLayoutLink('news'); ?>"><?php echo $config['lua']['serverName']; ?></a> &raquo; <?php echo $title; ?></td> <td><a href="<?php echo $template['link_news']; ?>"><?php echo $config['lua']['serverName']; ?></a> &raquo; <?php echo $title; ?></td>
<td> <td>
<?php <?php
if($status['online']) if($status['online'])