Skip to content

Commit

Permalink
Fixed Issue #124
Browse files Browse the repository at this point in the history
Also created new method isRankVisible to handle better if the rank can
be show or not.
  • Loading branch information
LucasKovacs committed May 21, 2016
1 parent 93f69ac commit 42cbd1c
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 60 deletions.
1 change: 1 addition & 0 deletions src/xgp3.0.0/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [#120] Fixed empty alliance tag for alliances administration on the admin cp, other issues were fixed too (Thanks JonaMiX).-
- [#122] Fixed notice in the fleet shortcuts page (Thanks JonaMiX).-
- [#123] Fixed notice on the fleet 2 page when there are shortcuts available (Thanks JonaMiX).-
- [#124] Fixed issue where the rank was being shown in the search and galaxy when it was disable for some levels.-
- [#000] Added missing language line on the home page title.-
- [#000] Fixed misplaced language line on the home page for login and register.-
- [#000] Minor improvement over registration page. Redirection from index.php?page=reg to index.php?page=register removed, default is now "register".-
Expand Down
99 changes: 51 additions & 48 deletions src/xgp3.0.0/upload/application/controllers/game/galaxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,54 +130,57 @@ private function build_page()
}
// END FIX BY alivan

$this->_galaxy_data = parent::$db->query("SELECT
(SELECT CONCAT ( GROUP_CONCAT(buddy_receiver) , ',' , GROUP_CONCAT(buddy_sender) ) AS buddys FROM " . BUDDY . " AS b WHERE (b.buddy_receiver = u.user_id OR b.buddy_sender = u.user_id ) ) AS buddys,
p.planet_debris_metal AS metal,
p.planet_debris_crystal AS crystal,
p.`planet_id` AS id_planet,
p.planet_galaxy,
p.planet_system,
p.planet_planet,
p.planet_type,
p.planet_destroyed,
p.planet_name,
p.planet_image,
p.planet_last_update,
p.planet_user_id,
u.user_id,
u.user_ally_id,
u.user_banned,
se.setting_vacations_status,
u.user_onlinetime,
u.user_name,
s.user_statistic_total_rank,
s.user_statistic_total_points,
m.planet_id AS id_luna,
m.planet_diameter,
m.planet_temp_min,
m.planet_destroyed AS destroyed_moon,
m.planet_name AS name_moon,
a.alliance_name,
a.alliance_tag,
a.alliance_web,
(SELECT COUNT(user_id) AS `ally_members` FROM `" . USERS . "` WHERE `user_ally_id` = a.`alliance_id`) AS `ally_members`
FROM " . PLANETS . " AS p
INNER JOIN " . USERS . " AS u ON p.planet_user_id = u.user_id
INNER JOIN " . SETTINGS . " AS se ON se.setting_user_id = u.user_id
INNER JOIN " . USERS_STATISTICS . " AS s ON s.user_statistic_user_id = u.user_id
LEFT JOIN " . ALLIANCE . " AS a ON a.alliance_id = u.user_ally_id
LEFT JOIN " . PLANETS . " AS m ON m.planet_id = (SELECT mp.`planet_id`
FROM " . PLANETS . " AS mp
WHERE (mp.planet_galaxy=p.planet_galaxy AND
mp.planet_system=p.planet_system AND
mp.planet_planet=p.planet_planet AND
mp.planet_type=3))
WHERE (p.planet_galaxy='" . $this->_galaxy . "' AND
p.planet_system='" . $this->_system . "' AND
p.planet_type='1' AND
(p.planet_planet>'0' AND
p.planet_planet<='" . MAX_PLANET_IN_SYSTEM . "'))
ORDER BY p.planet_planet;");
$this->_galaxy_data = parent::$db->query(
"SELECT
(SELECT CONCAT ( GROUP_CONCAT(buddy_receiver) , ',' , GROUP_CONCAT(buddy_sender) ) AS buddys FROM " . BUDDY . " AS b WHERE (b.buddy_receiver = u.user_id OR b.buddy_sender = u.user_id ) ) AS buddys,
p.planet_debris_metal AS metal,
p.planet_debris_crystal AS crystal,
p.`planet_id` AS id_planet,
p.planet_galaxy,
p.planet_system,
p.planet_planet,
p.planet_type,
p.planet_destroyed,
p.planet_name,
p.planet_image,
p.planet_last_update,
p.planet_user_id,
u.user_id,
u.user_ally_id,
u.user_banned,
se.setting_vacations_status,
u.user_onlinetime,
u.user_name,
u.user_authlevel,
s.user_statistic_total_rank,
s.user_statistic_total_points,
m.planet_id AS id_luna,
m.planet_diameter,
m.planet_temp_min,
m.planet_destroyed AS destroyed_moon,
m.planet_name AS name_moon,
a.alliance_name,
a.alliance_tag,
a.alliance_web,
(SELECT COUNT(user_id) AS `ally_members` FROM `" . USERS . "` WHERE `user_ally_id` = a.`alliance_id`) AS `ally_members`
FROM " . PLANETS . " AS p
INNER JOIN " . USERS . " AS u ON p.planet_user_id = u.user_id
INNER JOIN " . SETTINGS . " AS se ON se.setting_user_id = u.user_id
INNER JOIN " . USERS_STATISTICS . " AS s ON s.user_statistic_user_id = u.user_id
LEFT JOIN " . ALLIANCE . " AS a ON a.alliance_id = u.user_ally_id
LEFT JOIN " . PLANETS . " AS m ON m.planet_id = (SELECT mp.`planet_id`
FROM " . PLANETS . " AS mp
WHERE (mp.planet_galaxy=p.planet_galaxy AND
mp.planet_system=p.planet_system AND
mp.planet_planet=p.planet_planet AND
mp.planet_type=3))
WHERE (p.planet_galaxy='" . $this->_galaxy . "' AND
p.planet_system='" . $this->_system . "' AND
p.planet_type='1' AND
(p.planet_planet>'0' AND
p.planet_planet<='" . MAX_PLANET_IN_SYSTEM . "'))
ORDER BY p.planet_planet;"
);

$parse = $this->_lang;
$parse['js_path'] = XGP_ROOT . JS_PATH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Overview extends XGPCore
private $_lang;
private $_current_user;
private $_current_planet;
private $_noob;

/**
* __construct()
Expand All @@ -55,6 +56,7 @@ public function __construct()
$this->_lang = parent::$lang;
$this->_current_user = parent::$users->getUserData();
$this->_current_planet = parent::$users->getPlanetData();
$this->_noob = FunctionsLib::loadLibrary('NoobsProtectionLib');

$this->build_page();
}
Expand Down Expand Up @@ -421,7 +423,7 @@ private function get_user_rank()
$user_rank = '-';
$total_rank = $this->_current_user['user_statistic_total_rank'] == '' ? $this->_current_planet['stats_users'] : $this->_current_user['user_statistic_total_rank'];

if ($this->_current_user['user_authlevel'] <= FunctionsLib::readConfig('stat_admin_level')) {
if ($this->_noob->isRankVisible($this->_current_user['user_authlevel'])) {
$user_rank = FormatLib::prettyNumber($this->_current_user['user_statistic_total_points']) . " (" . $this->_lang['ov_place'] . ' ' . FunctionsLib::setUrl('game.php?page=statistics&range=' . $total_rank, $total_rank, $total_rank) . ' ' . $this->_lang['ov_of'] . ' ' . $this->_current_planet['stats_users'] . ")";
}

Expand Down
37 changes: 29 additions & 8 deletions src/xgp3.0.0/upload/application/controllers/game/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Search extends XGPCore

private $_current_user;
private $_lang;
private $_noob;

/**
* __construct()
Expand All @@ -50,6 +51,7 @@ public function __construct()

$this->_lang = parent::$lang;
$this->_current_user = parent::$users->getUserData();
$this->_noob = FunctionsLib::loadLibrary('NoobsProtectionLib');

$this->build_page();
}
Expand All @@ -71,18 +73,18 @@ public function __destruct()
*/
private function build_page()
{
$parse = $this->_lang;
$type = isset($_POST['type']) ? $_POST['type'] : '';
$searchtext = parent::$db->escapeValue(isset($_POST['searchtext']) ? $_POST['searchtext'] : '' );
$search_results = '';

$parse = $this->_lang;
$type = isset($_POST['type']) ? $_POST['type'] : '';
$searchtext = parent::$db->escapeValue(isset($_POST['searchtext']) ? $_POST['searchtext'] : '' );
$search_results = '';
if ($_POST) {
switch ($type) {
case 'playername':
default:
$table = parent::$page->getTemplate('search/search_user_table');
$row = parent::$page->getTemplate('search/search_user_row');
$search = parent::$db->query("SELECT u.user_id AS user_id, u.user_name, p.planet_name, p.planet_galaxy, p.planet_system, p.planet_planet, s.user_statistic_total_rank AS rank, a.alliance_id, a.alliance_name
$search = parent::$db->query("SELECT u.user_id AS user_id, u.user_name, u.user_authlevel, p.planet_name, p.planet_galaxy, p.planet_system, p.planet_planet, s.user_statistic_total_rank AS rank, a.alliance_id, a.alliance_name
FROM " . USERS . " AS u
INNER JOIN " . USERS_STATISTICS . " AS s ON s.user_statistic_user_id = u.user_id
INNER JOIN " . PLANETS . " AS p ON p.`planet_id` = u.user_home_planet_id
Expand All @@ -92,7 +94,7 @@ private function build_page()
case 'planetname':
$table = parent::$page->getTemplate('search/search_user_table');
$row = parent::$page->getTemplate('search/search_user_row');
$search = parent::$db->query("SELECT u.user_id AS user_id, u.user_name, p.planet_name, p.planet_galaxy, p.planet_system, p.planet_planet, s.user_statistic_total_rank AS rank, a.alliance_id, a.alliance_name
$search = parent::$db->query("SELECT u.user_id AS user_id, u.user_name, u.user_authlevel, p.planet_name, p.planet_galaxy, p.planet_system, p.planet_planet, s.user_statistic_total_rank AS rank, a.alliance_id, a.alliance_name
FROM " . USERS . " AS u
INNER JOIN " . USERS_STATISTICS . " AS s ON s.user_statistic_user_id = u.user_id
INNER JOIN " . PLANETS . " AS p ON p.`planet_id` = u.user_home_planet_id
Expand Down Expand Up @@ -141,7 +143,7 @@ private function build_page()
$s['planet_name'] = $s['planet_name'];
$s['username'] = $s['user_name'];
$s['alliance_name'] = ($s['alliance_name'] != '') ? "<a href=\"game.php?page=alliance&mode=ainfo&allyid={$s['alliance_id']}\">{$s['alliance_name']}</a>" : '';
$s['position'] = "<a href=\"game.php?page=statistics&start=" . $s['rank'] . "\">" . $s['rank'] . "</a>";
$s['position'] = $this->setPosition($s['rank'], $s['user_authlevel']);
$s['coordinated'] = "{$s['planet_galaxy']}:{$s['planet_system']}:{$s['planet_planet']}";
$result_list .= parent::$page->parseTemplate($row, $s);
} elseif ($type == 'allytag' or $type == 'allyname') {
Expand All @@ -166,6 +168,25 @@ private function build_page()

parent::$page->display(parent::$page->parseTemplate(parent::$page->getTemplate('search/search_body'), $parse));
}

/**
* Set the user position or not based on its level
*
* @param int $user_rank User rank
* @param int $user_level User level
*
* @return string
*/
private function setPosition($user_rank, $user_level)
{
if ($this->_noob->isRankVisible($user_level)) {

return '<a href="game.php?page=statistics&start=' . $user_rank . '">' . $user_rank . '</a>';
} else {

return '-';
}
}
}

/* end of search.php */
5 changes: 5 additions & 0 deletions src/xgp3.0.0/upload/application/libraries/GalaxyLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ private function usernameBlock()
$parse['username'] = $this->row_data['user_name'];
$parse['current_rank'] = $this->row_data['user_statistic_total_rank'];
$parse['start'] = (floor($this->row_data['user_statistic_total_rank'] / 100) * 100) + 1;

if (!$this->noob->isRankVisible($this->row_data['user_authlevel'])) {
$parse['current_rank'] = '-';
$parse['start'] = 0;
}

if ($this->row_data['user_id'] != $this->current_user['user_id']) {

Expand Down
26 changes: 23 additions & 3 deletions src/xgp3.0.0/upload/application/libraries/NoobsProtectionLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ class NoobsProtectionLib extends XGPCore
private $protection;
private $protectiontime;
private $protectionmulti;
private $allowed_level;

/**
* __construct()
*/
public function __construct()
{
$this->protection = FunctionsLib::readConfig('noobprotection');
$this->protectiontime = FunctionsLib::readConfig('noobprotectiontime');
$this->protectionmulti = FunctionsLib::readConfig('noobprotectionmulti');
$configs = FunctionsLib::readConfig('', true);

$this->protection = $configs['noobprotection'];
$this->protectiontime = $configs['noobprotectiontime'];
$this->protectionmulti = $configs['noobprotectionmulti'];
$this->allowed_level = $configs['stat_admin_level'];
}

/**
Expand Down Expand Up @@ -125,6 +129,22 @@ public function returnPoints($current_user_id, $other_user_id)
);
return $user_points;
}

/**
* Determines if the rank can be shown or not
*
* @param int $user_auth_level User authorization level (0-3)
*
* @return boolean
*/
public function isRankVisible($user_auth_level)
{
if ($user_auth_level <= $this->allowed_level) {
return true;
}

return false;
}
}

/* end of NoobsProtectionLib.php */

0 comments on commit 42cbd1c

Please sign in to comment.