forked from NB-Core/lotgd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hof.php
257 lines (236 loc) · 10.6 KB
/
hof.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
// translator ready
// addnews ready
// mail ready
// New Hall of Fame features by anpera
// http://www.anpera.net/forum/viewforum.php?f=27
require_once("common.php");
require_once("lib/http.php");
require_once("lib/villagenav.php");
tlschema("hof");
$superusermask = SU_HIDE_FROM_LEADERBOARD;
$standardwhere = "(locked=0 AND (superuser & $superusermask) = 0)";
page_header("Hall of Fame");
checkday();
addnav("Navigation");
villagenav();
$playersperpage = 50;
$op = httpget('op');
if ($op == "") $op = "kills";
$subop = httpget('subop');
if ($subop == "") $subop = "most";
$sql = "SELECT count(acctid) AS c FROM " . db_prefix("accounts") . " WHERE $standardwhere";
$extra = "";
if ($op == "kills") {
$extra = " AND dragonkills > 0";
} elseif ($op == "days") {
$extra = " AND dragonkills > 0 AND bestdragonage > 0";
}
$result = db_query($sql.$extra);
$row = db_fetch_assoc($result);
$totalplayers = $row['c'];
$page = (int)httpget('page');
if ($page == 0) $page = 1;
$pageoffset = $page;
if ($pageoffset > 0) $pageoffset--;
$pageoffset *= $playersperpage;
$from = $pageoffset+1;
$to = min($pageoffset+$playersperpage, $totalplayers);
$limit = "$pageoffset,$playersperpage";
$me = ''; //query at the end
addnav("Warrior Rankings");
addnav("Dragon Kills", "hof.php?op=kills&subop=$subop&page=1");
addnav("Gold", "hof.php?op=money&subop=$subop&page=1");
addnav("Gems", "hof.php?op=gems&subop=$subop&page=1");
addnav("Charm", "hof.php?op=charm&subop=$subop&page=1");
addnav("Toughness", "hof.php?op=tough&subop=$subop&page=1");
addnav("Resurrections", "hof.php?op=resurrects&subop=$subop&page=1");
addnav("Dragon Kill Speed", "hof.php?op=days&subop=$subop&page=1");
addnav("Sorting");
addnav("Best", "hof.php?op=$op&subop=most&page=$page");
addnav("Worst", "hof.php?op=$op&subop=least&page=$page");
addnav("Other Stats");
modulehook("hof-add",array());
if ($totalplayers > $playersperpage) {
addnav("Pages");
for($i = 0; $i < $totalplayers; $i+= $playersperpage) {
$pnum = ($i/$playersperpage+1);
$min = ($i+1);
$max = min($i+$playersperpage,$totalplayers);
if ($page == $pnum) {
addnav(array("`b`#Page %s`0 (%s-%s)`b", $pnum, $min, $max), "hof.php?op=$op&subop=$subop&page=$pnum");
} else {
addnav(array("Page %s (%s-%s)", $pnum, $min, $max), "hof.php?op=$op&subop=$subop&page=$pnum");
}
}
}
function display_table($title, $sql, $none=false, $foot=false,
$data_header=false, $tag=false, $translate=false)
{
global $session, $from, $to, $page, $playersperpage, $totalplayers;
$title = translate_inline($title);
if ($foot !== false) $foot = translate_inline($foot);
if ($none !== false) $none = translate_inline($none);
else $none = translate_inline("No players found.");
if ($data_header !== false) {
$data_header = translate_inline($data_header);
reset ($data_header);
}
if ($tag !== false) $tag = translate_inline($tag);
$rank = translate_inline("Rank");
$name = translate_inline("Name");
if ($totalplayers > $playersperpage) {
output("`c`b`^%s`0`b `7(Page %s: %s-%s of %s)`0`c`n", $title, $page, $from, $to, $totalplayers);
} else {
output("`c`b`^%s`0`b`c`n", $title);
}
rawoutput("<table cellspacing='0' cellpadding='2' align='center'>");
rawoutput("<tr class='trhead'>");
output_notl("<td>`b$rank`b</td><td>`b$name`b</td>", true);
if ($data_header !== false) {
for ($i = 0; $i < count($data_header); $i++) {
output_notl("<td>`b{$data_header[$i]}`b</td>", true);
}
}
$result = db_query($sql);
if (db_num_rows($result)==0){
$size = ($data_header === false) ? 2 : 2+count($data_header);
output_notl("<tr class='trlight'><td colspan='$size' align='center'>`&$none`0</td></tr>",true);
} else {
$i=-1;
while ($row = db_fetch_assoc($result)) {
$i++;
if ($row['name']==$session['user']['name']){
rawoutput("<tr class='hilight'>");
} else {
rawoutput("<tr class='".($i%2?"trlight":"trdark")."'>");
}
output_notl("<td>%s</td><td>`&%s`0</td>",($i+$from), $row['name'], true);
if ($data_header !== false) {
for ($j = 0; $j < count($data_header); $j++) {
$id = "data" . ($j+1);
$val = $row[$id];
if (isset($translate[$id]) &&
$translate[$id] == 1 && !is_numeric($val)) {
$val = translate_inline($val);
}
if ($tag !== false) $val = $val . " " . $tag[$j];
output_notl("<td align='right'>%s</td>", $val, true);
}
}
rawoutput("</tr>");
}
}
rawoutput("</table>");
if ($foot !== false) output_notl("`n`c%s`c", $foot);
}
if ($op=="days") {
if ($subop == "least") {
$order = "DESC";
$meop = ">=";
}else{
$order = "ASC";
$meop = "<=";
}
} else {
if ($subop == "least") {
$order = "ASC";
$meop = "<=";
}else{
$order = "DESC";
$meop = ">=";
}
}
$sexsel = "IF(sex,'`%Female`0','`!Male`0')";
$racesel = "IF(race!='0' and race!='',race,'".RACE_UNKNOWN."')";
//round modifier for gold - equals left side of , rounding
// + equals right side of , rounding
$round_money="-2";
if ($op=="money"){
// works only in mysql 5+ due to the derived table stuff
$sql = "SELECT name,(round(
(CAST(goldinbank as signed)+cast(gold as signed))
*(1+0.05*(rand())),$round_money
)) as sort1
FROM " . db_prefix("accounts") . " WHERE $standardwhere ORDER BY sort1 $order, level $order, experience $order, acctid $order LIMIT $limit";
// for formatting, we need another query...
$sql = "SELECT name,format(sort1,0) as data1 FROM ($sql) t";
$me = "SELECT count(acctid) AS count FROM ".db_prefix("accounts")." WHERE $standardwhere
AND round((CAST(goldinbank as signed)+cast(gold as signed))*(1+0.05*(rand())),$round_money)
$meop ".($session['user']['goldinbank'] + $session['user']['gold']);
//edward pointed out that a cast is necessary as signed+unsigned=boffo
// $sql = "SELECT name,(goldinbank+gold+round((((rand()*10)-5)/100)*(goldinbank+gold))) AS data1 FROM " . db_prefix("accounts") . " WHERE $standardwhere ORDER BY data1 $order, level $order, experience $order, acctid $order LIMIT $limit";
// $me = "SELECT count(acctid) AS count FROM ".db_prefix("accounts")." WHERE $standardwhere AND (goldinbank+gold+round((((rand()*10)-5)/100)*(goldinbank+gold))) $meop ".($session['user']['goldinbank'] + $session['user']['gold']);
$adverb = "richest";
if ($subop == "least") $adverb = "poorest";
$title = "The $adverb warriors in the land";
$foot = "(Gold Amount is accurate to +/- 5%)";
$headers = array("Estimated Gold");
$tags = array("gold");
$table = array($title, $sql, false, $foot, $headers, $tags);
} elseif ($op == "gems") {
$sql = "SELECT name FROM ". db_prefix("accounts") . " WHERE $standardwhere ORDER BY gems $order, level $order, experience $order, acctid $order LIMIT $limit";
$me = "SELECT count(acctid) AS count FROM ".db_prefix("accounts")." WHERE $standardwhere AND gems $meop {$session['user']['gems']}";
if ($subop == "least") $adverb = "least";
else $adverb = "most";
$title = "The warriors with the $adverb gems in the land";
$table = array($title, $sql);
} elseif ($op=="charm"){
$sql = "SELECT name,$sexsel AS data1, $racesel AS data2 FROM " . db_prefix("accounts") . " WHERE $standardwhere ORDER BY charm $order, level $order, experience $order, acctid $order LIMIT $limit";
$me = "SELECT count(acctid) AS count FROM ".db_prefix("accounts")." WHERE $standardwhere AND charm $meop {$session['user']['charm']}";
$adverb = "most beautiful";
if ($subop == "least") $adverb = "ugliest";
$title = "The $adverb warriors in the land.";
$headers = array("Gender", "Race");
$translate = array("data1"=>1, "data2"=>1);
$table = array($title, $sql, false, false, $headers, false, $translate);
} elseif ($op=="tough"){
$sql = "SELECT name,level AS data2 , $racesel as data1 FROM " . db_prefix("accounts") . " WHERE $standardwhere ORDER BY maxhitpoints $order, level $order, experience $order, acctid $order LIMIT $limit";
$me = "SELECT count(acctid) AS count FROM ".db_prefix("accounts")." WHERE $standardwhere AND maxhitpoints $meop {$session['user']['maxhitpoints']}";
$adverb = "toughest";
if ($subop == "least") $adverb = "wimpiest";
$title = "The $adverb warriors in the land";
$headers = array("Race", "Level");
$translate = array("data1"=>1);
$table = array($title, $sql, false, false, $headers, false, $translate);
} elseif ($op=="resurrects"){
$sql = "SELECT name,level AS data1 FROM " . db_prefix("accounts") . " WHERE $standardwhere ORDER BY resurrections $order, level $order, experience $order, acctid $order LIMIT $limit";
$me = "SELECT count(acctid) AS count FROM ".db_prefix("accounts")." WHERE $standardwhere AND resurrections $meop {$session['user']['resurrections']}";
$adverb = "most suicidal";
if ($subop == "least") $adverb = "least suicidal";
$title = "The $adverb warriors in the land";
$headers = array("Level");
$table = array($title, $sql, false, false, $headers, false);
} elseif ($op=="days") {
$unk = translate_inline("Unknown");
$sql = "SELECT name, IF(bestdragonage,bestdragonage,'$unk') AS data1 FROM " . db_prefix("accounts") . " WHERE $standardwhere $extra ORDER BY bestdragonage $order, level $order, experience $order, acctid $order LIMIT $limit";
$me = "SELECT count(acctid) AS count FROM ".db_prefix("accounts")." WHERE $standardwhere $extra AND bestdragonage $meop {$session['user']['bestdragonage']}";
$adverb = "fastest";
if ($subop == "least") $adverb = "slowest";
$title = "Heroes with the $adverb dragon kills in the land";
$headers = array("Best Days");
$none = "There are no heroes in the land.";
$table = array($title, $sql, $none, false, $headers, false);
} else {
$unk = translate_inline("Unknown");
$sql = "SELECT name,dragonkills AS data1,level AS data2,' ' AS data3, IF(dragonage,dragonage,'$unk') AS data4, ' ' AS data5, IF(bestdragonage,bestdragonage,'$unk') AS data6 FROM " . db_prefix("accounts") . " WHERE $standardwhere $extra ORDER BY dragonkills $order,level $order,experience $order, acctid $order LIMIT $limit";
if ($session['user']['dragonkills']>0) $me = "SELECT count(acctid) AS count FROM ".db_prefix("accounts")." WHERE $standardwhere $extra AND dragonkills $meop {$session['user']['dragonkills']}";
$adverb = "most";
if ($subop == "least") $adverb = "least";
$title = "Heroes with the $adverb dragon kills in the land";
$headers = array("Kills", "Level", " ", "Days", " ", "Best Days");
$none = "There are no heroes in the land.";
$table = array($title, $sql, $none, false, $headers, false);
}
if (isset($table) && is_array($table)){
call_user_func_array("display_table",$table);
if ($me>"" && $totalplayers){
$meresult = db_query($me);
$row = db_fetch_assoc($meresult);
$pct = round(100*$row['count']/$totalplayers, 0);
if ($pct < 1) $pct = 1;
output("`c`7You rank within around the top `&%s`7%% in this listing.`0`c",$pct);
}
}
page_footer();
?>