forked from kestasjk/webDiplomacy
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathboard.php
453 lines (374 loc) · 14.2 KB
/
board.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
<?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 Board
*/
require_once('header.php');
if ( ! isset($_REQUEST['gameID']) )
{
libHTML::error(l_t("You haven't specified a game to view, please go back to the game listings and choose one."));
}
$gameID = (int)$_REQUEST['gameID'];
// If we are trying to join the game lock it for update, so it won't get changed while we are joining it.
if ( $User->type['User'] && ( isset($_REQUEST['join']) || isset($_REQUEST['leave']) ) && libHTML::checkTicket() )
{
try
{
require_once(l_r('gamemaster/game.php'));
$Variant=libVariant::loadFromGameID($gameID);
libVariant::setGlobals($Variant);
$Game = $Variant->processGame($gameID);
// If viewing an archive page make that the title, otherwise us the name of the game
libHTML::starthtml(isset($_REQUEST['viewArchive'])?$_REQUEST['viewArchive']:$Game->titleBarName());
if ( isset($_REQUEST['join']) )
{
// They will be stopped here if they're not allowed.
$Game->Members->join(
( isset($_REQUEST['gamepass']) ? $_REQUEST['gamepass'] : null ),
( isset($_REQUEST['countryID']) ? $_REQUEST['countryID'] : null ) );
}
elseif ( isset($_REQUEST['leave']) )
{
$reason=$Game->Members->cantLeaveReason();
if($reason)
throw new Exception(l_t("Can't leave game; %s.",$reason));
else
$Game->Members->ByUserID[$User->id]->leave();
}
}
catch(Exception $e)
{
// Couldn't leave/join game
libHTML::error($e->getMessage());
}
}
else
{
try
{
require_once(l_r('objects/game.php'));
require_once(l_r('board/chatbox.php'));
require_once(l_r('gamepanel/gameboard.php'));
$Variant=libVariant::loadFromGameID($gameID);
libVariant::setGlobals($Variant);
$Game = $Variant->panelGameBoard($gameID);
// If viewing an archive page make that the title, otherwise us the name of the game
libHTML::starthtml(isset($_REQUEST['viewArchive'])?$_REQUEST['viewArchive']:$Game->titleBarName());
// In an game with strict rlPolicy don't allow users to join from a Left if they know someone else in this game
// Usually after a Mod set them to CD.
if ( $Game->Members->isJoined() && !$Game->Members->isTempBanned() && $Game->rlPolicy == 'Strict' && $User->rlGroup < 0 && $Game->Members->ByUserID[$User->id]->status == 'Left')
{
require_once ("lib/relations.php");
if ($message = libRelations::checkRelationsGame($User, $Game))
print "<b>Notice:</b> ".$message;
unset($Game->Members->ByUserID[$User->id]);
}
if ( $Game->Members->isJoined() && !$Game->Members->isTempBanned() )
{
// We are a member, load the extra code that we might need
require_once(l_r('gamemaster/gamemaster.php'));
require_once(l_r('board/member.php'));
require_once(l_r('board/orders/orderinterface.php'));
global $Member;
$Game->Members->makeUserMember($User->id);
$Member = $Game->Members->ByUserID[$User->id];
// Advanced-Log
$DB->sql_put("INSERT INTO wD_AccessLogAdvanced SET
userID = ".$User->id.",
request = CURRENT_TIMESTAMP,
ip = INET_ATON('".$_SERVER['REMOTE_ADDR']."'),
action = 'Board',
memberID = '".$Member->id."'"
);
}
}
catch(Exception $e)
{
// Couldn't load game
libHTML::error(l_t("Couldn't load specified game; this probably means this game was cancelled or abandoned.")." ".
($User->type['User'] ? l_t("Check your <a href='index.php' class='light'>notices</a> for messages regarding this game."):''));
}
}
if ( isset($_REQUEST['viewArchive']) )
{
// Start HTML with board gamepanel header
print '</div>';
print '<div class="content-bare content-board-header">';
print '<div class="boardHeader">'.$Game->contentHeader().'</div>';
print '</div>';
print '<div class="content content-follow-on">';
print '<p><a href="board.php?gameID='.$Game->id.'" class="light">'.l_t('< Return').'</a></p>';
switch($_REQUEST['viewArchive'])
{
case 'Orders': require_once(l_r('board/info/orders.php')); break;
case 'Messages': require_once(l_r('board/info/messages.php')); break;
case 'Graph': require_once(l_r('board/info/graph.php')); break;
case 'Maps': require_once(l_r('board/info/maps.php')); break;
case 'Reports':
require_once(l_r('lib/modnotes.php'));
libModNotes::checkDeleteNote();
libModNotes::checkInsertNote();
print libModNotes::reportBoxHTML('Game',$Game->id);
print libModNotes::reportsDisplay('Game', $Game->id);
break;
default: libHTML::error(l_t("Invalid info parameter given."));
}
print '</div>';
libHTML::footer();
}
if ( $Game->watched() && isset($_REQUEST['unwatch'])) {
print '<div class="content-notice gameTimeRemaining">'
.'<form method="post" action="redirect.php">'
.libAuth::formTokenHTML()
.'Are you sure you wish to remove this game from your spectated games list? '
.'<input type="hidden" name="gameID" value="'.$Game->id.'">'
.'<input type="submit" class="form-submit" name="unwatch" value="Confirm">
</form></div>';
}
// Before HTML pre-generate everything and check input, so game summary header will be accurate
if( ( (isset($Member) && $Member->status == 'Playing') || $User->id == $Game->directorUserID) && $Game->phase!='Finished' )
{
if( $Game->phase != 'Pre-game' )
{
if(isset($_REQUEST['Unpause'])) $_REQUEST['Pause']='on'; // Hack because Unpause = toggle Pause
foreach(Members::$votes as $possibleVoteType) {
if( isset($_REQUEST[$possibleVoteType]) && isset($Member) && libHTML::checkTicket() )
$Member->toggleVote($possibleVoteType);
}
}
$DB->sql_put("COMMIT");
if( $Game->processStatus!='Crashed' && $Game->processStatus!='Paused' && $Game->attempts > count($Game->Members->ByID)/2+4 )
{
require_once(l_r('gamemaster/game.php'));
$Game = $Game->Variant->processGame($Game->id);
$Game->crashed();
$DB->sql_put("COMMIT");
}
else
{
if( isset($Member) && $Game->Members->votesPassed() && $Game->phase!='Finished' )
{
$DB->sql_put("UPDATE wD_Games SET attempts=attempts+1 WHERE id=".$Game->id);
$DB->sql_put("COMMIT");
require_once(l_r('gamemaster/game.php'));
$Game = $Game->Variant->processGame($Game->id);
try
{
$Game->applyVotes(); // Will requery votesPassed()
$DB->sql_put("UPDATE wD_Games SET attempts=0 WHERE id=".$Game->id);
$DB->sql_put("COMMIT");
}
catch(Exception $e)
{
if( $e->getMessage() == "Abandoned" || $e->getMessage() == "Cancelled" )
{
assert($Game->phase == 'Pre-game' || $e->getMessage() == 'Cancelled');
$DB->sql_put("COMMIT");
libHTML::notice(l_t('Cancelled'), l_t("Game was cancelled or didn't have enough players to start."));
}
else
$DB->sql_put("ROLLBACK");
throw $e;
}
}
else if( $Game->needsProcess() )
{
$DB->sql_put("UPDATE wD_Games SET attempts=attempts+1 WHERE id=".$Game->id);
$DB->sql_put("COMMIT");
require_once(l_r('gamemaster/game.php'));
$Game = $Game->Variant->processGame($Game->id);
if( $Game->needsProcess() )
{
try
{
$Game->process();
$DB->sql_put("UPDATE wD_Games SET attempts=0 WHERE id=".$Game->id);
$DB->sql_put("COMMIT");
}
catch(Exception $e)
{
if( $e->getMessage() == "Abandoned" || $e->getMessage() == "Cancelled" )
{
assert($Game->phase == 'Pre-game' || $e->getMessage() == 'Cancelled');
$DB->sql_put("COMMIT");
libHTML::notice(l_t('Cancelled'), l_t("Game was cancelled or didn't have enough players to start."));
}
else
$DB->sql_put("ROLLBACK");
throw $e;
}
}
}
}
/* This is a bit ugly. BEcause of the countrySwitch-code it might be possible that a Member
* is no longer in the game, once it's processed.
* Skip the next few lines if so.
*/
if (!(isset($Game->Members->ByUserID[$User->id])) && isset($Member))
{
unset($Member);
goto NoMoreMember;
}
if( $Game instanceof processGame )
{
$Game = $Game->Variant->panelGameBoard($Game->id);
$Game->Members->makeUserMember($User->id);
$Member = $Game->Members->ByUserID[$User->id];
}
if ( 'Pre-game' != $Game->phase && $Game->phase!='Finished' && isset($Member))
{
if ($Game->adminLock == 'No' || $User->type['Admin'] || defined('AdminUserSwitch'))
{
$OI = OrderInterface::newBoard();
$OI->load();
$Orders = '<div id="orderDiv'.$Member->id.'">'.$OI->html().'</div>';
unset($OI);
}
else
{
$Orders = '<div align="center" id="orderDiv'.$Member->id.'">Game is currently locked by an admin (usually to fix some errors).</div>';
}
}
}
// Skip-target for the CountrySwitch-exit.
NoMoreMember:
if ( 'Pre-game' != $Game->phase && ( isset($Member) || $User->type['Moderator'] || $User->id == $Game->directorUserID ) )
{
$CB = $Game->Variant->Chatbox();
// Now that we have retrieved the latest messages we can update the time we last viewed the messages
// Post messages we sent, and get the user we're speaking to
$msgCountryID = $CB->findTab();
$CB->postMessage($msgCountryID);
$DB->sql_put("COMMIT");
$forum = $CB->output($msgCountryID);
unset($CB);
libHTML::$footerScript[] = 'makeFormsSafe();';
}
/*
* Display the chatbox in gunboat games if there are unread system messages
*/
if ( isset($Member) && count($Member->newMessagesFrom) > 0 && $Game->pressType=='NoPress')
{
$CB = $Game->Variant->Chatbox();
$forum = $CB->output(0);
$Member->seen(0);
unset($CB);
}
/*
* Pregame-chat hack
*/
if ($Game->phase == 'Pre-game')
{
$CB = $Game->Variant->Chatbox();
$forum = $CB->output(0);
unset($CB);
if (isset($Member))
$Member->seen(0);
libHTML::$footerScript[] = 'makeFormsSafe();';
}
// END PREGAME-CHAT
$map = $Game->mapHTML();
/*if( isset($_REQUEST['goNow']) )
{
$DB->sql_put("UPDATE wD_Games SET processTime=1 WHERE id=".$Game->id);
}//*/
/*require_once(l_r('gamemaster/game.php'));
$Game = $Variant->processGame($Game->id);
$tabl=$DB->sql_tabl("SELECT id FROM wD_Users WHERE points>150 LIMIT 4");
while(list($id)=$DB->tabl_row($tabl))
processMember::create($id, 5);
$Game = $Game->Variant->panelGameBoard($Game->id);//*/
/*
* Now there is $orders, $form, and $map. That's all the HTML cached, now begin printing
*/
print '</div>';
if (isset(Config::$hiddenVariants) && in_array($Game->Variant->id,Config::$hiddenVariants) && $User->type['Guest'])
{
print '</div>';
libHTML::footer();
exit;
}
print '<div class="content-bare content-board-header">';
print '<div class="boardHeader">'.$Game->contentHeader().'</div>';
print '</div>';
// Now print the forum, map, orders, and summary
if ( isset($forum) )
{
print '<div class="content content-follow-on variant'.$Game->Variant->name.'">';
print $forum.'<div class="hr"></div>';
print '</div>';
}
// Now print the map
print $map;
// Now print the orders, and summary
print '<div style="padding: 0px !important;" class="content content-follow-on variant'.$Game->Variant->name.'"><div class="hr"></div>';
if (isset($Orders))
{
print $Orders.'<div class="hr"></div>';
}
print $Game->summary(true);
if($User->type['Moderator'])
{
$modActions=array();
if($Game->gameOver=='No')
{
$modActions[] = libHTML::admincpType('Game',$Game->id);
$modActions[] = libHTML::admincp('resetMinimumBet',array('gameID'=>$Game->id), l_t('Reset Min Bet'));
$modActions[] = libHTML::admincp('togglePause',array('gameID'=>$Game->id), l_t('Toggle pause'));
if($Game->processStatus=='Not-processing')
{
$modActions[] = libHTML::admincp('setProcessTimeToNow',array('gameID'=>$Game->id), l_t('Process now'));
$modActions[] = libHTML::admincp('setProcessTimeToPhase',array('gameID'=>$Game->id), l_t('Reset Phase'));
}
$modActions[] = libHTML::admincp('updateCCIP',array('gameID'=>$Game->id), l_t('Recalculate IP and CC matches'));
if($User->type['Admin'])
{
if($Game->processStatus == 'Crashed')
$modActions[] = libHTML::admincp('unCrashGames',array('excludeGameIDs'=>''), l_t('Un-crash all crashed games'));
$modActions[] = libHTML::admincp('allReady',array('gameID'=>$Game->id), 'Set Ready');
}
if( $Game->phase!='Pre-game' && !$Game->isMemberInfoHidden() )
{
$userIDs=implode('%2C',array_keys($Game->Members->ByUserID));
$modActions[] = '<br /></br>'.l_t('Multi-check:');
foreach($Game->Members->ByCountryID as $countryID=>$Member)
{
$modActions[] = '<a href="admincp.php?tab=Multi-accounts&aUserID='.$Member->userID.'" class="light">'.
$Member->memberCountryName().'('.$Member->username.')</a>';
}
}
}
if($modActions)
{
print '<div class="hr"></div>';
print '<p class="notice">';
print implode(' - ', $modActions);
print '</p>';
print '<div class="hr"></div>';
}
}
// TODO: Have this loaded up when the game object is loaded up
list($directorUserID) = $DB->sql_row("SELECT directorUserID FROM wD_Games WHERE id = ".$Game->id);
list($tournamentDirector, $tournamentCodirector) = $DB->sql_row("SELECT directorID, coDirectorID FROM wD_Tournaments t INNER JOIN wD_TournamentGames g ON t.id = g.tournamentID WHERE g.gameID = ".$Game->id);
if( (isset($directorUserID) && $directorUserID == $User->id) || (isset($tournamentDirector) && $tournamentDirector == $User->id) || (isset($tournamentCodirector) && $tournamentCodirector == $User->id) )
{
// This guy is the game director
define("INBOARD", true);
require_once(l_r("admin/adminActionsForms.php"));
}
print '</div>';
libHTML::footer();
?>