-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgame.php
More file actions
331 lines (235 loc) · 9.38 KB
/
game.php
File metadata and controls
331 lines (235 loc) · 9.38 KB
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
<?php
session_start();
//Disable Including the File
if (get_included_files()[0] != __FILE__) {
return;
}
include_once 'main.php';
include_once 'game_handler.php';
include_once 'session_handler.php';
include_once 'roblox_handler.php';
/*
if (!$session) {
jsonError("You are not Logged In!");
}
*/
if (!isset($_POST['type'])) {
jsonError('400 Bad Request');
}
if ($_POST['type'] == 'cancel') {
if (!isset($_POST['game_id'])) {
jsonError('400 Bad Request');
}
$gameInfo = getGameData($_POST['game_id']);
if (!$gameInfo) {
jsonError('Game not found!');
}
if ($gameInfo['starter_id'] != $session['user_id']) {
jsonError('You are not the host of this game!');
}
if ($gameInfo['end_date']) {
jsonError('This game is already Completed!');
}
$resp = deleteGame($_POST['game_id']);
jsonError($resp[0] ? false : $resp[1]);
} elseif ($_POST['type'] == 'create') {
if (!isset($_POST['item_ids']) or !isset($_POST['side'])) {
jsonError('400 Bad Request');
}
$itemIds = json_decode($_POST['item_ids'], true);
if (!$itemIds) {
jsonError('400 Bad Request');
}
$side = $_POST['side'];
if ($side != 0 and $side != 1) {
jsonError('400 Bad Request');
}
if (count($itemIds) <= 0) {
jsonError('You need to select some items');
}
$gameId = createGame($session['user_id'], $side, $itemIds);
if (!$gameId[0]) {
jsonError($gameId[1]);
}
jsonError(false);
} elseif ($_POST['type'] == 'play') {
if (!isset($_POST['item_ids']) or !isset($_POST['game_id'])) {
jsonError('400 Bad Request');
}
$itemIds = json_decode($_POST['item_ids'], true);
$gameInfo = getGameData($_POST['game_id']);
if (!$gameInfo) {
jsonError('Game not found!');
}
if ($gameInfo['starter_id'] == $session['user_id']) {
jsonError('You are the host of this game!');
}
if (!$itemIds or count($itemIds) <= 0) {
jsonError('You need to select some items');
}
$gameId = playGame($_POST['game_id'], $session['user_id'], $itemIds);
if (!$gameId[0]) {
jsonError($gameId[1]);
}
jsonError(false, $gameId[1]);
} elseif ($_POST['type'] == 'gethtml') {
if (!isset($_POST['game_id'])) {
exit();
}
$match = getGameData($_POST['game_id']);
if (!$match) {
exit();
}
?>
<div id='game<?php echo $match['game_id']; ?>' class="<?php echo $session
? (($match['starter_id'] == $session['user_id'] or
$match['player_id'] == $session['user_id'])
? 'mymatch'
: 'publicmatch')
: 'publicmatch'; ?> row" style="justify-content:space-between;">
<div style="display:flex;flex-direction:column;gap:10px;align-items:center;width:calc(100% - 100px);">
<div style="display:flex;gap:10px;align-items:center;flex-wrap:wrap;justify-content:space-between;width:100%;">
<div style="display:flex;gap:10px;align-items:center;flex-wrap:wrap;">
<img src="<?php echo $match['starter_side'] == 0
? './img/gem.png'
: './img/dog.png'; ?>" alt="<?php echo $match[
'starter_side'
] == 0
? 'Gem'
: 'Dog'; ?>" width="32px" height="32px">
<img class="userthumb" src="<?php echo getUserThumbnail(
$match['starter_id']
); ?>" width="32px" height="32px">
<div style="font-size:24px;"><?php echo getName(
$match['starter_id']
); ?></div>
<?php foreach (
json_decode($match['starter_items'], true)
as $item
): ?>
<img src="<?php echo getItemInfo($item['item_id'])[
'item_image'
]; ?>" width="32px" height="32px">
<?php endforeach; ?>
</div>
<?php if (
$match['end_date']
): ?> <div style="font-size:24px;">Value: <?php echo $match[
'starter_value'
]; ?></div> <?php endif; ?>
</div>
<div style="display:flex;gap:10px;align-items:center;flex-wrap:wrap;justify-content:space-between;width:100%;">
<div style="display:flex;gap:10px;align-items:center;flex-wrap:wrap;">
<img src="<?php echo $match['starter_side'] == 1
? './img/gem.png'
: './img/dog.png'; ?>" alt="<?php echo $match[
'starter_side'
] == 1
? 'Gem'
: 'Dog'; ?>" width="32px" height="32px">
<?php if ($match['end_date']): ?>
<img class="userthumb" src="<?php echo getUserThumbnail(
$match['player_id']
); ?>" width="32px" height="32px">
<div style="font-size:24px;"><?php echo getName(
$match['player_id']
); ?></div>
<?php
$player_items = json_decode(
$match['player_items'],
true
);
if (!$player_items) {
$player_items = [];
}
foreach ($player_items as $item): ?>
<img src="<?php echo getItemInfo(
$item['item_id']
)['item_image']; ?>" width="32px" height="32px">
<?php endforeach;
?>
</div>
<div style="font-size:24px;">Value: <?php echo $match[
'player_value'
]; ?></div>
</div>
<?php else: ?>
<?php if (!$session): ?>
<button onclick="login()" class="btn-primary">Join Match (<?php if (
$match['starter_value'] > 200
) {
echo floor(
$match['starter_value'] -
$match['starter_value'] * 0.05
);
} else {
echo $match['starter_value'] - 10;
} ?> - <?php if ($match['starter_value'] > 200) {
echo floor($match['starter_value'] + $match['starter_value'] * 0.05);
} else {
echo $match['starter_value'] + 10;
} ?>)</button>
<?php elseif ($match['starter_id'] != $session['user_id']): ?>
<button onclick='joinMatch(<?php echo $match['game_id'] .
',' .
$match[
'starter_value'
]; ?>)' class="btn-primary">Join Match (<?php if (
$match['starter_value'] > 200
) {
echo floor($match['starter_value'] - $match['starter_value'] * 0.05);
} else {
echo $match['starter_value'] - 10;
} ?> - <?php if ($match['starter_value'] > 200) {
echo floor($match['starter_value'] + $match['starter_value'] * 0.05);
} else {
echo $match['starter_value'] + 10;
} ?>)</button>
<?php else: ?>
<button onclick='cancelMatch(<?php echo $match[
'game_id'
]; ?>)' class="btn-primary">Cancel Match</button>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</div>
<div style="display:flex;flex-direction:column;text-align:center;padding-right:10px;">
<?php if (!$match['end_date']): ?>
<h2>Value <br><?php echo $match['starter_value']; ?></h2>
<div style="color:cadetblue">(<?php if ($match['starter_value'] > 200) {
echo floor(
$match['starter_value'] - $match['starter_value'] * 0.05
);
} else {
echo $match['starter_value'] - 10;
} ?> - <?php if ($match['starter_value'] > 200) {
echo floor($match['starter_value'] + $match['starter_value'] * 0.05);
} else {
echo $match['starter_value'] + 10;
} ?>)</div>
<?php else: ?>
<div class="coin <?php echo $match['winner_side'] == 0
? 'red'
: 'blue'; ?> flip<?php echo $match['winner_side'] == 0
? 'red'
: 'blue'; ?>">
<div class='blue'>
<img src="./img/dog.png">
</div>
<div class='red'>
<img src="./img/gem.png">
</div>
</div>
<img style="border-radius:50%;" class="hidden" src="<?php echo $match[
'winner_side'
] == 0
? './img/gem.png'
: './img/dog.png'; ?>" width="80px" height="80px">
<?php endif; ?>
</div>
</div>
<?php
}
jsonError('400 Bad Request');
?>