forked from SWU-Karabast/SWUOnline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateGame.php
127 lines (112 loc) · 4.34 KB
/
CreateGame.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
<?php
ob_start();
include "HostFiles/Redirector.php";
include "Libraries/HTTPLibraries.php";
include "Libraries/SHMOPLibraries.php";
include_once "WriteLog.php";
include_once "Libraries/PlayerSettings.php";
include_once 'Assets/patreon-php-master/src/PatreonDictionary.php';
include_once "./AccountFiles/AccountDatabaseAPI.php";
include_once './includes/functions.inc.php';
include_once './includes/dbh.inc.php';
include_once './Database/ConnectionManager.php';
ob_end_clean();
$deck = TryGET("deck");
$decklink = TryGET("fabdb");
$deckTestMode = TryGET("deckTestMode", "");
$format = TryGET("format");
$visibility = TryGET("visibility");
$set = TryGET("set");
$decksToTry = TryGet("decksToTry");
$favoriteDeck = TryGet("favoriteDeck", "0");
$favoriteDeckLink = TryGet("favoriteDecks", "0");
$gameDescription = htmlentities(TryGet("gameDescription", "Game #"), ENT_QUOTES);
$deckbuilderID = TryGet("user", "");
$roguelikeGameID = TryGet("roguelikeGameID", "");
$startingHealth = TryGet("startingHealth", "");
if($favoriteDeckLink != 0)
{
$favDeckArr = explode("<fav>", $favoriteDeckLink);
if(count($favDeckArr) == 1) $favoriteDeckLink = $favDeckArr[0];
else {
$favoriteDeckIndex = $favDeckArr[0];
$favoriteDeckLink = $favDeckArr[1];
}
}
session_start();
if (!isset($_SESSION["userid"])) {
if (isset($_COOKIE["rememberMeToken"])) {
include_once './Assets/patreon-php-master/src/PatreonLibraries.php';
include_once './Assets/patreon-php-master/src/API.php';
include_once './Assets/patreon-php-master/src/PatreonDictionary.php';
loginFromCookie();
}
}
$isUserBanned = isset($_SESSION["userid"]) ? IsBanned($_SESSION["userid"]) : false;
if ($isUserBanned) {
header("Location: PlayerBanned.php");
exit;
}
if($visibility == "public" && $deckTestMode != "" && !isset($_SESSION["userid"])) {
//Must be logged in to use matchmaking
header("Location: MainMenu.php");
exit;
}
if(isset($_SESSION["userid"]))
{
//Save game creation settings
if(isset($favoriteDeckIndex))
{
ChangeSetting("", $SET_FavoriteDeckIndex, $favoriteDeckIndex, $_SESSION["userid"]);
}
ChangeSetting("", $SET_Format, FormatCode($format), $_SESSION["userid"]);
ChangeSetting("", $SET_GameVisibility, ($visibility == "public" ? 1 : 0), $_SESSION["userid"]);
if($deckbuilderID != "")
{
if(str_contains($decklink, "fabrary")) storeFabraryId($_SESSION["userid"], $deckbuilderID);
else if(str_contains($decklink, "fabdb")) storeFabDBId($_SESSION["userid"], $deckbuilderID);
}
}
session_write_close();
if($isUserBanned) {
if($format == "cc" || $format == "livinglegendscc") $format = "shadowcc";
else if($format == "compcc") $format = "shadowcompcc";
else if($format == "blitz" || $format == "compblitz" || $format == "commoner") $format = "shadowblitz";
}
$gameName = GetGameCounter();
if (file_exists("Games/$gameName") || !mkdir("Games/$gameName", 0700, true)) {
print_r("Encountered a problem creating a game. Please return to the main menu and try again");
}
$p1Data = [1];
$p2Data = [2];
$p1SideboardSubmitted = "0";
$p2SideboardSubmitted = "0";
if ($deckTestMode != "") {
$gameStatus = 4; //ReadyToStart
$p2SideboardSubmitted = "1";
$opponentDeck = "./Assets/Dummy.txt";
$fileName = "./Roguelike/Encounters/".$deckTestMode.".txt";
if(file_exists($fileName)) $opponentDeck = $fileName;
copy($opponentDeck, "./Games/" . $gameName . "/p2Deck.txt");
} else {
$gameStatus = 0; //Initial
}
$firstPlayerChooser = "";
$firstPlayer = 1;
$p1Key = hash("sha256", rand() . rand());
$p2Key = hash("sha256", rand() . rand() . rand());
$p1uid = "-";
$p2uid = "-";
$p1id = "-";
$p2id = "-";
$hostIP = $_SERVER['REMOTE_ADDR'];
$p1StartingHealth = $startingHealth;
$filename = "./Games/" . $gameName . "/GameFile.txt";
$gameFileHandler = fopen($filename, "w");
include "MenuFiles/WriteGamefile.php";
WriteGameFile();
CreateLog($gameName);
$currentTime = round(microtime(true) * 1000);
$cacheVisibility = ($visibility == "public" ? "1" : "0");
WriteCache($gameName, 1 . "!" . $currentTime . "!" . $currentTime . "!0!-1!" . $currentTime . "!!!" . $cacheVisibility . "!0!0!0!" . $format . "!" . $gameStatus . "!0!0!$currentTime!0!0"); //Initialize SHMOP cache for this game
header("Location:" . $redirectPath . "/JoinGameInput.php?gameName=$gameName&playerID=1&deck=$deck&fabdb=$decklink&format=$format&set=$set&decksToTry=$decksToTry&favoriteDeck=$favoriteDeck&favoriteDecks=$favoriteDeckLink");