Skip to content

Commit

Permalink
Merge pull request #153 from leojonathanoh/enhancement/asp-add-config…
Browse files Browse the repository at this point in the history
…uration-options-to-customize-rankings

Enhancement (ASP): Add configuration options to customize rankings
  • Loading branch information
leojonathanoh authored Jan 28, 2024
2 parents 81399b8 + 9224751 commit ee08343
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 37 deletions.
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ services:
- DB_PASS=admin
- ADMIN_HOSTS=127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 # Limit admins to private IPs
- GAME_HOSTS=127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 # Limit gameservers to private IPs
# - BFHQ_HIDE_BOTS=false
# - BFHQ_HIDE_HIDDEN_PLAYERS=false
# - BFHQ_HIDE_PIDS_START=1
# - BFHQ_HIDE_PIDS_END=999999999
- DEBUG_LVL=2
volumes:
- ./src/ASP:/src/ASP
Expand Down
37 changes: 36 additions & 1 deletion src/ASP/frontend/views/editconfig.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,41 @@
</div>
</div>

<!-- BFHQ -->
<h3 style="margin-left: 50px; margin-top: 35px;">BFHQ Options</h3>
<div class="mws-form-row">
<label>Hide bot stats:</label>
<div class="mws-form-item small">
<select name="cfg__bfhq_hide_bots" title="Hide bots stats from BFHQ ranking?">
<option value="true" <?php if('{config.bfhq_hide_bots}' == true) echo 'selected="selected"'; ?>>Yes</option>
<option value="false" <?php if('{config.bfhq_hide_bots}' == false) echo 'selected="selected"'; ?>>No</option>
</select>
</div>
</div>
<div class="mws-form-row">
<label>Hide hidden players:</label>
<div class="mws-form-item small">
<select name="cfg__bfhq_hide_hidden_players" title="Hide hidden players from BFHQ ranking?">
<option value="true" <?php if('{config.bfhq_hide_hidden_players}' == true) echo 'selected="selected"'; ?>>Yes</option>
<option value="false" <?php if('{config.bfhq_hide_hidden_players}' == false) echo 'selected="selected"'; ?>>No</option>
</select>
</div>
</div>
<div class="mws-form-row">
<label>Hide PIDS (lower limit):</label>
<div class="mws-form-item small">
<input name="cfg__bfhq_hide_pids_start" type="text" class="mws-textinput required" value="{config.bfhq_hide_pids_start}" title="Lower limit of PIDs to hide from BFHQ ranking."
/>
</div>
</div>
<div class="mws-form-row">
<label>Hide PIDS (upper limit):</label>
<div class="mws-form-item small">
<input name="cfg__bfhq_hide_pids_end" type="text" class="mws-textinput required" value="{config.bfhq_hide_pids_end}" title="Upper limit of PIDs to hide from BFHQ ranking."
/>
</div>
</div>

<!-- Global Config -->
<h3 style="margin-left: 50px; margin-top: 35px;">Global Game Server Configuration</h3>
<div class="mws-form-row">
Expand Down Expand Up @@ -269,4 +304,4 @@
</div>
</form>
</div>
</div>
</div>
74 changes: 44 additions & 30 deletions src/ASP/getleaderboard.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,32 @@ else
$max = $after + 1;
$out = "";

$WHERE = '1';
if (Config::Get('bfhq_hide_bots')) {
$WHERE .= ' AND player.isbot = 0';
}
if (Config::Get('bfhq_hide_hidden_players')) {
$WHERE .= ' AND player.hidden = 0';
}
if (Config::Get('bfhq_hide_pids_start')) {
$WHERE .= ' AND player.id >= ' . Config::Get('bfhq_hide_pids_start');
}
if (Config::Get('bfhq_hide_pids_end')) {
$WHERE .= ' AND player.id <= ' . Config::Get('bfhq_hide_pids_end');
}

if ($type == 'score')
{
if ($id == 'overall')
{
$result = $connection->query("SELECT COUNT(`id`) FROM `player` WHERE `hidden` = 0 AND `score` > 0");
$result = $connection->query("SELECT COUNT(`id`) FROM `player` WHERE $WHERE AND `score` > 0");
$count = $result->fetchColumn();
$out .= "D\t{$count}\t" . time() . "\n";
$out .= "H\tn\tpid\tnick\tscore\ttotaltime\tplayerrank\tcountrycode\n";

if(!$pid)
{
$query = "SELECT `id`, `name`, `rank`, `country`, `time`, `score` FROM `player` WHERE `hidden` = 0 AND `score` > 0 ORDER BY `score` DESC, `name` DESC LIMIT {$min}, {$max}";
$query = "SELECT `id`, `name`, `rank`, `country`, `time`, `score` FROM `player` WHERE $WHERE AND `score` > 0 ORDER BY `score` DESC, `name` DESC LIMIT {$min}, {$max}";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand All @@ -128,7 +142,7 @@ else
}
else
{
$query = "SELECT `id`, `name`, `rank`, `country`, `time`, `score` FROM `player` WHERE `hidden` = 0 AND `score` > 0 ORDER BY `score` DESC, `name` DESC";
$query = "SELECT `id`, `name`, `rank`, `country`, `time`, `score` FROM `player` WHERE $WHERE AND `score` > 0 ORDER BY `score` DESC, `name` DESC";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand All @@ -152,14 +166,14 @@ else
}
elseif ($id == 'commander')
{
$result = $connection->query("SELECT COUNT(`id`) FROM `player` WHERE `hidden` = 0 AND `cmdscore` > 0");
$result = $connection->query("SELECT COUNT(`id`) FROM `player` WHERE $WHERE AND `cmdscore` > 0");
$count = $result->fetchColumn();
$out .= "D\t{$count}\t" . time() . "\n";
$out .= "H\tn\tpid\tnick\tcoscore\tcotime\tplayerrank\tcountrycode\n";

if(!$pid)
{
$query = "SELECT `id`, `name`, `rank`, `country`, `cmdtime`, `cmdscore` FROM `player` WHERE `hidden` = 0 AND `cmdscore` > 0 ORDER BY `cmdscore` DESC, `name` DESC LIMIT {$min}, {$max}";
$query = "SELECT `id`, `name`, `rank`, `country`, `cmdtime`, `cmdscore` FROM `player` WHERE $WHERE AND `cmdscore` > 0 ORDER BY `cmdscore` DESC, `name` DESC LIMIT {$min}, {$max}";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand All @@ -177,7 +191,7 @@ else
}
else
{
$query = "SELECT `id`, `name`, `rank`, `country`, `cmdtime`, `cmdscore` FROM `player` WHERE `hidden` = 0 AND `cmdscore` > 0 ORDER BY `cmdscore` DESC, `name` DESC";
$query = "SELECT `id`, `name`, `rank`, `country`, `cmdtime`, `cmdscore` FROM `player` WHERE $WHERE AND `cmdscore` > 0 ORDER BY `cmdscore` DESC, `name` DESC";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand All @@ -201,14 +215,14 @@ else
}
elseif ($id == 'team')
{
$result = $connection->query("SELECT COUNT(`id`) FROM `player` WHERE `hidden` = 0 AND `teamscore` > 0");
$result = $connection->query("SELECT COUNT(`id`) FROM `player` WHERE $WHERE AND `teamscore` > 0");
$count = $result->fetchColumn();
$out .= "D\t{$count}\t" . time() . "\n";
$out .= "H\tn\tpid\tnick\tteamscore\ttotaltime\tplayerrank\tcountrycode\n";

if(!$pid)
{
$query = "SELECT `id`, `name`, `rank`, `country`, `time`, `teamscore` FROM `player` WHERE `hidden` = 0 AND `teamscore` > 0 ORDER BY `teamscore` DESC, `name` DESC LIMIT {$min}, {$max}";
$query = "SELECT `id`, `name`, `rank`, `country`, `time`, `teamscore` FROM `player` WHERE $WHERE AND `teamscore` > 0 ORDER BY `teamscore` DESC, `name` DESC LIMIT {$min}, {$max}";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand All @@ -226,7 +240,7 @@ else
}
else
{
$query = "SELECT `id`, `name`, `rank`, `country`, `time`, `teamscore` FROM `player` WHERE `hidden` = 0 AND `teamscore` > 0 ORDER BY `teamscore` DESC, `name` DESC";
$query = "SELECT `id`, `name`, `rank`, `country`, `time`, `teamscore` FROM `player` WHERE $WHERE AND `teamscore` > 0 ORDER BY `teamscore` DESC, `name` DESC";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand All @@ -249,14 +263,14 @@ else
}
elseif ($id == 'combat')
{
$result = $connection->query("SELECT COUNT(`id`) FROM `player` WHERE `hidden` = 0 AND `skillscore` > 0");
$result = $connection->query("SELECT COUNT(`id`) FROM `player` WHERE $WHERE AND `skillscore` > 0");
$count = $result->fetchColumn();
$out .= "D\t{$count}\t" . time() . "\n";
$out .= "H\tn\tpid\tnick\tscore\ttotalkills\ttotaltime\tplayerrank\tcountrycode\n";

if(!$pid)
{
$query = "SELECT `id`, `name`, `rank`, `country`, `time`, `kills`, `skillscore` FROM `player` WHERE `hidden` = 0 AND `skillscore` > 0 ORDER BY `skillscore` DESC, `name` DESC LIMIT {$min}, {$max}";
$query = "SELECT `id`, `name`, `rank`, `country`, `time`, `kills`, `skillscore` FROM `player` WHERE $WHERE AND `skillscore` > 0 ORDER BY `skillscore` DESC, `name` DESC LIMIT {$min}, {$max}";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand All @@ -275,7 +289,7 @@ else
}
else
{
$query = "SELECT `id`, `name`, `rank`, `country`, `time`, `kills`, `skillscore` FROM `player` WHERE `hidden` = 0 AND `skillscore` > 0 ORDER BY `skillscore` DESC, `name` DESC";
$query = "SELECT `id`, `name`, `rank`, `country`, `time`, `kills`, `skillscore` FROM `player` WHERE $WHERE AND `skillscore` > 0 ORDER BY `skillscore` DESC, `name` DESC";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand All @@ -302,18 +316,18 @@ else
# Need weekly score calculations!
elseif ($type == 'risingstar')
{
$query = "SELECT COUNT(DISTINCT(h.`id`)) FROM `player_history` h INNER JOIN player p ON p.id = h.id WHERE p.hidden = 0 AND h.`score` > 0 AND h.`timestamp` >= (UNIX_TIMESTAMP() - (60*60*24*7))";
$query = "SELECT COUNT(DISTINCT(h.`id`)) FROM `player_history` h INNER JOIN player ON player.id = h.id WHERE $WHERE AND h.`score` > 0 AND h.`timestamp` >= (UNIX_TIMESTAMP() - (60*60*24*7))";
$result = $connection->query($query);
$count = $result->fetchColumn();
$out .= "D\t{$count}\t" . time() . "\n";
$out .= "H\tn\tpid\tnick\tweeklyscore\ttotaltime\tdate\tplayerrank\tcountrycode\n";

if(!$pid)
{
$query = "SELECT p.id, p.name, p.rank, p.country, p.time, sum(h.score) as weeklyscore, p.joined
FROM player AS p JOIN player_history AS h ON p.id = h.id
WHERE p.hidden = 0 AND h.score > 0 AND h.timestamp >= (UNIX_TIMESTAMP() - (60*60*24*7))
GROUP BY p.id
$query = "SELECT player.id, player.name, player.rank, player.country, player.time, sum(h.score) as weeklyscore, player.joined
FROM player JOIN player_history AS h ON player.id = h.id
WHERE $WHERE AND h.score > 0 AND h.timestamp >= (UNIX_TIMESTAMP() - (60*60*24*7))
GROUP BY player.id
ORDER BY weeklyscore DESC, name DESC
LIMIT {$min}, {$max}";
$result = $connection->query($query);
Expand All @@ -334,10 +348,10 @@ else
}
else
{
$query = "SELECT p.id, p.name, p.rank, p.country, p.time, sum(h.score) as weeklyscore, p.joined
FROM player AS p JOIN player_history AS h ON p.id = h.id
WHERE p.hidden = 0 AND h.score > 0 AND h.timestamp >= (UNIX_TIMESTAMP() - (60*60*24*7))
GROUP BY p.id
$query = "SELECT player.id, player.name, player.rank, player.country, player.time, sum(h.score) as weeklyscore, player.joined
FROM player JOIN player_history AS h ON player.id = h.id
WHERE $WHERE AND h.score > 0 AND h.timestamp >= (UNIX_TIMESTAMP() - (60*60*24*7))
GROUP BY player.id
ORDER BY weeklyscore DESC, name DESC";
$result = $connection->query($query);
if($result instanceof PDOStatement)
Expand All @@ -363,14 +377,14 @@ else
}
elseif ($type == 'kit')
{
$result = $connection->query("SELECT COUNT(k.id) FROM kits k INNER JOIN player p ON p.id = k.id WHERE p.hidden = 0 AND `kills{$id}` > 0");
$result = $connection->query("SELECT COUNT(k.id) FROM kits k INNER JOIN player ON player.id = k.id WHERE $WHERE AND `kills{$id}` > 0");
$count = $result->fetchColumn();
$out .= "D\t{$count}\t" . time() . "\n";
$out .= "H\tn\tpid\tnick\tkillswith\tdeathsby\ttimeplayed\tplayerrank\tcountrycode\n";

if(!$pid)
{
$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time FROM player NATURAL JOIN kits WHERE hidden = 0 AND kills{$id} > 0 ORDER BY kills{$id} DESC, name DESC LIMIT {$min}, {$max}";
$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time FROM player NATURAL JOIN kits WHERE $WHERE AND kills{$id} > 0 ORDER BY kills{$id} DESC, name DESC LIMIT {$min}, {$max}";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand All @@ -389,7 +403,7 @@ else
}
else
{
$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time FROM player NATURAL JOIN kits WHERE hidden = 0 AND kills{$id} > 0 ORDER BY kills{$id} DESC, name DESC";
$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time FROM player NATURAL JOIN kits WHERE $WHERE AND kills{$id} > 0 ORDER BY kills{$id} DESC, name DESC";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand All @@ -414,14 +428,14 @@ else
}
elseif ($type == 'vehicle')
{
$result = $connection->query("SELECT COUNT(v.id) FROM vehicles v INNER JOIN player p ON p.id = v.id WHERE p.hidden = 0 AND `kills{$id}` > 0");
$result = $connection->query("SELECT COUNT(v.id) FROM vehicles v INNER JOIN player ON player.id = v.id WHERE $WHERE AND `kills{$id}` > 0");
$count = $result->fetchColumn();
$out .= "D\t{$count}\t" . time() . "\n";
$out .= "H\tn\tpid\tnick\tkillswith\tdetahsby\ttimeused\tplayerrank\tcountrycode\n";

if(!$pid)
{
$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time FROM player NATURAL JOIN vehicles WHERE hidden = 0 AND kills{$id} > 0 ORDER BY kills{$id} DESC, name DESC LIMIT {$min}, {$max}";
$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time FROM player NATURAL JOIN vehicles WHERE $WHERE AND kills{$id} > 0 ORDER BY kills{$id} DESC, name DESC LIMIT {$min}, {$max}";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand All @@ -440,7 +454,7 @@ else
}
else
{
$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time FROM player NATURAL JOIN vehicles WHERE hidden = 0 AND kills{$id} > 0 ORDER BY kills{$id} DESC, name DESC";
$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time FROM player NATURAL JOIN vehicles WHERE $WHERE AND kills{$id} > 0 ORDER BY kills{$id} DESC, name DESC";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand All @@ -465,15 +479,15 @@ else
}
elseif ($type == 'weapon')
{
$result = $connection->query("SELECT COUNT(w.id) FROM weapons w INNER JOIN player p ON p.id = w.id WHERE p.hidden = 0 AND `kills{$id}` > 0");
$result = $connection->query("SELECT COUNT(w.id) FROM weapons w INNER JOIN player ON player.id = w.id WHERE $WHERE AND `kills{$id}` > 0");
$count = $result->fetchColumn();
$out .= "D\t{$count}\t" . time() . "\n";
# NOTE: EA typo (deathsby=detahsby)
$out .= "H\tn\tpid\tnick\tkillswith\tdetahsby\ttimeused\taccuracy\tplayerrank\tcountrycode\n";

if (!$pid)
{
$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time, hit{$id} AS hit, fired{$id} AS fired FROM player NATURAL JOIN weapons WHERE hidden = 0 AND kills{$id} > 0 ORDER BY kills{$id} DESC, name DESC LIMIT {$min}, {$max}";
$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time, hit{$id} AS hit, fired{$id} AS fired FROM player NATURAL JOIN weapons WHERE $WHERE AND kills{$id} > 0 ORDER BY kills{$id} DESC, name DESC LIMIT {$min}, {$max}";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand All @@ -493,7 +507,7 @@ else
}
else
{
$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time, hit{$id} AS hit, fired{$id} AS fired FROM player NATURAL JOIN weapons WHERE hidden = 0 AND kills{$id} > 0 ORDER BY kills{$id} DESC, name DESC";
$query = "SELECT player.id AS plid, name, rank, country, kills{$id} AS kills, deaths{$id} AS deaths, time{$id} AS time, hit{$id} AS hit, fired{$id} AS fired FROM player NATURAL JOIN weapons WHERE $WHERE AND kills{$id} > 0 ORDER BY kills{$id} DESC, name DESC";
$result = $connection->query($query);
if($result instanceof PDOStatement)
{
Expand Down
40 changes: 34 additions & 6 deletions src/ASP/getplayerinfo.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ else
die($out);
}

$WHERE = '';
if (Config::Get('bfhq_hide_bots')) {
$WHERE .= ' AND player.isbot = 0';
}
if (Config::Get('bfhq_hide_hidden_players')) {
$WHERE .= ' AND player.hidden = 0';
}
if (Config::Get('bfhq_hide_pids_start')) {
$WHERE .= ' AND player.id >= ' . stripslashes(Config::Get('bfhq_hide_pids_start'));
}
if (Config::Get('bfhq_hide_pids_end')) {
$WHERE .= ' AND player.id <= ' . stripslashes(Config::Get('bfhq_hide_pids_end'));
}

// Player info
//'Reworked' for MNG stats =)
//omero, 2006-04-15
Expand Down Expand Up @@ -330,11 +344,18 @@ else
$favoi = $row2['attacker'];
$favok = $row2['count'];

$query = "SELECT `name`, `rank` FROM `player` WHERE `id` = {$favoi}";
$query = "SELECT `name`, `rank` FROM `player` WHERE `id` = {$favoi} $WHERE";
$result = $connection->query($query);
$row2 = $result->fetch();
$favon = trim($row2['name']);
$favor = $row2['rank'];
$favon = '';
$favor = '';
if ($row2) {
$favon = trim($row2['name']);
$favor = $row2['rank'];
}else {
$favoi = $favon = $favor = ' ';
$favok = '0';
}
}
else
{
Expand All @@ -355,11 +376,18 @@ else
$favvk = $row2['count'];

//
$query = "SELECT `name`, `rank` FROM `player` WHERE `id` = {$favvi}";
$query = "SELECT `name`, `rank` FROM `player` WHERE `id` = {$favvi} $WHERE";
$result = $connection->query($query);
$row2 = $result->fetch();
$favvn = trim($row2['name']);
$favvr = $row2['rank'];
$favvn = '';
$favvr = '';
if ($row2) {
$favvn = trim($row2['name']);
$favvr = $row2['rank'];
}else {
$favvi = $favvn = $favvr= ' ';
$favvk = '0';
}
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions src/ASP/system/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
$stats_awds_complete = 0;
$stats_lan_override = '174.49.21.221';
$stats_local_pids = array('LocalPlayer01','210.84.29.151','LocalPlayer02','210.84.29.151');
$bfhq_hide_bots = false;
$bfhq_hide_hidden_players = false;
$bfhq_hide_pids_start = 1;
$bfhq_hide_pids_end = 999999999;
$debug_lvl = 2;
$game_hosts = array('127.0.0.1','192.168.2.0/24','192.168.1.102','192.168.1.110','localhost','::1');
$game_custom_mapid = 700;
Expand Down
4 changes: 4 additions & 0 deletions src/ASP/system/core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ private static function getDefault()
'stats_awds_complete' => 0,
'stats_lan_override' => '174.49.21.221',
'stats_local_pids' => array('LocalPlayer01','210.84.29.151','LocalPlayer02','210.84.29.151'),
'bfhq_hide_bots' => false,
'bfhq_hide_hidden_players' => false,
'bfhq_hide_pids_start' => 1,
'bfhq_hide_pids_end' => 999999999,
'debug_lvl' => 2,
'game_hosts' => array('127.0.0.1','192.168.2.0/24','192.168.1.102','192.168.1.110','localhost','::1'),
'game_custom_mapid' => 700,
Expand Down

0 comments on commit ee08343

Please sign in to comment.