-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
333 lines (245 loc) · 16.8 KB
/
index.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
// Debug Meldungen einschalten
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
session_start();
$time = time();
require('conf/variables.php');
require('include/smileys.inc.php');
require_once('include/genericfunctions.inc.php');
date_default_timezone_set("$cfg_ladder_timezone");
?>
<?php
if (isset($_POST['user']) AND isset($_POST['pass'])) {
$fname = $_POST['user'];
$fpass = $_POST['pass'];
// Lets hinder players who havent verified their mail from logging in / creating logged in cookies...
//eye Check if the player has verified his email by clicking the activation link...
$sql = "SELECT * FROM $playerstable WHERE name = '$fname'";
$result = mysqli_query($db, $sql);
$row = mysqli_fetch_array($result);
if (empty($row)) {
require('top.php');
echo "<b>The nickname you entered doesn't exist.</b><br><br>";
require('bottom.php');
exit;
}
if ($row['Confirmation'] != "" AND $row['Confirmation'] == "Deleted") {
require('top.php');
echo "<b>You can't login because your account was deleted either on your request or by admin.</b><br><br>Feel free to contact us if you want to re-enable your account: All the data associated with it has been saved and can easily be restored by admin.";
require('bottom.php');
exit;
}
if ($row['Confirmation'] != "" AND $row['Confirmation'] != "Ok") {
require('top.php');
echo "<b>You can't login because you have not activated your account.</b><br /><br />When you registered a mail was sent to you containing a unique <i>activation link</i>. Please find that mail and click the activation link. Don't forget to check your spam box, as some services wrongly flag our activation mail as spam. <br><br>Feel free to contact us if you are sure that you have misplaced your activation email.";
require('bottom.php');
exit;
}
// Ok, we have checked that the user is verified and can let him in...
// Let's generate the encrypted pass, after all, it's the one that's stored in the database... we do it by applying the salt and hashing it twice.
// We need to take the user's real pass, "encrypt" it the same way we did when he registered, and then compare the results.
// The salt is read from the config file.
$passworddb = $salt . $fpass;
$passworddb = md5($passworddb);
$passworddb = md5($passworddb);
//echo "<br>Form: $fname / $fpass";
$sql = "SELECT * FROM $playerstable WHERE name='$fname' AND passworddb='$passworddb'";
$result = mysqli_query($db, $sql);
$bajs = mysqli_fetch_array($result);
//echo "<br>Test 2";
if (is_array($bajs) && $bajs['player_id'] > 0) {
// Set cookies... 776000 sec = 3 months before they expire.
setcookie("LadderofWesnoth1", $bajs['name'], $time + 7776000);
setcookie("LadderofWesnoth2", $bajs['passworddb'], $time + 7776000);
$_SESSION['username'] = $bajs['name'];
$_SESSION['real-username'] = $bajs['name'];
header("Location: index.php");
//echo $sql;
exit;
//header("Location: http://www.example.com/");
//DEB print_r($_COOKIE);
//DEB echo "<div align='right'>// $bajs[name]</div>";
} else {
$login_error = true;
// Show error msg if the login failed...
require('top.php');
echo "<h1>Login Failed.</h1><br><p>Please make sure that you're registered and that you typed in the correct username/password. If you've checked everything 5 times and the problem still remains please contact us and we'll assist you.</p>";
require('bottom.php');
exit;
}
}
// You must have autologin before top.php
require 'autologin.inc.php';
require('top.php');
?>
<br/>
<table border=0 width="100%" style="smallinfo">
<tr>
<td width="50%" valign="top" padding-right="20px">
<?php
If (INDEX_COMMENT_HILITE == 1) {
$sql = "SELECT winner, loser, replay_filename is not null as is_replay, reported_on, winner_comment, loser_comment, winner_elo, loser_elo FROM $gamestable WHERE withdrawn = 0 AND contested_by_loser = 0 AND replay_filename != '' AND (winner_comment != '' || loser_comment != '') ORDER BY reported_on DESC LIMIT 0,1";
$result = mysqli_query($db, $sql);
$row = mysqli_fetch_array($result);
echo "<div class=\"spotlight\"><h1 class=\"spotlight\">Spotlight</h1><br /> <b>" . $row['winner'] . " (" . $row['winner_elo'] . ") / " . $row['loser'] . " (" . $row['loser_elo'] . ")</b>";
if ($row['is_replay'] != 0) {
echo " <a href=\"download-replay.php?reported_on=$row[reported_on]\">®</a><br /><br />";
}
// We don't want to show the comments to members that are not logged in if comments are set to only display to logged in members...
if ((NONPUBLIC_REPLAY_COMMENTS == 0) || ((NONPUBLIC_REPLAY_COMMENTS == 1) && (isset($_SESSION['username'])))) {
if (trim($row['winner_comment']) != "") {
echo "<i>\"" . Linkify($row['winner_comment']) . "\" </i>~" . $row['winner'] . "<br /><br />";
}
if (trim($row['loser_comment']) != "") {
echo "<i>\"" . Linkify($row['loser_comment']) . "\" </i>~" . $row['loser'];
}
} else {
echo "<i>Please login to read game comments.</i>";
}
// Magic Commentator starts here ---------------------------------------------------------------
if ($MagicComGotEloSettings['Comments'] > 0) {
echo "<br><br>";
$sql = "SELECT * FROM $gamestable WHERE contested_by_loser = '0' AND withdrawn = '0' ORDER BY reported_on DESC LIMIT 0,1000";
//set some variables used in the next step (to avoid undefined variables notice)
$PreviousWinner = "";
$MagicCounter = 0;
$result = mysqli_query($db, $sql);
while ($RowAutoMent = mysqli_fetch_array($result)) {
// Get random messages for the magic commentator... (these are set in config)
$MagicComRandTopX = array_rand($MagicComRandTopXMsgs, 2);
$MagicComRandTop1st = array_rand($MagicComRandTop1stMsgs, 2);
$MagicComRandTop2 = array_rand($MagicComRandTop2Msgs, 2);
$MagicComRandTop5 = array_rand($MagicComRandTop5Msgs, 2);
$MagicComRandElo = array_rand($MagicComRandEloMsgs, 2);
// Don't touch the order of the IF statements, they're exectud the mist interesting first and should be kept like they are unless you really have some wierd desire.
// Took 1:st place
if (($PreviousWinner != $RowAutoMent['winner']) && stristr(INDEX_MAGIC_COMMENTATOR, 'Q') && (($RowAutoMent['w_rank'] > 1) || ($RowAutoMent['w_rank'] == 0)) && (($RowAutoMent['w_new_rank'] == 1) && ($RowAutoMent['w_new_rank'] > 0))) {
echo "<br>[" . GetOnlyMonthDay($RowAutoMent['reported_on']) . "] <a href=\"profile.php?name=" . $RowAutoMent['winner'] . "\">" . $RowAutoMent['winner'] . "</a> " . $MagicComRandTop1stMsgs[$MagicComRandTop1st[0]];
// Remember the persons involved in the last display, to not show info twice in a row about the same person
$PreviousWinner = $RowAutoMent['winner'];
$PreviousLoser = $RowAutoMent['loser'];
$MagicCounter++;
}
// Took 2:nd place
if (($PreviousWinner != $RowAutoMent['winner']) && stristr(INDEX_MAGIC_COMMENTATOR, 'W') && (($RowAutoMent['w_rank'] > 2) || ($RowAutoMent['w_rank'] == 0)) && (($RowAutoMent['w_new_rank'] == 2) && ($RowAutoMent['w_new_rank'] > 0))) {
echo "<br>[" . GetOnlyMonthDay($RowAutoMent['reported_on']) . "] <a href=\"profile.php?name=" . $RowAutoMent['winner'] . "\">" . $RowAutoMent['winner'] . "</a> " . $MagicComRandTop2Msgs[$MagicComRandTop2[0]] . " 2nd place.";
// Remember the persons involved in the last display, to not show info twice in a row about the same person
$PreviousWinner = $RowAutoMent['winner'];
$PreviousLoser = $RowAutoMent['loser'];
$MagicCounter++;
}
// Took 3:d place
if (($PreviousWinner != $RowAutoMent['winner']) && stristr(INDEX_MAGIC_COMMENTATOR, 'E') && (($RowAutoMent['w_rank'] > 3) || ($RowAutoMent['w_rank'] == 0)) && (($RowAutoMent['w_new_rank'] == 3) && ($RowAutoMent['w_new_rank'] > 0))) {
echo "<br>[" . GetOnlyMonthDay($RowAutoMent['reported_on']) . "] <a href=\"profile.php?name=" . $RowAutoMent['winner'] . "\">" . $RowAutoMent['winner'] . "</a> " . $MagicComRandTop2Msgs[$MagicComRandTop2[0]] . " 3rd place.";
// Remember the persons involved in the last display, to not show info twice in a row about the same person
$PreviousWinner = $RowAutoMent['winner'];
$PreviousLoser = $RowAutoMent['loser'];
$MagicCounter++;
}
// Entered Top 5
if (($PreviousWinner != $RowAutoMent['winner']) && stristr(INDEX_MAGIC_COMMENTATOR, 'R') && (($RowAutoMent['w_rank'] > 5) || ($RowAutoMent['w_rank'] == 0)) && (($RowAutoMent['w_new_rank'] <= 5) && ($RowAutoMent['w_new_rank'] > 0) && ($RowAutoMent['w_new_rank'] > 3))) {
echo "<br>[" . GetOnlyMonthDay($RowAutoMent['reported_on']) . "] <a href=\"profile.php?name=" . $RowAutoMent['winner'] . "\">" . $RowAutoMent['winner'] . "</a> " . $MagicComRandTop5Msgs[$MagicComRandTop5[0]] . " Top 5.";
$PreviousWinner = $RowAutoMent['winner'];
$PreviousLoser = $RowAutoMent['loser'];
$MagicCounter++;
}
// Entered Top 10
if (($PreviousWinner != $RowAutoMent['winner']) && stristr(INDEX_MAGIC_COMMENTATOR, 'T') && (($RowAutoMent['w_rank'] > 10) || ($RowAutoMent['w_rank'] == 0)) && (($RowAutoMent['w_new_rank'] <= 10) && ($RowAutoMent['w_new_rank'] > 0))) {
echo "<br>[" . GetOnlyMonthDay($RowAutoMent['reported_on']) . "] <a href=\"profile.php?name=" . $RowAutoMent['winner'] . "\">" . $RowAutoMent['winner'] . "</a> " . $MagicComRandTopXMsgs[$MagicComRandTopX[0]] . " Top 10.";
$PreviousWinner = $RowAutoMent['winner'];
$PreviousLoser = $RowAutoMent['loser'];
$MagicCounter++;
}
// Entered Top 20
if (($PreviousWinner != $RowAutoMent['winner']) && stristr(INDEX_MAGIC_COMMENTATOR, 'Y') && (($RowAutoMent['w_rank'] > 20) || ($RowAutoMent['w_rank'] == 0)) && (($RowAutoMent['w_new_rank'] <= 20) && ($RowAutoMent['w_new_rank'] > 0))) {
echo "<br>[" . GetOnlyMonthDay($RowAutoMent['reported_on']) . "] <a href=\"profile.php?name=" . $RowAutoMent['winner'] . "\">" . $RowAutoMent['winner'] . "</a> " . $MagicComRandTopXMsgs[$MagicComRandTopX[0]] . " Top 20.";
$PreviousWinner = $RowAutoMent['winner'];
$PreviousLoser = $RowAutoMent['loser'];
$MagicCounter++;
}
if (($PreviousWinner != $RowAutoMent['winner']) && stristr(INDEX_MAGIC_COMMENTATOR, 'L')) {
// Check if user has reachead a rating that's, for example, gone from being 15xx to 16xx, or 19xx to 20xx. Ranges are is set in the config file.
$MCcurrentrating = $MagicComGotEloSettings['FirstRating'];
$WinnersEloBeforeGame = ($RowAutoMent['winner_elo'] - $RowAutoMent['winner_points']);
while (($PreviousWinner != $RowAutoMent['winner']) && ($MCcurrentrating <= $MagicComGotEloSettings['LastRating'])) {
if (($PreviousWinner != $RowAutoMent['winner']) && ($WinnersEloBeforeGame < $MCcurrentrating) && ($RowAutoMent['winner_elo'] > $MCcurrentrating) && ($RowAutoMent['winner_elo'] < ($MCcurrentrating + $MagicComGotEloSettings['AddThis']))) {
echo "<br>[" . GetOnlyMonthDay($RowAutoMent['reported_on']) . "] <a href=\"profile.php?name=" . $RowAutoMent['winner'] . "\">" . $RowAutoMent['winner'] . "</a> " . $MagicComRandEloMsgs[$MagicComRandElo[0]] . " " . $MCcurrentrating . " Elo points.";
$PreviousWinner = $RowAutoMent['winner'];
$PreviousLoser = $RowAutoMent['loser'];
$MagicCounter++;
}
$MCcurrentrating = $MCcurrentrating + $MagicComGotEloSettings['AddThis'];
}
}
/* Show negative comments...
if (($RowAutoMent['l_rank'] < 80) && ($RowAutoMent['l_new_rank'] >= 80)) {
echo "<br>[". GetOnlyMonthDay($RowAutoMent['reported_on']) ."] ". $RowAutoMent['loser'] ." entered the bottom 80 at rank ". $RowAutoMent['l_new_rank'];
*/
// Check if we've shown enough comments
if ($MagicCounter >= $MagicComGotEloSettings['Comments']) {
break;
}
} // Magic commentator While-loop ends here.
} // Magic commentator ends here
} // If comment hilite is on anything within the } will happen
echo "<h1>News</h1>";
if (isset($_GET['readnews'])) {
$newsId = intval($_GET['readnews']);
$sql = "SELECT * FROM $newstable WHERE news_id = '$newsId' ORDER BY news_id DESC LIMIT 0, $newsitems";
$result = mysqli_query($db, $sql);
$row = mysqli_fetch_array($result);
$news = nl2br($row["news"]);
$news = addSmileys($news);
print("
<p class=header>$row[title]</p>
<p class=text>$news</p>
<hr size=1><br>
");
} else {
$sql = "SELECT * FROM $newstable ORDER BY news_id DESC LIMIT 0, $newsitems";
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_array($result)) {
$news = nl2br($row["news"]);
$news = addSmileys($news);
print("
<p class=header>$row[title]</p>
<p class=text>$news</p>
<br>
<hr size=1<br />
");
}
}
print("
<p class=header>Other news articles:</p>
<p class=text>
");
/* If the user has clicked on a specific news he only sees that one and we need to change the list of old news below it,
so it shows news that are older than the news item he is viewing. So, if he reads newsitem 45, we want a list below it with
news with a lower id than 45. That's what the following does, and we simply alter the sql query depending on if he views the
index page or if he has clicked a specific news item...
*/
if (isset($_GET['readnews'])) {
$query = "SELECT COUNT(*) FROM $newstable";
$result = mysqli_query($db, $query) or die(mysqli_error($db));
$row = mysqli_fetch_array($result);
// Let's count the number of news items in the database. Rumors say this is a faster method than getrows, but I don't know.
// $numindexnews2 = $row['COUNT(*)'] - $_GET['readnews'];
$newsId = intval($_GET['readnews']);
$sql = "SELECT * FROM $newstable WHERE news_id < $newsId ORDER BY news_id DESC LIMIT $newsitems, $numindexnews";
} else {
// This is what happens when he hasn't clicked a specific news item, not complicated at all, the variables are all in the config file.
$sql = "SELECT * FROM $newstable ORDER BY news_id DESC LIMIT $newsitems, $numindexnews";
}
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_array($result)) {
echo "<a href='index.php?readnews=$row[news_id]'>$row[date] - $row[title]</a><br>";
}
?>
</td>
<?php
include('sidebar.php');
echo "<br>";
//require_once('include/cronjobs.inc.php');
require('bottom.php');
?>