-
Notifications
You must be signed in to change notification settings - Fork 114
/
board.php
executable file
·276 lines (228 loc) · 9.01 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
<?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['joinBeta']) || 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']) || isset($_REQUEST['joinBeta']))
{
// They will be stopped here if they're not allowed.
$Game->Members->join(
( $_REQUEST['gamepass'] ?? null ),
( $_REQUEST['countryID'] ?? null ),
( $_REQUEST['joinBeta'] ?? 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());
}
die(); // This point in the code isn't reached, all code paths above will have terminated by here (this means no need to get a different Game object)
}
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());
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];
// As a member check for any vote submissions, order submissions, and if the game needs to be processed
// Before HTML pre-generate everything and check input, so game summary header will be accurate
if( $Member->status == 'Playing' && $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);
}
}
if ( $Game->phase !='Finished' )
{
$OI = OrderInterface::newBoard();
$OI->load();
$Orders = '<div id="orderDiv'.$Member->id.'">'.$OI->html().'</div>';
unset($OI);
}
}
if( $Game->needsProcess() )
{
$MC->append('processHint',','.$Game->id);
}
}
}
// Process the chatbox / game messages
if( $Game->phase != 'Pre-game' && ( (isset($Member) && is_a($Member, 'userMember') ) || $User->type['Moderator'] || $Game->isDirector($User->id) ) )
{
$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);
$forum = $CB->output($msgCountryID);
unset($CB);
libHTML::$footerScript[] = 'makeFormsSafe();';
}
}
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();
}
// The error where this isn't a panelGameBoard but is probably a processGame appears to be related to someone rejoining a game they were previously
// in civil disorder for. Need to trace how $Game gets set up when rejoining from a CD TODO
$map = $Game->mapHTML();
/*
* Now there is $orders, $form, and $map. That's all the HTML cached, now begin printing
*/
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>';
}
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 variant'.$Game->Variant->name.'">';
// Now print the forum, map, orders, and summary
if ( isset($forum) )
{
print $forum.'<div class="hr"></div>';
}
print $map.'<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'));
}
if($User->type['Admin'])
{
if($Game->processStatus == 'Crashed')
$modActions[] = libHTML::admincp('unCrashGames',array('excludeGameIDs'=>''), l_t('Un-crash all crashed games'));
}
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>';
}
}
if( $Game->isDirector($User->id) )
{
define("INBOARD", true);
require_once(l_r("admin/adminActionsForms.php"));
}
print '</div>';
libHTML::footer();
?>