mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 09:19:22 +02:00

* New admin panel Pages: Options + Config [WIP] * Forgot the plugin example of options * Rename to settings.php * Add Settings Class * New myaac_settings table * Add $limit parameter to $db->select method * Add $member var annotation * Remove useless title_separator from config * Move $menus to menus.php Also fix active link when menu item has subpage * Settings [WIP] New Settings class New Plugins::load() method Move config.php to settings.php MyAAC Settings will have plugin_name = 'core' Add compat_config.php * Change options.php to settings.php * Change name to settings * Add Settings menu * Add Sections + Add setting($key) function Reorganisation * Add email + password fields as type * Update 33.php * add settings migration * php 8 compatibility * add missing hook * Add categories in tabs, move more settings, revert back getPluginSettings Categories and sections are now not numbered Remove example settings plugin * fix typo * Update .gitignore * Add 36th migration for settings table * Execute migrations just after db connect * Update plugins.php * [WIP] Some work on settings Add hidden settings New method: parse, to parse settings from array Move base html to twig template Remove vocation loading from .xml, instead use predefined voc names * Rename * Fix path * [WIP] More work on settings Move more config to settings (mainly mail_* + some other) Remove mail_admin, wasnt used anywhere Add return type to some functions Add Twig settings(key) function Possibility to save setting to db * Add min, max, step to number field option * Re-enable plugin if disabled and already installed * Add Settings menu, including all plugins with settings One change included in previous commit, due to missclick * Nothing important * Better boolean detection * More detailed error message in settings * Lets call it settings.name instead * Add new function: only_if, to hide fields when they are not enabled [WIP] Not fully finished yet * guild_management: show_if * Hide section title on show_if * Fix: check on page load if radio button is checked * Add: show_if - account_mail_verify * nothing important * Rename team_* variables + add to deprecated * Change variable name * Extract Settings:save function * Add settings.callbacks.get * Move forum config to settings * Move status config to settings * Remove whitespaces * More config to settings: account_types, genders, highscores, admin * Move signature config to settings * Move news config to settings * Rename variable * Save config.php in Settings Egg and hen problem solved :) * Test database connection on save settings -> prevents from making website unusable if connection is wrong * Test server_path -> same There is no config.php anymore, just config.local.php, which can be edited manually and also from admin panel * Remove configs from previous commit * Fix create account, if account_create_character_create is enabled * Add more deprecated configs * Add more info into comment * Update 5-database.php * Fix menu highlighting & opening * Update template.php * Enable script option * Reword email settings + move two new settings * add last_kills_limit + move shop * google_analytics_id * add mail_lost_account_interval * Create character blocked words (by @gpedro), just moved to settings * Fix google_analytics * create character name config moved to settings * Fix for install warning - min/max length * New create character checks configurable: block monsters & spells names * fixes * Improve character npc name check * New setting: donate_column + move donate config to settings * Add super fancy No Refresh saving with a toast * Add new possibility: to deny saving setting if condition is not met * Move database settings to separate category * Fix default value displaying * Add database_hash setting * add last_kills_limit to compat config * Move create character blocked names down * Every setting needs to have default * Move rest of config to settings Remove config.php completely Add new settings category: Game Fix account_login_by_email Min textarea size = 2 + adjusted automatically
323 lines
11 KiB
PHP
323 lines
11 KiB
PHP
<?php
|
|
/**
|
|
* Highscores
|
|
*
|
|
* @package MyAAC
|
|
* @author Gesior <jerzyskalski@wp.pl>
|
|
* @author Slawkens <slawkens@gmail.com>
|
|
* @copyright 2019 MyAAC
|
|
* @link https://my-aac.org
|
|
*/
|
|
defined('MYAAC') or die('Direct access not allowed!');
|
|
$title = 'Highscores';
|
|
|
|
$settingHighscoresCountryBox = setting('core.highscores_country_box');
|
|
if(config('account_country') && $settingHighscoresCountryBox)
|
|
require SYSTEM . 'countries.conf.php';
|
|
|
|
$list = $_GET['list'] ?? 'experience';
|
|
$page = $_GET['page'] ?? 1;
|
|
$vocation = $_GET['vocation'] ?? 'all';
|
|
|
|
if(!is_numeric($page) || $page < 1 || $page > PHP_INT_MAX) {
|
|
$page = 1;
|
|
}
|
|
|
|
$add_sql = '';
|
|
|
|
$settingHighscoresVocationBox = setting('core.highscores_vocation_box');
|
|
$configVocations = config('vocations');
|
|
$configVocationsAmount = config('vocations_amount');
|
|
|
|
if($settingHighscoresVocationBox && $vocation !== 'all')
|
|
{
|
|
foreach($configVocations as $id => $name) {
|
|
if(strtolower($name) == $vocation) {
|
|
$add_vocs = array($id);
|
|
|
|
$i = $id + $configVocationsAmount;
|
|
while(isset($configVocations[$i])) {
|
|
$add_vocs[] = $i;
|
|
$i += $configVocationsAmount;
|
|
}
|
|
|
|
$add_sql = 'AND `vocation` IN (' . implode(', ', $add_vocs) . ')';
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
const SKILL_FRAGS = -1;
|
|
const SKILL_BALANCE = -2;
|
|
|
|
$skill = POT::SKILL__LEVEL;
|
|
if(is_numeric($list))
|
|
{
|
|
$list = (int) $list;
|
|
if($list >= POT::SKILL_FIRST && $list <= POT::SKILL__LAST)
|
|
$skill = $list;
|
|
}
|
|
else
|
|
{
|
|
switch($list)
|
|
{
|
|
case 'fist':
|
|
$skill = POT::SKILL_FIST;
|
|
break;
|
|
|
|
case 'club':
|
|
$skill = POT::SKILL_CLUB;
|
|
break;
|
|
|
|
case 'sword':
|
|
$skill = POT::SKILL_SWORD;
|
|
break;
|
|
|
|
case 'axe':
|
|
$skill = POT::SKILL_AXE;
|
|
break;
|
|
|
|
case 'distance':
|
|
$skill = POT::SKILL_DIST;
|
|
break;
|
|
|
|
case 'shield':
|
|
$skill = POT::SKILL_SHIELD;
|
|
break;
|
|
|
|
case 'fishing':
|
|
$skill = POT::SKILL_FISH;
|
|
break;
|
|
|
|
case 'level':
|
|
case 'experience':
|
|
$skill = POT::SKILL_LEVEL;
|
|
break;
|
|
|
|
case 'magic':
|
|
$skill = POT::SKILL__MAGLEVEL;
|
|
break;
|
|
|
|
case 'frags':
|
|
if(setting('core.highscores_frags'))
|
|
$skill = SKILL_FRAGS;
|
|
break;
|
|
|
|
case 'balance':
|
|
if(setting('core.highscores_balance'))
|
|
$skill = SKILL_BALANCE;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$promotion = '';
|
|
if($db->hasColumn('players', 'promotion'))
|
|
$promotion = ',promotion';
|
|
|
|
$online = '';
|
|
if($db->hasColumn('players', 'online'))
|
|
$online = ',online';
|
|
|
|
$deleted = 'deleted';
|
|
if($db->hasColumn('players', 'deletion'))
|
|
$deleted = 'deletion';
|
|
|
|
$outfit_addons = false;
|
|
$outfit = '';
|
|
|
|
$settingHighscoresOutfit = setting('core.highscores_outfit');
|
|
|
|
if($settingHighscoresOutfit) {
|
|
$outfit = ', lookbody, lookfeet, lookhead, looklegs, looktype';
|
|
if($db->hasColumn('players', 'lookaddons')) {
|
|
$outfit .= ', lookaddons';
|
|
$outfit_addons = true;
|
|
}
|
|
}
|
|
|
|
$configHighscoresPerPage = setting('core.highscores_per_page');
|
|
$limit = $configHighscoresPerPage + 1;
|
|
|
|
$needReCache = true;
|
|
$cacheKey = 'highscores_' . $skill . '_' . $vocation . '_' . $page . '_' . $configHighscoresPerPage;
|
|
|
|
$cache = Cache::getInstance();
|
|
if ($cache->enabled()) {
|
|
$tmp = '';
|
|
if ($cache->fetch($cacheKey, $tmp)) {
|
|
$highscores = unserialize($tmp);
|
|
$needReCache = false;
|
|
}
|
|
}
|
|
|
|
$offset = ($page - 1) * $configHighscoresPerPage;
|
|
if (!isset($highscores) || empty($highscores)) {
|
|
if ($skill >= POT::SKILL_FIRST && $skill <= POT::SKILL_LAST) { // skills
|
|
if ($db->hasColumn('players', 'skill_fist')) {// tfs 1.0
|
|
$skill_ids = array(
|
|
POT::SKILL_FIST => 'skill_fist',
|
|
POT::SKILL_CLUB => 'skill_club',
|
|
POT::SKILL_SWORD => 'skill_sword',
|
|
POT::SKILL_AXE => 'skill_axe',
|
|
POT::SKILL_DIST => 'skill_dist',
|
|
POT::SKILL_SHIELD => 'skill_shielding',
|
|
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(', ', 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(', ', 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(', ', 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();
|
|
} else {
|
|
$db->query("SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));");
|
|
|
|
$highscores = $db->query('SELECT `a`.country, `p`.id, `p`.name' . $online . ',`p`.level, vocation' . $promotion . $outfit . ', COUNT(`pd`.`killed_by`) as value
|
|
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(', ', setting('core.highscores_ids_hidden')) . ')
|
|
AND `p`.' . $deleted . ' = 0
|
|
AND `p`.group_id < ' . setting('core.highscores_groups_hidden') . ' ' . $add_sql . '
|
|
AND `pd`.`unjustified` = 1
|
|
GROUP BY `killed_by`
|
|
ORDER BY value DESC
|
|
LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
|
|
}
|
|
} 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(', ', 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(', ', 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(', ', 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), setting('core.highscores_cache_ttl') * 60);
|
|
}
|
|
|
|
$online_exist = false;
|
|
if($db->hasColumn('players', 'online'))
|
|
$online_exist = true;
|
|
|
|
$players = array();
|
|
foreach($highscores as $player) {
|
|
$players[] = $player['id'];
|
|
}
|
|
|
|
if($db->hasTable('players_online') && count($players) > 0) {
|
|
$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;
|
|
}
|
|
}
|
|
|
|
$show_link_to_next_page = false;
|
|
$i = 0;
|
|
|
|
$settingHighscoresVocation = setting('core.highscores_vocation');
|
|
|
|
foreach($highscores as $id => &$player)
|
|
{
|
|
if(isset($is_online)) {
|
|
$player['online'] = (isset($is_online[$player['id']]) ? 1 : 0);
|
|
} else {
|
|
if(!isset($player['online'])) {
|
|
$player['online'] = 0;
|
|
}
|
|
}
|
|
|
|
if(++$i <= $configHighscoresPerPage)
|
|
{
|
|
if($skill == POT::SKILL__MAGIC)
|
|
$player['value'] = $player['maglevel'];
|
|
else if($skill == POT::SKILL__LEVEL) {
|
|
$player['value'] = $player['level'];
|
|
$player['experience'] = number_format($player['experience']);
|
|
}
|
|
|
|
if($settingHighscoresVocation) {
|
|
if(isset($player['promotion'])) {
|
|
if((int)$player['promotion'] > 0) {
|
|
$player['vocation'] += ($player['promotion'] * $configVocationsAmount);
|
|
}
|
|
}
|
|
|
|
$tmp = 'Unknown';
|
|
if(isset($configVocations[$player['vocation']])) {
|
|
$tmp = $configVocations[$player['vocation']];
|
|
}
|
|
|
|
$player['vocation'] = $tmp;
|
|
}
|
|
|
|
|
|
$player['link'] = getPlayerLink($player['name'], false);
|
|
$player['flag'] = getFlagImage($player['country']);
|
|
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;
|
|
}
|
|
else {
|
|
unset($highscores[$id]);
|
|
$show_link_to_next_page = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//link to previous page if actual page is not first
|
|
$linkPreviousPage = '';
|
|
if($page > 1) {
|
|
$linkPreviousPage = getLink('highscores') . '/' . $list . ($vocation !== 'all' ? '/' . $vocation : '') . '/' . ($page - 1);
|
|
}
|
|
|
|
//link to next page if any result will be on next page
|
|
$linkNextPage = '';
|
|
if($show_link_to_next_page) {
|
|
$linkNextPage = getLink('highscores') . '/' . $list . ($vocation !== 'all' ? '/' . $vocation : '') . '/' . ($page + 1);
|
|
}
|
|
|
|
$types = array(
|
|
'experience' => 'Experience',
|
|
'magic' => 'Magic',
|
|
'shield' => 'Shielding',
|
|
'distance' => 'Distance',
|
|
'club' => 'Club',
|
|
'sword' => 'Sword',
|
|
'axe' => 'Axe',
|
|
'fist' => 'Fist',
|
|
'fishing' => 'Fishing',
|
|
);
|
|
|
|
if(setting('core.highscores_frags')) {
|
|
$types['frags'] = 'Frags';
|
|
}
|
|
if(setting('core.highscores_balance'))
|
|
$types['balance'] = 'Balance';
|
|
|
|
/** @var Twig\Environment $twig */
|
|
$twig->display('highscores.html.twig', [
|
|
'highscores' => $highscores,
|
|
'list' => $list,
|
|
'skill' => $skill,
|
|
'skillName' => ($skill == SKILL_FRAGS ? 'Frags' : ($skill == SKILL_BALANCE ? 'Balance' : getSkillName($skill))),
|
|
'levelName' => ($skill != SKILL_FRAGS && $skill != SKILL_BALANCE ? 'Level' : ($skill == SKILL_BALANCE ? 'Balance' : 'Frags')),
|
|
'vocation' => $vocation !== 'all' ? $vocation : null,
|
|
'types' => $types,
|
|
'linkPreviousPage' => $linkPreviousPage,
|
|
'linkNextPage' => $linkNextPage,
|
|
]);
|