forked from Talishar/Talishar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateGame.php
More file actions
143 lines (126 loc) · 4.86 KB
/
CreateGame.php
File metadata and controls
143 lines (126 loc) · 4.86 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
<?php
ob_start();
include "HostFiles/Redirector.php";
include "Libraries/HTTPLibraries.php";
include "Libraries/SHMOPLibraries.php";
include_once "Libraries/PlayerSettings.php";
include_once 'Assets/patreon-php-master/src/PatreonDictionary.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];
}
}
$isisShadowBanned = false;
session_start();
if (!isset($_SESSION["userid"])) {
if (isset($_COOKIE["rememberMeToken"])) {
include_once './includes/functions.inc.php';
include_once './includes/dbh.inc.php';
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();
}
}
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
include_once 'includes/functions.inc.php';
include_once 'includes/dbh.inc.php';
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();
$bannedIPHandler = fopen("./HostFiles/bannedIPs.txt", "r");
while (!feof($bannedIPHandler)) {
$bannedIP = trim(fgets($bannedIPHandler), "\r\n");
// echo ($_SERVER['REMOTE_ADDR'] . " " . $bannedIP . "<BR>");
if ($_SERVER['REMOTE_ADDR'] == $bannedIP) {
$isisShadowBanned = true;
}
}
fclose($bannedIPHandler);
if ($isisShadowBanned) {
if ($format == "cc" || $format == "livinglegendscc") $format = "shadowcc";
else if ($format == "compcc") $format = "shadowcompcc";
else if ($format == "blitz" || $format == "compblitz") $format = "shadowblitz";
else if ($format == "commoner") $format = "shadowcommoner";
}
$gameName = GetGameCounter();
if ( (!file_exists("Games/$gameName")) && (mkdir("Games/$gameName", 0700, true)) ){
} else {
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";
switch($deckTestMode)
{
case "Woottonhog": $opponentDeck = "./Roguelike/Encounters/Woottonhog.txt"; break;
case "RavenousRabble": $opponentDeck = "./Roguelike/Encounters/RavenousRabble.txt"; break;
case "BarragingBrawnhide": $opponentDeck = "./Roguelike/Encounters/BarragingBrawnhide.txt"; break;
case "ShockStriker": $opponentDeck = "./Roguelike/Encounters/ShockStriker.txt"; break;
default: break;
}
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();
$filename = "./Games/" . $gameName . "/gamelog.txt";
$handler = fopen($filename, "w");
fclose($handler);
$currentTime = round(microtime(true) * 1000);
$cacheVisibility = ($visibility == "public" ? "1" : "0");
WriteCache($gameName, 1 . "!" . $currentTime . "!" . $currentTime . "!0!-1!" . $currentTime . "!!!" . $cacheVisibility . "!0!0!0"); //Initialize SHMOP cache for this game
header("Location: JoinGameInput.php?gameName=$gameName&playerID=1&deck=$deck&fabdb=$decklink&format=$format&set=$set&decksToTry=$decksToTry&favoriteDeck=$favoriteDeck&favoriteDecks=$favoriteDeckLink");