-
Notifications
You must be signed in to change notification settings - Fork 5
/
typematches.php
218 lines (192 loc) · 6.73 KB
/
typematches.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
<?php
/*
UTStatsDB
Copyright (C) 2002-2009 Patrick Contreras / Paul Gallier
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require("includes/main.inc.php");
$plr = -1;
$mapnum = -1;
$servernum = -1;
$page = 1;
check_get($plr, "player");
check_get($mapnum, "map");
check_get($servernum, "server");
check_get($page, "page");
if (!is_numeric($plr))
$plr = -1;
if (!is_numeric($mapnum))
$mapnum = -1;
if (!is_numeric($servernum))
$servernum = -1;
if (!is_numeric($page))
$page = 1;
if ($plr <= 0 && $servernum <= 0 && $mapnum <= 0) {
echo "Run from the main index program.<br>\n";
exit;
}
$link = sql_connect();
if ($plr > 0) {
$result = sql_queryn($link, "SELECT plr_name,plr_bot FROM {$dbpre}players WHERE pnum=$plr LIMIT 1");
if (!$result) {
echo "Player Database Error.<br>\n";
exit;
}
$row = sql_fetch_row($result);
sql_free_result($result);
if (!$row) {
echo "Player not found in database.<br>\n";
exit;
}
$plrname = stripspecialchars($row[0]);
$plrbot = intval($row[1]);
if ($plrbot)
$bot = " (bot)";
else
$bot = "";
$heading = "{$plrname}{$bot} [$plr]";
$pagetype = "player=$plr";
}
else if ($servernum > 0) {
$result = sql_queryn($link, "SELECT sv_name,sv_shortname FROM {$dbpre}servers WHERE sv_num=$servernum LIMIT 1");
if (!$result) {
echo "Server Database Error.<br>\n";
exit;
}
list($sv_name,$sv_shortname) = sql_fetch_row($result);
sql_free_result($result);
if ($useshortname && $sv_shortname != "")
$servername = stripspecialchars($sv_shortname);
else
$servername = stripspecialchars($sv_name);
$heading = "$servername";
$pagetype = "server=$servernum";
}
else {
$result = sql_queryn($link, "SELECT mp_name FROM {$dbpre}maps WHERE mp_num=$mapnum LIMIT 1");
if (!$result) {
echo "Map Database Error.<br>\n";
exit;
}
list($mp_name) = sql_fetch_row($result);
sql_free_result($result);
$mapname = stripspecialchars($mp_name);
$heading = "$mapname";
$pagetype = "map=$mapnum";
}
// Calculate Number of Pages
if ($plr > 0)
$result = sql_queryn($link, "SELECT COUNT(*) FROM {$dbpre}gplayers WHERE gp_pnum=$plr");
else if ($servernum > 0)
$result = sql_queryn($link, "SELECT COUNT(*) FROM {$dbpre}matches WHERE gm_server=$servernum");
else
$result = sql_queryn($link, "SELECT COUNT(*) FROM {$dbpre}matches WHERE gm_map=$mapnum");
list($nummatches) = sql_fetch_row($result);
sql_free_result($result);
$numpages = (int) ceil($nummatches / $matchespage);
if (!$page)
$page = 1;
else if ($page < 1 || $page > $numpages)
$page = 1;
if ($numpages > 1) {
echo "<div class=\"pages\"><b>Page [$page/$numpages] Selection: ";
$prev = $page - 1;
$next = $page + 1;
if ($page != 1)
echo "<a class=\"pages\" href=\"typematches.php?$pagetype&page=1\">[First]</a> / <a class=\"pages\" href=\"typematches.php?$pagetype&page=$prev\">[Previous]</a> / ";
else
echo "[First] / [Previous] / ";
if ($page < $numpages)
echo "<a class=\"pages\" href=\"typematches.php?$pagetype&page=$next\">[Next]</a> / <a class=\"pages\" href=\"typematches.php?$pagetype&page=$numpages\">[Last]</a>";
else
echo "[Next] / [Last]";
echo "</b></div>";
}
echo <<<EOF
<table cellpadding="1" cellspacing="2" border="0" class="box">
<tr>
<td class="heading" colspan="5" align="center">Unreal Tournament Match List for $heading</td>
</tr>
<tr>
<td class="smheading" align="center" width="250">Date</td>
<td class="smheading" align="center" width="180">Match Type</td>
<td class="smheading" align="center" width="225">Map</td>
<td class="smheading" align="center" width="50">Players</td>
<td class="smheading" align="center" width="50">Minutes</td>
</tr>
EOF;
// Load game types
$numtypes = 0;
$result = sql_queryn($link, "SELECT tp_num,tp_desc FROM {$dbpre}type");
while($row = sql_fetch_row($result))
$gtype[$numtypes++] = $row;
sql_free_result($result);
// Load Game Stats
$matches = 0;
$start = ($page * $matchespage) - $matchespage;
if ($plr > 0)
$result = sql_queryn($link, "SELECT gm_num,gm_type,gm_start,gm_timeoffset,gm_length,gm_map,gm_numplayers,mp_name FROM {$dbpre}gplayers,{$dbpre}matches,{$dbpre}maps WHERE {$dbpre}gplayers.gp_pnum=$plr AND {$dbpre}matches.gm_num={$dbpre}gplayers.gp_match AND {$dbpre}maps.mp_num=gm_map ORDER BY gm_num DESC LIMIT $start,$matchespage");
else if ($servernum > 0)
$result = sql_queryn($link, "SELECT gm_num,gm_type,gm_start,gm_timeoffset,gm_length,gm_map,gm_numplayers,mp_name FROM {$dbpre}matches USE INDEX (gm_svnum),{$dbpre}maps WHERE gm_server=$servernum AND {$dbpre}maps.mp_num=gm_map ORDER BY gm_num DESC LIMIT $start,$matchespage");
else
$result = sql_queryn($link, "SELECT gm_num,gm_type,gm_start,gm_timeoffset,gm_length,gm_map,gm_numplayers,mp_name FROM {$dbpre}matches,{$dbpre}maps WHERE gm_map=$mapnum AND {$dbpre}maps.mp_num=gm_map ORDER BY gm_num DESC LIMIT $start,$matchespage");
if (!$result) {
echo "Game database error.<br>\n";
exit;
}
while($row = sql_fetch_assoc($result)) {
while (list ($key, $val) = each ($row))
${$key} = $val;
$gametype = "";
for ($i = 0; $i < $numtypes && !$gametype; $i++) {
if ($gtype[$i][0] == $gm_type)
$gametype = $gtype[$i][1];
}
$start = strtotime($gm_start);
$matchdate = formatdate($start, 1);
$length = sprintf("%0.1f", $gm_length / (60.0 * $gm_timeoffset));
$map = stripspecialchars($mp_name);
$matches++;
echo <<<EOF
<tr>
<td class="dark" align="center"><a class="dark" href="matchstats.php?match=$gm_num">$matchdate</a></td>
<td class="grey" align="center">$gametype</td>
<td class="grey" align="center"><a class="grey" href="mapstats.php?map=$gm_map">$map</a></td>
<td class="grey" align="center">$gm_numplayers</td>
<td class="grey" align="center">$length</td>
</tr>
EOF;
}
sql_free_result($result);
sql_close($link);
echo "</table>\n";
if (!$matches) {
echo <<<EOF
<table cellpadding="1" cellspacing="2" border="0" width="600">
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5" align="center"><b>No matches available.</b></td>
</tr>
</table>
EOF;
}
echo <<<EOF
</td>
</tr>
</table>
</body>
</html>
EOF;
?>