-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathGameLobby.php
332 lines (293 loc) · 13.1 KB
/
GameLobby.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
<?php
ob_start();
include "CardDictionary.php";
include "HostFiles/Redirector.php";
include "Libraries/UILibraries2.php";
include "Libraries/SHMOPLibraries.php";
include_once "Libraries/PlayerSettings.php";
include_once "Libraries/HTTPLibraries.php";
include_once "Assets/patreon-php-master/src/PatreonDictionary.php";
include_once "WriteLog.php";
include_once './AccountFiles/AccountDatabaseAPI.php';
ob_end_clean();
session_start();
// Check if the user is banned
if (isset($_SESSION["userid"]) && IsBanned($_SESSION["userid"])) {
header("Location: ./PlayerBanned.php");
exit;
}
$authKey = "";
$gameName = TryGET("gameName", "");
$playerID = TryGET("playerID", "");
if($gameName == "" || $playerID == "") exit;
if ($playerID == 1 && isset($_SESSION["p1AuthKey"]))
$authKey = $_SESSION["p1AuthKey"];
else if ($playerID == 2 && isset($_SESSION["p2AuthKey"]))
$authKey = $_SESSION["p2AuthKey"];
else if (isset($_GET["authKey"]))
$authKey = $_GET["authKey"];
session_write_close();
if (($playerID == 1 || $playerID == 2) && $authKey == "") {
if (isset($_COOKIE["lastAuthKey"]))
$authKey = $_COOKIE["lastAuthKey"];
}
if (!file_exists("./Games/" . $gameName . "/GameFile.txt")) {
header("Location: " . $redirectPath . "/MainMenu.php"); //If the game file happened to get deleted from inactivity, redirect back to the main menu instead of erroring out
exit;
}
ob_start();
include "MenuFiles/ParseGamefile.php";
ob_end_clean();
$targetAuth = ($playerID == 1 ? $p1Key : $p2Key);
if (!isset($authKey) || $authKey != $targetAuth) {
echo ("Invalid Auth Key");
exit;
}
if ($gameStatus == $MGS_GameStarted) {
$authKey = ($playerID == 1 ? $p1Key : $p2Key);
if (isset($gameUIPath))
header("Location: " . $gameUIPath . "?gameName=$gameName&playerID=$playerID");
else
header("Location: " . $redirectPath . "/NextTurn4.php?gameName=$gameName&playerID=$playerID");
exit;
}
$icon = "ready.png";
if ($gameStatus == $MGS_ChooseFirstPlayer)
$icon = $playerID == $firstPlayerChooser ? "ready.png" : "notReady.png";
else if ($playerID == 1 && $gameStatus < $MGS_ReadyToStart)
$icon = "notReady.png";
else if ($playerID == 2 && $gameStatus >= $MGS_ReadyToStart)
$icon = "notReady.png";
$isMobile = IsMobile();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="content-type" content="text/html; charset=utf-8" >
<title>Game Lobby</title>
<link id="icon" rel="shortcut icon" type="image/png" href="./Images/<?= $icon ?>"/>
<link rel="stylesheet" href="./css/chat.css">
<link rel="stylesheet" href="./css/karabast011625.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Barlow:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Teko:wght@700&display=swap" rel="stylesheet">
<style>
<?php include 'PlayerColors.php' ?>
</style>
</head>
<body onload='OnLoadCallback(<?php echo (filemtime(LogPath($gameName))); ?>)'>
<div class="lobby-container">
<div id="cardDetail" style="display:none; position:absolute;"></div>
<div class="lobby-header">
<h1>Game Lobby</h1>
<p class="leave-lobby"><a href='MainMenu.php'>Leave Lobby</a></p>
</div>
<div class="lobby-wrapper">
<div class="game-lobby">
<div id='mainPanel' style='text-align:center;'>
<div class='game-set-up container bg-blue'>
<h2>Set Up</h2>
<div id="setup-content"></div>
<div id='submitForm' style='width:100%; text-align: center; display: none;'>
<form action='./SubmitSideboard.php'>
<input type='hidden' id='gameName' name='gameName' value='<?= $gameName ?>'>
<input type='hidden' id='playerID' name='playerID' value='<?= $playerID ?>'>
<input type='hidden' id='playerCharacter' name='playerCharacter' value=''>
<input type='hidden' id='playerDeck' name='playerDeck' value=''>
<input type='hidden' id='authKey' name='authKey' value='<?= $authKey ?>'>
<input class='GameLobby_Button' type='submit' value='<?= $playerID == 1 ? "Start" : "Ready" ?>'>
</form>
</div>
</div>
</div>
<div class='chat-log container bg-black'>
<h2>Chat</h2>
<div id='gamelog' class="gamelog"></div>
<div id='chatbox' class="chatbox">
<div class="lobby-chat-input">
<input class='GameLobby_Input' type='text' id='chatText' name='chatText' value='' autocomplete='off' onkeypress='ChatKey(event)'>
<button class='GameLobby_Button' style='cursor:pointer;' onclick='SubmitChat()'>Chat</button>
</div>
</div>
</div>
</div>
<div class="player-info container bg-black">
<h2>Players</h2>
<div id="my-info">
<?php
$contentCreator = ContentCreators::tryFrom(($playerID == 1 ? $p1ContentCreatorID : $p2ContentCreatorID));
$nameColor = ($contentCreator != null ? $contentCreator->NameColor() : "");
$displayName = "<span style='color:$nameColor'>$playerName</span>";
$deckFile = "./Games/" . $gameName . "/p" . $playerID . "Deck.txt";
$handler = fopen($deckFile, "r");
echo ("<h3>$displayName</h3>");
if ($handler) {
$material = GetArray($handler);
echo ("<div style='position:relative; display: inline-block;'>");
$overlayURL = ($contentCreator != null ? $contentCreator->HeroOverlayURL($material[1]) : "");
echo (Card($material[1], "CardImages", ($isMobile ? 100 : 250), 0, 1, 0, 0, 0, "", "", true));
if ($overlayURL != "")
echo ("<img title='Portrait' style='position:absolute; z-index:1001; top: 27px; left: 0px; cursor:pointer; height:" . ($isMobile ? 100 : 250) . "; width:100%;' src='" . $overlayURL . "' />");
echo ("</div>");
echo ("<div style='position:relative; display: inline-block;'>");
$overlayURL = ($contentCreator != null ? $contentCreator->HeroOverlayURL($material[0]) : "");
echo (Card($material[0], "CardImages", ($isMobile ? 100 : 250), 0, 1, 0, 0, 0, "", "", true));
if ($overlayURL != "")
echo ("<img title='Portrait' style='position:absolute; z-index:1001; top: 27px; left: 0px; cursor:pointer; height:" . ($isMobile ? 100 : 250) . "; width:" . ($isMobile ? 100 : 250) . ";' src='" . $overlayURL . "' />");
echo ("</div>");
$deck = GetArray($handler);
$deckSB = GetArray($handler);
fclose($handler);
}
?>
</div>
<div id="their-info">
</div>
</div>
<div class="deck-info container bg-black">
<div id="deckTab" class="deck-header">
<?php if (isset($deck)): ?>
<h2 class='deck-title'>Your Deck</h2>
<h2 class='deck-count'><span id='mbCount'><?= count($deck) ?></span>/<?= count($deck) + count($deckSB) ?></h2>
<?php endif; ?>
</div>
<h4>Click Cards to Select/Unselect</h4>
<div class="deck-display">
<?php
if (isset($deck)) {
$cardSize = 110;
$count = 0;
sort($deck);
for ($i = 0; $i < count($deck); ++$i) {
$id = "DECK-" . $count;
$isUnimplemented = IsUnimplemented($deck[$i]);
echo ("<span style='cursor:pointer; padding-bottom:5px; padding-left:3px;' onclick='CardClick(\"" . $id . "\")'>" . Card($deck[$i], "concat", $cardSize, 0, 1, 0, 0, 0, "", $id, isUnimplemented:$isUnimplemented) . "</span>");
++$count;
}
for ($i = 0; $i < count($deckSB); ++$i) {
$id = "DECK-" . $count;
$isUnimplemented = IsUnimplemented($deckSB[$i]);
echo ("<span style='cursor:pointer; padding-bottom:5px; padding-left:3px;' onclick='CardClick(\"" . $id . "\")'>" . Card($deckSB[$i], "concat", $cardSize, 0, 1, 1, 0, 0, "", $id, isUnimplemented:$isUnimplemented) . "</span>");
++$count;
}
}
?>
</div>
</div>
</div>
<div class="lobby-footer">
<?php include_once 'Disclaimer.php'; ?>
</div>
</div>
<audio id="playerJoinedAudio">
<source src="./Assets/playerJoinedSound.mp3" type="audio/mpeg">
</audio>
<script src="./jsInclude.js"></script>
<script>
function copyText() {
var gameLink = document.getElementById("gameLink");
gameLink.select();
gameLink.setSelectionRange(0, 99999);
// Copy it to clipboard
document.execCommand("copy");
}
function OnLoadCallback(lastUpdate) {
<?php
if ($playerID == "1" && $gameStatus == $MGS_ChooseFirstPlayer) {
echo ("var audio = document.getElementById('playerJoinedAudio');");
echo ("audio.play();");
}
?>
UpdateFormInputs();
var log = document.getElementById('gamelog');
if (log !== null) log.scrollTop = log.scrollHeight;
CheckReloadNeeded(0);
}
function UpdateFormInputs() {
var playerCharacter = document.getElementById("playerCharacter");
if (!!playerCharacter) playerCharacter.value = GetCharacterCards();
var playerDeck = document.getElementById("playerDeck");
if (!!playerDeck) playerDeck.value = GetDeckCards();
}
function CardClick(id) {
var idArr = id.split("-");
if (idArr[0] == "DECK") {
var overlay = document.getElementById(id + "-ovr");
overlay.style.visibility = (overlay.style.visibility == "hidden" ? "visible" : "hidden");
var mbCount = document.getElementById("mbCount");
mbCount.innerText = parseInt(mbCount.innerText) + (overlay.style.visibility == "hidden" ? 1 : -1);
}
UpdateFormInputs();
}
function GetCharacterCards() {
var types = ["WEAPONS", "OFFHAND", "QUIVER", "HEAD", "CHEST", "ARMS", "LEGS"];
var returnValue = "<?php echo (isset($material) ? implode(",", $material) : ""); ?>";
return returnValue;
}
function GetDeckCards() {
var count = 0;
var returnValue = "";
var overlay = document.getElementById("DECK-" + count + "-ovr");
while (!!overlay) {
if (overlay.style.visibility == "hidden") {
var imageSrc = document.getElementById("DECK-" + count + "-img").src;
if (returnValue != "") returnValue += ",";
var splitArr = imageSrc.split("/");
returnValue += splitArr[splitArr.length-1].split(".")[0];
}
++count;
var overlay = document.getElementById("DECK-" + count + "-ovr");
}
return returnValue;
}
var audioPlayed = false;
function CheckReloadNeeded(lastUpdate) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (parseInt(this.responseText) != 0) {
if (parseInt(this.responseText) == 1) location.reload();
else {
response = JSON.parse(this.responseText);
document.getElementById("setup-content").innerHTML = response["setupContent"];
document.getElementById("gamelog").innerHTML = response["logContent"];
document.getElementById("their-info").innerHTML = response["theirInfo"];
document.getElementById("submitForm").style.display = response["showSubmit"] ? "block" : "none";
if (response["playerJoinAudio"] === true && !audioPlayed) {
var audio = document.getElementById('playerJoinedAudio');
audio.play();
audioPlayed = true;
} else if (response["playerJoinAudio"] === false && audioPlayed) {
//reset audio if player left
audioPlayed = false;
}
// document.getElementById("icon").href = "./Images/" + document.getElementById("iconHolder").innerText;
var log = document.getElementById('gamelog');
if (log !== null) log.scrollTop = log.scrollHeight;
CheckReloadNeeded(parseInt(response["timestamp"]));
}
}
}
};
xmlhttp.open("GET", "GetLobbyRefresh.php?gameName=<?php echo ($gameName); ?>&playerID=<?php echo ($playerID); ?>&lastUpdate=" + lastUpdate + "&authKey=<?php echo ($authKey); ?>", true);
xmlhttp.send();
}
function SubmitFirstPlayer(action) {
if (action == 1) action = "Go First";
else action = "Go Second";
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {}
}
var ajaxLink = "ChooseFirstPlayer.php?gameName=" + <?php echo ($gameName); ?>;
ajaxLink += "&playerID=" + <?php echo ($playerID); ?>;
ajaxLink += "&action=" + action;
ajaxLink += <?php echo ("\"&authKey=" . $authKey . "\""); ?>;
xmlhttp.open("GET", ajaxLink, true);
xmlhttp.send();
}
</script>
</body>
</html>