* cache $db->hasTable and $db->hasColumn functions

* changed tableExist and fieldExist to $db->hasTable(table) +
$db->hasColumn(table, column)
* new configurable: database_log - can log database queries and show in
website source when logged as super admin
* removed debug_level configurable, enabled by default when logged on
super admin
* added OTS_Account:getCountry()
* added posibility to load OTS_Player partially, and without skills
* (internal) changed depracated $ots->createObject() functions with
their OTS_ equivalents
* (internal) removed unused code
This commit is contained in:
slawkens1 2018-01-06 05:44:33 +01:00
parent 31537687c1
commit 1025fad0e6
65 changed files with 446 additions and 417 deletions

2
TODO
View File

@ -14,10 +14,8 @@
* should the link blink? * should the link blink?
* cache: * cache:
* hooks * hooks
* fieldExist and tableExist functions
* Menus in templates * Menus in templates
* move highscores to twig * move highscores to twig
* $db->hasTable(table) + $db->hasColumn(table, column)
* migrations: option to downgrade the database * migrations: option to downgrade the database
* hooks: login + logout * hooks: login + logout

View File

@ -46,8 +46,6 @@ $config = array(
// footer // footer
'footer' => ''/*'<br/>Your Server &copy; 2016. All rights reserved.'*/, 'footer' => ''/*'<br/>Your Server &copy; 2016. All rights reserved.'*/,
'debug_level' => 0, // 0 - disabled, 1 - show load time, 2 - show db query counter, 3 - both, 4 - memory usage, 5 - load time & memory usage, 6 - queries & memory usage, 7 - all
'language' => 'en', // default language (currently only 'en' available) 'language' => 'en', // default language (currently only 'en' available)
'language_allow_change' => false, 'language_allow_change' => false,
@ -65,6 +63,7 @@ $config = array(
'database_user' => '', 'database_user' => '',
'database_password' => '', 'database_password' => '',
'database_name' => '', 'database_name' => '',
'database_log' => false, // should database queries be logged and displayed in the page source? They will be included at the end of the .html source of the page
// multiworld system (only TFS 0.3) // multiworld system (only TFS 0.3)
'multiworld' => false, // use multiworld system? 'multiworld' => false, // use multiworld system?

View File

@ -423,15 +423,18 @@ else
die('ERROR: Cannot load template.'); die('ERROR: Cannot load template.');
} }
$super = superAdmin();
echo '<!-- MyAAC ' . MYAAC_VERSION . ' :: http://www.my-aac.org/ -->' . "\n"; echo '<!-- MyAAC ' . MYAAC_VERSION . ' :: http://www.my-aac.org/ -->' . "\n";
if(($config['debug_level'] & 1) == 1) if($super) {
echo '<!-- Generated in :: ' . round(microtime(true) - START_TIME, 4) . ' -->'; echo '<!-- Generated in: ' . round(microtime(true) - START_TIME, 4) . 'ms -->';
echo PHP_EOL . '<!-- Queries done: ' . $db->queries() . ' -->';
if(($config['debug_level'] & 2) == 2) if(function_exists('memory_get_peak_usage')) {
echo "\n" . '<!-- Queries done :: ' . $db->queries() . ' -->'; echo PHP_EOL . '<!-- Peak memory usage: ' . convert_bytes(memory_get_peak_usage(true)) . ' -->';
}
if(($config['debug_level'] & 4) == 4 && function_exists('memory_get_peak_usage')) }
echo "\n" . '<!-- Peak memory usage: ' . convert_bytes(memory_get_peak_usage(true)) . ' -->';
if($config['database_log'] && $super) {
echo PHP_EOL . '<!-- Database Queries Done by MyAAC:' . PHP_EOL . $db->getLog() . '-->';
}
$hooks->trigger(HOOK_FINISH); $hooks->trigger(HOOK_FINISH);
?> ?>

View File

@ -5,8 +5,8 @@ require(SYSTEM . 'libs/pot/OTS.php');
$ots = POT::getInstance(); $ots = POT::getInstance();
require(SYSTEM . 'database.php'); require(SYSTEM . 'database.php');
if(tableExist('accounts')) if($db->hasTable('accounts'))
define('USE_ACCOUNT_NAME', fieldExist('name', 'accounts')); define('USE_ACCOUNT_NAME', $db->hasColumn('accounts', 'name'));
else else
define('USE_ACCOUNT_NAME', false); define('USE_ACCOUNT_NAME', false);
?> ?>

View File

@ -47,23 +47,23 @@ if(!$error) {
success($locale['step_database_importing']); success($locale['step_database_importing']);
require(BASE . 'install/includes/database.php'); require(BASE . 'install/includes/database.php');
if(!tableExist('accounts')) { if(!$db->hasTable('accounts')) {
$locale['step_database_error_table'] = str_replace('$TABLE$', 'accounts', $locale['step_database_error_table']); $locale['step_database_error_table'] = str_replace('$TABLE$', 'accounts', $locale['step_database_error_table']);
error($locale['step_database_error_table']); error($locale['step_database_error_table']);
$error = true; $error = true;
} }
else if(!tableExist('players')) { else if(!$db->hasTable('players')) {
$locale['step_database_error_table'] = str_replace('$TABLE$', 'players', $locale['step_database_error_table']); $locale['step_database_error_table'] = str_replace('$TABLE$', 'players', $locale['step_database_error_table']);
error($locale['step_database_error_table']); error($locale['step_database_error_table']);
$error = true; $error = true;
} }
else if(!tableExist('guilds')) { else if(!$db->hasTable('guilds')) {
$locale['step_database_error_table'] = str_replace('$TABLE$', 'guilds', $locale['step_database_error_table']); $locale['step_database_error_table'] = str_replace('$TABLE$', 'guilds', $locale['step_database_error_table']);
error($locale['step_database_error_table']); error($locale['step_database_error_table']);
$error = true; $error = true;
} }
if(tableExist(TABLE_PREFIX . 'account_actions')) { if($db->hasTable(TABLE_PREFIX . 'account_actions')) {
$locale['step_database_error_table_exist'] = str_replace('$TABLE$', TABLE_PREFIX . 'account_actions', $locale['step_database_error_table_exist']); $locale['step_database_error_table_exist'] = str_replace('$TABLE$', TABLE_PREFIX . 'account_actions', $locale['step_database_error_table_exist']);
warning($locale['step_database_error_table_exist']); warning($locale['step_database_error_table_exist']);
} }
@ -85,7 +85,7 @@ if(!$error) {
} }
if(!$error) { if(!$error) {
if(fieldExist('key', 'accounts')) { if($db->hasColumn('accounts', 'key')) {
if(query("ALTER TABLE `accounts` MODIFY `key` VARCHAR(64) NOT NULL DEFAULT '';")) if(query("ALTER TABLE `accounts` MODIFY `key` VARCHAR(64) NOT NULL DEFAULT '';"))
success($locale['step_database_modifying_field'] . ' accounts.key...'); success($locale['step_database_modifying_field'] . ' accounts.key...');
} }
@ -94,75 +94,75 @@ if(!$error) {
success($locale['step_database_adding_field'] . ' accounts.key...'); success($locale['step_database_adding_field'] . ' accounts.key...');
} }
if(!fieldExist('blocked', 'accounts')) { if(!$db->hasColumn('accounts', 'blocked')) {
if(query("ALTER TABLE `accounts` ADD `blocked` TINYINT(1) NOT NULL DEFAULT FALSE COMMENT 'internal usage' AFTER `key`;")) if(query("ALTER TABLE `accounts` ADD `blocked` TINYINT(1) NOT NULL DEFAULT FALSE COMMENT 'internal usage' AFTER `key`;"))
success($locale['step_database_adding_field'] . ' accounts.blocked...'); success($locale['step_database_adding_field'] . ' accounts.blocked...');
} }
if(!fieldExist('created', 'accounts')) { if(!$db->hasColumn('accounts', 'created')) {
if(query("ALTER TABLE `accounts` ADD `created` INT(11) NOT NULL DEFAULT 0 AFTER `" . (fieldExist('group_id', 'accounts') ? 'group_id' : 'blocked') . "`;")) if(query("ALTER TABLE `accounts` ADD `created` INT(11) NOT NULL DEFAULT 0 AFTER `" . ($db->hasColumn('accounts', 'group_id') ? 'group_id' : 'blocked') . "`;"))
success($locale['step_database_adding_field'] . ' accounts.created...'); success($locale['step_database_adding_field'] . ' accounts.created...');
} }
if(!fieldExist('rlname', 'accounts')) { if(!$db->hasColumn('accounts', 'rlname')) {
if(query("ALTER TABLE `accounts` ADD `rlname` VARCHAR(255) NOT NULL DEFAULT '' AFTER `created`;")) if(query("ALTER TABLE `accounts` ADD `rlname` VARCHAR(255) NOT NULL DEFAULT '' AFTER `created`;"))
success($locale['step_database_adding_field'] . ' accounts.rlname...'); success($locale['step_database_adding_field'] . ' accounts.rlname...');
} }
if(!fieldExist('location', 'accounts')) { if(!$db->hasColumn('accounts', 'location')) {
if(query("ALTER TABLE `accounts` ADD `location` VARCHAR(255) NOT NULL DEFAULT '' AFTER `rlname`;")) if(query("ALTER TABLE `accounts` ADD `location` VARCHAR(255) NOT NULL DEFAULT '' AFTER `rlname`;"))
success($locale['step_database_adding_field'] . ' accounts.location...'); success($locale['step_database_adding_field'] . ' accounts.location...');
} }
if(!fieldExist('country', 'accounts')) { if(!$db->hasColumn('accounts', 'country')) {
if(query("ALTER TABLE `accounts` ADD `country` VARCHAR(3) NOT NULL DEFAULT '' AFTER `location`;")) if(query("ALTER TABLE `accounts` ADD `country` VARCHAR(3) NOT NULL DEFAULT '' AFTER `location`;"))
success($locale['step_database_adding_field'] . ' accounts.country...'); success($locale['step_database_adding_field'] . ' accounts.country...');
} }
if(fieldExist('page_lastday', 'accounts')) { if($db->hasColumn('accounts', 'page_lastday')) {
if(query("ALTER TABLE `accounts` CHANGE `page_lastday` `web_lastlogin` INT(11) NOT NULL DEFAULT 0;")) { if(query("ALTER TABLE `accounts` CHANGE `page_lastday` `web_lastlogin` INT(11) NOT NULL DEFAULT 0;")) {
$tmp = str_replace('$FIELD$', 'accounts.page_lastday', $locale['step_database_changing_field']); $tmp = str_replace('$FIELD$', 'accounts.page_lastday', $locale['step_database_changing_field']);
$tmp = str_replace('$FIELD_NEW$', 'accounts.web_lastlogin', $tmp); $tmp = str_replace('$FIELD_NEW$', 'accounts.web_lastlogin', $tmp);
success($tmp); success($tmp);
} }
} }
else if(!fieldExist('web_lastlogin', 'accounts')) { else if(!$db->hasColumn('accounts', 'web_lastlogin')) {
if(query("ALTER TABLE `accounts` ADD `web_lastlogin` INT(11) NOT NULL DEFAULT 0 AFTER `country`;")) if(query("ALTER TABLE `accounts` ADD `web_lastlogin` INT(11) NOT NULL DEFAULT 0 AFTER `country`;"))
success($locale['step_database_adding_field'] . ' accounts.web_lastlogin...'); success($locale['step_database_adding_field'] . ' accounts.web_lastlogin...');
} }
if(!fieldExist('web_flags', 'accounts')) { if(!$db->hasColumn('accounts', 'web_flags')) {
if(query("ALTER TABLE `accounts` ADD `web_flags` INT(11) NOT NULL DEFAULT 0 AFTER `web_lastlogin`;")) if(query("ALTER TABLE `accounts` ADD `web_flags` INT(11) NOT NULL DEFAULT 0 AFTER `web_lastlogin`;"))
success($locale['step_database_adding_field'] . ' accounts.web_flags...'); success($locale['step_database_adding_field'] . ' accounts.web_flags...');
} }
if(!fieldExist('email_hash', 'accounts')) { if(!$db->hasColumn('accounts', 'email_hash')) {
if(query("ALTER TABLE `accounts` ADD `email_hash` VARCHAR(32) NOT NULL DEFAULT '' AFTER `web_flags`;")) if(query("ALTER TABLE `accounts` ADD `email_hash` VARCHAR(32) NOT NULL DEFAULT '' AFTER `web_flags`;"))
success($locale['step_database_adding_field'] . ' accounts.email_hash...'); success($locale['step_database_adding_field'] . ' accounts.email_hash...');
} }
if(!fieldExist('email_verified', 'accounts')) { if(!$db->hasColumn('accounts', 'email_verified')) {
if(query("ALTER TABLE `accounts` ADD `email_verified` TINYINT(1) NOT NULL DEFAULT 0 AFTER `email_hash`;")) if(query("ALTER TABLE `accounts` ADD `email_verified` TINYINT(1) NOT NULL DEFAULT 0 AFTER `email_hash`;"))
success($locale['step_database_adding_field'] . ' accounts.email_verified...'); success($locale['step_database_adding_field'] . ' accounts.email_verified...');
} }
if(!fieldExist('email_new', 'accounts')) { if(!$db->hasColumn('accounts', 'email_new')) {
if(query("ALTER TABLE `accounts` ADD `email_new` VARCHAR(255) NOT NULL DEFAULT '' AFTER `email_hash`;")) if(query("ALTER TABLE `accounts` ADD `email_new` VARCHAR(255) NOT NULL DEFAULT '' AFTER `email_hash`;"))
success($locale['step_database_adding_field'] . ' accounts.email_new...'); success($locale['step_database_adding_field'] . ' accounts.email_new...');
} }
if(!fieldExist('email_new_time', 'accounts')) { if(!$db->hasColumn('accounts', 'email_new_time')) {
if(query("ALTER TABLE `accounts` ADD `email_new_time` INT(11) NOT NULL DEFAULT 0 AFTER `email_new`;")) if(query("ALTER TABLE `accounts` ADD `email_new_time` INT(11) NOT NULL DEFAULT 0 AFTER `email_new`;"))
success($locale['step_database_adding_field'] . ' accounts.email_new_time...'); success($locale['step_database_adding_field'] . ' accounts.email_new_time...');
} }
if(!fieldExist('email_code', 'accounts')) { if(!$db->hasColumn('accounts', 'email_code')) {
if(query("ALTER TABLE `accounts` ADD `email_code` VARCHAR(255) NOT NULL DEFAULT '' AFTER `email_new_time`;")) if(query("ALTER TABLE `accounts` ADD `email_code` VARCHAR(255) NOT NULL DEFAULT '' AFTER `email_new_time`;"))
success($locale['step_database_adding_field'] . ' accounts.email_code...'); success($locale['step_database_adding_field'] . ' accounts.email_code...');
} }
if(fieldExist('next_email', 'accounts')) { if($db->hasColumn('accounts', 'next_email')) {
if(!fieldExist('email_next', 'accounts')) { if(!$db->hasColumn('accounts', 'email_next')) {
if(query("ALTER TABLE `accounts` CHANGE `next_email` `email_next` INT(11) NOT NULL DEFAULT 0;")) { if(query("ALTER TABLE `accounts` CHANGE `next_email` `email_next` INT(11) NOT NULL DEFAULT 0;")) {
$tmp = str_replace('$FIELD$', 'accounts.next_email', $locale['step_database_changing_field']); $tmp = str_replace('$FIELD$', 'accounts.next_email', $locale['step_database_changing_field']);
$tmp = str_replace('$FIELD_NEW$', 'accounts.email_next', $tmp); $tmp = str_replace('$FIELD_NEW$', 'accounts.email_next', $tmp);
@ -170,45 +170,45 @@ if(!$error) {
} }
} }
} }
else if(!fieldExist('email_next', 'accounts')) { else if(!$db->hasColumn('accounts', 'email_next')) {
if(query("ALTER TABLE `accounts` ADD `email_next` INT(11) NOT NULL DEFAULT 0 AFTER `email_code`;")) if(query("ALTER TABLE `accounts` ADD `email_next` INT(11) NOT NULL DEFAULT 0 AFTER `email_code`;"))
success($locale['step_database_adding_field'] . ' accounts.email_next...'); success($locale['step_database_adding_field'] . ' accounts.email_next...');
} }
if(!fieldExist('premium_points', 'accounts')) { if(!$db->hasColumn('accounts', 'premium_points')) {
if(query("ALTER TABLE `accounts` ADD `premium_points` INT(11) NOT NULL DEFAULT 0 AFTER `email_next`;")) if(query("ALTER TABLE `accounts` ADD `premium_points` INT(11) NOT NULL DEFAULT 0 AFTER `email_next`;"))
success($locale['step_database_adding_field'] . ' accounts.premium_points...'); success($locale['step_database_adding_field'] . ' accounts.premium_points...');
} }
if(!fieldExist('description', 'guilds')) { if(!$db->hasColumn('guilds', 'description')) {
if(query("ALTER TABLE `guilds` ADD `description` TEXT NOT NULL;")) if(query("ALTER TABLE `guilds` ADD `description` TEXT NOT NULL;"))
success($locale['step_database_adding_field'] . ' guilds.description...'); success($locale['step_database_adding_field'] . ' guilds.description...');
} }
if(fieldExist('logo_gfx_name', 'guilds')) { if($db->hasColumn('guilds', 'logo_gfx_name')) {
if(query("ALTER TABLE `guilds` CHANGE `logo_gfx_name` `logo_name` VARCHAR( 255 ) NOT NULL DEFAULT 'default.gif';")) { if(query("ALTER TABLE `guilds` CHANGE `logo_gfx_name` `logo_name` VARCHAR( 255 ) NOT NULL DEFAULT 'default.gif';")) {
$tmp = str_replace('$FIELD$', 'guilds.logo_gfx_name', $locale['step_database_changing_field']); $tmp = str_replace('$FIELD$', 'guilds.logo_gfx_name', $locale['step_database_changing_field']);
$tmp = str_replace('$FIELD_NEW$', 'guilds.logo_name', $tmp); $tmp = str_replace('$FIELD_NEW$', 'guilds.logo_name', $tmp);
success($tmp); success($tmp);
} }
} }
else if(!fieldExist('logo_name', 'guilds')) { else if(!$db->hasColumn('guilds', 'logo_name')) {
if(query("ALTER TABLE `guilds` ADD `logo_name` VARCHAR( 255 ) NOT NULL DEFAULT 'default.gif';")) if(query("ALTER TABLE `guilds` ADD `logo_name` VARCHAR( 255 ) NOT NULL DEFAULT 'default.gif';"))
success($locale['step_database_adding_field'] . ' guilds.logo_name...'); success($locale['step_database_adding_field'] . ' guilds.logo_name...');
} }
if(!fieldExist('created', 'players')) { if(!$db->hasColumn('players', 'created')) {
if(query("ALTER TABLE `players` ADD `created` INT(11) NOT NULL DEFAULT 0;")) if(query("ALTER TABLE `players` ADD `created` INT(11) NOT NULL DEFAULT 0;"))
success($locale['step_database_adding_field'] . ' players.created...'); success($locale['step_database_adding_field'] . ' players.created...');
} }
if(!fieldExist('deleted', 'players') && !fieldExist('deletion', 'players')) { if(!$db->hasColumn('players', 'deleted') && !$db->hasColumn('players', 'deletion')) {
if(query("ALTER TABLE `players` ADD `deleted` TINYINT(1) NOT NULL DEFAULT 0;")) if(query("ALTER TABLE `players` ADD `deleted` TINYINT(1) NOT NULL DEFAULT 0;"))
success($locale['step_database_adding_field'] . ' players.comment...'); success($locale['step_database_adding_field'] . ' players.comment...');
} }
if(fieldExist('hide_char', 'players')) { if($db->hasColumn('players', 'hide_char')) {
if(!fieldExist('hidden', 'players')) { if(!$db->hasColumn('players', 'hidden')) {
if(query("ALTER TABLE `players` CHANGE `hide_char` `hidden` TINYINT(1) NOT NULL DEFAULT 0;")) { if(query("ALTER TABLE `players` CHANGE `hide_char` `hidden` TINYINT(1) NOT NULL DEFAULT 0;")) {
$tmp = str_replace('$FIELD$', 'players.hide_char', $locale['step_database_changing_field']); $tmp = str_replace('$FIELD$', 'players.hide_char', $locale['step_database_changing_field']);
$tmp = str_replace('$FIELD_NEW$', 'players.hidden', $tmp); $tmp = str_replace('$FIELD_NEW$', 'players.hidden', $tmp);
@ -216,12 +216,12 @@ if(!$error) {
} }
} }
} }
else if(!fieldExist('hidden', 'players')) { else if(!$db->hasColumn('players', 'hidden')) {
if(query("ALTER TABLE `players` ADD `hidden` TINYINT(1) NOT NULL DEFAULT 0;")) if(query("ALTER TABLE `players` ADD `hidden` TINYINT(1) NOT NULL DEFAULT 0;"))
success($locale['step_database_adding_field'] . ' players.hidden...'); success($locale['step_database_adding_field'] . ' players.hidden...');
} }
if(!fieldExist('comment', 'players')) { if(!$db->hasColumn('players', 'comment')) {
if(query("ALTER TABLE `players` ADD `comment` TEXT NOT NULL;")) if(query("ALTER TABLE `players` ADD `comment` TEXT NOT NULL;"))
success($locale['step_database_adding_field'] . ' players.comment...'); success($locale['step_database_adding_field'] . ' players.comment...');
} }

View File

@ -15,7 +15,7 @@ else {
$password = $_SESSION['var_password']; $password = $_SESSION['var_password'];
$config_salt_enabled = fieldExist('salt', 'accounts'); $config_salt_enabled = $db->hasColumn('accounts', 'salt');
if($config_salt_enabled) if($config_salt_enabled)
{ {
$salt = generateRandomString(10, false, true, true); $salt = generateRandomString(10, false, true, true);
@ -77,9 +77,9 @@ else {
$account_used->setCustomField('web_flags', FLAG_ADMIN + FLAG_SUPER_ADMIN); $account_used->setCustomField('web_flags', FLAG_ADMIN + FLAG_SUPER_ADMIN);
$account_used->setCustomField('country', 'us'); $account_used->setCustomField('country', 'us');
if(fieldExist('group_id', 'accounts')) if($db->hasColumn('accounts', 'group_id'))
$account_used->setCustomField('group_id', $groups->getHighestId()); $account_used->setCustomField('group_id', $groups->getHighestId());
if(fieldExist('type', 'accounts')) if($db->hasColumn('accounts', 'type'))
$account_used->setCustomField('type', 5); $account_used->setCustomField('type', 5);
if(!$player_db->isLoaded()) if(!$player_db->isLoaded())
@ -116,7 +116,7 @@ else {
} }
$deleted = 'deleted'; $deleted = 'deleted';
if(fieldExist('deletion', 'players')) if($db->hasColumn('players', 'deletion'))
$deleted = 'deletion'; $deleted = 'deletion';
$insert_into_players = "INSERT INTO `players` (`id`, `name`, `group_id`, `account_id`, `level`, `vocation`, `health`, `healthmax`, `experience`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `maglevel`, `mana`, `manamax`, `manaspent`, `soul`, `town_id`, `posx`, `posy`, `posz`, `conditions`, `cap`, `sex`, `lastlogin`, `lastip`, `save`, `lastlogout`, `balance`, `$deleted`, `created`, `hidden`, `comment`) VALUES "; $insert_into_players = "INSERT INTO `players` (`id`, `name`, `group_id`, `account_id`, `level`, `vocation`, `health`, `healthmax`, `experience`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `maglevel`, `mana`, `manamax`, `manaspent`, `soul`, `town_id`, `posx`, `posy`, `posz`, `conditions`, `cap`, `sex`, `lastlogin`, `lastip`, `save`, `lastlogout`, `balance`, `$deleted`, `created`, `hidden`, `comment`) VALUES ";

View File

@ -60,4 +60,16 @@ function check_guild_name($name, &$errors = '') {
function news_place() { function news_place() {
return tickers(); return tickers();
} }
function tableExist($table)
{
global $db;
return $db->hasTable($table);
}
function fieldExist($field, $table)
{
global $db;
return $db->hasColumn($table, $field);
}
?> ?>

View File

@ -76,13 +76,17 @@ defined('MYAAC') or die('Direct access not allowed!');
if(isset($config['lua']['useMD5Passwords']) && getBoolean($config['lua']['useMD5Passwords'])) if(isset($config['lua']['useMD5Passwords']) && getBoolean($config['lua']['useMD5Passwords']))
$config['database_encryption'] = 'md5'; $config['database_encryption'] = 'md5';
if(!isset($config['database_log'])) {
$config['database_log'] = false;
}
try { try {
$ots->connect(POT::DB_MYSQL, $ots->connect(array(
array(
'host' => $config['database_host'], 'host' => $config['database_host'],
'user' => $config['database_user'], 'user' => $config['database_user'],
'password' => $config['database_password'], 'password' => $config['database_password'],
'database' => $config['database_name'] 'database' => $config['database_name'],
'log' => $config['database_log']
) )
); );
} }

View File

@ -69,7 +69,7 @@ function getPlayerLink($name, $generate = true)
if(is_numeric($name)) if(is_numeric($name))
{ {
$player = $ots->createObject('Player'); $player = new OTS_Player();
$player->load(intval($name)); $player->load(intval($name));
if($player->isLoaded()) if($player->isLoaded())
$name = $player->getName(); $name = $player->getName();
@ -302,22 +302,6 @@ function encrypt($str)
return $str; return $str;
} }
function tableExist($table)
{
global $db, $config;
$query = $db->query("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA` = " . $db->quote($config['database_name']) . " AND `TABLE_NAME` = " . $db->quote($table) . ";");
return $query->rowCount() > 0;
}
function fieldExist($field, $table)
{
global $db;
if(count($db->query("SHOW COLUMNS FROM `" . $table . "` LIKE '" . $field . "'")->fetchAll()))
return true;
return false;
}
//delete player with name //delete player with name
function delete_player($name) function delete_player($name)
{ {
@ -376,9 +360,9 @@ function delete_guild($id)
global $db, $ots; global $db, $ots;
foreach($rank_list as $rank_in_guild) { foreach($rank_list as $rank_in_guild) {
if(tableExist('guild_members')) if($db->hasTable('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`;'); $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 if(tableExist('guild_membership')) else if($db->hasTable('guild_membership'))
$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`;');
else else
$players_with_rank = $db->query('SELECT `id`, `rank_id` FROM `players` WHERE `rank_id` = ' . $rank_in_guild->getId() . ' AND `deleted` = 0;'); $players_with_rank = $db->query('SELECT `id`, `rank_id` FROM `players` WHERE `rank_id` = ' . $rank_in_guild->getId() . ' AND `deleted` = 0;');
@ -386,7 +370,7 @@ function delete_guild($id)
$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) {
foreach($players_with_rank as $result) { foreach($players_with_rank as $result) {
$player = $ots->createObject('Player'); $player = new OTS_Player();
$player->load($result['id']); $player->load($result['id']);
if(!$player->isLoaded()) if(!$player->isLoaded())
continue; continue;
@ -563,7 +547,7 @@ function getCreatureName($killer, $showStatus = false, $extendedInfo = false)
if(is_numeric($killer)) if(is_numeric($killer))
{ {
$player = $ots->createObject('Player'); $player = new OTS_Player();
$player->load($killer); $player->load($killer);
if($player->isLoaded()) if($player->isLoaded())
{ {
@ -971,10 +955,10 @@ function getTopPlayers($limit = 5) {
if($fetch_from_db) if($fetch_from_db)
{ {
$deleted = 'deleted'; $deleted = 'deleted';
if(fieldExist('deletion', 'players')) if($db->hasColumn('players', 'deletion'))
$deleted = 'deletion'; $deleted = 'deletion';
$is_tfs10 = tableExist('players_online'); $is_tfs10 = $db->hasTable('players_online');
$players = $db->query('SELECT `id`, `name`, `level`, `experience`' . ($is_tfs10 ? '' : ', `online`') . ' FROM `players` WHERE `group_id` < ' . $config['highscores_groups_hidden'] . ' AND `id` NOT IN (' . implode(', ', $config['highscores_ids_hidden']) . ') AND `' . $deleted . '` = 0 AND `account_id` != 1 ORDER BY `experience` DESC LIMIT ' . (int)$limit)->fetchAll(); $players = $db->query('SELECT `id`, `name`, `level`, `experience`' . ($is_tfs10 ? '' : ', `online`') . ' FROM `players` WHERE `group_id` < ' . $config['highscores_groups_hidden'] . ' AND `id` NOT IN (' . implode(', ', $config['highscores_ids_hidden']) . ') AND `' . $deleted . '` = 0 AND `account_id` != 1 ORDER BY `experience` DESC LIMIT ' . (int)$limit)->fetchAll();
if($is_tfs10) { if($is_tfs10) {

View File

@ -164,7 +164,7 @@ require_once(SYSTEM . 'libs/pot/OTS.php');
$ots = POT::getInstance(); $ots = POT::getInstance();
require_once(SYSTEM . 'database.php'); require_once(SYSTEM . 'database.php');
define('USE_ACCOUNT_NAME', fieldExist('name', 'accounts')); define('USE_ACCOUNT_NAME', $db->hasColumn('accounts', 'name'));
// load vocation names // load vocation names
$tmp = ''; $tmp = '';
if($cache->enabled() && $cache->fetch('vocations', $tmp)) { if($cache->enabled() && $cache->fetch('vocations', $tmp)) {

View File

@ -29,50 +29,6 @@
*/ */
class POT class POT
{ {
/**
* MySQL driver.
*/
const DB_MYSQL = 1;
/**
* SQLite driver.
*/
const DB_SQLITE = 2;
/**
* PostgreSQL driver.
*
* @version 0.0.4
* @since 0.0.4
*/
const DB_PGSQL = 3;
/**
* ODBC driver.
*
* @version 0.0.4
* @since 0.0.4
*/
const DB_ODBC = 4;
/**
* @deprecated 0.0.5 Vocations are now loaded dynamicly from vocations.xml file.
*/
const VOCATION_NONE = 0;
/**
* @deprecated 0.0.5 Vocations are now loaded dynamicly from vocations.xml file.
*/
const VOCATION_SORCERER = 1;
/**
* @deprecated 0.0.5 Vocations are now loaded dynamicly from vocations.xml file.
*/
const VOCATION_DRUID = 2;
/**
* @deprecated 0.0.5 Vocations are now loaded dynamicly from vocations.xml file.
*/
const VOCATION_PALADIN = 3;
/**
* @deprecated 0.0.5 Vocations are now loaded dynamicly from vocations.xml file.
*/
const VOCATION_KNIGHT = 4;
/** /**
* North. * North.
*/ */
@ -401,15 +357,13 @@ class POT
* </p> * </p>
* *
* @version 0.1.3 * @version 0.1.3
* @param int|null $driver Database driver type.
* @param array $params Connection info. * @param array $params Connection info.
* @throws E_OTS_Generic When driver is not supported or not supported.
* @throws LogicException When PDO extension is not loaded. * @throws LogicException When PDO extension is not loaded.
* @throws PDOException On PDO operation error. * @throws PDOException On PDO operation error.
* @example examples/quickstart.php quickstart.php * @example examples/quickstart.php quickstart.php
* @tutorial POT/Basics.pkg#basics.database * @tutorial POT/Basics.pkg#basics.database
*/ */
public function connect($driver, $params) public function connect($params)
{ {
// checks if PDO extension is loaded // checks if PDO extension is loaded
if( !extension_loaded('PDO') ) if( !extension_loaded('PDO') )
@ -417,47 +371,7 @@ class POT
throw new LogicException(); throw new LogicException();
} }
// $params['driver'] option instead of $driver
if( !isset($driver) )
{
if( isset($params['driver']) )
{
$driver = $params['driver'];
}
else
{
throw new E_OTS_Generic(E_OTS_Generic::CONNECT_NO_DRIVER);
}
}
unset($params['driver']);
// switch() structure provides us further flexibility
switch($driver)
{
// MySQL database
case self::DB_MYSQL:
$this->db = new OTS_DB_MySQL($params); $this->db = new OTS_DB_MySQL($params);
break;
// SQLite database
case self::DB_SQLITE:
$this->db = new OTS_DB_SQLite($params);
break;
// SQLite database
case self::DB_PGSQL:
$this->db = new OTS_DB_PostgreSQL($params);
break;
// SQLite database
case self::DB_ODBC:
$this->db = new OTS_DB_ODBC($params);
break;
// unsupported driver
default:
throw new E_OTS_Generic(E_OTS_Generic::CONNECT_INVALID_DRIVER);
}
$this->db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION); $this->db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);
// $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

View File

@ -41,6 +41,7 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
*/ */
private $data = array('email' => '', 'blocked' => false, 'rlname' => '','location' => '','web_flags' => 0, 'lastday' => 0, 'premdays' => 0, 'created' => 0); private $data = array('email' => '', 'blocked' => false, 'rlname' => '','location' => '','web_flags' => 0, 'lastday' => 0, 'premdays' => 0, 'created' => 0);
public static $cache = array();
/** /**
* Creates new account. * Creates new account.
* *
@ -167,10 +168,16 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
* @param int $id Account number. * @param int $id Account number.
* @throws PDOException On PDO operation error. * @throws PDOException On PDO operation error.
*/ */
public function load($id) public function load($id, $fresh = false)
{ {
if(!$fresh && isset(self::$cache[$id])) {
$this->data = self::$cache[$id];
return;
}
// SELECT query on database // SELECT query on database
$this->data = $this->db->query('SELECT `id`, ' . (fieldExist('name', 'accounts') ? '`name`,' : '') . '`password`, `email`, ' . $this->db->fieldName('blocked') . ', ' . $this->db->fieldName('rlname') . ', ' . $this->db->fieldName('location') . ', ' . $this->db->fieldName('web_flags') . ', ' . (fieldExist('premdays', 'accounts') ? $this->db->fieldName('premdays') . ',' : '') . (fieldExist('lastday', 'accounts') ? $this->db->fieldName('lastday') . ',' : (fieldExist('premend', 'accounts') ? $this->db->fieldName('premend') . ',' : '')) . $this->db->fieldName('created') . ' FROM ' . $this->db->tableName('accounts') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . (int) $id)->fetch(); $this->data = $this->db->query('SELECT `id`, ' . ($this->db->hasColumn('accounts', 'name') ? '`name`,' : '') . '`password`, `email`, `blocked`, `rlname`, `location`, `country`, `web_flags`, ' . ($this->db->hasColumn('accounts', 'premdays') ? '`premdays`, ' : '') . ($this->db->hasColumn('accounts', 'lastday') ? '`lastday`, ' : ($this->db->hasColumn('accounts', 'premend') ? '`premend`,' : '')) . '`created` FROM `accounts` WHERE `id` = ' . (int) $id)->fetch();
self::$cache[$id] = $this->data;
} }
/** /**
@ -188,7 +195,7 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
public function find($name) public function find($name)
{ {
// finds player's ID // finds player's ID
$id = $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('accounts') . ' WHERE ' . $this->db->fieldName('name') . ' = ' . $this->db->quote($name) )->fetch(); $id = $this->db->query('SELECT `id` FROM `accounts` WHERE `name` = ' . $this->db->quote($name) )->fetch();
// if anything was found // if anything was found
if( isset($id['id']) ) if( isset($id['id']) )
@ -208,7 +215,7 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
public function findByEMail($email) public function findByEMail($email)
{ {
// finds player's ID // finds player's ID
$id = $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('accounts') . ' WHERE ' . $this->db->fieldName('email') . ' = ' . $this->db->quote($email) )->fetch(); $id = $this->db->query('SELECT `id` FROM `accounts` WHERE `email` = ' . $this->db->quote($email) )->fetch();
// if anything was found // if anything was found
if( isset($id['id']) ) if( isset($id['id']) )
@ -250,7 +257,7 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
} }
$field = 'lastday'; $field = 'lastday';
if(fieldExist('premend', 'accounts')) { // othire if($this->db->hasColumn('accounts', 'premend')) { // othire
$field = 'premend'; $field = 'premend';
if(!isset($this->data['premend'])) { if(!isset($this->data['premend'])) {
$this->data['premend'] = 0; $this->data['premend'] = 0;
@ -258,7 +265,7 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
} }
// UPDATE query on database // UPDATE query on database
$this->db->query('UPDATE `accounts` SET ' . (fieldExist('name', 'accounts') ? '`name` = ' . $this->db->quote($this->data['name']) . ',' : '') . '`password` = ' . $this->db->quote($this->data['password']) . ', `email` = ' . $this->db->quote($this->data['email']) . ', `blocked` = ' . (int) $this->data['blocked'] . ', `rlname` = ' . $this->db->quote($this->data['rlname']) . ', `location` = ' . $this->db->quote($this->data['location']) . ', `web_flags` = ' . (int) $this->data['web_flags'] . ', ' . (fieldExist('premdays', 'accounts') ? '`premdays` = ' . (int) $this->data['premdays'] . ',' : '') . '`' . $field . '` = ' . (int) $this->data[$field] . ' WHERE `id` = ' . $this->data['id']); $this->db->query('UPDATE `accounts` SET ' . ($this->db->hasColumn('accounts', 'name') ? '`name` = ' . $this->db->quote($this->data['name']) . ',' : '') . '`password` = ' . $this->db->quote($this->data['password']) . ', `email` = ' . $this->db->quote($this->data['email']) . ', `blocked` = ' . (int) $this->data['blocked'] . ', `rlname` = ' . $this->db->quote($this->data['rlname']) . ', `location` = ' . $this->db->quote($this->data['location']) . ', `web_flags` = ' . (int) $this->data['web_flags'] . ', ' . ($this->db->hasColumn('accounts', 'premdays') ? '`premdays` = ' . (int) $this->data['premdays'] . ',' : '') . '`' . $field . '` = ' . (int) $this->data[$field] . ' WHERE `id` = ' . $this->data['id']);
} }
/** /**
@ -302,6 +309,16 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
return $this->data['location']; return $this->data['location'];
} }
public function getCountry()
{
if( !isset($this->data['country']) )
{
throw new E_OTS_NotLoaded();
}
return $this->data['country'];
}
public function getWebFlags() public function getWebFlags()
{ {
if( !isset($this->data['web_flags']) ) if( !isset($this->data['web_flags']) )
@ -375,34 +392,6 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
return $this->data['created']; return $this->data['created'];
} }
/**
* @version 0.1.0
* @since 0.0.4
* @return OTS_Group Group of which current account is member (currently random group).
* @throws E_OTS_NotLoaded If account is not loaded.
* @deprecated 0.0.6 There is no more group_id field in database.
*/
public function getGroup()
{
if( !isset($this->data['id']) )
{
throw new E_OTS_NotLoaded();
}
// loads default group
$groups = new OTS_Groups_List();
$groups->rewind();
return $groups->current();
}
/**
* @version 0.0.6
* @param OTS_Group $group Group to be a member.
* @deprecated 0.0.6 There is no more group_id field in database.
*/
public function setGroup(OTS_Group $group)
{
}
/** /**
* Name. * Name.
@ -772,13 +761,13 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
throw new E_OTS_NotLoaded(); throw new E_OTS_NotLoaded();
} }
if(tableExist('account_bans')) { if($this->db->hasTable('account_bans')) {
$ban = $this->db->query('SELECT `expires_at` FROM `account_bans` WHERE `account_id` = ' . $this->data['id'] . ' AND (`expires_at` > ' . time() .' OR `expires_at` = -1) ORDER BY `expires_at` DESC')->fetch(); $ban = $this->db->query('SELECT `expires_at` FROM `account_bans` WHERE `account_id` = ' . $this->data['id'] . ' AND (`expires_at` > ' . time() .' OR `expires_at` = -1) ORDER BY `expires_at` DESC')->fetch();
$this->data['banned'] = isset($ban['expires_at']); $this->data['banned'] = isset($ban['expires_at']);
$this->data['banned_time'] = $ban['expires_at']; $this->data['banned_time'] = $ban['expires_at'];
} }
else if(tableExist('bans')) { else if($this->db->hasTable('bans')) {
if(fieldExist('active', 'bans')) { if($this->db->hasColumn('bans', 'active')) {
$ban = $this->db->query('SELECT `active`, `expires` FROM `bans` WHERE (`type` = 3 OR `type` = 5) AND `active` = 1 AND `value` = ' . $this->data['id'] . ' AND (`expires` > ' . time() .' OR `expires` = -1) ORDER BY `expires` DESC')->fetch(); $ban = $this->db->query('SELECT `active`, `expires` FROM `bans` WHERE (`type` = 3 OR `type` = 5) AND `active` = 1 AND `value` = ' . $this->data['id'] . ' AND (`expires` > ' . time() .' OR `expires` = -1) ORDER BY `expires` DESC')->fetch();
$this->data['banned'] = $ban['active']; $this->data['banned'] = $ban['active'];
$this->data['banned_time'] = $ban['expires']; $this->data['banned_time'] = $ban['expires'];
@ -830,20 +819,28 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
public function getGroupId() public function getGroupId()
{ {
global $db;; if(isset($this->data['group_id'])) {
if(fieldExist('group_id', 'accounts')) { return $this->data['group_id'];
}
global $db;
if($db->hasColumn('accounts', 'group_id')) {
$query = $this->db->query('SELECT `group_id` FROM `accounts` WHERE `id` = ' . (int) $this->getId())->fetch(); $query = $this->db->query('SELECT `group_id` FROM `accounts` WHERE `id` = ' . (int) $this->getId())->fetch();
// if anything was found // if anything was found
if(isset($query['group_id'])) if(isset($query['group_id'])) {
$this->data['group_id'] = $query['group_id'];
return $query['group_id']; return $query['group_id'];
} }
}
$query = $this->db->query('SELECT `group_id` FROM `players` WHERE `account_id` = ' . (int) $this->getId() . ' ORDER BY `group_id` DESC LIMIT 1'); $query = $this->db->query('SELECT `group_id` FROM `players` WHERE `account_id` = ' . (int) $this->getId() . ' ORDER BY `group_id` DESC LIMIT 1');
if($query->rowCount() == 1) if($query->rowCount() == 1)
{ {
$query = $query->fetch(); $query = $query->fetch();
$this->data['group_id'] = $query['group_id'];
return $query['group_id']; return $query['group_id'];
} }
return 0; return 0;
} }

View File

@ -37,6 +37,9 @@ abstract class OTS_Base_DB extends PDO implements IOTS_DB
*/ */
private $queries = 0; private $queries = 0;
protected $logged = false;
private $log = '';
/** /**
* Query-quoted field name. * Query-quoted field name.
* *
@ -96,6 +99,10 @@ abstract class OTS_Base_DB extends PDO implements IOTS_DB
public function query($query) public function query($query)
{ {
if($this->logged) {
$this->log .= $query . PHP_EOL;
}
$this->queries++; $this->queries++;
//echo $query . PHP_EOL; //echo $query . PHP_EOL;
return parent::query($query); return parent::query($query);
@ -235,6 +242,10 @@ abstract class OTS_Base_DB extends PDO implements IOTS_DB
public function queries() { public function queries() {
return $this->queries; return $this->queries;
} }
public function getLog() {
return $this->log;
}
} }
/**#@-*/ /**#@-*/

View File

@ -24,6 +24,8 @@
*/ */
class OTS_DB_MySQL extends OTS_Base_DB class OTS_DB_MySQL extends OTS_Base_DB
{ {
private $has_table_cache = array();
private $has_column_cache = array();
/** /**
* Creates database connection. * Creates database connection.
* *
@ -92,9 +94,48 @@ class OTS_DB_MySQL extends OTS_Base_DB
$this->prefix = $params['prefix']; $this->prefix = $params['prefix'];
} }
if( isset($params['log']) )
{
$this->logged = true;
}
global $cache, $config;
if($cache->enabled()) {
$tmp = null;
$need_revalidation = true;
if($cache->fetch('database_checksum', $tmp) && $tmp) {
$tmp = unserialize($tmp);
if(sha1($config['database_host'] . '.' . $config['database_name']) == $tmp) {
$need_revalidation = false;
}
}
if(!$need_revalidation) {
$tmp = null;
if($cache->fetch('database_tables', $tmp) && $tmp) {
$this->has_table_cache = unserialize($tmp);
}
$tmp = null;
if($cache->fetch('database_columns', $tmp) && $tmp) {
$this->has_column_cache = unserialize($tmp);
}
}
}
parent::__construct('mysql:' . implode(';', $dns), $user, $password); parent::__construct('mysql:' . implode(';', $dns), $user, $password);
} }
public function __destruct()
{
global $cache, $config;
if($cache->enabled()) {
$cache->set('database_tables', serialize($this->has_table_cache));
$cache->set('database_columns', serialize($this->has_column_cache));
$cache->set('database_checksum', serialize(sha1($config['database_host'] . '.' . $config['database_name'])));
}
}
/** /**
* Query-quoted field name. * Query-quoted field name.
* *
@ -133,6 +174,23 @@ class OTS_DB_MySQL extends OTS_Base_DB
return $sql; return $sql;
} }
public function hasTable($name) {
if(isset($this->has_table_cache[$name])) {
return $this->has_table_cache[$name];
}
global $config;
return ($this->has_table_cache[$name] = $this->query("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA` = " . $this->quote($config['database_name']) . " AND `TABLE_NAME` = " . $this->quote($name) . " LIMIT 1;")->rowCount() > 0);
}
public function hasColumn($table, $column) {
if(isset($this->has_column_cache[$table . '.' . $column])) {
return $this->has_column_cache[$table . '.' . $column];
}
return ($this->has_column_cache[$table . '.' . $column] = count($this->query("SHOW COLUMNS FROM `" . $table . "` LIKE '" . $column . "'")->fetchAll()) > 0);
}
} }
/**#@-*/ /**#@-*/

View File

@ -490,7 +490,7 @@ class OTS_Group extends OTS_Row_DAO implements IteratorAggregate, Countable
// creates filter // creates filter
$filter = new OTS_SQLFilter(); $filter = new OTS_SQLFilter();
$filter->compareField('group_id', (int) $this->data['id']); $filter->compareField('group_id', (int) $this->data['id']);
if(fieldExist('deletion', 'players')) if($this->db->hasColumn('players', 'deletion'))
$filter->compareField('deletion', 0); $filter->compareField('deletion', 0);
else else
$filter->compareField('deleted', 0); $filter->compareField('deleted', 0);

View File

@ -31,9 +31,8 @@ class OTS_Groups_List implements IteratorAggregate, Countable
*/ */
public function __construct($file = '') public function __construct($file = '')
{ {
if(tableExist('groups')) { // read groups from database
global $db; global $db;
if($db->hasTable('groups')) { // read groups from database
foreach($db->query('SELECT `id`, `name`, `access` FROM `groups`;') as $group) foreach($db->query('SELECT `id`, `name`, `access` FROM `groups`;') as $group)
{ {
$info = array(); $info = array();

View File

@ -122,13 +122,13 @@ class OTS_Guild extends OTS_Row_DAO implements IteratorAggregate, Countable
public function load($id) public function load($id)
{ {
$ownerid = 'ownerid'; $ownerid = 'ownerid';
if(fieldExist('owner_id', 'guilds')) if($this->db->hasColumn('guilds', 'owner_id'))
$ownerid = 'owner_id'; $ownerid = 'owner_id';
$creationdata = 'creationdata'; $creationdata = 'creationdata';
if(fieldExist('creationdate', 'guilds')) if($this->db->hasColumn('guilds', 'creationdate'))
$creationdata = 'creationdate'; $creationdata = 'creationdate';
else if(fieldExist('creation_time', 'guilds')) else if($this->db->hasColumn('guilds', 'creation_time'))
$creationdata = 'creation_time'; $creationdata = 'creation_time';
// SELECT query on database // SELECT query on database
@ -177,13 +177,13 @@ class OTS_Guild extends OTS_Row_DAO implements IteratorAggregate, Countable
public function save() public function save()
{ {
$ownerid = 'ownerid'; $ownerid = 'ownerid';
if(fieldExist('owner_id', 'guilds')) if($this->db->hasColumn('guilds', 'owner_id'))
$ownerid = 'owner_id'; $ownerid = 'owner_id';
$creationdata = 'creationdata'; $creationdata = 'creationdata';
if(fieldExist('creationdate', 'guilds')) if($this->db->hasColumn('guilds', 'creationdate'))
$creationdata = 'creationdate'; $creationdata = 'creationdate';
else if(fieldExist('creation_time', 'guilds')) else if($this->db->hasColumn('guilds', 'creation_time'))
$creationdata = 'creation_time'; $creationdata = 'creation_time';
// updates existing guild // updates existing guild

View File

@ -344,7 +344,7 @@ class OTS_GuildRank extends OTS_Row_DAO implements IteratorAggregate, Countable
} }
// creates filter // creates filter
if(fieldExist('rank_id', 'players')) { if($this->db->hasColumn('players', 'rank_id')) {
$filter = new OTS_SQLFilter(); $filter = new OTS_SQLFilter();
$filter->compareField('rank_id', (int) $this->data['id']); $filter->compareField('rank_id', (int) $this->data['id']);
} }

View File

@ -129,14 +129,14 @@ class OTS_Player extends OTS_Row_DAO
* @param int $id Player's ID. * @param int $id Player's ID.
* @throws PDOException On PDO operation error. * @throws PDOException On PDO operation error.
*/ */
public function load($id) public function load($id, $fields = null, $load_skills = true)
{ {
global $__load; global $__load;
if(!isset($__load['loss_experience'])) if(!isset($__load['loss_experience']))
{ {
$loss = ''; $loss = '';
if(fieldExist('loss_experience', 'players')) { if($this->db->hasColumn('players', 'loss_experience')) {
$loss = ', `loss_experience`, `loss_mana`, `loss_skills`'; $loss = ', `loss_experience`, `loss_mana`, `loss_skills`';
} }
@ -146,7 +146,7 @@ class OTS_Player extends OTS_Row_DAO
if(!isset($__load['loss_items'])) if(!isset($__load['loss_items']))
{ {
$loss_items = ''; $loss_items = '';
if(fieldExist('loss_items', 'players')) { if($this->db->hasColumn('players', 'loss_items')) {
$loss_items = ', `loss_items`, `loss_containers`'; $loss_items = ', `loss_items`, `loss_containers`';
} }
@ -156,7 +156,7 @@ class OTS_Player extends OTS_Row_DAO
if(!isset($__load['guild_info'])) if(!isset($__load['guild_info']))
{ {
$guild_info = ''; $guild_info = '';
if(!tableExist('guild_members') && fieldExist('guildnick', 'players')) { if(!$this->db->hasTable('guild_members') && $this->db->hasColumn('players', 'guildnick')) {
$guild_info = ', `guildnick`, `rank_id`'; $guild_info = ', `guildnick`, `rank_id`';
} }
@ -166,7 +166,7 @@ class OTS_Player extends OTS_Row_DAO
if(!isset($__load['skull_type'])) if(!isset($__load['skull_type']))
{ {
$skull_type = 'skull'; $skull_type = 'skull';
if(fieldExist('skull_type', 'players')) { if($this->db->hasColumn('players', 'skull_type')) {
$skull_type = 'skull_type'; $skull_type = 'skull_type';
} }
@ -176,7 +176,7 @@ class OTS_Player extends OTS_Row_DAO
if(!isset($__load['skull_time'])) if(!isset($__load['skull_time']))
{ {
$skull_time = 'skulltime'; $skull_time = 'skulltime';
if(fieldExist('skull_time', 'players')) { if($this->db->hasColumn('players', 'skull_time')) {
$skull_time = 'skull_time'; $skull_time = 'skull_time';
} }
@ -184,31 +184,56 @@ class OTS_Player extends OTS_Row_DAO
} }
if(!isset($__load['blessings'])) { if(!isset($__load['blessings'])) {
$__load['blessings'] = fieldExist('blessings', 'players'); $__load['blessings'] = $this->db->hasColumn('players', 'blessings');
} }
if(!isset($__load['direction'])) { if(!isset($__load['direction'])) {
$__load['direction'] = fieldExist('direction', 'players'); $__load['direction'] = $this->db->hasColumn('players', 'direction');
} }
if(!isset($__load['stamina'])) { if(!isset($__load['stamina'])) {
$__load['stamina'] = fieldExist('stamina', 'players'); $__load['stamina'] = $this->db->hasColumn('players', 'stamina');
} }
if(!isset($__load['world_id'])) { if(!isset($__load['world_id'])) {
$__load['world_id'] = fieldExist('world_id', 'players'); $__load['world_id'] = $this->db->hasColumn('players', 'world_id');
} }
if(!isset($__load['online'])) { if(!isset($__load['online'])) {
$__load['online'] = fieldExist('online', 'players'); $__load['online'] = $this->db->hasColumn('players', 'online');
} }
if(!isset($__load['deletion'])) { if(!isset($__load['deletion'])) {
$__load['deletion'] = fieldExist('deletion', 'players'); $__load['deletion'] = $this->db->hasColumn('players', 'deletion');
} }
if(!isset($__load['promotion'])) { if(!isset($__load['promotion'])) {
$__load['promotion'] = fieldExist('promotion', 'players'); $__load['promotion'] = $this->db->hasColumn('players', 'promotion');
} }
if(!isset($__load['marriage'])) { if(!isset($__load['marriage'])) {
$__load['marriage'] = fieldExist('marriage', 'players'); $__load['marriage'] = $this->db->hasColumn('players', 'marriage');
} }
global $db;
if(isset($fields)) { // load only what we wish
if(in_array('promotion', $fields)) {
if(!$this->db->hasColumn('players', 'promotion')) {
unset($fields[array_search('promotion')]);
}
}
if(in_array('deleted', $fields)) {
if($this->db->hasColumn('players', 'deletion')) {
unset($fields[array_search('deleted')]);
$fields[] = 'deletion';
}
}
if(in_array('online', $fields)) {
if(!$this->db->hasColumn('players', 'online')) {
unset($fields[array_search('online')]);
}
}
$this->data = $this->db->query('SELECT ' . implode(', ', $fields) . ' FROM `players` WHERE `id` = ' . (int)$id)->fetch();
}
else {
// SELECT query on database // SELECT query on database
$this->data = $this->db->query('SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`' . (fieldExist('lookaddons', 'players') ? ', `lookaddons`' : '') . ', `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `save`, `conditions`, `' . $__load['skull_time'] . '` as `skulltime`, `' . $__load['skull_type'] . '` as `skull`' . $__load['guild_info'] . ', `town_id`' . $__load['loss_experience'] . $__load['loss_items'] . ', `balance`' . ($__load['blessings'] ? ', `blessings`' : '') . ($__load['direction'] ? ', `direction`' : '') . ($__load['stamina'] ? ', `stamina`' : '') . ($__load['world_id'] ? ', `world_id`' : '') . ($__load['online'] ? ', `online`' : '') . ', `' . ($__load['deletion'] ? 'deletion' : 'deleted') . '`' . ($__load['promotion'] ? ', `promotion`' : '') . ($__load['marriage'] ? ', `marriage`' : '') . ', `comment`, `created`, `hidden` FROM `players` WHERE `id` = ' . (int)$id)->fetch(); $this->data = $this->db->query('SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`' . ($this->db->hasColumn('players', 'lookaddons') ? ', `lookaddons`' : '') . ', `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `save`, `conditions`, `' . $__load['skull_time'] . '` as `skulltime`, `' . $__load['skull_type'] . '` as `skull`' . $__load['guild_info'] . ', `town_id`' . $__load['loss_experience'] . $__load['loss_items'] . ', `balance`' . ($__load['blessings'] ? ', `blessings`' : '') . ($__load['direction'] ? ', `direction`' : '') . ($__load['stamina'] ? ', `stamina`' : '') . ($__load['world_id'] ? ', `world_id`' : '') . ($__load['online'] ? ', `online`' : '') . ', `' . ($__load['deletion'] ? 'deletion' : 'deleted') . '`' . ($__load['promotion'] ? ', `promotion`' : '') . ($__load['marriage'] ? ', `marriage`' : '') . ', `comment`, `created`, `hidden` FROM `players` WHERE `id` = ' . (int)$id)->fetch();
}
if(!isset($this->data['guildnick']) || $this->data['guildnick']) if(!isset($this->data['guildnick']) || $this->data['guildnick'])
$this->data['guildnick'] = ''; $this->data['guildnick'] = '';
@ -222,9 +247,9 @@ class OTS_Player extends OTS_Row_DAO
$this->data['vocation'] += ($this->data['promotion'] * $config['vocations_amount']); $this->data['vocation'] += ($this->data['promotion'] * $config['vocations_amount']);
} }
// loads skills // loads skills
if( $this->isLoaded() ) if( $this->isLoaded() && $load_skills)
{ {
if(fieldExist('skill_fist', 'players')) { if($this->db->hasColumn('players', 'skill_fist')) {
$skill_ids = array( $skill_ids = array(
'skill_fist' => POT::SKILL_FIST, 'skill_fist' => POT::SKILL_FIST,
@ -252,7 +277,7 @@ class OTS_Player extends OTS_Row_DAO
$this->skills[$id] = array('value' => $skills[$name], 'tries' => $skills[$name . '_tries']); $this->skills[$id] = array('value' => $skills[$name], 'tries' => $skills[$name . '_tries']);
} }
} }
else if(tableExist('player_skills')) { else if($this->db->hasTable('player_skills')) {
foreach( $this->db->query('SELECT ' . $this->db->fieldName('skillid') . ', ' . $this->db->fieldName('value') . ', ' . $this->db->fieldName('count') . ' FROM ' . $this->db->tableName('player_skills') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'])->fetchAll() as $skill) foreach( $this->db->query('SELECT ' . $this->db->fieldName('skillid') . ', ' . $this->db->fieldName('value') . ', ' . $this->db->fieldName('count') . ' FROM ' . $this->db->tableName('player_skills') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'])->fetchAll() as $skill)
{ {
$this->skills[ $skill['skillid'] ] = array('value' => $skill['value'], 'tries' => $skill['count']); $this->skills[ $skill['skillid'] ] = array('value' => $skill['value'], 'tries' => $skill['count']);
@ -272,7 +297,7 @@ class OTS_Player extends OTS_Row_DAO
public function find($name) public function find($name)
{ {
// finds player's ID // finds player's ID
$id = $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('players') . ' WHERE ' . $this->db->fieldName('name') . ' = ' . $this->db->quote($name) )->fetch(); $id = $this->db->query('SELECT `id` FROM `players` WHERE `name` = ' . $this->db->quote($name) )->fetch();
// if anything was found // if anything was found
if( isset($id['id']) ) if( isset($id['id']) )
@ -304,12 +329,12 @@ class OTS_Player extends OTS_Row_DAO
public function save() public function save()
{ {
$skull_type = 'skull'; $skull_type = 'skull';
if(fieldExist('skull_type', 'players')) { if($this->db->hasColumn('players', 'skull_type')) {
$skull_type = 'skull_type'; $skull_type = 'skull_type';
} }
$skull_time = 'skulltime'; $skull_time = 'skulltime';
if(fieldExist('skull_time', 'players')) { if($this->db->hasColumn('players', 'skull_time')) {
$skull_time = 'skull_time'; $skull_time = 'skull_time';
} }
@ -350,37 +375,37 @@ class OTS_Player extends OTS_Row_DAO
if( isset($this->data['id']) ) if( isset($this->data['id']) )
{ {
$loss = ''; $loss = '';
if(fieldExist('loss_experience', 'players')) { if($this->db->hasColumn('players', 'loss_experience')) {
$loss = ', `loss_experience` = ' . $this->data['loss_experience'] . ', `loss_mana` = ' . $this->data['loss_mana'] . ', `loss_skills` = ' . $this->data['loss_skills']; $loss = ', `loss_experience` = ' . $this->data['loss_experience'] . ', `loss_mana` = ' . $this->data['loss_mana'] . ', `loss_skills` = ' . $this->data['loss_skills'];
} }
$loss_items = ''; $loss_items = '';
if(fieldExist('loss_items', 'players')) { if($this->db->hasColumn('players', 'loss_items')) {
$loss_items = ', `loss_items` = ' . $this->data['loss_items'] . ', `loss_containers` = ' . $this->data['loss_containers']; $loss_items = ', `loss_items` = ' . $this->data['loss_items'] . ', `loss_containers` = ' . $this->data['loss_containers'];
} }
$guild_info = ''; $guild_info = '';
if(!tableExist('guild_members') && fieldExist('guildnick', 'players')) { if(!$this->db->hasTable('guild_members') && $this->db->hasColumn('players', 'guildnick')) {
$guild_info = ', `guildnick` = ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->db->fieldName('rank_id') . ' = ' . $this->data['rank_id']; $guild_info = ', `guildnick` = ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->db->fieldName('rank_id') . ' = ' . $this->data['rank_id'];
} }
$direction = ''; $direction = '';
if(fieldExist('direction', 'players')) { if($this->db->hasColumn('players', 'direction')) {
$direction = ', `direction` = ' . $this->db->quote($this->data['direction']); $direction = ', `direction` = ' . $this->db->quote($this->data['direction']);
} }
$blessings = ''; $blessings = '';
if(fieldExist('blessings', 'players')) { if($this->db->hasColumn('players', 'blessings')) {
$blessings = ', `blessings` = ' . $this->db->quote($this->data['blessings']); $blessings = ', `blessings` = ' . $this->db->quote($this->data['blessings']);
} }
$stamina = ''; $stamina = '';
if(fieldExist('stamina', 'players')) { if($this->db->hasColumn('players', 'stamina')) {
$stamina = ', `stamina` = ' . $this->db->quote($this->data['stamina']); $stamina = ', `stamina` = ' . $this->db->quote($this->data['stamina']);
} }
$lookaddons = ''; $lookaddons = '';
if(fieldExist('lookaddons', 'players')) { if($this->db->hasColumn('players', 'lookaddons')) {
$lookaddons = ', `lookaddons` = ' . $this->db->quote($this->data['lookaddons']); $lookaddons = ', `lookaddons` = ' . $this->db->quote($this->data['lookaddons']);
} }
@ -392,56 +417,56 @@ class OTS_Player extends OTS_Row_DAO
{ {
$loss = ''; $loss = '';
$loss_data = ''; $loss_data = '';
if(fieldExist('loss_experience', 'players')) { if($this->db->hasColumn('players', 'loss_experience')) {
$loss = ', `loss_experience`, `loss_mana`, `loss_skills`'; $loss = ', `loss_experience`, `loss_mana`, `loss_skills`';
$loss_data = ', ' . $this->data['loss_experience'] . ', ' . $this->data['loss_mana'] . ', ' . $this->data['loss_skills']; $loss_data = ', ' . $this->data['loss_experience'] . ', ' . $this->data['loss_mana'] . ', ' . $this->data['loss_skills'];
} }
$loss_items = ''; $loss_items = '';
$loss_items_data = ''; $loss_items_data = '';
if(fieldExist('loss_items', 'players')) { if($this->db->hasColumn('players', 'loss_items')) {
$loss_items = ', `loss_items`, `loss_containers`'; $loss_items = ', `loss_items`, `loss_containers`';
$loss_items_data = ', ' . $this->data['loss_items'] . ', ' . $this->data['loss_containers']; $loss_items_data = ', ' . $this->data['loss_items'] . ', ' . $this->data['loss_containers'];
} }
$guild_info = ''; $guild_info = '';
$guild_info_data = ''; $guild_info_data = '';
if(!tableExist('guild_members') && fieldExist('guildnick', 'players')) { if(!$this->db->hasTable('guild_members') && $this->db->hasColumn('players', 'guildnick')) {
$guild_info = ', `guildnick`, `rank_id`'; $guild_info = ', `guildnick`, `rank_id`';
$guild_info_data = ', ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->data['rank_id']; $guild_info_data = ', ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->data['rank_id'];
} }
$promotion = ''; $promotion = '';
$promotion_data = ''; $promotion_data = '';
if(fieldExist('promotion', 'players')) { if($this->db->hasColumn('players', 'promotion')) {
$promotion = ', `promotion`'; $promotion = ', `promotion`';
$promotion_data = ', ' . $this->data['promotion']; $promotion_data = ', ' . $this->data['promotion'];
} }
$direction = ''; $direction = '';
$direction_data = ''; $direction_data = '';
if(fieldExist('direction', 'players')) { if($this->db->hasColumn('players', 'direction')) {
$direction = ', `direction`'; $direction = ', `direction`';
$direction_data = ', ' . $this->data['direction']; $direction_data = ', ' . $this->data['direction'];
} }
$blessings = ''; $blessings = '';
$blessings_data = ''; $blessings_data = '';
if(fieldExist('blessings', 'players')) { if($this->db->hasColumn('players', 'blessings')) {
$blessings = ', `blessings`'; $blessings = ', `blessings`';
$blessings_data = ', ' . $this->data['blessings']; $blessings_data = ', ' . $this->data['blessings'];
} }
$stamina = ''; $stamina = '';
$stamina_data = ''; $stamina_data = '';
if(fieldExist('stamina', 'players')) { if($this->db->hasColumn('players', 'stamina')) {
$stamina = ', `stamina`'; $stamina = ', `stamina`';
$stamina_data = ', ' . $this->data['stamina']; $stamina_data = ', ' . $this->data['stamina'];
} }
$lookaddons = ''; $lookaddons = '';
$lookaddons_data = ''; $lookaddons_data = '';
if(fieldExist('lookaddons', 'players')) { if($this->db->hasColumn('players', 'lookaddons')) {
$lookaddons = ', `lookaddons`'; $lookaddons = ', `lookaddons`';
$lookaddons_data = ', ' . $this->data['lookaddons']; $lookaddons_data = ', ' . $this->data['lookaddons'];
} }
@ -453,7 +478,7 @@ class OTS_Player extends OTS_Row_DAO
} }
// updates skills - doesn't matter if we have just created character - trigger inserts new skills // updates skills - doesn't matter if we have just created character - trigger inserts new skills
if(fieldExist('skill_fist', 'players')) { // tfs 1.0 if($this->db->hasColumn('players', 'skill_fist')) { // tfs 1.0
$set = ''; $set = '';
$skill_ids = array( $skill_ids = array(
@ -477,7 +502,7 @@ class OTS_Player extends OTS_Row_DAO
$skills = $this->db->query('UPDATE `players` SET ' . $set . ' WHERE `id` = ' . $this->data['id']); $skills = $this->db->query('UPDATE `players` SET ' . $set . ' WHERE `id` = ' . $this->data['id']);
} }
else if(tableExist('player_skills')) { else if($this->db->hasTable('player_skills')) {
foreach($this->skills as $id => $skill) foreach($this->skills as $id => $skill)
{ {
$this->db->query('UPDATE ' . $this->db->tableName('player_skills') . ' SET ' . $this->db->fieldName('value') . ' = ' . $skill['value'] . ', ' . $this->db->fieldName('count') . ' = ' . $skill['tries'] . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('skillid') . ' = ' . $id); $this->db->query('UPDATE ' . $this->db->tableName('player_skills') . ' SET ' . $this->db->fieldName('value') . ' = ' . $skill['value'] . ', ' . $this->db->fieldName('count') . ' = ' . $skill['tries'] . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('skillid') . ' = ' . $id);
@ -513,7 +538,7 @@ class OTS_Player extends OTS_Row_DAO
throw new E_OTS_NotLoaded(); throw new E_OTS_NotLoaded();
} }
return $this->data['hidden']; return $this->data['hidden'] == 1;
} }
public function setHidden($hidden) public function setHidden($hidden)
@ -523,7 +548,7 @@ class OTS_Player extends OTS_Row_DAO
public function getMarriage() public function getMarriage()
{ {
if(!fieldExist('marriage', 'players')) if(!$this->db->hasColumn('players', 'marriage'))
return ''; return '';
if( !isset($this->data['marriage']) ) if( !isset($this->data['marriage']) )
@ -725,7 +750,7 @@ class OTS_Player extends OTS_Row_DAO
public function isDeleted() public function isDeleted()
{ {
$field = 'deleted'; $field = 'deleted';
if(fieldExist('deletion', 'players')) if($this->db->hasColumn('players', 'deletion'))
$field = 'deletion'; $field = 'deletion';
if( !isset($this->data[$field]) ) if( !isset($this->data[$field]) )
@ -743,7 +768,7 @@ class OTS_Player extends OTS_Row_DAO
public function isOnline() public function isOnline()
{ {
if(tableExist('players_online')) // tfs 1.0 if($this->db->hasTable('players_online')) // tfs 1.0
{ {
$query = $this->db->query('SELECT `player_id` FROM `players_online` WHERE `player_id` = ' . $this->data['id']); $query = $this->db->query('SELECT `player_id` FROM `players_online` WHERE `player_id` = ' . $this->data['id']);
return $query->rowCount() > 0; return $query->rowCount() > 0;
@ -1833,7 +1858,7 @@ class OTS_Player extends OTS_Row_DAO
public function loadRank() public function loadRank()
{ {
$table = 'guild_membership'; $table = 'guild_membership';
if(tableExist('guild_members')) if($this->db->hasTable('guild_members'))
$table = 'guild_members'; $table = 'guild_members';
$ranks = $this->db->query('SELECT `rank_id`, `nick` FROM `' . $table . '` WHERE `player_id` = ' . $this->db->quote($this->getID()))->fetch(); $ranks = $this->db->query('SELECT `rank_id`, `nick` FROM `' . $table . '` WHERE `player_id` = ' . $this->db->quote($this->getID()))->fetch();
@ -1869,11 +1894,11 @@ class OTS_Player extends OTS_Row_DAO
public function setGuildNick($guildnick) public function setGuildNick($guildnick)
{ {
$this->data['guildnick'] = (string) $guildnick; $this->data['guildnick'] = (string) $guildnick;
if(tableExist('guild_members')) if($this->db->hasTable('guild_members'))
$this->db->query('UPDATE `guild_members` SET `nick` = ' . $this->db->quote($this->data['guildnick']) . ' WHERE `player_id` = ' . $this->getId()); $this->db->query('UPDATE `guild_members` SET `nick` = ' . $this->db->quote($this->data['guildnick']) . ' WHERE `player_id` = ' . $this->getId());
else if(tableExist('guild_membership')) else if($this->db->hasTable('guild_membership'))
$this->db->query('UPDATE `guild_membership` SET `nick` = ' . $this->db->quote($this->data['guildnick']) . ' WHERE `player_id` = ' . $this->getId()); $this->db->query('UPDATE `guild_membership` SET `nick` = ' . $this->db->quote($this->data['guildnick']) . ' WHERE `player_id` = ' . $this->getId());
else if(fieldExist('guildnick', 'players')) else if($this->db->hasColumn('players', 'guildnick'))
$this->db->query('UPDATE `players` SET `guildnick` = ' . $this->db->quote($this->data['guildnick']) . ' WHERE `id` = ' . $this->getId()); $this->db->query('UPDATE `players` SET `guildnick` = ' . $this->db->quote($this->data['guildnick']) . ' WHERE `id` = ' . $this->getId());
} }
@ -1908,21 +1933,21 @@ class OTS_Player extends OTS_Row_DAO
public function getRank() public function getRank()
{ {
$rank_id = 0; $rank_id = 0;
if(tableExist('guild_members')) { if($this->db->hasTable('guild_members')) {
$query = $this->db->query('SELECT `rank_id` FROM `guild_members` WHERE `player_id`= ' . $this->data['id'] . ' LIMIT 1;'); $query = $this->db->query('SELECT `rank_id` FROM `guild_members` WHERE `player_id`= ' . $this->data['id'] . ' LIMIT 1;');
if($query->rowCount() == 1) { if($query->rowCount() == 1) {
$query = $query->fetch(); $query = $query->fetch();
$rank_id = $query['rank_id']; $rank_id = $query['rank_id'];
} }
} }
else if(tableExist('guild_membership')) { else if($this->db->hasTable('guild_membership')) {
$query = $this->db->query('SELECT `rank_id` FROM `guild_membership` WHERE `player_id`= ' . $this->data['id'] . ' LIMIT 1;'); $query = $this->db->query('SELECT `rank_id` FROM `guild_membership` WHERE `player_id`= ' . $this->data['id'] . ' LIMIT 1;');
if($query->rowCount() == 1) { if($query->rowCount() == 1) {
$query = $query->fetch(); $query = $query->fetch();
$rank_id = $query['rank_id']; $rank_id = $query['rank_id'];
} }
} }
else if(fieldExist('rank_id', 'players')) { else if($this->db->hasColumn('players', 'rank_id')) {
$query = $this->db->query('SELECT `rank_id` FROM `players` WHERE `id`= ' . $this->data['id'] . ';')->fetch(); $query = $this->db->query('SELECT `rank_id` FROM `players` WHERE `id`= ' . $this->data['id'] . ';')->fetch();
$rank_id = $query['rank_id']; $rank_id = $query['rank_id'];
} }
@ -1944,10 +1969,10 @@ class OTS_Player extends OTS_Row_DAO
{ {
if( isset($rank_id) && isset($guild)) { if( isset($rank_id) && isset($guild)) {
if($rank_id == 0) { if($rank_id == 0) {
if(tableExist('guild_membership')) { if($this->db->hasTable('guild_membership')) {
$this->db->query('DELETE FROM `guild_membership` WHERE `player_id` = ' . $this->getId()); $this->db->query('DELETE FROM `guild_membership` WHERE `player_id` = ' . $this->getId());
} }
else if(tableExist('guild_members')) { else if($this->db->hasTable('guild_members')) {
$this->db->query('DELETE FROM `guild_members` WHERE `player_id` = ' . $this->getId()); $this->db->query('DELETE FROM `guild_members` WHERE `player_id` = ' . $this->getId());
} }
else { else {
@ -1956,7 +1981,7 @@ class OTS_Player extends OTS_Row_DAO
} }
} }
else { else {
if(tableExist('guild_membership')) { if($this->db->hasTable('guild_membership')) {
$query = $this->db->query('SELECT `player_id` FROM `guild_membership` WHERE `player_id` = ' . $this->getId() . ' LIMIT 1;'); $query = $this->db->query('SELECT `player_id` FROM `guild_membership` WHERE `player_id` = ' . $this->getId() . ' LIMIT 1;');
if($query->rowCount() == 1) if($query->rowCount() == 1)
$this->db->query('UPDATE `guild_membership` SET `guild_id` = ' . (int)$guild . ', `rank_id` = ' . (int)$rank_id . ' WHERE `player_id` = ' . $this->getId()); $this->db->query('UPDATE `guild_membership` SET `guild_id` = ' . (int)$guild . ', `rank_id` = ' . (int)$rank_id . ' WHERE `player_id` = ' . $this->getId());
@ -1964,7 +1989,7 @@ class OTS_Player extends OTS_Row_DAO
$this->db->query('INSERT INTO `guild_membership` (`player_id`, `guild_id`, `rank_id`, `nick`) VALUES (' . $this->db->quote($this->getId()) . ', ' . $this->db->quote($guild) . ', ' . $this->db->quote($rank_id) . ', ' . $this->db->quote('') . ')'); $this->db->query('INSERT INTO `guild_membership` (`player_id`, `guild_id`, `rank_id`, `nick`) VALUES (' . $this->db->quote($this->getId()) . ', ' . $this->db->quote($guild) . ', ' . $this->db->quote($rank_id) . ', ' . $this->db->quote('') . ')');
} }
} }
else if(tableExist('guild_members')) { else if($this->db->hasTable('guild_members')) {
$query = $this->db->query('SELECT `player_id` FROM `guild_members` WHERE `player_id` = ' . $this->getId() . ' LIMIT 1;'); $query = $this->db->query('SELECT `player_id` FROM `guild_members` WHERE `player_id` = ' . $this->getId() . ' LIMIT 1;');
if($query->rowCount() == 1) if($query->rowCount() == 1)
$this->db->query('UPDATE `guild_members` SET `rank_id` = ' . (int)$rank_id . ' WHERE `player_id` = ' . $this->getId()); $this->db->query('UPDATE `guild_members` SET `rank_id` = ' . (int)$rank_id . ' WHERE `player_id` = ' . $this->getId());

View File

@ -296,7 +296,7 @@ class Validator
} }
//check if was namelocked previously //check if was namelocked previously
if(tableExist('player_namelocks') && fieldExist('name', 'player_namelocks')) { if($db->hasTable('player_namelocks') && $db->hasColumn('player_namelocks', 'name')) {
$namelock = $db->query('SELECT `player_id` FROM `player_namelocks` WHERE `name` = ' . $db->quote($name)); $namelock = $db->query('SELECT `player_id` FROM `player_namelocks` WHERE `name` = ' . $db->quote($name));
if($namelock->rowCount() > 0) { if($namelock->rowCount() > 0) {
self::$lastError = 'Character with this name has been namelocked.'; self::$lastError = 'Character with this name has been namelocked.';

View File

@ -58,13 +58,13 @@ else
$t = isset($tmp[$ip]) ? $tmp[$ip] : NULL; $t = isset($tmp[$ip]) ? $tmp[$ip] : NULL;
} }
$account_logged = $ots->createObject('Account'); $account_logged = new OTS_Account();
if(USE_ACCOUNT_NAME) if(USE_ACCOUNT_NAME)
$account_logged->find($login_account); $account_logged->find($login_account);
else else
$account_logged->load($login_account); $account_logged->load($login_account);
$config_salt_enabled = fieldExist('salt', 'accounts'); $config_salt_enabled = $db->hasColumn('accounts', 'salt');
if($account_logged->isLoaded() && encrypt(($config_salt_enabled ? $account_logged->getCustomField('salt') : '') . $login_password) == $account_logged->getPassword() if($account_logged->isLoaded() && encrypt(($config_salt_enabled ? $account_logged->getCustomField('salt') : '') . $login_password) == $account_logged->getPassword()
&& (!isset($t) || $t['attempts'] < 5) && (!isset($t) || $t['attempts'] < 5)
) )

View File

@ -1,8 +1,8 @@
<?php <?php
if(!fieldExist('ordering', TABLE_PREFIX . 'hooks')) if(!$db->hasColumn(TABLE_PREFIX . 'hooks', 'ordering'))
$db->query("ALTER TABLE `" . TABLE_PREFIX . "hooks` ADD `ordering` INT(11) NOT NULL DEFAULT 0 AFTER `file`;"); $db->query("ALTER TABLE `" . TABLE_PREFIX . "hooks` ADD `ordering` INT(11) NOT NULL DEFAULT 0 AFTER `file`;");
if(!tableExist(TABLE_PREFIX . 'admin_menu')) if(!$db->hasTable(TABLE_PREFIX . 'admin_menu'))
$db->query(" $db->query("
CREATE TABLE `myaac_admin_menu` CREATE TABLE `myaac_admin_menu`
( (

View File

@ -1,7 +1,7 @@
<?php <?php
// add new item_id field for runes // add new item_id field for runes
if(!fieldExist('item_id', TABLE_PREFIX . 'spells')) if(!$db->hasColumn(TABLE_PREFIX . 'spells', 'item_id'))
$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` ADD `item_id` INT(11) NOT NULL DEFAULT 0 AFTER `conjure_count`;"); $db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` ADD `item_id` INT(11) NOT NULL DEFAULT 0 AFTER `conjure_count`;");
// change unique index from spell to name // change unique index from spell to name
@ -12,7 +12,7 @@ $db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` ADD UNIQUE INDEX (`name`);"
$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` MODIFY `type` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '1 - instant, 2 - conjure, 3 - rune';"); $db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` MODIFY `type` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '1 - instant, 2 - conjure, 3 - rune';");
// new items table // new items table
if(!tableExist(TABLE_PREFIX . 'items')) if(!$db->hasTable(TABLE_PREFIX . 'items'))
$db->query(" $db->query("
CREATE TABLE `" . TABLE_PREFIX . "items` CREATE TABLE `" . TABLE_PREFIX . "items`
( (
@ -25,7 +25,7 @@ CREATE TABLE `" . TABLE_PREFIX . "items`
) ENGINE = MyISAM;"); ) ENGINE = MyISAM;");
// new weapons table // new weapons table
if(!tableExist(TABLE_PREFIX . 'weapons')) if(!$db->hasTable(TABLE_PREFIX . 'weapons'))
$db->query(" $db->query("
CREATE TABLE `" . TABLE_PREFIX . "weapons` CREATE TABLE `" . TABLE_PREFIX . "weapons`
( (

View File

@ -1,4 +1,4 @@
<?php <?php
if(fieldExist('spell', TABLE_PREFIX . 'spells')) if($db->hasColumn(TABLE_PREFIX . 'spells', 'spell'))
$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` DROP COLUMN `spell`;"); $db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` DROP COLUMN `spell`;");
?> ?>

View File

@ -1,7 +1,7 @@
<?php <?php
// change monsters.file_path field to loot // change monsters.file_path field to loot
if(fieldExist('file_path', TABLE_PREFIX . 'monsters')) { if($db->hasColumn(TABLE_PREFIX . 'monsters', 'file_path')) {
$db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` CHANGE `file_path` `loot` VARCHAR(5000);"); $db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` CHANGE `file_path` `loot` VARCHAR(5000);");
} }
@ -12,7 +12,7 @@ $db->query("UPDATE `" . TABLE_PREFIX . "monsters` SET `loot` = '';");
$db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `gfx_name`;"); $db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `gfx_name`;");
// rename hide_creature to hidden // rename hide_creature to hidden
if(fieldExist('hide_creature', TABLE_PREFIX . 'monsters')) { if($db->hasColumn(TABLE_PREFIX . 'monsters', 'hide_creature')) {
$db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` CHANGE `hide_creature` `hidden` TINYINT(1) NOT NULL DEFAULT 0;"); $db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` CHANGE `hide_creature` `hidden` TINYINT(1) NOT NULL DEFAULT 0;");
} }
?> ?>

View File

@ -1,11 +1,11 @@
<?php <?php
// add new forum.guild and forum.access fields // add new forum.guild and forum.access fields
if(!fieldExist('guild', TABLE_PREFIX . 'forum_boards')) { if(!$db->hasColumn(TABLE_PREFIX . 'forum_boards', 'guild')) {
$db->query("ALTER TABLE `" . TABLE_PREFIX . "forum_boards` ADD `guild` TINYINT(1) NOT NULL DEFAULT 0 AFTER `closed`;"); $db->query("ALTER TABLE `" . TABLE_PREFIX . "forum_boards` ADD `guild` TINYINT(1) NOT NULL DEFAULT 0 AFTER `closed`;");
} }
if(!fieldExist('access', TABLE_PREFIX . 'forum_boards')) { if(!$db->hasColumn(TABLE_PREFIX . 'forum_boards', 'access')) {
$db->query("ALTER TABLE `" . TABLE_PREFIX . "forum_boards` ADD `access` TINYINT(1) NOT NULL DEFAULT 0 AFTER `guild`;"); $db->query("ALTER TABLE `" . TABLE_PREFIX . "forum_boards` ADD `access` TINYINT(1) NOT NULL DEFAULT 0 AFTER `guild`;");
} }
?> ?>

View File

@ -1,6 +1,6 @@
<?php <?php
if(!tableExist('myaac_menu')) { if(!$db->hasTable('myaac_menu')) {
$db->query(" $db->query("
CREATE TABLE `myaac_menu` CREATE TABLE `myaac_menu`
( (

View File

@ -1,4 +1,4 @@
<?php <?php
if(!fieldExist('id', TABLE_PREFIX . 'monsters')) if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'id'))
$db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `id` int(11) NOT NULL AUTO_INCREMENT primary key FIRST;"); $db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `id` int(11) NOT NULL AUTO_INCREMENT primary key FIRST;");
?> ?>

View File

@ -1,4 +1,4 @@
<?php <?php
if(fieldExist('cities', TABLE_PREFIX . 'spells')) if($db->hasColumn(TABLE_PREFIX . 'spells', 'cities'))
$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` DROP COLUMN cities;"); $db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` DROP COLUMN cities;");
?> ?>

View File

@ -1,4 +1,4 @@
<?php <?php
if(!fieldExist('enabled', TABLE_PREFIX . 'hooks')) if(!$db->hasColumn(TABLE_PREFIX . 'hooks', 'enabled'))
$db->query("ALTER TABLE `" . TABLE_PREFIX . "hooks` ADD `enabled` INT(1) NOT NULL DEFAULT 1;"); $db->query("ALTER TABLE `" . TABLE_PREFIX . "hooks` ADD `enabled` INT(1) NOT NULL DEFAULT 1;");
?> ?>

View File

@ -1,4 +1,4 @@
<?php <?php
if(fieldExist('name', TABLE_PREFIX . 'screenshots')) if($db->hasColumn(TABLE_PREFIX . 'screenshots', 'name'))
$db->query("ALTER TABLE `" . TABLE_PREFIX . "screenshots` DROP `name`;"); $db->query("ALTER TABLE `" . TABLE_PREFIX . "screenshots` DROP `name`;");
?> ?>

View File

@ -1,5 +1,5 @@
<?php <?php
if(tableExist(TABLE_PREFIX . 'forum_sections')) if($db->hasTable(TABLE_PREFIX . 'forum_sections'))
$db->query('RENAME TABLE `' . TABLE_PREFIX . 'forum_sections` TO `' . TABLE_PREFIX . 'forum_boards`;'); $db->query('RENAME TABLE `' . TABLE_PREFIX . 'forum_sections` TO `' . TABLE_PREFIX . 'forum_boards`;');
$query = $db->query('SELECT `id` FROM `' . TABLE_PREFIX . 'forum_boards` WHERE `ordering` > 0;'); $query = $db->query('SELECT `id` FROM `' . TABLE_PREFIX . 'forum_boards` WHERE `ordering` > 0;');

View File

@ -94,17 +94,18 @@ if($save) {
{ {
if($newchar_sex == "0") if($newchar_sex == "0")
$char_to_copy->setLookType(136); $char_to_copy->setLookType(136);
$player = $ots->createObject('Player');
$player = new OTS_Player();
$player->setName($newchar_name); $player->setName($newchar_name);
$player->setAccount($account_logged); $player->setAccount($account_logged);
//$player->setGroupId($char_to_copy->getGroup()->getId()); //$player->setGroupId($char_to_copy->getGroup()->getId());
$player->setGroupId(1); $player->setGroupId(1);
$player->setSex($newchar_sex); $player->setSex($newchar_sex);
$player->setVocation($char_to_copy->getVocation()); $player->setVocation($char_to_copy->getVocation());
if(fieldExist('promotion', 'players')) if($db->hasColumn('players', 'promotion'))
$player->setPromotion($char_to_copy->getPromotion()); $player->setPromotion($char_to_copy->getPromotion());
if(fieldExist('direction', 'players')) if($db->hasColumn('players', 'direction'))
$player->setDirection($char_to_copy->getDirection()); $player->setDirection($char_to_copy->getDirection());
$player->setConditions($char_to_copy->getConditions()); $player->setConditions($char_to_copy->getConditions());
@ -113,7 +114,7 @@ if($save) {
$player->setRank($char_to_copy->getRank()); $player->setRank($char_to_copy->getRank());
} }
if(fieldExist('lookaddons', 'players')) if($db->hasColumn('players', 'lookaddons'))
$player->setLookAddons($char_to_copy->getLookAddons()); $player->setLookAddons($char_to_copy->getLookAddons());
$player->setTownId($newchar_town); $player->setTownId($newchar_town);
@ -141,12 +142,12 @@ if($save) {
$player->setPosY(0); $player->setPosY(0);
$player->setPosZ(0); $player->setPosZ(0);
$player->setStamina($config['otserv_version'] == TFS_03 ? 151200000 : 2520); $player->setStamina($config['otserv_version'] == TFS_03 ? 151200000 : 2520);
if(fieldExist('loss_experience', 'players')) { if($db->hasColumn('players', 'loss_experience')) {
$player->setLossExperience($char_to_copy->getLossExperience()); $player->setLossExperience($char_to_copy->getLossExperience());
$player->setLossMana($char_to_copy->getLossMana()); $player->setLossMana($char_to_copy->getLossMana());
$player->setLossSkills($char_to_copy->getLossSkills()); $player->setLossSkills($char_to_copy->getLossSkills());
} }
if(fieldExist('loss_items', 'players')) { if($db->hasColumn('players', 'loss_items')) {
$player->setLossItems($char_to_copy->getLossItems()); $player->setLossItems($char_to_copy->getLossItems());
$player->setLossContainers($char_to_copy->getLossContainers()); $player->setLossContainers($char_to_copy->getLossContainers());
} }
@ -162,7 +163,7 @@ if($save) {
$player->find($newchar_name); $player->find($newchar_name);
if($player->isLoaded()) { if($player->isLoaded()) {
if(tableExist('player_skills')) { if($db->hasTable('player_skills')) {
for($i=0; $i<7; $i++) { for($i=0; $i<7; $i++) {
$skillExists = $db->query('SELECT `skillid` FROM `player_skills` WHERE `player_id` = ' . $player->getId() . ' AND `skillid` = ' . $i); $skillExists = $db->query('SELECT `skillid` FROM `player_skills` WHERE `player_id` = ' . $player->getId() . ' AND `skillid` = ' . $i);
if($skillExists->rowCount() <= 0) { if($skillExists->rowCount() <= 0) {

View File

@ -27,7 +27,7 @@ if(isset($_POST['deletecharactersave']) && $_POST['deletecharactersave'] == 1) {
//dont show table "delete character" again //dont show table "delete character" again
$show_form = false; $show_form = false;
//delete player //delete player
if(fieldExist('deletion', 'players')) if($db->hasColumn('players', 'deletion'))
$player->setCustomField('deletion', 1); $player->setCustomField('deletion', 1);
else else
$player->setCustomField('deleted', 1); $player->setCustomField('deleted', 1);

View File

@ -17,7 +17,7 @@ if($config['account_country'])
$groups = new OTS_Groups_List(); $groups = new OTS_Groups_List();
$show_form = true; $show_form = true;
$config_salt_enabled = fieldExist('salt', 'accounts'); $config_salt_enabled = $db->hasColumn('accounts', 'salt');
if(!$logged) if(!$logged)
{ {
if($action == "logout") { if($action == "logout") {
@ -74,7 +74,7 @@ $errors = array();
$account_registered = '<b><font color="green">Yes</font></b>'; $account_registered = '<b><font color="green">Yes</font></b>';
} }
$account_created = $account_logged->getCustomField("created"); $account_created = $account_logged->getCreated();
$account_email = $account_logged->getEMail(); $account_email = $account_logged->getEMail();
$email_new_time = $account_logged->getCustomField("email_new_time"); $email_new_time = $account_logged->getCustomField("email_new_time");
if($email_new_time > 1) if($email_new_time > 1)

View File

@ -78,7 +78,7 @@ else if(isset($_REQUEST['search_name'])) {
$groups = new OTS_Groups_List(); $groups = new OTS_Groups_List();
if($id > 0) { if($id > 0) {
$player = $ots->createObject('Player'); $player = new OTS_Player();
$player->load($id); $player->load($id);
if(isset($player) && $player->isLoaded() && isset($_POST['save'])) {// we want to save if(isset($player) && $player->isLoaded() && isset($_POST['save'])) {// we want to save
@ -95,7 +95,7 @@ if($id > 0) {
//if(!Validator::newCharacterName($name) //if(!Validator::newCharacterName($name)
// echo_error(Validator::getLastError()); // echo_error(Validator::getLastError());
$player_db = $ots->createObject('Player'); $player_db = new OTS_Player();
$player_db->find($name); $player_db->find($name);
if($player_db->isLoaded() && $player->getName() != $name) if($player_db->isLoaded() && $player->getName() != $name)
echo_error('This name is already used. Please choose another name!'); echo_error('This name is already used. Please choose another name!');
@ -149,7 +149,7 @@ if($id > 0) {
verify_number($look_legs, 'Look legs', 11); verify_number($look_legs, 'Look legs', 11);
$look_type = $_POST['look_type']; $look_type = $_POST['look_type'];
verify_number($look_type, 'Look type', 11); verify_number($look_type, 'Look type', 11);
if(fieldExist('lookaddons', 'players')) { if($db->hasColumn('players', 'lookaddons')) {
$look_addons = $_POST['look_addons']; $look_addons = $_POST['look_addons'];
verify_number($look_addons, 'Look addons', 11); verify_number($look_addons, 'Look addons', 11);
} }
@ -188,7 +188,7 @@ if($id > 0) {
$skull_time = $_POST['skull_time']; $skull_time = $_POST['skull_time'];
verify_number($skull_time, 'Skull time', 11); verify_number($skull_time, 'Skull time', 11);
if(fieldExist('loss_experience', 'players')) { if($db->hasColumn('players', 'loss_experience')) {
$loss_experience = $_POST['loss_experience']; $loss_experience = $_POST['loss_experience'];
verify_number($loss_experience, 'Loss experience', 11); verify_number($loss_experience, 'Loss experience', 11);
$loss_mana = $_POST['loss_mana']; $loss_mana = $_POST['loss_mana'];
@ -201,13 +201,13 @@ if($id > 0) {
verify_number($loss_items, 'Loss items', 11); verify_number($loss_items, 'Loss items', 11);
} }
if(fieldExist('blessings', 'players')) { if($db->hasColumn('players', 'blessings')) {
$blessings = $_POST['blessings']; $blessings = $_POST['blessings'];
verify_number($blessings, 'Blessings', 2); verify_number($blessings, 'Blessings', 2);
} }
$balance = $_POST['balance']; $balance = $_POST['balance'];
verify_number($balance, 'Balance', 20); verify_number($balance, 'Balance', 20);
if(fieldExist('stamina', 'players')) { if($db->hasColumn('players', 'stamina')) {
$stamina = $_POST['stamina']; $stamina = $_POST['stamina'];
verify_number($stamina, 'Stamina', 20); verify_number($stamina, 'Stamina', 20);
} }
@ -243,7 +243,7 @@ if($id > 0) {
$player->setLookHead($look_head); $player->setLookHead($look_head);
$player->setLookLegs($look_legs); $player->setLookLegs($look_legs);
$player->setLookType($look_type); $player->setLookType($look_type);
if(fieldExist('lookaddons', 'players')) if($db->hasColumn('players', 'lookaddons'))
$player->setLookAddons($look_addons); $player->setLookAddons($look_addons);
$player->setPosX($pos_x); $player->setPosX($pos_x);
$player->setPosY($pos_y); $player->setPosY($pos_y);
@ -257,19 +257,19 @@ if($id > 0) {
$player->setLastIP(ip2long($lastip)); $player->setLastIP(ip2long($lastip));
$player->setSkull($skull); $player->setSkull($skull);
$player->setSkullTime($skull_time); $player->setSkullTime($skull_time);
if(fieldExist('loss_experience', 'players')) { if($db->hasColumn('players', 'loss_experience')) {
$player->setLossExperience($loss_experience); $player->setLossExperience($loss_experience);
$player->setLossMana($loss_mana); $player->setLossMana($loss_mana);
$player->setLossSkills($loss_skills); $player->setLossSkills($loss_skills);
$player->setLossContainers($loss_containers); $player->setLossContainers($loss_containers);
$player->setLossItems($loss_items); $player->setLossItems($loss_items);
} }
if(fieldExist('blessings', 'players')) if($db->hasColumn('players', 'blessings'))
$player->setBlessings($blessings); $player->setBlessings($blessings);
$player->setBalance($balance); $player->setBalance($balance);
if(fieldExist('stamina', 'players')) if($db->hasColumn('players', 'stamina'))
$player->setStamina($stamina); $player->setStamina($stamina);
if(fieldExist('deletion', 'players')) if($db->hasColumn('players', 'deletion'))
$player->setCustomField('deletion', $deleted ? '1' : '0'); $player->setCustomField('deletion', $deleted ? '1' : '0');
else else
$player->setCustomField('deleted', $deleted ? '1' : '0'); $player->setCustomField('deleted', $deleted ? '1' : '0');
@ -399,7 +399,7 @@ $account = $player->getAccount();
Head:<input type="text" name="look_head" size="2" maxlength="11" value="<?php echo $player->getLookHead(); ?>" /> Head:<input type="text" name="look_head" size="2" maxlength="11" value="<?php echo $player->getLookHead(); ?>" />
Legs:<input type="text" name="look_legs" size="2" maxlength="11" value="<?php echo $player->getLookLegs(); ?>" /> Legs:<input type="text" name="look_legs" size="2" maxlength="11" value="<?php echo $player->getLookLegs(); ?>" />
Type:<input type="text" name="look_type" size="2" maxlength="11" value="<?php echo $player->getLookType(); ?>" /> Type:<input type="text" name="look_type" size="2" maxlength="11" value="<?php echo $player->getLookType(); ?>" />
<?php if(fieldExist('lookaddons', 'players')): ?> <?php if($db->hasColumn('lookaddons', 'players')): ?>
Addons:<input type="text" name="look_addons" size="2" maxlength="11" value="<?php echo $player->getLookAddons(); ?>" /> Addons:<input type="text" name="look_addons" size="2" maxlength="11" value="<?php echo $player->getLookAddons(); ?>" />
<?php endif; ?> <?php endif; ?>
</td> </td>
@ -472,7 +472,7 @@ $account = $player->getAccount();
</table> </table>
</td> </td>
</tr> </tr>
<?php if(fieldExist('loss_experience', 'players')): ?> <?php if($db->hasColumn('players', 'loss_experience')): ?>
<tr> <tr>
<td colspan="2"> <td colspan="2">
<table> <table>
@ -500,14 +500,14 @@ $account = $player->getAccount();
<td colspan="2"> <td colspan="2">
<table> <table>
<tr style="background-color: transparent;"> <tr style="background-color: transparent;">
<?php if(fieldExist('blessings', 'players')): ?> <?php if($db->hasColumn('players', 'blessings')): ?>
<td>Blessings:</td> <td>Blessings:</td>
<td><input type="text" name="blessings" size="2" maxlength="2" value="<?php echo $player->getBlessings(); ?>" /></td> <td><input type="text" name="blessings" size="2" maxlength="2" value="<?php echo $player->getBlessings(); ?>" /></td>
<?php endif; ?> <?php endif; ?>
<td>Balance:</td> <td>Balance:</td>
<td><input type="text" name="balance" size="16" maxlength="20" value="<?php echo $player->getBalance(); ?>" /></td> <td><input type="text" name="balance" size="16" maxlength="20" value="<?php echo $player->getBalance(); ?>" /></td>
<?php if(fieldExist('stamina', 'players')): ?> <?php if($db->hasColumn('players', 'stamina')): ?>
<td>Stamina:</td> <td>Stamina:</td>
<td><input type="text" name="stamina" size="16" maxlength="20" value="<?php echo $player->getStamina(); ?>" /></td> <td><input type="text" name="stamina" size="16" maxlength="20" value="<?php echo $player->getStamina(); ?>" /></td>
<?php endif; ?> <?php endif; ?>
@ -520,10 +520,10 @@ $account = $player->getAccount();
<table> <table>
<tr style="background-color: transparent;"> <tr style="background-color: transparent;">
<td><label for="deleted">Deleted:</label></td> <td><label for="deleted">Deleted:</label></td>
<td><input type="checkbox" name="deleted" id="deleted" value="true" <?php echo ($player->getCustomField(fieldExist('deletion', 'players') ? 'deletion' : 'deleted') == '1' ? ' checked' : ''); ?>/></td> <td><input type="checkbox" name="deleted" id="deleted" value="true" <?php echo ($player->getCustomField($db->hasColumn('deletion', 'players') ? 'deletion' : 'deleted') == '1' ? ' checked' : ''); ?>/></td>
<td><label for="hidden">Hidden:</label></td> <td><label for="hidden">Hidden:</label></td>
<td><input type="checkbox" name="hidden" id="hidden" value="true" <?php echo ($player->getCustomField('hidden') == 1 ? ' checked' : ''); ?>/></td> <td><input type="checkbox" name="hidden" id="hidden" value="true" <?php echo ($player->isHidden() ? ' checked' : ''); ?>/></td>
<td>Created:</td> <td>Created:</td>
<td><input type="text" name="created" id="created" value="<?php echo $player->getCustomField('created'); ?>"/></td> <td><input type="text" name="created" id="created" value="<?php echo $player->getCustomField('created'); ?>"/></td>

View File

@ -170,7 +170,7 @@ function getPlayerNameByAccount($id)
global $vowels, $ots, $db; global $vowels, $ots, $db;
if(is_numeric($id)) if(is_numeric($id))
{ {
$player = $ots->createObject('Player'); $player = new OTS_Player();
$player->load($id); $player->load($id);
if($player->isLoaded()) if($player->isLoaded())
return $player->getName(); return $player->getName();

View File

@ -27,7 +27,7 @@ function retrieve_former_name($name)
{ {
global $oldName, $db; global $oldName, $db;
if(tableExist('player_namelocks') && fieldExist('name', 'player_namelocks')) { if($db->hasTable('player_namelocks') && $db->hasColumn('player_namelocks', 'name')) {
$newNameSql = $db->query('SELECT `name`, `new_name` FROM `player_namelocks` WHERE `name` = ' . $db->quote($name)); $newNameSql = $db->query('SELECT `name`, `new_name` FROM `player_namelocks` WHERE `name` = ' . $db->quote($name));
if($newNameSql->rowCount() > 0) // namelocked if($newNameSql->rowCount() > 0) // namelocked
{ {
@ -79,24 +79,27 @@ if($player->isLoaded() && !$player->isDeleted())
$rows = 0; $rows = 0;
if($config['characters']['outfit']) if($config['characters']['outfit'])
$outfit = $config['outfit_images_url'] . '?id=' . $player->getLookType() . (fieldExist('lookaddons', 'players') ? '&addons=' . $player->getLookAddons() : '') . '&head=' . $player->getLookHead() . '&body=' . $player->getLookBody() . '&legs=' . $player->getLookLegs() . '&feet=' . $player->getLookFeet(); $outfit = $config['outfit_images_url'] . '?id=' . $player->getLookType() . ($db->hasColumn('players', 'lookaddons') ? '&addons=' . $player->getLookAddons() : '') . '&head=' . $player->getLookHead() . '&body=' . $player->getLookBody() . '&legs=' . $player->getLookLegs() . '&feet=' . $player->getLookFeet();
$flag = ''; $flag = '';
if($config['account_country']) if($config['account_country'])
$flag = getFlagImage($account->getCustomField('country')); $flag = getFlagImage($account->getCountry());
$player_sex = 'Unknown'; $player_sex = 'Unknown';
if(isset($config['genders'][$player->getSex()])) if(isset($config['genders'][$player->getSex()]))
$player_sex = strtolower($config['genders'][$player->getSex()]); $player_sex = strtolower($config['genders'][$player->getSex()]);
$marriage = new OTS_Player();
$marriage->load($player->getMarriage());
$marital_status = 'single'; $marital_status = 'single';
if($marriage->isLoaded()) $marriage_id = $player->getMarriage();
if($marriage_id > 0) {
$marriage = new OTS_Player();
$marriage->load($player->getMarriage(), array('id', 'name'), false);
if($marriage->isLoaded()) {
$marital_status = 'married to ' . getPlayerLink($marriage->getName()); $marital_status = 'married to ' . getPlayerLink($marriage->getName());
}
}
$frags_enabled = tableExist('player_killers') && $config['characters']['frags']; $frags_enabled = $db->hasTable('player_killers') && $config['characters']['frags'];
$frags_count = 0; $frags_count = 0;
if($frags_enabled) { if($frags_enabled) {
$query = $db->query( $query = $db->query(
@ -114,14 +117,14 @@ if($player->isLoaded() && !$player->isDeleted())
} }
$town_field = 'town'; $town_field = 'town';
if(fieldExist('town_id', 'houses')) if($db->hasColumn('houses', 'town_id'))
$town_field = 'town_id'; $town_field = 'town_id';
else if(fieldExist('townid', 'houses')) else if($db->hasColumn('houses', 'townid'))
$town_field = 'townid'; $town_field = 'townid';
else if(!fieldExist('town', 'houses')) else if(!$db->hasColumn('houses', 'town'))
$town_field = false; $town_field = false;
if(fieldExist('name', 'houses')) { if($db->hasColumn('houses', 'name')) {
$house = $db->query('SELECT `id`, `paid`, `name`' . ($town_field != false ? ', `' . $town_field . '` as `town`' : '') . ' FROM `houses` WHERE `owner` = '.$player->getId())->fetch(); $house = $db->query('SELECT `id`, `paid`, `name`' . ($town_field != false ? ', `' . $town_field . '` as `town`' : '') . ' FROM `houses` WHERE `owner` = '.$player->getId())->fetch();
if(isset($house['id'])) if(isset($house['id']))
{ {
@ -143,7 +146,7 @@ if($player->isLoaded() && !$player->isDeleted())
if($config['characters']['skills']) if($config['characters']['skills'])
{ {
if(fieldExist('skill_fist', 'players')) {// tfs 1.0+ if($db->hasColumn('players', 'skill_fist')) {// tfs 1.0+
$skills_db = $db->query('SELECT `skill_fist`, `skill_club`, `skill_sword`, `skill_axe`, `skill_dist`, `skill_shielding`, `skill_fishing` FROM `players` WHERE `id` = ' . $player->getId())->fetch(); $skills_db = $db->query('SELECT `skill_fist`, `skill_club`, `skill_sword`, `skill_axe`, `skill_dist`, `skill_shielding`, `skill_fishing` FROM `players` WHERE `id` = ' . $player->getId())->fetch();
$skill_ids = array( $skill_ids = array(
@ -230,7 +233,7 @@ if($player->isLoaded() && !$player->isDeleted())
$dead_add_content = ''; $dead_add_content = '';
$deaths = array(); $deaths = array();
if(tableExist('killers')) { if($db->hasTable('killers')) {
$player_deaths = $db->query('SELECT `id`, `date`, `level` FROM `player_deaths` WHERE `player_id` = '.$player->getId().' ORDER BY `date` DESC LIMIT 0,10;'); $player_deaths = $db->query('SELECT `id`, `date`, `level` FROM `player_deaths` WHERE `player_id` = '.$player->getId().' ORDER BY `date` DESC LIMIT 0,10;');
if(count($player_deaths)) if(count($player_deaths))
{ {
@ -284,7 +287,7 @@ WHERE killers.death_id = '".$death['id']."' ORDER BY killers.final_hit DESC, kil
} }
else { else {
$mostdamage = ''; $mostdamage = '';
if(fieldExist('mostdamage_by', 'player_deaths')) if($db->hasColumn('player_deaths', 'mostdamage_by'))
$mostdamage = ', `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`'; $mostdamage = ', `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`';
$deaths_db = $db->query('SELECT $deaths_db = $db->query('SELECT
`player_id`, `time`, `level`, `killed_by`, `is_player`' . $mostdamage . ' `player_id`, `time`, `level`, `killed_by`, `is_player`' . $mostdamage . '
@ -345,15 +348,15 @@ WHERE killers.death_id = '".$death['id']."' ORDER BY killers.final_hit DESC, kil
$signature_url = BASE_URL . ($config['friendly_urls'] ? '' : '?') . urlencode($player->getName()) . '.png'; $signature_url = BASE_URL . ($config['friendly_urls'] ? '' : '?') . urlencode($player->getName()) . '.png';
} }
$hidden = $player->getCustomField('hidden'); $hidden = $player->isHidden();
if($hidden != 1) { if(!$hidden) {
// check if account has been banned // check if account has been banned
$bannedUntil = ''; $bannedUntil = '';
$banned = array(); $banned = array();
if(tableExist('account_bans')) if($db->hasTable('account_bans'))
$banned = $db->query('SELECT `expires_at` as `expires` FROM `account_bans` WHERE `account_id` = ' . $account->getId() . ' and (`expires_at` > ' . time() . ' OR `expires_at` = -1);'); $banned = $db->query('SELECT `expires_at` as `expires` FROM `account_bans` WHERE `account_id` = ' . $account->getId() . ' and (`expires_at` > ' . time() . ' OR `expires_at` = -1);');
else if (tableExist('bans')) { else if ($db->hasTable('bans')) {
if (fieldExist('expires', 'bans')) if ($db->hasColumn('bans', 'expires'))
$banned = $db->query('SELECT `expires` FROM `bans` WHERE (`value` = ' . $account->getId() . ' or `value` = ' . $player->getId() . ') and `active` = 1 and `type` != 2 and `type` != 4 and (`expires` > ' . time() . ' OR `expires` = -1);'); $banned = $db->query('SELECT `expires` FROM `bans` WHERE (`value` = ' . $account->getId() . ' or `value` = ' . $player->getId() . ') and `active` = 1 and `type` != 2 and `type` != 4 and (`expires` > ' . time() . ' OR `expires` = -1);');
else else
$banned = $db->query('SELECT `time` as `time` FROM `bans` WHERE (`account` = ' . $account->getId() . ' or `player` = ' . $player->getId() . ') and `type` != 2 and `type` != 4 and (`time` > ' . time() . ' OR `time` = -1);'); $banned = $db->query('SELECT `time` as `time` FROM `bans` WHERE (`account` = ' . $account->getId() . ' or `player` = ' . $player->getId() . ') and `type` != 2 and `type` != 4 and (`time` > ' . time() . ' OR `time` = -1);');
@ -362,8 +365,16 @@ WHERE killers.death_id = '".$death['id']."' ORDER BY killers.final_hit DESC, kil
$bannedUntil = $ban['expires']; $bannedUntil = $ban['expires'];
} }
$account_players = $account->getPlayersList(); $account_players = array();
$account_players->orderBy('name'); $query = $db->query('SELECT `id` FROM `players` WHERE `account_id` = ' . $account->getId() . ' ORDER BY `name`')->fetchAll();
foreach($query as $p) {
$_player = new OTS_Player();
$fields = array('id', 'name', 'vocation', 'level', 'online', 'deleted', 'hidden');
$_player->load($p['id'], $fields, false);
if($_player->isLoaded()) {
$account_players[] = $_player;
}
}
} }
echo $twig->render('characters.html.twig', array( echo $twig->render('characters.html.twig', array(
@ -373,7 +384,7 @@ WHERE killers.death_id = '".$death['id']."' ORDER BY killers.final_hit DESC, kil
'flag' => $flag, 'flag' => $flag,
'oldName' => $oldName, 'oldName' => $oldName,
'sex' => $player_sex, 'sex' => $player_sex,
'marriage_enabled' => $config['characters']['marriage_info'] && fieldExist('marriage', 'players'), 'marriage_enabled' => $config['characters']['marriage_info'] && $db->hasColumn('players', 'marriage'),
'marital_status' => $marital_status, 'marital_status' => $marital_status,
'vocation' => $config['vocations'][$player->getVocation()], 'vocation' => $config['vocations'][$player->getVocation()],
'frags_enabled' => $frags_enabled, 'frags_enabled' => $frags_enabled,
@ -414,11 +425,11 @@ else
$search_errors = array(); $search_errors = array();
$promotion = ''; $promotion = '';
if(fieldExist('promotion', 'players')) if($db->hasColumn('players', 'promotion'))
$promotion = ', `promotion`'; $promotion = ', `promotion`';
$deleted = 'deleted'; $deleted = 'deleted';
if(fieldExist('deletion', 'players')) if($db->hasColumn('players', 'deletion'))
$deleted = 'deletion'; $deleted = 'deletion';
$query = $db->query('SELECT `name`, `level`, `vocation`' . $promotion . ' FROM `players` WHERE `name` LIKE ' . $db->quote('%' . $name . '%') . ' AND ' . $deleted . ' != 1;'); $query = $db->query('SELECT `name`, `level`, `vocation`' . $promotion . ' FROM `players` WHERE `name` LIKE ' . $db->quote('%' . $name . '%') . ' AND ' . $deleted . ' != 1;');

View File

@ -121,7 +121,7 @@ if($save)
else else
$new_account->create(NULL, $account_id); $new_account->create(NULL, $account_id);
$config_salt_enabled = fieldExist('salt', 'accounts'); $config_salt_enabled = $db->hasColumn('accounts', 'salt');
if($config_salt_enabled) if($config_salt_enabled)
{ {
$salt = generateRandomString(10, false, true, true); $salt = generateRandomString(10, false, true, true);
@ -144,7 +144,7 @@ if($save)
} }
if($config['account_premium_days'] && $config['account_premium_days'] > 0) { if($config['account_premium_days'] && $config['account_premium_days'] > 0) {
if(fieldExist('premend', 'accounts')) { // othire if($db->hasColumn('accounts', 'premend')) { // othire
$new_account->setCustomField('premend', time() + $config['account_premium_days'] * 86400); $new_account->setCustomField('premend', time() + $config['account_premium_days'] * 86400);
} }
else { // rest else { // rest

View File

@ -38,6 +38,7 @@ if(isset($posts[0]['player_id'])) {
$db->query("UPDATE `" . TABLE_PREFIX . "forum` SET `views`=`views`+1 WHERE `id` = ".(int) $thread_id); $db->query("UPDATE `" . TABLE_PREFIX . "forum` SET `views`=`views`+1 WHERE `id` = ".(int) $thread_id);
} }
$lookaddons = $db-hasColumn('players', 'lookaddons');
$groups = new OTS_Groups_List(); $groups = new OTS_Groups_List();
foreach($posts as &$post) foreach($posts as &$post)
{ {
@ -50,7 +51,7 @@ foreach($posts as &$post)
} }
if($config['characters']['outfit']) { if($config['characters']['outfit']) {
$post['outfit'] = $config['outfit_images_url'] . '?id=' . $player->getLookType() . (fieldExist('lookaddons', 'players') ? '&addons=' . $player->getLookAddons() : '') . '&head=' . $player->getLookHead() . '&body=' . $player->getLookBody() . '&legs=' . $player->getLookLegs() . '&feet=' . $player->getLookFeet(); $post['outfit'] = $config['outfit_images_url'] . '?id=' . $player->getLookType() . ($lookaddons ? '&addons=' . $player->getLookAddons() : '') . '&head=' . $player->getLookHead() . '&body=' . $player->getLookBody() . '&legs=' . $player->getLookLegs() . '&feet=' . $player->getLookFeet();
} }
$groupName = ''; $groupName = '';

View File

@ -11,12 +11,12 @@
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$title = 'Guilds'; $title = 'Guilds';
if(tableExist('guild_members')) if($db->hasTable('guild_members'))
define('GUILD_MEMBERS_TABLE', 'guild_members'); define('GUILD_MEMBERS_TABLE', 'guild_members');
else else
define('GUILD_MEMBERS_TABLE', 'guild_membership'); define('GUILD_MEMBERS_TABLE', 'guild_membership');
define('MOTD_EXISTS', fieldExist('motd', 'guilds')); define('MOTD_EXISTS', $db->hasColumn('guilds', 'motd'));
//show list of guilds //show list of guilds
if(empty($action)) { if(empty($action)) {

View File

@ -22,7 +22,7 @@ if(!Validator::guildName($guild_name)) {
} }
if(empty($errors)) { if(empty($errors)) {
$guild = $ots->createObject('Guild'); $guild = new OTS_Guild();
$guild->find($guild_name); $guild->find($guild_name);
if(!$guild->isLoaded()) { if(!$guild->isLoaded()) {
$errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.'; $errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.';

View File

@ -23,7 +23,7 @@ if(empty($errors)) {
if(!$logged) { if(!$logged) {
$errors[] = 'You are not logged.'; $errors[] = 'You are not logged.';
} }
$guild = $ots->createObject('Guild'); $guild = new OTS_Guild();
$guild->find($guild_name); $guild->find($guild_name);
if(!$guild->isLoaded()) { if(!$guild->isLoaded()) {
$errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.'; $errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.';

View File

@ -16,7 +16,7 @@ if(!Validator::guildName($guild_name)) {
} }
if(empty($errors)) { if(empty($errors)) {
$guild = $ots->createObject('Guild'); $guild = new OTS_Guild();
$guild->find($guild_name); $guild->find($guild_name);
if(!$guild->isLoaded()) { if(!$guild->isLoaded()) {
$errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.'; $errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.';

View File

@ -21,7 +21,7 @@ else {
if(empty($errors)) if(empty($errors))
{ {
$guild = $ots->createObject('Guild'); $guild = new OTS_Guild();
$guild->find($guild_name); $guild->find($guild_name);
if(!$guild->isLoaded()) if(!$guild->isLoaded())
$errors[] = 'Guild with name <b>' . $guild_name . '</b> doesn\'t exist.'; $errors[] = 'Guild with name <b>' . $guild_name . '</b> doesn\'t exist.';
@ -75,7 +75,7 @@ if($guild_vice)
$ranks[$rid]['1'] = $rank->getName(); $ranks[$rid]['1'] = $rank->getName();
$rid++; $rid++;
if(fieldExist('rank_id', 'players')) if($db->hasColumn('players', 'rank_id'))
$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_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 = $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`;');
@ -107,7 +107,7 @@ if($guild_vice)
$new_rank = (int) $_REQUEST['rankid']; $new_rank = (int) $_REQUEST['rankid'];
if(!Validator::characterName($player_name)) if(!Validator::characterName($player_name))
$change_errors[] = 'Invalid player name format.'; $change_errors[] = 'Invalid player name format.';
$rank = $ots->createObject('GuildRank'); $rank = new OTS_GuildRank();
$rank->load($new_rank); $rank->load($new_rank);
if(!$rank->isLoaded()) if(!$rank->isLoaded())
$change_errors[] = 'Rank with this ID doesn\'t exist.'; $change_errors[] = 'Rank with this ID doesn\'t exist.';
@ -115,7 +115,7 @@ if($guild_vice)
$change_errors[] = 'You can\'t set ranks with equal or higher level than your.'; $change_errors[] = 'You can\'t set ranks with equal or higher level than your.';
if(empty($change_errors)) if(empty($change_errors))
{ {
$player_to_change = $ots->createObject('Player'); $player_to_change = new OTS_Player();
$player_to_change->find($player_name); $player_to_change->find($player_name);
if(!$player_to_change->isLoaded()) if(!$player_to_change->isLoaded())
$change_errors[] = 'Player with name '.$player_name.'</b> doesn\'t exist.'; $change_errors[] = 'Player with name '.$player_name.'</b> doesn\'t exist.';
@ -163,7 +163,7 @@ if($guild_vice)
$ranks[$rid]['1'] = $rank->getName(); $ranks[$rid]['1'] = $rank->getName();
$rid++; $rid++;
if(fieldExist('rank_id', 'players')) if($db->hasColumn('players', 'rank_id'))
$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_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 = $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`;');
@ -173,7 +173,7 @@ if($guild_vice)
{ {
foreach($players_with_rank as $result) foreach($players_with_rank as $result)
{ {
$player = $ots->createObject('Player'); $player = new OTS_Player();
$player->load($result['id']); $player->load($result['id']);
if(!$player->isLoaded()) if(!$player->isLoaded())
continue; continue;

View File

@ -54,7 +54,7 @@ if($todo == 'save')
} }
if(empty($guild_errors)) { if(empty($guild_errors)) {
$player = $ots->createObject('Player'); $player = new OTS_Player();
$player->find($name); $player->find($name);
if(!$player->isLoaded()) { if(!$player->isLoaded()) {
$guild_errors[] = 'Character <b>'.$name.'</b> doesn\'t exist.'; $guild_errors[] = 'Character <b>'.$name.'</b> doesn\'t exist.';
@ -64,7 +64,7 @@ if($todo == 'save')
if(empty($guild_errors)) if(empty($guild_errors))
{ {
$guild = $ots->createObject('Guild'); $guild = new OTS_Guild();
$guild->find($guild_name); $guild->find($guild_name);
if($guild->isLoaded()) { if($guild->isLoaded()) {
$guild_errors[] = 'Guild <b>'.$guild_name.'</b> already exist. Select other name.'; $guild_errors[] = 'Guild <b>'.$guild_name.'</b> already exist. Select other name.';

View File

@ -17,7 +17,7 @@ if(!Validator::guildName($guild_name)) {
$guild_errors[] = Validator::getLastError(); $guild_errors[] = Validator::getLastError();
} }
if(empty($guild_errors)) { if(empty($guild_errors)) {
$guild = $ots->createObject('Guild'); $guild = new OTS_Guild();
$guild->find($guild_name); $guild->find($guild_name);
if(!$guild->isLoaded()) { if(!$guild->isLoaded()) {
$guild_errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.'; $guild_errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.';
@ -55,7 +55,7 @@ if(empty($guild_errors)) {
} }
else else
{ {
if(fieldExist('rank_id', 'players')) if($db->hasColumn('players', 'rank_id'))
$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_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 = $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`;');

View File

@ -22,7 +22,7 @@ if(!Validator::guildName($guild_name)) {
} }
if(empty($errors)) { if(empty($errors)) {
$guild = $ots->createObject('Guild'); $guild = new OTS_Guild();
$guild->find($guild_name); $guild->find($guild_name);
if(!$guild->isLoaded()) { if(!$guild->isLoaded()) {
$errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.'; $errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.';

View File

@ -27,7 +27,7 @@ if(!Validator::characterName($name)) {
} }
if(empty($errors)) { if(empty($errors)) {
$guild = $ots->createObject('Guild'); $guild = new OTS_Guild();
$guild->find($guild_name); $guild->find($guild_name);
if(!$guild->isLoaded()) { if(!$guild->isLoaded()) {
$errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.'; $errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.';

View File

@ -1,6 +1,6 @@
<?php <?php
$guilds_list = $ots->createObject('Guilds_List'); $guilds_list = new OTS_Guilds_List();
if(!isset($_REQUEST['preview'])) if(!isset($_REQUEST['preview']))
$_REQUEST['preview'] = 1; $_REQUEST['preview'] = 1;

View File

@ -17,7 +17,7 @@ if(!Validator::guildName($guild_name)) {
} }
if(empty($guild_errors)) { if(empty($guild_errors)) {
$guild = $ots->createObject('Guild'); $guild = new OTS_Guild();
$guild->find($guild_name); $guild->find($guild_name);
if(!$guild->isLoaded()) { if(!$guild->isLoaded()) {
$guild_errors[] = "Guild with name <b>" . $guild_name . "</b> doesn't exist."; $guild_errors[] = "Guild with name <b>" . $guild_name . "</b> doesn't exist.";

View File

@ -16,7 +16,7 @@ if(!Validator::guildName($guild_name)) {
} }
if(empty($errors)) { if(empty($errors)) {
$guild = $ots->createObject('Guild'); $guild = new OTS_Guild();
$guild->find($guild_name); $guild->find($guild_name);
if(!$guild->isLoaded()) { if(!$guild->isLoaded()) {
$errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.'; $errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.';

View File

@ -16,7 +16,7 @@ if(!Validator::guildName($guild_name))
if(empty($errors)) if(empty($errors))
{ {
$guild = $ots->createObject('Guild'); $guild = new OTS_Guild();
$guild->find($guild_name); $guild->find($guild_name);
if(!$guild->isLoaded()) if(!$guild->isLoaded())
$errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.'; $errors[] = 'Guild with name <b>'.$guild_name.'</b> doesn\'t exist.';
@ -110,9 +110,9 @@ else
$showed_players = 1; $showed_players = 1;
foreach($rank_list as $rank) foreach($rank_list as $rank)
{ {
if(tableExist(GUILD_MEMBERS_TABLE)) if($db->hasTable(GUILD_MEMBERS_TABLE))
$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 = $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`;');
else if(fieldExist('rank_id', 'players')) else if($db->hasColumn('players', 'rank_id'))
$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;');
$players_with_rank_number = $players_with_rank->rowCount(); $players_with_rank_number = $players_with_rank->rowCount();
@ -127,7 +127,7 @@ else
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>'; <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>';
foreach($players_with_rank as $result) foreach($players_with_rank as $result)
{ {
$player = $ots->createObject('Player'); $player = new OTS_Player();
$player->load($result['id']); $player->load($result['id']);
if(!$player->isLoaded()) if(!$player->isLoaded())
continue; continue;

View File

@ -85,22 +85,22 @@ else
} }
$promotion = ''; $promotion = '';
if(fieldExist('promotion', 'players')) if($db->hasColumn('players', 'promotion'))
$promotion = ',promotion'; $promotion = ',promotion';
$online = ''; $online = '';
if(fieldExist('online', 'players')) if($db->hasColumn('players', 'online'))
$online = ',online'; $online = ',online';
$deleted = 'deleted'; $deleted = 'deleted';
if(fieldExist('deletion', 'players')) if($db->hasColumn('players', 'deletion'))
$deleted = 'deletion'; $deleted = 'deletion';
$outfit_addons = false; $outfit_addons = false;
$outfit = ''; $outfit = '';
if($config['highscores_outfit']) { if($config['highscores_outfit']) {
$outfit = ', lookbody, lookfeet, lookhead, looklegs, looktype'; $outfit = ', lookbody, lookfeet, lookhead, looklegs, looktype';
if(fieldExist('lookaddons', 'players')) { if($db->hasColumn('players', 'lookaddons')) {
$outfit .= ', lookaddons'; $outfit .= ', lookaddons';
$outfit_addons = true; $outfit_addons = true;
} }
@ -108,7 +108,7 @@ if($config['highscores_outfit']) {
$offset = $_page * $config['highscores_length']; $offset = $_page * $config['highscores_length'];
if($skill <= POT::SKILL_LAST) { // skills if($skill <= POT::SKILL_LAST) { // skills
if(fieldExist('skill_fist', 'players')) {// tfs 1.0 if($db->hasColumn('players', 'skill_fist')) {// tfs 1.0
$skill_ids = array( $skill_ids = array(
POT::SKILL_FIST => 'skill_fist', POT::SKILL_FIST => 'skill_fist',
POT::SKILL_CLUB => 'skill_club', POT::SKILL_CLUB => 'skill_club',
@ -119,10 +119,10 @@ if($skill <= POT::SKILL_LAST) { // skills
POT::SKILL_FISH => 'skill_fishing', POT::SKILL_FISH => 'skill_fishing',
); );
$skills = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',level,vocation' . $promotion . $outfit . ', ' . $skill_ids[$skill] . ' as value FROM accounts,players WHERE players.id NOT IN (' . implode(', ', $config['highscores_ids_hidden']) . ') AND players.' . $deleted . ' = 0 AND players.group_id < '.$config['highscores_groups_hidden'].' '.$add_sql.' AND players.id > 6 AND accounts.id = players.account_id ORDER BY ' . $skill_ids[$skill] . ' DESC LIMIT 101 OFFSET '.$offset); $skills = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',level,vocation' . $promotion . $outfit . ', ' . $skill_ids[$skill] . ' as value FROM accounts,players WHERE players.id NOT IN (' . implode(', ', $config['highscores_ids_hidden']) . ') AND players.' . $deleted . ' = 0 AND players.group_id < '.$config['highscores_groups_hidden'].' '.$add_sql.' AND accounts.id = players.account_id ORDER BY ' . $skill_ids[$skill] . ' DESC LIMIT 101 OFFSET '.$offset)->fetchAll();
} }
else else
$skills = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',value,level,vocation' . $promotion . $outfit . ' FROM accounts,players,player_skills WHERE players.id NOT IN (' . implode(', ', $config['highscores_ids_hidden']) . ') AND players.' . $deleted . ' = 0 AND players.group_id < '.$config['highscores_groups_hidden'].' '.$add_sql.' AND players.id > 6 AND players.id = player_skills.player_id AND player_skills.skillid = '.$skill.' AND accounts.id = players.account_id ORDER BY value DESC, count DESC LIMIT 101 OFFSET '.$offset); $skills = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',value,level,vocation' . $promotion . $outfit . ' FROM accounts,players,player_skills WHERE players.id NOT IN (' . implode(', ', $config['highscores_ids_hidden']) . ') AND players.' . $deleted . ' = 0 AND players.group_id < '.$config['highscores_groups_hidden'].' '.$add_sql.' AND players.id = player_skills.player_id AND player_skills.skillid = '.$skill.' AND accounts.id = players.account_id ORDER BY value DESC, count DESC LIMIT 101 OFFSET '.$offset)->fetchAll();
} }
else if($skill == 666 && $config['otserv_version'] == TFS_03) // frags else if($skill == 666 && $config['otserv_version'] == TFS_03) // frags
{ {
@ -131,15 +131,15 @@ else if($skill == 666 && $config['otserv_version'] == TFS_03) // frags
' WHERE players.id NOT IN (' . implode(', ', $config['highscores_ids_hidden']) . ') AND players.' . $deleted . ' = 0 AND players.group_id < '.$config['highscores_groups_hidden'].' '.$add_sql.' AND players.id = player_killers.player_id AND accounts.id = players.account_id' . ' WHERE players.id NOT IN (' . implode(', ', $config['highscores_ids_hidden']) . ') AND players.' . $deleted . ' = 0 AND players.group_id < '.$config['highscores_groups_hidden'].' '.$add_sql.' AND players.id = player_killers.player_id AND accounts.id = players.account_id' .
' GROUP BY `player_id`' . ' GROUP BY `player_id`' .
' ORDER BY value DESC' . ' ORDER BY value DESC' .
' LIMIT 101 OFFSET '.$offset); ' LIMIT 101 OFFSET '.$offset)->fetchAll();
} }
else else
{ {
if($skill == POT::SKILL__MAGLEVEL) { if($skill == POT::SKILL__MAGLEVEL) {
$skills = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',maglevel,level,vocation' . $promotion . $outfit . ' FROM accounts, players WHERE players.id NOT IN (' . implode(', ', $config['highscores_ids_hidden']) . ') AND players.' . $deleted . ' = 0 '.$add_sql.' AND players.group_id < '.$config['highscores_groups_hidden'].' AND players.id > 6 AND accounts.id = players.account_id ORDER BY maglevel DESC, manaspent DESC LIMIT 101 OFFSET '.$offset); $skills = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',maglevel,level,vocation' . $promotion . $outfit . ' FROM accounts, players WHERE players.id NOT IN (' . implode(', ', $config['highscores_ids_hidden']) . ') AND players.' . $deleted . ' = 0 '.$add_sql.' AND players.group_id < '.$config['highscores_groups_hidden'].' AND accounts.id = players.account_id ORDER BY maglevel DESC, manaspent DESC LIMIT 101 OFFSET '.$offset)->fetchAll();
} }
else { // level else { // level
$skills = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',level,experience,vocation' . $promotion . $outfit . ' FROM accounts, players WHERE players.id NOT IN (' . implode(', ', $config['highscores_ids_hidden']) . ') AND players.' . $deleted . ' = 0 '.$add_sql.' AND players.group_id < '.$config['highscores_groups_hidden'].' AND players.id > 6 AND accounts.id = players.account_id ORDER BY level DESC, experience DESC LIMIT 101 OFFSET '.$offset); $skills = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',level,experience,vocation' . $promotion . $outfit . ' FROM accounts, players WHERE players.id NOT IN (' . implode(', ', $config['highscores_ids_hidden']) . ') AND players.' . $deleted . ' = 0 '.$add_sql.' AND players.group_id < '.$config['highscores_groups_hidden'].' AND accounts.id = players.account_id ORDER BY level DESC, experience DESC LIMIT 101 OFFSET '.$offset)->fetchAll();
$list = 'experience'; $list = 'experience';
} }
} }
@ -174,13 +174,25 @@ $show_link_to_next_page = false;
$i = 0; $i = 0;
$online_exist = false; $online_exist = false;
if(fieldExist('online', 'players')) if($db->hasColumn('players', 'online'))
$online_exist = true; $online_exist = true;
$players = array();
foreach($skills as $player) {
$players[] = $player['id'];
}
if($db->hasTable('players_online')) {
$query = $db->query('SELECT `player_id`, 1 FROM `players_online` WHERE `player_id` IN (' . implode(', ', $players) . ')')->fetchAll();
foreach($query as $t) {
$is_online[$t['player_id']] = true;
}
}
foreach($skills as $player) foreach($skills as $player)
{ {
if(!$online_exist) { if(isset($is_online)) {
$query = $db->query('SELECT `player_id` FROM `players_online` WHERE `player_id` = ' . $player['id']); $player['online'] = (isset($is_online[$player['id']]) ? 1 : 0);
$player['online'] = $query->rowCount() > 0;
} }
if(++$i <= $config['highscores_length']) if(++$i <= $config['highscores_length'])

View File

@ -11,7 +11,7 @@
defined('MYAAC') or die('Direct access not allowed!'); defined('MYAAC') or die('Direct access not allowed!');
$title = 'Houses'; $title = 'Houses';
if(!fieldExist('name', 'houses')) { if(!$db->hasColumn('houses', 'name')) {
echo 'Houses list is not available on this server.'; echo 'Houses list is not available on this server.';
return; return;
} }
@ -87,7 +87,7 @@ $type = '';
$who = $guild->getName(); $who = $guild->getName();
else else
{ {
$player = $ots->createObject('Player'); $player = new OTS_Player();
$player->load($houseOwner); $player->load($houseOwner);
if($player->isLoaded()) if($player->isLoaded())
{ {
@ -107,7 +107,7 @@ $type = '';
else else
{ {
echo ' echo '
Here you can see the list of all available houses, flats' . (tableExist('guild', 'houses') ? ' or guildhall' : '') . '. Here you can see the list of all available houses, flats' . ($db->hasTable('houses', 'guild') ? ' or guildhall' : '') . '.
Click on any view button to get more information about a house or adjust Click on any view button to get more information about a house or adjust
the search criteria and start a new search.<br/><br/>'; the search criteria and start a new search.<br/><br/>';
if(isset($config['lua']['houseCleanOld'])) { if(isset($config['lua']['houseCleanOld'])) {
@ -134,7 +134,7 @@ $type = '';
echo '<br/>'; echo '<br/>';
if(isset($_POST['town']) && isset($_POST['state']) && isset($_POST['order']) if(isset($_POST['town']) && isset($_POST['state']) && isset($_POST['order'])
&& (isset($_POST['type']) || !tableExist('guild', 'houses'))) && (isset($_POST['type']) || !$db->hasTable('houses', 'guild')))
{ {
$order = $_POST['order']; $order = $_POST['order'];
$orderby = '`name`'; $orderby = '`name`';
@ -147,9 +147,9 @@ $type = '';
} }
$town = 'town'; $town = 'town';
if(fieldExist('town_id', 'houses')) if($db->hasColumn('houses', 'town_id'))
$town = 'town_id'; $town = 'town_id';
else if(fieldExist('townid', 'houses')) else if($db->hasColumn('houses', 'townid'))
$town = 'townid'; $town = 'townid';
$whereby = '`' . $town . '` = ' .(int)$_POST['town']; $whereby = '`' . $town . '` = ' .(int)$_POST['town'];
@ -158,7 +158,7 @@ $type = '';
$whereby .= ' AND `owner` ' . ($state == 'free' ? '' : '!'). '= 0'; $whereby .= ' AND `owner` ' . ($state == 'free' ? '' : '!'). '= 0';
$type = isset($_POST['type']) ? $_POST['type'] : NULL; $type = isset($_POST['type']) ? $_POST['type'] : NULL;
if($type == 'guildhalls' && !fieldExist('guild', 'houses')) if($type == 'guildhalls' && !$db->hasColumn('houses', 'guild'))
$type = 'all'; $type = 'all';
if(!empty($type) && $type != 'all') if(!empty($type) && $type != 'all')
@ -202,7 +202,7 @@ $type = '';
<TD WIDTH="10%"><NOBR>'.$house['size'].' sqm</TD> <TD WIDTH="10%"><NOBR>'.$house['size'].' sqm</TD>
<TD WIDTH="10%"><NOBR>'.$house['rent'].' gold</TD> <TD WIDTH="10%"><NOBR>'.$house['rent'].' gold</TD>
<TD WIDTH="40%"><NOBR>'; <TD WIDTH="40%"><NOBR>';
if(fieldExist('guild', 'houses') && $house['guild'] == 1 && $house['owner'] != 0) if($db->hasColumn('houses', 'guild') && $house['guild'] == 1 && $house['owner'] != 0)
{ {
$guild = new OTS_Guild(); $guild = new OTS_Guild();
$guild->load($house['owner']); $guild->load($house['owner']);
@ -285,7 +285,7 @@ $type = '';
</TD> </TD>
</TR>'; </TR>';
if(fieldExist('guild', 'houses')) { if($db->hasColumn('houses', 'guild')) {
echo ' echo '
<TR BGCOLOR='.$config['darkborder'].'> <TR BGCOLOR='.$config['darkborder'].'>
<TD VALIGN=top> <TD VALIGN=top>

View File

@ -13,9 +13,9 @@ $title = 'Last Kills';
$players_deaths_count = 0; $players_deaths_count = 0;
$players_rows = ''; $players_rows = '';
if(tableExist('player_killers')) // tfs 0.3 if($db->hasTable('player_killers')) // tfs 0.3
{ {
$players_deaths = $db->query('SELECT `player_deaths`.`id`, `player_deaths`.`date`, `player_deaths`.`level`, `players`.`name`' . (fieldExist('world_id', 'players') ? ', `players`.`world_id`' : '') . ' FROM `player_deaths` LEFT JOIN `players` ON `player_deaths`.`player_id` = `players`.`id` ORDER BY `date` DESC LIMIT 0, ' . $config['last_kills_limit']); $players_deaths = $db->query('SELECT `player_deaths`.`id`, `player_deaths`.`date`, `player_deaths`.`level`, `players`.`name`' . ($db->hasColumn('players', 'world_id') ? ', `players`.`world_id`' : '') . ' FROM `player_deaths` LEFT JOIN `players` ON `player_deaths`.`player_id` = `players`.`id` ORDER BY `date` DESC LIMIT 0, ' . $config['last_kills_limit']);
if(!empty($players_deaths)) if(!empty($players_deaths))
{ {
foreach($players_deaths as $death) foreach($players_deaths as $death)

View File

@ -17,7 +17,7 @@ if(!$config['mail_enabled'])
return; return;
} }
$config_salt_enabled = fieldExist('salt', 'accounts'); $config_salt_enabled = $db->hasColumn('accounts', 'salt');
$action_type = isset($_REQUEST['action_type']) ? $_REQUEST['action_type'] : ''; $action_type = isset($_REQUEST['action_type']) ? $_REQUEST['action_type'] : '';
if($action == '') if($action == '')
{ {

View File

@ -15,7 +15,7 @@ if($config['account_country'])
require(SYSTEM . 'countries.conf.php'); require(SYSTEM . 'countries.conf.php');
$promotion = ''; $promotion = '';
if(fieldExist('promotion', 'players')) if($db->hasColumn('players', 'promotion'))
$promotion = '`promotion`,'; $promotion = '`promotion`,';
$order = isset($_GET['order']) ? $_GET['order'] : 'name'; $order = isset($_GET['order']) ? $_GET['order'] : 'name';
if(!in_array($order, array('country', 'name', 'level', 'vocation'))) if(!in_array($order, array('country', 'name', 'level', 'vocation')))
@ -26,12 +26,12 @@ else if($order == 'vocation')
$order = $promotion . 'vocation ASC'; $order = $promotion . 'vocation ASC';
$skull_type = 'skull'; $skull_type = 'skull';
if(fieldExist('skull_type', 'players')) { if($db->hasColumn('players', 'skull_type')) {
$skull_type = 'skull_type'; $skull_type = 'skull_type';
} }
$skull_time = 'skulltime'; $skull_time = 'skulltime';
if(fieldExist('skull_time', 'players')) { if($db->hasColumn('players', 'skull_time')) {
$skull_time = 'skull_time'; $skull_time = 'skull_time';
} }
@ -39,7 +39,7 @@ $outfit_addons = false;
$outfit = ''; $outfit = '';
if($config['online_outfit']) { if($config['online_outfit']) {
$outfit = ', lookbody, lookfeet, lookhead, looklegs, looktype'; $outfit = ', lookbody, lookfeet, lookhead, looklegs, looktype';
if(fieldExist('lookaddons', 'players')) { if($db->hasColumn('players', 'lookaddons')) {
$outfit .= ', lookaddons'; $outfit .= ', lookaddons';
$outfit_addons = true; $outfit_addons = true;
} }
@ -51,7 +51,7 @@ if($config['online_vocations']) {
$vocs[$id] = 0; $vocs[$id] = 0;
} }
if(tableExist('players_online')) // tfs 1.0 if($db->hasTable('players_online')) // tfs 1.0
$playersOnline = $db->query('SELECT `accounts`.`country`, `players`.`name`, `level`, `vocation`' . $outfit . ', `' . $skull_time . '` as `skulltime`, `' . $skull_type . '` as `skull` FROM `accounts`, `players`, `players_online` WHERE `players`.`id` = `players_online`.`player_id` AND `accounts`.`id` = `players`.`account_id` ORDER BY ' . $order); $playersOnline = $db->query('SELECT `accounts`.`country`, `players`.`name`, `level`, `vocation`' . $outfit . ', `' . $skull_time . '` as `skulltime`, `' . $skull_type . '` as `skull` FROM `accounts`, `players`, `players_online` WHERE `players`.`id` = `players_online`.`player_id` AND `accounts`.`id` = `players`.`account_id` ORDER BY ' . $order);
else else
$playersOnline = $db->query('SELECT `accounts`.`country`, `players`.`name`, `level`, `vocation`' . $outfit . ', ' . $promotion . ' `' . $skull_time . '` as `skulltime`, `' . $skull_type . '` as `skull` FROM `accounts`, `players` WHERE `players`.`online` > 0 AND `accounts`.`id` = `players`.`account_id` ORDER BY ' . $order); $playersOnline = $db->query('SELECT `accounts`.`country`, `players`.`name`, `level`, `vocation`' . $outfit . ', ' . $promotion . ' `' . $skull_time . '` as `skulltime`, `' . $skull_type . '` as `skull` FROM `accounts`, `players` WHERE `players`.`online` > 0 AND `accounts`.`id` = `players`.`account_id` ORDER BY ' . $order);
@ -99,14 +99,14 @@ if($players > 0)
if($config['online_record']) if($config['online_record'])
{ {
$timestamp = false; $timestamp = false;
if(tableExist('server_record')) { if($db->hasTable('server_record')) {
$query = $query =
$db->query( $db->query(
'SELECT `record`, `timestamp` FROM `server_record` WHERE `world_id` = ' . (int)$config['lua']['worldId'] . 'SELECT `record`, `timestamp` FROM `server_record` WHERE `world_id` = ' . (int)$config['lua']['worldId'] .
' ORDER BY `record` DESC LIMIT 1'); ' ORDER BY `record` DESC LIMIT 1');
$timestamp = true; $timestamp = true;
} }
else if(tableExist('server_config')) { // tfs 1.0 else if($db->hasTable('server_config')) { // tfs 1.0
$query = $db->query('SELECT `value` as `record` FROM `server_config` WHERE `config` = ' . $db->quote('players_record')); $query = $db->query('SELECT `value` as `record` FROM `server_config` WHERE `config` = ' . $db->quote('players_record'));
} }
else else

View File

@ -13,7 +13,7 @@ $title = 'Polls';
/* Polls System By Averatec from pervera.pl & otland.net */ /* Polls System By Averatec from pervera.pl & otland.net */
if(!tableExist('z_polls')) if(!$db->hasTable('z_polls'))
$db->query(' $db->query('
CREATE TABLE `z_polls` ( CREATE TABLE `z_polls` (
`id` int(11) NOT NULL auto_increment, `id` int(11) NOT NULL auto_increment,
@ -26,7 +26,7 @@ CREATE TABLE `z_polls` (
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;'); ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;');
if(!tableExist('z_polls_answers')) if(!$db->hasTable('z_polls_answers'))
$db->query(' $db->query('
CREATE TABLE `z_polls_answers` ( CREATE TABLE `z_polls_answers` (
`poll_id` int(11) NOT NULL, `poll_id` int(11) NOT NULL,
@ -35,7 +35,7 @@ $db->query('
`votes` int(11) NOT NULL DEFAULT 0 `votes` int(11) NOT NULL DEFAULT 0
) ENGINE=MyISAM DEFAULT CHARSET=latin1;'); ) ENGINE=MyISAM DEFAULT CHARSET=latin1;');
if(!fieldExist('vote', 'accounts')) if(!$db->hasColumn('accounts', 'vote'))
$db->query('ALTER TABLE `accounts` ADD `vote` INT( 11 ) NOT NULL ;'); $db->query('ALTER TABLE `accounts` ADD `vote` INT( 11 ) NOT NULL ;');
function getColorByPercent($percent) function getColorByPercent($percent)

View File

@ -44,13 +44,13 @@ foreach($groupList as $id => $group)
$groupNames = array(); $groupNames = array();
foreach($group_members as $member) foreach($group_members as $member)
{ {
if(!admin() && $member->getCustomField('hidden') > 0) if(!admin() && $member->isHidden())
continue; continue;
$members_count++; $members_count++;
$flag = ''; $flag = '';
if($config['account_country']) if($config['account_country'])
$flag = getFlagImage($member->getAccount()->getCustomField('country')); $flag = getFlagImage($member->getAccount()->getCountry());
$tmp = '<tr bgcolor="' . getStyle($i++) . '">'; $tmp = '<tr bgcolor="' . getStyle($i++) . '">';
if(!$newStyle) if(!$newStyle)

View File

@ -103,7 +103,7 @@ function updateStatus() {
if($config['online_afk']) if($config['online_afk'])
{ {
// get amount of players that are currently logged in-game, including disconnected clients (exited) // get amount of players that are currently logged in-game, including disconnected clients (exited)
if(tableExist('players_online')) { // tfs 1.x if($db->hasTable('players_online')) { // tfs 1.x
$query = $db->query('SELECT COUNT(`player_id`) AS `playersTotal` FROM `players_online`;'); $query = $db->query('SELECT COUNT(`player_id`) AS `playersTotal` FROM `players_online`;');
} }
else { else {

View File

@ -36,7 +36,7 @@ If you do not want to specify a certain field, just leave it blank.<br/><br/>
<td class="LabelV" >Hide Account:</td> <td class="LabelV" >Hide Account:</td>
<td> <td>
<input type="hidden" value="0" name="accountvisible"> <input type="hidden" value="0" name="accountvisible">
<input type="checkbox" name="accountvisible" id="accountvisible" value="1" {% if player.getCustomField('hidden') == 1 %}checked="checked"{% endif %}> <input type="checkbox" name="accountvisible" id="accountvisible" value="1" {% if player.isHidden() %}checked="checked"{% endif %}>
<label for="accountvisible"> check to hide your account information</label> <label for="accountvisible"> check to hide your account information</label>
{% if player.getCustomField('group_id') > 1 %} (you will be also hidden on the Team page!){% endif %} {% if player.getCustomField('group_id') > 1 %} (you will be also hidden on the Team page!){% endif %}
</td> </td>

View File

@ -315,7 +315,7 @@
<!-- SIGNATURE_END --> <!-- SIGNATURE_END -->
{% endif %} {% endif %}
{{ hook(constant('HOOK_CHARACTERS_AFTER_SIGNATURE')) }} {{ hook(constant('HOOK_CHARACTERS_AFTER_SIGNATURE')) }}
{% if hidden != 1 %} {% if not hidden %}
{% set rows = 0 %} {% set rows = 0 %}
<!-- ACCOUNT_INFORMATION --> <!-- ACCOUNT_INFORMATION -->
<br/><br/> <br/><br/>
@ -324,7 +324,7 @@
<td colspan="2" class="white"><b>Account Information</b></td> <td colspan="2" class="white"><b>Account Information</b></td>
</tr> </tr>
{% set realName = account.getCustomField('rlname') %} {% set realName = account.getRLName() %}
{% if realName is not empty %} {% if realName is not empty %}
{% set rows = rows + 1 %} {% set rows = rows + 1 %}
<tr bgcolor="{{ getStyle(rows) }}"> <tr bgcolor="{{ getStyle(rows) }}">
@ -342,7 +342,7 @@
</tr> </tr>
{% endif %} {% endif %}
{% set realLocation = account.getCustomField('location') %} {% set realLocation = account.getLocation() %}
{% if realLocation is not empty %} {% if realLocation is not empty %}
{% set rows = rows + 1 %} {% set rows = rows + 1 %}
<tr bgcolor="{{ getStyle(rows) }}"> <tr bgcolor="{{ getStyle(rows) }}">
@ -354,7 +354,7 @@
{% set rows = rows + 1 %} {% set rows = rows + 1 %}
<tr bgcolor="{{ getStyle(rows) }}"> <tr bgcolor="{{ getStyle(rows) }}">
<td width="20%">Created:</td> <td width="20%">Created:</td>
<td>{{ account.getCustomField("created")|date("j F Y, g:i a") }} <td>{{ account.getCreated()|date("j F Y, g:i a") }}
{% if bannedUntil matches '/^\\d+$/' or bannedUntil == '-1' %} {% if bannedUntil matches '/^\\d+$/' or bannedUntil == '-1' %}
<font color="red">[Banished {% if bannedUntil == '-1' %}forever{% else %}until {{ bannedUntil|date('d F Y, h:s') }}{% endif %}]</font> <font color="red">[Banished {% if bannedUntil == '-1' %}forever{% else %}until {{ bannedUntil|date('d F Y, h:s') }}{% endif %}]</font>
{% else %} {% else %}

View File

@ -65,7 +65,7 @@
/** HOUSE **/ /** HOUSE **/
$town = 'town'; $town = 'town';
if(fieldExist('town_id', 'houses')) if($db->hasColumn('houses', 'town_id'))
$town = 'town_id'; $town = 'town_id';
$house = $db->query( 'SELECT `houses`.`name`, `houses`.`' . $town . '` as town FROM `houses` WHERE `houses`.`owner` = '.$player->getId().';' )->fetchAll(); $house = $db->query( 'SELECT `houses`.`name`, `houses`.`' . $town . '` as town FROM `houses` WHERE `houses`.`owner` = '.$player->getId().';' )->fetchAll();

View File

@ -101,7 +101,7 @@
imagefilledrectangle($img, 225, 40, 225, 130, $title); //seperator imagefilledrectangle($img, 225, 40, 225, 130, $title); //seperator
$posy = 50; $posy = 50;
if(fieldExist('skill_fist', 'players')) {// tfs 1.0+ if($db->hasColumn('players', 'skill_fist')) {// tfs 1.0+
$skills_db = $db->query('SELECT `skill_fist`, `skill_club`, `skill_sword`, `skill_axe`, `skill_dist`, `skill_shielding`, `skill_fishing` FROM `players` WHERE `id` = ' . $player->getId())->fetch(); $skills_db = $db->query('SELECT `skill_fist`, `skill_club`, `skill_sword`, `skill_axe`, `skill_dist`, `skill_shielding`, `skill_fishing` FROM `players` WHERE `id` = ' . $player->getId())->fetch();
$skill_ids = array( $skill_ids = array(