forked from SWU-Karabast/SWUOnline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubmitSideboard.php
82 lines (71 loc) · 2.74 KB
/
SubmitSideboard.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
<?php
include "Libraries/HTTPLibraries.php";
include "Libraries/SHMOPLibraries.php";
$gameName = $_GET["gameName"];
if (!IsGameNameValid($gameName)) {
echo ("Invalid game name.");
exit;
}
$playerID = $_GET["playerID"];
$playerCharacter = $_GET["playerCharacter"];
$playerDeck = $_GET["playerDeck"];
$authKey = $_GET["authKey"];
include "WriteLog.php";
include "HostFiles/Redirector.php";
include "CardDictionary.php";
include "MenuFiles/ParseGamefile.php";
include "MenuFiles/WriteGamefile.php";
$targetAuth = ($playerID == 1 ? $p1Key : $p2Key);
if ($authKey != $targetAuth) {
echo ("Invalid Auth Key");
exit;
}
if ($playerCharacter != "" && $playerDeck != "") //If they submitted before loading even finished, use the deck as it existed before
{
$char = explode(",", $playerCharacter);
$playerDeck = explode(",", $playerDeck);
$deckCount = count($playerDeck);
$base = "";
$leader = "";
for($i = 0; $i < count($char); $i++) {
if(DefinedCardType($char[$i]) == "Base") $base = $char[$i];
else if(DefinedCardType($char[$i]) == "Leader") $leader = $char[$i];
}
/*
if ($deckCount < 60 && ($format == "cc" || $format == "compcc")) {
WriteLog("Unable to submit player " . $playerID . "'s deck. " . $deckCount . " cards selected is under the legal minimum.");
header("Location: " . $redirectPath . "/GameLobby.php?gameName=$gameName&playerID=$playerID");
exit;
}
if ($deckCount < 40 && ($format == "blitz" || $format == "compblitz" || $format == "commoner")) {
WriteLog("Unable to submit player " . $playerID . "'s deck. " . $deckCount . " cards selected is under the legal minimum.");
header("Location: " . $redirectPath . "/GameLobby.php?gameName=$gameName&playerID=$playerID");
exit;
}
for ($i = $deckCount - 1; $i >= 0; --$i) {
$cardType = CardType($playerDeck[$i]);
if ($cardType == "" || $cardType == "C" || $cardType == "E" || $cardType == "W") unset($playerDeck[$i]);
}
$playerDeck = array_values($playerDeck);
*/
$filename = "./Games/" . $gameName . "/p" . $playerID . "Deck.txt";
$deckFile = fopen($filename, "w");
fwrite($deckFile, $base . " " . $leader . "\r\n");
fwrite($deckFile, implode(" ", $playerDeck));
fclose($deckFile);
}
if($playerID == 1) $p1SideboardSubmitted = "1";
else if($playerID == 2) $p2SideboardSubmitted = "1";
$gameStarted = false;
if ($p1SideboardSubmitted == "1" && $p2SideboardSubmitted == "1") {
$gameStatus = $MGS_ReadyToStart;
SetCachePiece($gameName, 14, $gameStatus);
$gameStarted = true;
}
WriteGameFile();
GamestateUpdated($gameName);
if ($gameStarted == 1) {
header("Location: " . $redirectPath . "/Start.php?gameName=$gameName&playerID=$playerID");
} else {
header("Location: " . $redirectPath . "/GameLobby.php?gameName=$gameName&playerID=$playerID");
}