mirror of
https://github.com/Znote/ZnoteAAC.git
synced 2025-10-13 18:04:54 +02:00
Remade Highscores: Added multi-page support, built-in score type navigation, using GET instead of POST.
Tested on TFS 1.0 and 0.3/4, but should work on 0.2 as well.
This commit is contained in:
195
highscores.php
195
highscores.php
@@ -1,110 +1,105 @@
|
||||
<?php require_once 'engine/init.php'; include 'layout/overall/header.php';
|
||||
|
||||
if ($config['log_ip']) {
|
||||
znote_visitor_insert_detailed_data(3);
|
||||
}
|
||||
if (empty($_POST) === false) {
|
||||
|
||||
#if ($_POST['token'] == $_SESSION['token']) {
|
||||
|
||||
/* Token used for cross site scripting security */
|
||||
if (isset($_POST['token']) && Token::isValid($_POST['token'])) {
|
||||
|
||||
$skillid = (int)$_POST['selected'];
|
||||
$cache = new Cache('engine/cache/highscores');
|
||||
|
||||
if ($cache->hasExpired()) {
|
||||
if ($config['TFSVersion'] != 'TFS_10') $tmp = highscore_getAll();
|
||||
else $tmp = highscore_getAll_10(0, 30);
|
||||
// Fetch highscore type
|
||||
$type = getValue($_GET['type']);
|
||||
if (!$type) $type = 7;
|
||||
else $type = (int)$type;
|
||||
if ($type > 9) $type = 7;
|
||||
|
||||
$cache->setContent($tmp);
|
||||
$cache->save();
|
||||
// Fetch highscore page
|
||||
$page = getValue($_GET['page']);
|
||||
if (!$page || $page == 0) $page = 1;
|
||||
else $page = (int)$page;
|
||||
|
||||
$array = isset($tmp[$skillid]) ? $tmp[$skillid] : $tmp[7];
|
||||
} else {
|
||||
$tmp = $cache->load();
|
||||
$array = $tmp[$skillid];
|
||||
}
|
||||
|
||||
if ($skillid < 9) {
|
||||
// Design and present the list
|
||||
if ($array) {
|
||||
?>
|
||||
<h2>
|
||||
<?php echo ucfirst(skillid_to_name($skillid)); ?> scoreboard. Next update:
|
||||
<?php
|
||||
if ($cache->remainingTime() > 0) {
|
||||
$hours = seconds_to_hours($cache->remainingTime());
|
||||
$minutes = ($hours - (int)$hours) * 60;
|
||||
$seconds = ($minutes - (int)$minutes) * 60;
|
||||
if ($hours >= 1) {
|
||||
echo (int)$hours .'h';
|
||||
}
|
||||
if ($minutes >= 1) {
|
||||
echo ' '. (int)$minutes .'m';
|
||||
}
|
||||
if ($seconds >= 1) {
|
||||
echo ' '. (int)$seconds .'s';
|
||||
}
|
||||
} else {
|
||||
echo '0s';
|
||||
}
|
||||
|
||||
?>. <?php echo remaining_seconds_to_clock($cache->remainingTime());?>
|
||||
</h2>
|
||||
<table id="highscoresTable" class="table table-striped table-hover">
|
||||
<tr class="yellow">
|
||||
<th>Name:</th>
|
||||
<?php
|
||||
if ($skillid == 7) echo '<th>Level:</th><th>Experience:</th>';
|
||||
else {
|
||||
?>
|
||||
<th>Value:</th>
|
||||
<?php
|
||||
}
|
||||
if ($skillid == 7 || $skillid == 6 || $skillid == 5) {
|
||||
echo '<th>Vocation:</th>';
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
<?php
|
||||
foreach ($array as $value) {
|
||||
// start foreach
|
||||
if ($config['TFSVersion'] == 'TFS_10' || $value['group_id'] < 2) {
|
||||
echo '<tr>';
|
||||
echo '<td><a href="characterprofile.php?name='. $value['name'] .'">'. $value['name'] .'</a></td>';
|
||||
if ($skillid == 7) echo '<td>'. $value['level'] .'</td>';
|
||||
echo '<td>'. $value['value'] .'</td>';
|
||||
if ($skillid == 7 || $skillid == 6 || $skillid == 5) {
|
||||
echo '<td>'. $value['vocation'] .'</td>';
|
||||
}
|
||||
echo '</tr>';
|
||||
}
|
||||
// end foreach
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
} else {
|
||||
echo 'Empty list, it appears all players have less than 500 experience points.';
|
||||
}
|
||||
//Done.
|
||||
}
|
||||
} else {
|
||||
echo 'Token appears to be incorrect.<br><br>';
|
||||
//Token::debug($_POST['token']);
|
||||
echo 'Please clear your web cache/cookies <b>OR</b> use another web browser<br>';
|
||||
}
|
||||
$highscore = $config['highscore'];
|
||||
|
||||
$rows = $highscore['rows'];
|
||||
$rowsPerPage = $highscore['rowsPerPage'];
|
||||
|
||||
function skillName($type) {
|
||||
$types = array(
|
||||
1 => "Club",
|
||||
2 => "Sword",
|
||||
3 => "Axe",
|
||||
4 => "Distance",
|
||||
5 => "Shield",
|
||||
6 => "Fish",
|
||||
7 => "Experience", // Hardcoded
|
||||
8 => "Magic Level", // Hardcoded
|
||||
9 => "Fist", // Since 0 returns false I will make 9 = 0. :)
|
||||
);
|
||||
return $types[(int)$type];
|
||||
}
|
||||
|
||||
/*
|
||||
0 fist: SELECT (SELECT `name` from `players` WHERE `player_id`=`id`) AS `name`, `value` FROM `player_skills` WHERE `skillid`=0
|
||||
1 club:
|
||||
2 sword:
|
||||
3 axe:
|
||||
4 dist:
|
||||
5 Shield:
|
||||
6 Fish
|
||||
7 Hardcoded experience
|
||||
8 Hardcoded maglevel
|
||||
*/
|
||||
function pageCheck($index, $page, $rowPerPage) {
|
||||
return ($index < ($page * $rowPerPage) && $index >= ($page * $rowPerPage) - $rowPerPage) ? true : false;
|
||||
}
|
||||
|
||||
$cache = new Cache('engine/cache/highscores');
|
||||
if ($cache->hasExpired()) {
|
||||
$scores = fetchAllScores($rows, $config['TFSVersion'], $highscore['ignoreGroupId']);
|
||||
|
||||
$cache->setContent($scores);
|
||||
$cache->save();
|
||||
} else {
|
||||
$scores = $cache->load();
|
||||
}
|
||||
|
||||
if ($scores) {
|
||||
?>
|
||||
<h1>Ranking for <?php echo skillName($type); ?>.</h1>
|
||||
<form action="" method="GET">
|
||||
<select name="type">
|
||||
<option value="7" <?php if ($type == 7) echo "selected"; ?>>Experience</option>
|
||||
<option value="8" <?php if ($type == 8) echo "selected"; ?>>Magic</option>
|
||||
<option value="5" <?php if ($type == 5) echo "selected"; ?>>Shield</option>
|
||||
<option value="2" <?php if ($type == 2) echo "selected"; ?>>Sword</option>
|
||||
<option value="1" <?php if ($type == 1) echo "selected"; ?>>Club</option>
|
||||
<option value="3" <?php if ($type == 3) echo "selected"; ?>>Axe</option>
|
||||
<option value="4" <?php if ($type == 4) echo "selected"; ?>>Distance</option>
|
||||
<option value="6" <?php if ($type == 6) echo "selected"; ?>>Fish</option>
|
||||
<option value="9" <?php if ($type == 9) echo "selected"; ?>>Fist</option>
|
||||
</select>
|
||||
<select name="page">
|
||||
<?php
|
||||
$pages = (int)($highscore['rows'] / $highscore['rowsPerPage']) + 1;
|
||||
for ($i = 0; $i < $pages; $i++) {
|
||||
$x = $i + 1;
|
||||
if ($x == $page) echo "<option value='".$x."' selected>Page: ".$x."</option>";
|
||||
else echo "<option value='".$x."'>Page: ".$x."</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<input type="submit" value=" View " class="btn btn-info">
|
||||
</form>
|
||||
<table id="highscoresTable" class="table table-striped table-hover">
|
||||
<tr class="yellow">
|
||||
<td>Rank</td>
|
||||
<td>Name</td>
|
||||
<td>Vocation</td>
|
||||
<td>Level</td>
|
||||
<?php if ($type === 7) echo "<td>Points</td>"; ?>
|
||||
</tr>
|
||||
<?php
|
||||
for ($i = 0; $i < count($scores[$type]); $i++) {
|
||||
if (pageCheck($i, $page, $rowsPerPage)) {
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $i+1; ?></td>
|
||||
<td><a href="characterprofile.php?name=<?php echo $scores[$type][$i]['name']; ?>"><?php echo $scores[$type][$i]['name']; ?></a></td>
|
||||
<td><?php echo vocation_id_to_name($scores[$type][$i]['vocation']); ?></td>
|
||||
<td><?php echo $scores[$type][$i]['value']; ?></td>
|
||||
<?php if ($type === 7) echo "<td>". $scores[$type][$i]['experience'] ."</td>"; ?>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
include 'layout/overall/footer.php'; ?>
|
Reference in New Issue
Block a user