More config to settings: account_types, genders, highscores, admin

This commit is contained in:
slawkens
2023-07-20 20:24:07 +02:00
parent ac3a6c36d5
commit 978090c8ae
15 changed files with 198 additions and 143 deletions

View File

@@ -1,6 +1,8 @@
<?php
$deprecatedConfig = [
'date_timezone',
'genders',
'template',
'template_allow_change',
'vocations_amount',
@@ -21,6 +23,8 @@ $deprecatedConfig = [
'outfit_images_wrong_looktypes',
'item_images_url',
'account_country',
'highscores_groups_hidden',
'highscores_ids_hidden',
'online_record',
'online_vocations',
'online_vocations_images',

View File

@@ -1054,7 +1054,7 @@ function getTopPlayers($limit = 5) {
$deleted = 'deletion';
$is_tfs10 = $db->hasTable('players_online');
$players = $db->query('SELECT `id`, `name`, `level`, `vocation`, `experience`, `looktype`' . ($db->hasColumn('players', 'lookaddons') ? ', `lookaddons`' : '') . ', `lookhead`, `lookbody`, `looklegs`, `lookfeet`' . ($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`, `vocation`, `experience`, `looktype`' . ($db->hasColumn('players', 'lookaddons') ? ', `lookaddons`' : '') . ', `lookhead`, `lookbody`, `looklegs`, `lookfeet`' . ($is_tfs10 ? '' : ', `online`') . ' FROM `players` WHERE `group_id` < ' . setting('core.highscores_groups_hidden') . ' AND `id` NOT IN (' . implode(', ', setting('core.highscores_ids_hidden')) . ') AND `' . $deleted . '` = 0 AND `account_id` != 1 ORDER BY `experience` DESC LIMIT ' . (int)$limit)->fetchAll();
if($is_tfs10) {
foreach($players as &$player) {

View File

@@ -22,7 +22,6 @@ if(config('env') === 'dev') {
require SYSTEM . 'exception.php';
}
date_default_timezone_set($config['date_timezone']);
// take care of trailing slash at the end
if($config['server_path'][strlen($config['server_path']) - 1] !== '/')
$config['server_path'] .= '/';
@@ -119,11 +118,6 @@ if(!isset($foundValue)) {
$config['data_path'] = $foundValue;
unset($foundValue);
// new config values for compatibility
if(!isset($config['highscores_ids_hidden']) || count($config['highscores_ids_hidden']) == 0) {
$config['highscores_ids_hidden'] = array(0);
}
$config['account_create_character_create'] = config('account_create_character_create') && (!setting('core.mail_enabled') || !config('account_mail_verify'));
// POT

View File

@@ -239,14 +239,14 @@ class CreateCharacter
}
if($db->hasTable('player_skills')) {
for($i=0; $i<7; $i++) {
for($skill = POT::SKILL_FIRST; $skill <= POT::SKILL_LAST; $skill++) {
$value = 10;
if (config('use_character_sample_skills')) {
$value = $char_to_copy->getSkill($i);
$value = $char_to_copy->getSkill($skill);
}
$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` = ' . $skill);
if($skillExists->rowCount() <= 0) {
$db->query('INSERT INTO `player_skills` (`player_id`, `skillid`, `value`, `count`) VALUES ('.$player->getId().', '.$i.', ' . $value . ', 0)');
$db->query('INSERT INTO `player_skills` (`player_id`, `skillid`, `value`, `count`) VALUES ('.$player->getId().', '.$skill.', ' . $value . ', 0)');
}
}
}

View File

@@ -1,47 +1,15 @@
<?php
if(!isset($database_migration_20)) {
databaseMigration20();
$query = $db->query("SELECT `id` FROM `players` WHERE (`name` = " . $db->quote("Rook Sample") . " OR `name` = " . $db->quote("Sorcerer Sample") . " OR `name` = " . $db->quote("Druid Sample") . " OR `name` = " . $db->quote("Paladin Sample") . " OR `name` = " . $db->quote("Knight Sample") . " OR `name` = " . $db->quote("Account Manager") . ") ORDER BY `id`;");
$highscores_ignored_ids = array();
if($query->rowCount() > 0) {
foreach($query->fetchAll() as $result)
$highscores_ignored_ids[] = $result['id'];
}
else {
$highscores_ignored_ids[] = 0;
}
function databaseMigration20(&$content = '') {
global $db;
$config_file = BASE . 'config.local.php';
if(!is_writable($config_file)) { // we can't do anything, just ignore
return false;
}
$content_of_file = trim(file_get_contents($config_file));
if(strpos($content_of_file, 'highscores_ids_hidden') !== false) { // already present
return true;
}
$query = $db->query("SELECT `id` FROM `players` WHERE (`name` = " . $db->quote("Rook Sample") . " OR `name` = " . $db->quote("Sorcerer Sample") . " OR `name` = " . $db->quote("Druid Sample") . " OR `name` = " . $db->quote("Paladin Sample") . " OR `name` = " . $db->quote("Knight Sample") . " OR `name` = " . $db->quote("Account Manager") . ") ORDER BY `id`;");
$highscores_ignored_ids = array();
if($query->rowCount() > 0) {
foreach($query->fetchAll() as $result)
$highscores_ignored_ids[] = $result['id'];
}
else {
$highscores_ignored_ids[] = 0;
}
$php_on_end = substr($content_of_file, -2, 2) == '?>';
$content = PHP_EOL;
if($php_on_end) {
$content .= '<?php';
}
$content .= PHP_EOL;
$content .= '$config[\'highscores_ids_hidden\'] = array(' . implode(', ', $highscores_ignored_ids) . ');';
$content .= PHP_EOL;
if($php_on_end) {
$content .= '?>';
}
file_put_contents($config_file, $content, FILE_APPEND);
return true;
}
$settings = Settings::getInstance();
$settings->updateInDatabase('core', 'highscores_ids_hidden', implode(', ', $highscores_ignored_ids));

View File

@@ -11,8 +11,8 @@
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Highscores';
$configHighscoresCountryBox = config('highscores_country_box');
if(config('account_country') && $configHighscoresCountryBox)
$settingHighscoresCountryBox = setting('core.highscores_country_box');
if(config('account_country') && $settingHighscoresCountryBox)
require SYSTEM . 'countries.conf.php';
$list = $_GET['list'] ?? 'experience';
@@ -25,11 +25,11 @@ if(!is_numeric($page) || $page < 1 || $page > PHP_INT_MAX) {
$add_sql = '';
$configHighscoresVocationBox = config('highscores_vocation_box');
$settingHighscoresVocationBox = setting('core.highscores_vocation_box');
$configVocations = config('vocations');
$configVocationsAmount = config('vocations_amount');
if($configHighscoresVocationBox && $vocation !== 'all')
if($settingHighscoresVocationBox && $vocation !== 'all')
{
foreach($configVocations as $id => $name) {
if(strtolower($name) == $vocation) {
@@ -99,12 +99,12 @@ else
break;
case 'frags':
if(config('highscores_frags'))
if(setting('core.highscores_frags'))
$skill = SKILL_FRAGS;
break;
case 'balance':
if(config('highscores_balance'))
if(setting('core.highscores_balance'))
$skill = SKILL_BALANCE;
break;
}
@@ -125,9 +125,9 @@ if($db->hasColumn('players', 'deletion'))
$outfit_addons = false;
$outfit = '';
$configHighscoresOutfit = config('highscores_outfit');
$settingHighscoresOutfit = setting('core.highscores_outfit');
if($configHighscoresOutfit) {
if($settingHighscoresOutfit) {
$outfit = ', lookbody, lookfeet, lookhead, looklegs, looktype';
if($db->hasColumn('players', 'lookaddons')) {
$outfit .= ', lookaddons';
@@ -135,7 +135,7 @@ if($configHighscoresOutfit) {
}
}
$configHighscoresPerPage = config('highscores_per_page');
$configHighscoresPerPage = setting('core.highscores_per_page');
$limit = $configHighscoresPerPage + 1;
$needReCache = true;
@@ -164,15 +164,15 @@ if (!isset($highscores) || empty($highscores)) {
POT::SKILL_FISH => 'skill_fishing',
);
$highscores = $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 ' . $limit . ' OFFSET ' . $offset)->fetchAll();
$highscores = $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(', ', setting('core.highscores_ids_hidden')) . ') AND players.' . $deleted . ' = 0 AND players.group_id < ' . setting('core.highscores_groups_hidden') . ' ' . $add_sql . ' AND accounts.id = players.account_id ORDER BY ' . $skill_ids[$skill] . ' DESC LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
} else
$highscores = $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 ' . $limit . ' OFFSET ' . $offset)->fetchAll();
$highscores = $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(', ', setting('core.highscores_ids_hidden')) . ') AND players.' . $deleted . ' = 0 AND players.group_id < ' . setting('core.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 ' . $limit . ' OFFSET ' . $offset)->fetchAll();
} else if ($skill == SKILL_FRAGS) // frags
{
if ($db->hasTable('player_killers')) {
$highscores = $db->query('SELECT accounts.country, players.id, players.name' . $online . ',level, vocation' . $promotion . $outfit . ', COUNT(`player_killers`.`player_id`) as value' .
' FROM `accounts`, `players`, `player_killers` ' .
' 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(', ', setting('core.highscores_ids_hidden')) . ') AND players.' . $deleted . ' = 0 AND players.group_id < ' . setting('core.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 ' . $limit . ' OFFSET ' . $offset)->fetchAll();
@@ -183,9 +183,9 @@ if (!isset($highscores) || empty($highscores)) {
FROM `players` p
LEFT JOIN `accounts` a ON `a`.`id` = `p`.`account_id`
LEFT JOIN `player_deaths` pd ON `pd`.`killed_by` = `p`.`name`
WHERE `p`.id NOT IN (' . implode(', ', config('highscores_ids_hidden')) . ')
WHERE `p`.id NOT IN (' . implode(', ', setting('core.highscores_ids_hidden')) . ')
AND `p`.' . $deleted . ' = 0
AND `p`.group_id < ' . config('highscores_groups_hidden') . ' ' . $add_sql . '
AND `p`.group_id < ' . setting('core.highscores_groups_hidden') . ' ' . $add_sql . '
AND `pd`.`unjustified` = 1
GROUP BY `killed_by`
ORDER BY value DESC
@@ -193,19 +193,19 @@ if (!isset($highscores) || empty($highscores)) {
}
} else if ($skill == SKILL_BALANCE) // balance
{
$highscores = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',level,balance as value,vocation' . $promotion . $outfit . ' 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 value DESC LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
$highscores = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',level,balance as value,vocation' . $promotion . $outfit . ' FROM accounts,players WHERE players.id NOT IN (' . implode(', ', setting('core.highscores_ids_hidden')) . ') AND players.' . $deleted . ' = 0 AND players.group_id < ' . setting('core.highscores_groups_hidden') . ' ' . $add_sql . ' AND accounts.id = players.account_id ORDER BY value DESC LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
} else {
if ($skill == POT::SKILL__MAGLEVEL) {
$highscores = $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 ' . $limit . ' OFFSET ' . $offset)->fetchAll();
$highscores = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',maglevel,level,vocation' . $promotion . $outfit . ' FROM accounts, players WHERE players.id NOT IN (' . implode(', ', setting('core.highscores_ids_hidden')) . ') AND players.' . $deleted . ' = 0 ' . $add_sql . ' AND players.group_id < ' . setting('core.highscores_groups_hidden') . ' AND accounts.id = players.account_id ORDER BY maglevel DESC, manaspent DESC LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
} else { // level
$highscores = $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 ' . $limit . ' OFFSET ' . $offset)->fetchAll();
$highscores = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',level,experience,vocation' . $promotion . $outfit . ' FROM accounts, players WHERE players.id NOT IN (' . implode(', ', setting('core.highscores_ids_hidden')) . ') AND players.' . $deleted . ' = 0 ' . $add_sql . ' AND players.group_id < ' . setting('core.highscores_groups_hidden') . ' AND accounts.id = players.account_id ORDER BY level DESC, experience DESC LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
$list = 'experience';
}
}
}
if ($cache->enabled() && $needReCache) {
$cache->set($cacheKey, serialize($highscores), config('highscores_cache_ttl') * 60);
$cache->set($cacheKey, serialize($highscores), setting('core.highscores_cache_ttl') * 60);
}
$online_exist = false;
@@ -227,7 +227,7 @@ if($db->hasTable('players_online') && count($players) > 0) {
$show_link_to_next_page = false;
$i = 0;
$configHighscoresVocation = config('highscores_vocation');
$settingHighscoresVocation = setting('core.highscores_vocation');
foreach($highscores as $id => &$player)
{
@@ -248,7 +248,7 @@ foreach($highscores as $id => &$player)
$player['experience'] = number_format($player['experience']);
}
if($configHighscoresVocation) {
if($settingHighscoresVocation) {
if(isset($player['promotion'])) {
if((int)$player['promotion'] > 0) {
$player['vocation'] += ($player['promotion'] * $configVocationsAmount);
@@ -266,7 +266,7 @@ foreach($highscores as $id => &$player)
$player['link'] = getPlayerLink($player['name'], false);
$player['flag'] = getFlagImage($player['country']);
if($configHighscoresOutfit) {
if($settingHighscoresOutfit) {
$player['outfit'] = '<img style="position:absolute;margin-top:' . (in_array($player['looktype'], config('outfit_images_wrong_looktypes')) ? '-15px;margin-left:5px' : '-45px;margin-left:-25px') . ';" src="' . config('outfit_images_url') . '?id=' . $player['looktype'] . ($outfit_addons ? '&addons=' . $player['lookaddons'] : '') . '&head=' . $player['lookhead'] . '&body=' . $player['lookbody'] . '&legs=' . $player['looklegs'] . '&feet=' . $player['lookfeet'] . '" alt="" />';
}
$player['rank'] = $offset + $i;
@@ -302,10 +302,10 @@ $types = array(
'fishing' => 'Fishing',
);
if(config('highscores_frags')) {
if(setting('core.highscores_frags')) {
$types['frags'] = 'Frags';
}
if(config('highscores_balance'))
if(setting('core.highscores_balance'))
$types['balance'] = 'Balance';
/** @var Twig\Environment $twig */

View File

@@ -25,6 +25,28 @@ return [
'desc' => 'Timezone of the server, more info at http://php.net/manual/en/timezones.php',
'default' => 'Europe/Warsaw',
],
'genders' => [
'name' => 'Genders (aka sex)',
'type' => 'textarea',
'desc' => 'Separated with comma',
'default' => 'Female, Male',
'callbacks' => [
'get' => function ($value) {
return array_map('trim', explode(',', $value));
},
],
],
'account_types' => [
'name' => 'Account Types',
'type' => 'textarea',
'desc' => 'Separated with comma, you may need to adjust this for older tfs versions by removing Community Manager',
'default' => 'None, Normal, Tutor, Senior Tutor, Gamemaster, Community Manager, God',
'callbacks' => [
'get' => function ($value) {
return array_map('trim', explode(',', $value));
},
],
],
[
'type' => 'section',
'title' => 'Template'
@@ -605,6 +627,77 @@ Sent by MyAAC,<br/>
'forum', '=', 'site',
],
],
[
'type' => 'section',
'title' => 'Highscores Page',
],
'highscores_per_page' => [
'name' => 'Highscores per Page',
'type' => 'number',
'min' => 1,
'desc' => 'How many records per page on highscores',
'default' => 100,
],
'highscores_cache_ttl' => [
'name' => 'Highscores Cache TTL (in minutes)',
'type' => 'number',
'min' => 1,
'desc' => 'How often to update highscores from database in minutes (default 15 minutes). Too low may cause lags on website.',
'default' => 15,
],
'highscores_vocation_box' => [
'name' => 'Display Vocation Box',
'type' => 'boolean',
'desc' => 'show "Choose a vocation" box on the highscores (allowing peoples to sort highscores by vocation)?',
'default' => true,
],
'highscores_vocation' => [
'name' => 'Display Vocation',
'type' => 'boolean',
'desc' => 'Show player vocation under his nickname?',
'default' => true,
],
'highscores_frags' => [
'name' => 'Display Top Frags',
'type' => 'boolean',
'desc' => 'Show "Frags" tab (best fraggers on the server)?',
'default' => false,
],
'highscores_balance' => [
'name' => 'Display Balance',
'type' => 'boolean',
'desc' => 'Show "Balance" tab (richest players on the server)?',
'default' => false,
],
'highscores_outfit' => [
'name' => 'Display Player Outfit',
'type' => 'boolean',
'desc' => 'Show player outfit?',
'default' => true,
],
'highscores_country_box' => [ // not implemented yet
'name' => 'Display Country Box',
'type' => 'hidden',
'desc' => 'Show player outfit?',
'default' => false,
],
'highscores_groups_hidden' => [
'name' => 'Hidden Groups',
'type' => 'number',
'desc' => "This group id and higher won't be shown on highscores",
'default' => 3,
],
'highscores_ids_hidden' => [
'name' => 'Hidden IDs of players',
'type' => 'textarea',
'desc' => "this ids of players will be hidden on the highscores (should be ids of samples)",
'default' => '0',
'callbacks' => [
'get' => function ($value) {
return array_map('trim', explode(',', $value));
},
],
],
[
'type' => 'section',
'title' => 'Online Page'
@@ -685,10 +778,11 @@ Sent by MyAAC,<br/>
'title' => 'Bans Page'
],
'bans_per_page' => [
'name' => 'Display Players Record',
'type' => 'boolean',
'name' => 'Bans per Page',
'type' => 'number',
'min' => 1,
'default' => 20,
'desc' => '',
'default' => true,
],
[
'type' => 'section',
@@ -842,5 +936,36 @@ Sent by MyAAC,<br/>
'status_enabled', '=', 'true',
]
],
[
'type' => 'category',
'title' => 'Admin',
],
[
'type' => 'section',
'title' => 'Admin Panel'
],
'admin_plugins_manage_enable' => [
'name' => 'Enable Plugins Manage',
'type' => 'boolean',
'desc' => 'You can disable possibility to upload, enable/disable and uninstall plugins, for security',
'default' => true,
],
'admin_pages_php_enable' => [
'name' => 'Enable PHP Pages',
'type' => 'boolean',
'desc' => 'You can disable support for plain php pages in admin panel, for security.<br/>Existing pages still will be working, so you need to delete them manually',
'default' => false,
],
'admin_panel_modules' => [
'name' => 'Modules Enabled',
'type' => 'textarea',
'desc' => 'What modules will be shown on Admin Panel Dashboard page',
'default' => 'statistics,web_status,server_status,lastlogin,created,points,coins,balance',
'callbacks' => [
'get' => function ($value) {
return array_map('trim', explode(',', $value));
},
],
],
],
];