forked from Sleepcap/vDiplomacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·529 lines (426 loc) · 14.3 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
<?php
/*
Copyright (C) 2004-2010 Kestas J. Kuliukas
This file is part of webDiplomacy.
webDiplomacy is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
webDiplomacy 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 Affero General Public License
along with webDiplomacy. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @package Base
*/
require_once('header.php');
require_once(l_r('lib/message.php'));
require_once(l_r('objects/game.php'));
require_once(l_r('gamepanel/gamehome.php'));
/*
* A field
*
* add(field, index)
* compare(field1, field2) -> 1 if aligned, 0 if not
*
*/
libHTML::starthtml(l_t('Home'));
if( !isset($_SESSION['lastSeenHome']) || $_SESSION['lastSeenHome'] < $User->timeLastSessionEnded )
{
$_SESSION['lastSeenHome']=$User->timeLastSessionEnded;
}
class libHome
{
static public function getType($type=false, $limit=35)
{
global $DB, $User;
$notices=array();
$tabl=$DB->sql_tabl("SELECT *
FROM wD_Notices WHERE toUserID=".$User->id.($type ? " AND type='".$type."'" : '')."
ORDER BY timeSent DESC ".($limit?'LIMIT '.$limit:''));
while($hash=$DB->tabl_hash($tabl))
{
$notices[] = new notice($hash);
}
return $notices;
}
public static function PMs()
{
$pms = self::getType('PM', 10);
$buf = '';
foreach($pms as $pm)
{
$buf .= $pm->html();
}
return $buf;
}
public static function Game()
{
global $User;
$pms = self::getType('Game');
if(!count($pms))
{
print '<div class="hr"></div>';
print '<p class="notice">'.l_t('No game notices found.').'</p>';
return;
}
print '<div class="hr"></div>';
foreach($pms as $pm)
{
print $pm->viewedSplitter();
print $pm->html();
}
}
public static function NoticePMs()
{
global $User;
try
{
$message=notice::sendPMs();
}
catch(Exception $e)
{
$message=$e->getMessage();
}
if ( $message )
print '<p class="notice">'.$message.'</p>';
$pms = self::getType('PM');
if(!count($pms))
{
print '<div class="hr"></div>';
print '<p class="notice">'.l_t('No private messages found; you can send them to other people on their profile page.').'</p>';
return;
}
print '<div class="hr"></div>';
foreach($pms as $pm)
{
print $pm->viewedSplitter();
print $pm->html();
}
}
public static function NoticeGame()
{
global $User;
$pms = self::getType('Game');
if(!count($pms))
{
print '<div class="hr"></div>';
print '<p class="notice">'.l_t('No game notices found; try browsing the <a href="gamelistings.php">game listings</a>, '.
'or <a href="gamecreate.php">create your own</a> game.').'</p>';
return;
}
print '<div class="hr"></div>';
foreach($pms as $pm)
{
print $pm->viewedSplitter();
print $pm->html();
}
}
public static function Notice()
{
global $User;
$pms = self::getType();
if(!count($pms))
{
print '<div class="hr"></div>';
print '<p class="notice">'.l_t('No notices found.').'</p>';
return;
}
print '<div class="hr"></div>';
foreach($pms as $pm)
{
print $pm->viewedSplitter();
print $pm->html();
}
}
static function topUsers()
{
global $DB;
$rows=array();
$tabl = $DB->sql_tabl("SELECT id, username, points FROM wD_Users
order BY points DESC LIMIT 10");
$i=1;
while(list($userID,$username,$points)=$DB->tabl_row($tabl))
{
$rows[] = '#'.$i.': <a href="profile.php?userID='.$userID.'">'.$username.'</a> ('.$points.libHTML::points().')';
$i++;
}
return $rows;
}
static function statsGlobalGame()
{
global $Misc;
$stats=array(
'Starting'=>$Misc->GamesNew,
'Joinable'=>$Misc->GamesOpen,
'Active'=>$Misc->GamesActive,
'Finished'=>$Misc->GamesFinished
);
return $stats;
}
static function statsGlobalUser()
{
global $Misc;
$stats=array(
'Logged on'=>$Misc->OnlinePlayers,
'Playing'=>$Misc->ActivePlayers,
'Registered'=>$Misc->TotalPlayers
);
if( $stats['Logged on'] <= 1 ) unset($stats['Logged on']);
if( $stats['Playing'] < 25 ) unset($stats['Playing']);
return $stats;
}
static function globalInfo()
{
$userStats = self::statsGlobalUser();
$gameStats = self::statsGlobalGame();
//$topUsers = self::topUsers();
//$buf='<div class="content" style="text-align:center;"><strong>Users:</strong> ';
$buf='<strong>'.l_t('Users:').'</strong> ';
$first=true;
foreach($userStats as $name => $val)
{
if( $first ) $first=false; else $buf .= ' - ';
$buf .= l_t($name).':<strong>'.$val.'</strong>';
}
$buf .= '<br /><strong>'.l_t('Games:').'</strong> ';
$first=true;
foreach($gameStats as $name => $val)
{
if( $first ) $first=false; else $buf .= ' - ';
$buf .= l_t($name).':<strong>'.$val.'</strong>';
}
//$buf .= '</div>';
//$buf .= '<br /><h3>Hall of fame</h3>'.implode('<br />',$topUsers);
return $buf;
}
static public function gameNotifyBlock ()
{
global $User, $DB;
$tabl=$DB->sql_tabl("SELECT g.* FROM wD_Games g
INNER JOIN wD_Members m ON ( (m.userID = ".$User->id." OR g.directorUserID = ".$User->id.") AND m.gameID = g.id )
WHERE NOT g.phase = 'Finished'
GROUP BY g.id
ORDER BY g.processTime ASC");
$buf = '';
$count=0;
while($game=$DB->tabl_hash($tabl))
{
$count++;
$Variant=libVariant::loadFromVariantID($game['variantID']);
$Game=$Variant->panelGameHome($game);
$buf .= '<div class="hr"></div>';
$buf .= $Game->summary();
}
if($count==0)
{
$buf .= '<div class="hr"></div>';
$buf .= '<div><p class="notice">'.l_t('You\'re not joined to any games!').'<br />
'.l_t('Access the <a href="gamelistings.php?tab=">Games</a> '.
'link above to find games you can join, or start a '.
'<a href="gamecreate.php">New game</a> yourself.</a>').'</p></div>';
}
elseif ( $count == 1 && $User->points > 5 )
{
$buf .= '<div class="hr"></div>';
$buf .= '<div><p class="notice">'.l_t('You can join as many games as you '.
'have the points to join.').' </a></p></div>';
}
return $buf;
}
static function forumNew() {
// Select by id, prints replies and new threads
global $DB, $Misc, $User;
$tabl = $DB->sql_tabl("
SELECT m.id as postID, t.id as threadID, m.type, m.timeSent, IF(t.replies IS NULL,m.replies,t.replies) as replies,
IF(t.subject IS NULL,m.subject,t.subject) as subject,
m.anon,
u.id as userID, u.username, u.points, IF(s.userID IS NULL,0,1) as online, u.type as userType,
SUBSTRING(m.message,1,100) as message, m.latestReplySent, t.fromUserID as threadStarterUserID
FROM wD_ForumMessages m
INNER JOIN wD_Users u ON ( m.fromUserID = u.id )
LEFT JOIN wD_Sessions s ON ( m.fromUserID = s.userID )
LEFT JOIN wD_ForumMessages t ON ( m.toID = t.id AND t.type = 'ThreadStart' AND m.type = 'ThreadReply' )
ORDER BY m.timeSent DESC
LIMIT 50");
$oldThreads=0;
$threadCount=0;
$threadIDs = array();
$threads = array();
while(list(
$postID, $threadID, $type, $timeSent, $replies, $subject,
$anon,
$userID, $username, $points, $online, $userType, $message, $latestReplySent,$threadStarterUserID
) = $DB->tabl_row($tabl))
{
// Anonymize the forum posts on the home-screen too
if ($anon == 'Yes')
{
$username = 'Anon';
$userID = 0;
$points = '??';
$userType = 'User';
}
// End anonymizer
$threadCount++;
if( $threadID )
$iconMessage=libHTML::forumMessage($threadID, $postID);
else
$iconMessage=libHTML::forumMessage($postID, $postID);
if ( $type == 'ThreadStart' ) $threadID = $postID;
if( !isset($threads[$threadID]) )
{
if(strlen($subject)>30) $subject = substr($subject,0,40).'...';
$threadIDs[] = $threadID;
$threads[$threadID] = array('subject'=>$subject, 'replies'=>$replies,
'posts'=>array(),'threadStarterUserID'=>$threadStarterUserID);
}
$message=Message::refilterHTML($message);
if( strlen($message) >= 50 ) $message = substr($message,0,50).'...';
$message = '<div class="message-contents threadID'.$threadID.'" fromUserID="'.$userID.'">'.$message.'</div>';
$threads[$threadID]['posts'][] = array(
'iconMessage'=>$iconMessage,'userID'=>$userID, 'username'=>$username,
'message'=>$message,'points'=>$points, 'online'=>$online, 'userType'=>$userType, 'timeSent'=>$timeSent
);
}
$buf = '';
$threadCount=0;
foreach($threadIDs as $threadID)
{
$data = $threads[$threadID];
$buf .= '<div class="hr userID'.$threads[$threadID]['threadStarterUserID'].' threadID'.$threadID.'"></div>';
$buf .= '<div class="homeForumGroup homeForumAlt'.($threadCount%2 + 1).
' userID'.$threads[$threadID]['threadStarterUserID'].' threadID'.$threadID.'">
<div class="homeForumSubject homeForumTopBorder">'.libHTML::forumParticipated($threadID).' '.$data['subject'].'</div> ';
if( count($data['posts']) < $data['replies'])
{
$buf .= '<div class="homeForumPost homeForumMessage homeForumPostAlt'.libHTML::alternate().' ">
...</div>';
}
$data['posts'] = array_reverse($data['posts']);
foreach($data['posts'] as $post)
{
$buf .= '<div class="homeForumPost homeForumPostAlt'.libHTML::alternate().' userID'.$post['userID'].'">
<div class="homeForumPostTime">'.libTime::text($post['timeSent']).' '.$post['iconMessage'].'</div>
<a href="profile.php?userID='.$post['userID'].'" class="light">'.$post['username'].'</a>
'.libHTML::loggedOn($post['userID']) . ' ('.$post['points'].libHTML::points().
User::typeIcon($post['userType']).')
<div style="clear:both"></div>
<div class="homeForumMessage">'.$post['message'].'</div>
</div>';
}
$buf .= '<div class="homeForumLink">
<div class="homeForumReplies">'.l_t('%s replies','<strong>'.$data['replies'].'</strong>').'</div>
<a href="forum.php?threadID='.$threadID.'#'.$threadID.'">'.l_t('Open').'</a>
</div>
</div>';
}
if( $buf )
{
return $buf;
}
else
{
return '<div class="homeNoActivity">'.l_t('No forum posts found, why not '.
'<a href="forum.php?postboxopen=1#postbox" class="light">start one</a>?');
}
}
static function forumBlock()
{
$buf = '<div class="homeHeader">'.l_t('Forum').'</div>';
$forumNew=libHome::forumNew();
$buf .= '<table><tr><td>'.implode('</td></tr><tr><td>',$forumNew).'</td></tr></table>';
return $buf;
}
}
if( !$User->type['User'] )
{
print '<div class="content-notice" style="text-align:center">'.libHome::globalInfo().'</div>';
print libHTML::pageTitle(l_t('Welcome to vDiplomacy!'),l_t('A multiplayer web implementation of the popular turn-based strategy game Diplomacy.'));
//print '<div class="content">';
?>
<p style="text-align: center;"><img
src="<?php print l_s('images/vmap.png'); ?>" alt="<?php print l_t('The map'); ?>"
title="<?php print l_t('A vDiplomacy map'); ?>" /></p>
<p class="welcome"><?php print l_t('<em> "Luck plays no part in Diplomacy. Cunning and
cleverness, honesty and perfectly-timed betrayal are the tools needed to
outwit your fellow players. The most skillful negotiator will climb to
victory over the backs of both enemies and friends.<br />
<br />
Who do you trust?"<br />
(<a href="http://www.wizards.com/default.asp?x=ah/prod/diplomacy"
class="light">Avalon Hill</a>)</em>'); ?></p>
<?php
print '</div>';
/*print '<div class="homeInfoList">
'.libHome::globalInfo()
.'</div>';*/
require_once(l_r('locales/English/intro.php'));
print '</div>';
}
elseif( isset($_REQUEST['notices']) )
{
$User->clearNotification('PrivateMessage');
print '<div class="content"><a href="index.php" class="light">< '.l_t('Back').'</a></div>';
print '<div class="content-bare content-home-header">';
print '<table class="homeTable"><tr>';
notice::$noticesPage=true;
print '<td class="homeNoticesPMs">';
print '<div class="homeHeader">'.l_t('Private messages').'</a></div>';
print libHome::NoticePMs();
print '</td>';
print '<td class="homeSplit"></td>';
print '<td class="homeNoticesGame">';
print '<div class="homeHeader">'.l_t('Game messages').'</a></div>';
print libHome::NoticeGame();
print '</td>';
print '</tr></table>';
print '</div>';
print '</div>';
}
else
{
/*
print '<div class="content-bare content-home-header">';
print '<div class="boardHeader">blabla</div>';
print '</div>';
*/
print '<div class="content-bare content-home-header">';// content-follow-on">';
print '<table class="homeTable"><tr>';
print '<td class="homeMessages">';
print '<div class="homeHeader">'.l_t('Forum').' <a href="forum.php">'.libHTML::link().'</a></div>';
if( file_exists(libCache::dirName('forum').'/home-forum.html') )
print file_get_contents(libCache::dirName('forum').'/home-forum.html');
else
{
$buf_home_forum=libHome::forumNew();
file_put_contents(libCache::dirName('forum').'/home-forum.html', $buf_home_forum);
print $buf_home_forum;
}
print '</td>';
print '<td class="homeSplit"></td>';
print '<td class="homeGameNotices">';
/*$buf = libHome::PMs();
if(strlen($buf))
print '<div class="homeHeader">Private messages</div>'.$buf;
*/
print '<div class="homeHeader">'.l_t('Notices').' <a href="index.php?notices=on">'.libHTML::link().'</a></div>';
print libHome::Notice();
print '</td>';
print '<td class="homeSplit"></td>';
print '<td class="homeGamesStats">';
print '<div class="homeHeader">'.l_t('My games').' <a href="gamelistings.php?page=1&gamelistType=My games">'.libHTML::link().'</a></div>';
print libHome::gameNotifyBlock();
print '</td>
</tr></table>';
print '</div>';
print '</div>';
}
libHTML::$footerIncludes[] = l_j('home.js');
libHTML::$footerScript[] = l_jf('homeGameHighlighter').'();';
$_SESSION['lastSeenHome']=time();
libHTML::footer();
?>