1<?php
2require_once '../../module.php';
3
4// Module version
5$response['version']['module'] = 1;
6
7function highscoresTopSkillName(int $type): string {
8 $types = [
9 1 => 'Club', 2 => 'Sword', 3 => 'Axe', 4 => 'Distance', 5 => 'Shield',
10 6 => 'Fish', 7 => 'Experience', 8 => 'Magic Level', 9 => 'Fist',
11 ];
12 return $types[$type] ?? 'Experience';
13}
14
15$type = isset($_GET['type']) ? (int)getValue($_GET['type'] ?? null) : 7;
16if ($type > 9 || $type < 1) $type = 7;
17
18$configVocations = $config['vocations'];
19$vocationIds = array_keys($configVocations);
20
21$vocation = 'all';
22if (isset($_GET['vocation']) && is_numeric($_GET['vocation'])) {
23 $vocation = (int)$_GET['vocation'];
24 if (!in_array($vocation, $vocationIds, true)) {
25 $vocation = 'all';
26 }
27}
28
29$highscore = $config['highscore'];
30
31$rows = isset($_GET['rows']) && is_numeric($_GET['rows'])
32 ? max(1, (int)$_GET['rows'])
33 : (int)$highscore['rows'];
34$rows = min($rows, 100);
35
36$loadFlags = ($config['country_flags']['enabled'] && $config['country_flags']['highscores']) ? true : false;
37$loadOutfits = ($config['show_outfits']['highscores']) ? true : false;
38
39$defaultRows = (int) $highscore['rows'];
40$cache = new Cache('engine/cache/highscores');
41if ($rows === $defaultRows && !$cache->hasExpired()) {
42 $vocGroups = $cache->load();
43} else {
44 $vocGroups = fetchAllScores($rows, znote_server_adapter()->normalizedEngine(), $highscore['ignoreGroupId'], $configVocations, $vocation, $loadFlags, $loadOutfits);
45 if ($rows === $defaultRows) {
46 $cache->setContent($vocGroups);
47 $cache->save();
48 }
49}
50
51$vocGroup = [];
52if ($vocGroups) {
53 $vocGroup = is_array($vocGroups[$vocation]) ? $vocGroups[$vocation] : $vocGroups[$vocGroups[$vocation]];
54}
55
56$response['config'] = [
57 'type' => $type,
58 'skill_name' => highscoresTopSkillName($type),
59 'vocation' => $vocation,
60 'rows' => $rows,
61];
62$response['data']['rows'] = $vocGroup[$type] ?? [];
63
64SendResponse($response);
65?>
66