-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui_create_game.php
330 lines (306 loc) · 14.1 KB
/
gui_create_game.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
<?php
session_start();
// https://www.php-einfach.de/php-tutorial/php-sessions/
require('./logger.php');
require('./db.php');
if (!isset($_SESSION['playerid'])) {
echo "Not logged in... redirecting.<br>";
echo "<meta http-equiv='refresh' content='0;url=./login.php?auto=1'>";
header("Location: ./login.php?auto=1");
//die("Check position 10");
}
// Get data on units from db
$pid = $_SESSION['playerid'];
$gid = $_SESSION['gameid'];
$pname = $_SESSION['name'];
$pimage = $_SESSION['playerimage'];
$opt3 = $_SESSION['option3'];
$playMode = $opt3;
$sql_asc_playerround = "SELECT SQL_NO_CACHE * FROM asc_player where playerid = " . $pid . ";";
$result_asc_playerround = mysqli_query($conn, $sql_asc_playerround);
if (mysqli_num_rows($result_asc_playerround) > 0) {
while($row = mysqli_fetch_assoc($result_asc_playerround)) {
$CURRENTROUND = $row["round"];
}
}
$sql_asc_game = "SELECT SQL_NO_CACHE * FROM asc_game where ownerPlayerId = " . $pid . ";";
$result_asc_game = mysqli_query($conn, $sql_asc_game);
if (mysqli_num_rows($result_asc_game) > 0) {
while($row = mysqli_fetch_assoc($result_asc_game)) {
$GAMEID = $row["gameid"];
$OWNERPLAYERID = $row["ownerPlayerId"];
$ACCESSCODE = $row["accessCode"];
$LOCKED = $row["locked"];
$DESC = $row["description"];
}
} else {
// this player does not have a game yet
if (endsWith($pname, 's')) {
$description = $pname . "' game";
} else {
$description = $pname . "'s game";
}
$accesscodeGenerated = substr(str_shuffle("0123456789"), 0, 4);
$sqlinsertgame = "INSERT INTO asc_game (ownerPlayerId, accessCode, locked, description) VALUES ";
$sqlinsertgame = $sqlinsertgame . "(".$pid.", '".$accesscodeGenerated."', false, '".$description."');";
if (mysqli_query($conn, $sqlinsertgame)) {
// Success inserting new game for this player
$GAMEID = mysqli_insert_id($conn);
$OWNERPLAYERID = $pid;
$ACCESSCODE = $accesscodeGenerated;
$LOCKED = 0;
$DESC = $description;
} else {
// Error
echo "Error: " . $sqlinsertgame . "<br>" . mysqli_error($conn);
}
}
$array_joinedUsers = array();
$sql_asc_playerround = "SELECT SQL_NO_CACHE * FROM asc_player;";
$result_asc_playerround = mysqli_query($conn, $sql_asc_playerround);
if (mysqli_num_rows($result_asc_playerround) > 0) {
$i = 1;
while($row = mysqli_fetch_assoc($result_asc_playerround)) {
if ($GAMEID == $row["gameid"]) {
// this player is joined in the game of the currently logged in player
$array_joinedUsers[$i] = $row["name"];
$i++;
}
}
}
$array_availableGamesToJoin = array();
$array_availableGamesToJoinAccessCode = array();
$sql_asc_gameslist = "SELECT SQL_NO_CACHE * FROM asc_game order by 1 asc;";
$result_asc_gameslist = mysqli_query($conn, $sql_asc_gameslist);
if (mysqli_num_rows($result_asc_gameslist) > 0) {
$ii = 0;
while($rowGamesList = mysqli_fetch_assoc($result_asc_gameslist)) {
$kgameid = $rowGamesList["gameid"];
$kownerplayerid = $rowGamesList["ownerPlayerId"];
$kaccesscode = $rowGamesList["accessCode"];
$klocked = $rowGamesList["locked"];
$kdesc = $rowGamesList["description"];
$array_availableGamesToJoin[$ii] = $kdesc . " (" . $kgameid . ")";
$array_availableGamesToJoinAccessCode[$ii] = $kaccesscode;
$ii++;
}
}
function endsWith( $haystack, $needle ) {
$length = strlen( $needle );
if( !$length ) {
return true;
}
return substr( $haystack, -$length ) === $needle;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<title>ClanWolf.net: AplhaStrike Card App (ASCard): Game creator</title>
<meta charset="utf-8">
<!-- <meta http-equiv="expires" content="0"> -->
<!-- <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> -->
<meta name="description" content="Cards app for the AlphaStrike TableTop (BattleTech).">
<meta name="keywords" content="BattleTech, AlphaStrike, Mech">
<meta name="robots" content="noindex,nofollow">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=0.75, minimum-scale=0.75, maximum-scale=0.75, user-scalable=no" />
<link rel="manifest" href="./manifest.json">
<!-- <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css"> -->
<link rel="stylesheet" type="text/css" href="./fontawesome/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="./styles/styles.css">
<link rel="stylesheet" type="text/css" href="./styles/jquery.jscrollpane.css">
<link rel="icon" href="./favicon.png" type="image/png">
<link rel="shortcut icon" href="./images/icon_196x196.png" type="image/png" sizes="196x196">
<link rel="apple-touch-icon" href="./images/icon_57x57.png" type="image/png" sizes="57x57">
<link rel="apple-touch-icon" href="./images/icon_72x72.png" type="image/png" sizes="72x72">
<link rel="apple-touch-icon" href="./images/icon_76x76.png" type="image/png" sizes="76x76">
<link rel="apple-touch-icon" href="./images/icon_114x114.png" type="image/png" sizes="114x114">
<link rel="apple-touch-icon" href="./images/icon_120x120.png" type="image/png" sizes="120x120">
<link rel="apple-touch-icon" href="./images/icon_144x144.png" type="image/png" sizes="144x144">
<link rel="apple-touch-icon" href="./images/icon_152x152.png" type="image/png" sizes="152x152">
<link rel="apple-touch-icon" href="./images/icon_180x180.png" type="image/png" sizes="180x180">
<script type="text/javascript" src="./scripts/jquery-3.6.1.min.js"></script>
<script type="text/javascript" src="./scripts/jquery.jscrollpane.min.js"></script>
<script type="text/javascript" src="./scripts/jquery.mousewheel.js"></script>
<script type="text/javascript" src="./scripts/howler.min.js"></script>
<script type="text/javascript" src="./scripts/cookies.js"></script>
<style>
html, body {
background-image: url('./images/body-bg_2.jpg');
}
table {
margin-left: auto;
margin-right: auto;
}
.box {
width: 80%;
background-color: #transparent;
top: 50%;
left: 50%;
}
.options {
border-radius: 5px;
border-style: solid;
border-width: 3px;
padding: 5px;
background: rgba(60,60,60,0.75);
color: #ddd;
border-color: #aaa;
}
input, select {
width: 80px;
vertical-align: middle;
color: #ddd;
border-width: 0px;
padding: 2px;
font-family: 'Pathway Gothic One', sans-serif;
}
select:focus, textarea:focus, input:focus {
outline: none;
}
select:invalid, input:invalid {
background: rgba(40,40,40,0.75);;
}
select:valid, input:valid {
background: rgba(70,70,70,0.75);;
}
.scroll-pane {
width: 100%;
height: 200px;
overflow: auto;
}
.horizontal-only {
height: auto;
max-height: 200px;
}
</style>
</head>
<body>
<script>
$(function() {
$('.scroll-pane').jScrollPane();
});
$(document).ready(function() {
$("#cover").hide();
});
</script>
<div id="cover"></div>
<?php
if ($playMode) {
$buttonWidth = "34%";
} else {
$buttonWidth = "17%";
}
?>
<div id="header">
<table style="width:100%;height:60px;border:none;border-collapse:collapse;background:rgba(50,50,50,1.0);" cellspacing="0" cellpadding="0">
<tr>
<td nowrap onclick="location.href='./logout.php'" width="60px" style="width: 100px;background: rgba(50,50,50,1.0); text-align: center; vertical-align: middle;">
<div><a style="color: #eee;" href="./logout.php"> <i class="fas fa-power-off" aria-hidden="true"></i> </a></div>
</td>
<!--
<td nowrap onclick="location.href='./gui_finalize_round.php'" width="100px" style="width: 100px;background: rgba(56,87,26,1.0); text-align: center; vertical-align: middle;">
<div><a style="color: #eee;" href="./gui_finalize_round.php"> <i class="fas fa-redo"></i> </a></div>
</td>
-->
<td nowrap onclick="location.href='./gui_finalize_round.php'" style="width: 100px;background:rgba(81,125,37,1.0);">
<div style='vertical-align:middle;font-size:28px;color:#eee;'> G<?php echo $gid ?> R<?php echo $CURRENTROUND ?> </div>
</td>
<td style="width:5px;"> </td>
<td nowrap onclick="location.href='./gui_select_unit.php'" width="<?php echo $buttonWidth ?>"><div class='mechselect_button_normal'><a href='./gui_select_unit.php'>ROSTER</a><br><span style='font-size:16px;'>Choose a Mech</span></div></td>
<td style="width:5px;"> </td>
<td nowrap onclick="location.href='./gui_select_enemy_unit.php'" width="<?php echo $buttonWidth ?>"><div class='mechselect_button_normal'><a href='./gui_select_enemy_unit.php'>FORCES</a><br><span style='font-size:16px;'>All bidding units</span></div></td>
<td style="width:5px;"> </td>
<?php
if (!$playMode) {
echo " <td nowrap onclick=\"location.href='./gui_assign_unit.php'\" width='17%'><div class='mechselect_button_normal'><a href='./gui_assign_unit.php'>ASSIGN</a><br><span style='font-size:16px;'>Assign Mech/BA</span></div></td><td style='width:5px;'> </td>\n";
echo " <td nowrap onclick=\"location.href='./gui_create_mech.php'\" width='17%'><div class='mechselect_button_normal'><a href='./gui_create_mech.php'>ADD</a><br><span style='font-size:16px;'>Create a Mech/BA</span></div></td><td style='width:5px;'> </td>\n";
echo " <td nowrap onclick=\"location.href='./gui_create_player.php'\" width='17%'><div class='mechselect_button_normal'><a href='./gui_create_player.php'>PLAYER</a><br><span style='font-size:16px;'>Manage players</span></div></td><td style='width:5px;'> </td>\n";
}
?>
<td nowrap onclick="location.href='./gui_edit_option.php'" width="<?php echo $buttonWidth ?>"><div class='mechselect_button_normal'><a href='./gui_edit_option.php'>OPTIONS</a><br><span style='font-size:16px;'>Change options</span></div></td>
<td style="width:5px;"> </td>
<td style="width: 100px;" nowrap width="100px" style="background: rgba(50,50,50,1.0); text-align: center; vertical-align: middle;"><img src='./images/player/<?=$pimage?>' width='60px' height='60px'></td>
</tr>
</table>
</div>
<div id="liberapay"><a href="./gui_support.php"><i class="fa-solid fa-handshake-simple"></i></a></div>
<div id="disclaimer"><a href="./gui_disclaimer.php">Disclaimer</a></div>
<br>
<div id="header">
<table width="60%" align="center" class="options" cellspacing="4" cellpadding="4" border="0px">
<tr>
<td valign="top" width="75%">
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td nowrap colspan="3" align="left">My game: "<?php echo $DESC; ?>"<br><br></td>
</tr>
<tr>
<td nowrap align="left" width="3%">Game:</td><td></td><td nowrap align="left" width="94%"> <?php echo $GAMEID; ?></td>
</tr>
<tr>
<?php if ($LOCKED == 0) {
echo "<td nowrap align='left' width='3%'>Accessible:</td><td nowrap align='left' width='3%'> <a href='#' onClick='unlockGame();'><i class='fa-solid fa-lock'></i></i></a></td><td nowrap align='left' width='94%'> no (new players NOT allowed)</td>";
} else {
echo "<td nowrap align='left' width='3%'>Accessible:</td><td nowrap align='left' width='3%'> <a href='#' onClick='lockGame();'><i class='fa-solid fa-lock-open'></i></a></td><td nowrap align='left' width='94%'> yes (joinable with access code)</td>";
} ?>
</tr>
<tr>
<td nowrap align="left" width="3%">Access code:</td><td nowrap align="left" width="3%"> <i class="fa-solid fa-rotate-right"></i></td><td nowrap align="left" width="94%"> <?php echo $ACCESSCODE; ?>
</tr>
</table>
</td>
<td nowrap valign="top" align="left" width="25%" rowspan="3">
Joined in my game:<br><br>
<div class="scroll-pane">
<table>
<?php
foreach ($array_joinedUsers as &$value) {
echo "<tr><td nowrap align='left' width='3%'><i class='fas fa-minus-square'></i></td><td> " . $value . "</td><td nowrap align='right' width='3%'> <i class='fas fa-minus-square'></i></td></tr>";
}
?>
</table>
</div>
</td>
</tr>
<tr><td colspan="1"><hr></td></tr>
<tr>
<td colspan="1">
<form autocomplete="autocomplete_off_hack_xfr4!k">
<table cellspacing="2" cellpadding="2" border="0px" width="100%">
<tr>
<td colspan="1" class='datalabel' nowrap align="left">Join:</td>
<td colspan="1" class='datalabel' nowrap align="left">
<select required name='game' id='game' size='1' onchange="" style="width: 220px;">
<?php
for ($i661 = 1; $i661 < sizeof($array_availableGamesToJoin); $i661++) { // ignore the first one, dummy game
echo "<option value='" . $array_availableGamesToJoin[$i661] . "'>" . $array_availableGamesToJoin[$i661] . "</option>";
}
?>
</select>
</td>
<td colspan="1" class='datalabel' nowrap align="right">Code:</td>
<td colspan="1" class='datalabel' nowrap align="center"><input autocomplete="autocomplete_off_hack_xfr4!k" required type="text" id="AccessCode" style="width: 100px;"></td>
<td colspan="1" class='datalabel' nowrap align="right"><a href="#" onClick="joinGame();"><i class="fas fa-plus-square"></i></a></td>
</tr>
<tr>
<td colspan="1" class='datalabel' nowrap align="left">Leave:</td>
<?php
if ($gid == 1) {
echo "<td colspan='6' class='datalabel' nowrap align='left'>I am NOT in any game.</td>";
} else {
echo "<td colspan='6' class='datalabel' nowrap align='left'><a href='#' onClick='leaveGame();'><i class='fas fa-minus-square'></i> (I am in game " . $gid . ")</a></td>";
}
?>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
<p align="center"><span style='font-size:24px;color:#fff;'>Inaccessible games do NOT show up to join!<br>Access code is ALWAYS needed to join accessible games!</span></p>
</body>
</html>