forked from jmlue42/Talishar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateReplayGame.php
66 lines (52 loc) · 1.85 KB
/
CreateReplayGame.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
<?php
session_start();
ob_start();
include "HostFiles/Redirector.php";
include "Libraries/HTTPLibraries.php";
include "Libraries/SHMOPLibraries.php";
include_once "Libraries/PlayerSettings.php";
ob_end_clean();
$userId = "";
if(isset($_SESSION["userid"])) $userId = $_SESSION["userid"];
if($userId == "")
{
echo("You must be logged in to use this feature.");
exit;
}
$replayNumber = TryGet("replayNumber", "");
if(!file_exists("./Replays/" . $userId . "/" . $replayNumber . "/"))
{
echo("That replay file does not exist.");
exit;
}
$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];
$gameStatus = 5; //Game started
$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);
$isReplay = "1";
WriteCache($gameName, 1 . "!" . $currentTime . "!" . $currentTime . "!0!-1!" . $currentTime . "!!!0!" . $isReplay . "!"); //Initialize SHMOP cache for this game
copy("./Replays/" . $userId . "/" . $replayNumber . "/origGamestate.txt", "./Games/" . $gameName . "/gamestate.txt");
copy("./Replays/" . $userId . "/" . $replayNumber . "/replayCommands.txt", "./Games/" . $gameName . "/replayCommands.txt");
header("Location: NextTurn4.php?gameName=$gameName&playerID=3");