* 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

View File

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

View File

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

View File

@@ -17,7 +17,7 @@ if($config['account_country'])
$groups = new OTS_Groups_List();
$show_form = true;
$config_salt_enabled = fieldExist('salt', 'accounts');
$config_salt_enabled = $db->hasColumn('accounts', 'salt');
if(!$logged)
{
if($action == "logout") {
@@ -74,7 +74,7 @@ $errors = array();
$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();
$email_new_time = $account_logged->getCustomField("email_new_time");
if($email_new_time > 1)

View File

@@ -78,7 +78,7 @@ else if(isset($_REQUEST['search_name'])) {
$groups = new OTS_Groups_List();
if($id > 0) {
$player = $ots->createObject('Player');
$player = new OTS_Player();
$player->load($id);
if(isset($player) && $player->isLoaded() && isset($_POST['save'])) {// we want to save
@@ -95,7 +95,7 @@ if($id > 0) {
//if(!Validator::newCharacterName($name)
// echo_error(Validator::getLastError());
$player_db = $ots->createObject('Player');
$player_db = new OTS_Player();
$player_db->find($name);
if($player_db->isLoaded() && $player->getName() != $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);
$look_type = $_POST['look_type'];
verify_number($look_type, 'Look type', 11);
if(fieldExist('lookaddons', 'players')) {
if($db->hasColumn('players', 'lookaddons')) {
$look_addons = $_POST['look_addons'];
verify_number($look_addons, 'Look addons', 11);
}
@@ -188,7 +188,7 @@ if($id > 0) {
$skull_time = $_POST['skull_time'];
verify_number($skull_time, 'Skull time', 11);
if(fieldExist('loss_experience', 'players')) {
if($db->hasColumn('players', 'loss_experience')) {
$loss_experience = $_POST['loss_experience'];
verify_number($loss_experience, 'Loss experience', 11);
$loss_mana = $_POST['loss_mana'];
@@ -201,13 +201,13 @@ if($id > 0) {
verify_number($loss_items, 'Loss items', 11);
}
if(fieldExist('blessings', 'players')) {
if($db->hasColumn('players', 'blessings')) {
$blessings = $_POST['blessings'];
verify_number($blessings, 'Blessings', 2);
}
$balance = $_POST['balance'];
verify_number($balance, 'Balance', 20);
if(fieldExist('stamina', 'players')) {
if($db->hasColumn('players', 'stamina')) {
$stamina = $_POST['stamina'];
verify_number($stamina, 'Stamina', 20);
}
@@ -243,7 +243,7 @@ if($id > 0) {
$player->setLookHead($look_head);
$player->setLookLegs($look_legs);
$player->setLookType($look_type);
if(fieldExist('lookaddons', 'players'))
if($db->hasColumn('players', 'lookaddons'))
$player->setLookAddons($look_addons);
$player->setPosX($pos_x);
$player->setPosY($pos_y);
@@ -257,19 +257,19 @@ if($id > 0) {
$player->setLastIP(ip2long($lastip));
$player->setSkull($skull);
$player->setSkullTime($skull_time);
if(fieldExist('loss_experience', 'players')) {
if($db->hasColumn('players', 'loss_experience')) {
$player->setLossExperience($loss_experience);
$player->setLossMana($loss_mana);
$player->setLossSkills($loss_skills);
$player->setLossContainers($loss_containers);
$player->setLossItems($loss_items);
}
if(fieldExist('blessings', 'players'))
if($db->hasColumn('players', 'blessings'))
$player->setBlessings($blessings);
$player->setBalance($balance);
if(fieldExist('stamina', 'players'))
if($db->hasColumn('players', 'stamina'))
$player->setStamina($stamina);
if(fieldExist('deletion', 'players'))
if($db->hasColumn('players', 'deletion'))
$player->setCustomField('deletion', $deleted ? '1' : '0');
else
$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(); ?>" />
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(); ?>" />
<?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(); ?>" />
<?php endif; ?>
</td>
@@ -472,7 +472,7 @@ $account = $player->getAccount();
</table>
</td>
</tr>
<?php if(fieldExist('loss_experience', 'players')): ?>
<?php if($db->hasColumn('players', 'loss_experience')): ?>
<tr>
<td colspan="2">
<table>
@@ -500,14 +500,14 @@ $account = $player->getAccount();
<td colspan="2">
<table>
<tr style="background-color: transparent;">
<?php if(fieldExist('blessings', 'players')): ?>
<?php if($db->hasColumn('players', 'blessings')): ?>
<td>Blessings:</td>
<td><input type="text" name="blessings" size="2" maxlength="2" value="<?php echo $player->getBlessings(); ?>" /></td>
<?php endif; ?>
<td>Balance:</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><input type="text" name="stamina" size="16" maxlength="20" value="<?php echo $player->getStamina(); ?>" /></td>
<?php endif; ?>
@@ -520,10 +520,10 @@ $account = $player->getAccount();
<table>
<tr style="background-color: transparent;">
<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><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><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;
if(is_numeric($id))
{
$player = $ots->createObject('Player');
$player = new OTS_Player();
$player->load($id);
if($player->isLoaded())
return $player->getName();

View File

@@ -27,7 +27,7 @@ function retrieve_former_name($name)
{
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));
if($newNameSql->rowCount() > 0) // namelocked
{
@@ -79,24 +79,27 @@ if($player->isLoaded() && !$player->isDeleted())
$rows = 0;
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 = '';
if($config['account_country'])
$flag = getFlagImage($account->getCustomField('country'));
$flag = getFlagImage($account->getCountry());
$player_sex = 'Unknown';
if(isset($config['genders'][$player->getSex()]))
$player_sex = strtolower($config['genders'][$player->getSex()]);
$marriage = new OTS_Player();
$marriage->load($player->getMarriage());
$marital_status = 'single';
if($marriage->isLoaded())
$marital_status = 'married to ' . getPlayerLink($marriage->getName());
$frags_enabled = tableExist('player_killers') && $config['characters']['frags'];
$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());
}
}
$frags_enabled = $db->hasTable('player_killers') && $config['characters']['frags'];
$frags_count = 0;
if($frags_enabled) {
$query = $db->query(
@@ -114,14 +117,14 @@ if($player->isLoaded() && !$player->isDeleted())
}
$town_field = 'town';
if(fieldExist('town_id', 'houses'))
if($db->hasColumn('houses', 'town_id'))
$town_field = 'town_id';
else if(fieldExist('townid', 'houses'))
else if($db->hasColumn('houses', 'townid'))
$town_field = 'townid';
else if(!fieldExist('town', 'houses'))
else if(!$db->hasColumn('houses', 'town'))
$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();
if(isset($house['id']))
{
@@ -143,7 +146,7 @@ if($player->isLoaded() && !$player->isDeleted())
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();
$skill_ids = array(
@@ -230,7 +233,7 @@ if($player->isLoaded() && !$player->isDeleted())
$dead_add_content = '';
$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;');
if(count($player_deaths))
{
@@ -284,7 +287,7 @@ WHERE killers.death_id = '".$death['id']."' ORDER BY killers.final_hit DESC, kil
}
else {
$mostdamage = '';
if(fieldExist('mostdamage_by', 'player_deaths'))
if($db->hasColumn('player_deaths', 'mostdamage_by'))
$mostdamage = ', `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`';
$deaths_db = $db->query('SELECT
`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';
}
$hidden = $player->getCustomField('hidden');
if($hidden != 1) {
$hidden = $player->isHidden();
if(!$hidden) {
// check if account has been banned
$bannedUntil = '';
$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);');
else if (tableExist('bans')) {
if (fieldExist('expires', 'bans'))
else if ($db->hasTable('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);');
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);');
@@ -362,8 +365,16 @@ WHERE killers.death_id = '".$death['id']."' ORDER BY killers.final_hit DESC, kil
$bannedUntil = $ban['expires'];
}
$account_players = $account->getPlayersList();
$account_players->orderBy('name');
$account_players = array();
$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(
@@ -373,7 +384,7 @@ WHERE killers.death_id = '".$death['id']."' ORDER BY killers.final_hit DESC, kil
'flag' => $flag,
'oldName' => $oldName,
'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,
'vocation' => $config['vocations'][$player->getVocation()],
'frags_enabled' => $frags_enabled,
@@ -414,11 +425,11 @@ else
$search_errors = array();
$promotion = '';
if(fieldExist('promotion', 'players'))
if($db->hasColumn('players', 'promotion'))
$promotion = ', `promotion`';
$deleted = 'deleted';
if(fieldExist('deletion', 'players'))
if($db->hasColumn('players', 'deletion'))
$deleted = 'deletion';
$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
$new_account->create(NULL, $account_id);
$config_salt_enabled = fieldExist('salt', 'accounts');
$config_salt_enabled = $db->hasColumn('accounts', 'salt');
if($config_salt_enabled)
{
$salt = generateRandomString(10, false, true, true);
@@ -144,7 +144,7 @@ if($save)
}
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);
}
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);
}
$lookaddons = $db-hasColumn('players', 'lookaddons');
$groups = new OTS_Groups_List();
foreach($posts as &$post)
{
@@ -50,7 +51,7 @@ foreach($posts as &$post)
}
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 = '';

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -85,22 +85,22 @@ else
}
$promotion = '';
if(fieldExist('promotion', 'players'))
if($db->hasColumn('players', 'promotion'))
$promotion = ',promotion';
$online = '';
if(fieldExist('online', 'players'))
if($db->hasColumn('players', 'online'))
$online = ',online';
$deleted = 'deleted';
if(fieldExist('deletion', 'players'))
if($db->hasColumn('players', 'deletion'))
$deleted = 'deletion';
$outfit_addons = false;
$outfit = '';
if($config['highscores_outfit']) {
$outfit = ', lookbody, lookfeet, lookhead, looklegs, looktype';
if(fieldExist('lookaddons', 'players')) {
if($db->hasColumn('players', 'lookaddons')) {
$outfit .= ', lookaddons';
$outfit_addons = true;
}
@@ -108,7 +108,7 @@ if($config['highscores_outfit']) {
$offset = $_page * $config['highscores_length'];
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(
POT::SKILL_FIST => 'skill_fist',
POT::SKILL_CLUB => 'skill_club',
@@ -119,10 +119,10 @@ if($skill <= POT::SKILL_LAST) { // skills
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
$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
{
@@ -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' .
' GROUP BY `player_id`' .
' ORDER BY value DESC' .
' LIMIT 101 OFFSET '.$offset);
' LIMIT 101 OFFSET '.$offset)->fetchAll();
}
else
{
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
$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';
}
}
@@ -174,13 +174,25 @@ $show_link_to_next_page = false;
$i = 0;
$online_exist = false;
if(fieldExist('online', 'players'))
if($db->hasColumn('players', 'online'))
$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)
{
if(!$online_exist) {
$query = $db->query('SELECT `player_id` FROM `players_online` WHERE `player_id` = ' . $player['id']);
$player['online'] = $query->rowCount() > 0;
if(isset($is_online)) {
$player['online'] = (isset($is_online[$player['id']]) ? 1 : 0);
}
if(++$i <= $config['highscores_length'])

View File

@@ -11,7 +11,7 @@
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Houses';
if(!fieldExist('name', 'houses')) {
if(!$db->hasColumn('houses', 'name')) {
echo 'Houses list is not available on this server.';
return;
}
@@ -87,7 +87,7 @@ $type = '';
$who = $guild->getName();
else
{
$player = $ots->createObject('Player');
$player = new OTS_Player();
$player->load($houseOwner);
if($player->isLoaded())
{
@@ -107,7 +107,7 @@ $type = '';
else
{
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
the search criteria and start a new search.<br/><br/>';
if(isset($config['lua']['houseCleanOld'])) {
@@ -134,7 +134,7 @@ $type = '';
echo '<br/>';
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'];
$orderby = '`name`';
@@ -147,9 +147,9 @@ $type = '';
}
$town = 'town';
if(fieldExist('town_id', 'houses'))
if($db->hasColumn('houses', 'town_id'))
$town = 'town_id';
else if(fieldExist('townid', 'houses'))
else if($db->hasColumn('houses', 'townid'))
$town = 'townid';
$whereby = '`' . $town . '` = ' .(int)$_POST['town'];
@@ -158,7 +158,7 @@ $type = '';
$whereby .= ' AND `owner` ' . ($state == 'free' ? '' : '!'). '= 0';
$type = isset($_POST['type']) ? $_POST['type'] : NULL;
if($type == 'guildhalls' && !fieldExist('guild', 'houses'))
if($type == 'guildhalls' && !$db->hasColumn('houses', 'guild'))
$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['rent'].' gold</TD>
<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->load($house['owner']);
@@ -285,7 +285,7 @@ $type = '';
</TD>
</TR>';
if(fieldExist('guild', 'houses')) {
if($db->hasColumn('houses', 'guild')) {
echo '
<TR BGCOLOR='.$config['darkborder'].'>
<TD VALIGN=top>

View File

@@ -13,9 +13,9 @@ $title = 'Last Kills';
$players_deaths_count = 0;
$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))
{
foreach($players_deaths as $death)

View File

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

View File

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

View File

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

View File

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