forked from SWU-Karabast/SWUOnline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetUpdateSSE.php
67 lines (54 loc) · 1.45 KB
/
GetUpdateSSE.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
<?php
include 'Libraries/HTTPLibraries.php';
include "HostFiles/Redirector.php";
include "Libraries/SHMOPLibraries.php";
include "WriteLog.php";
// array holding allowed Origin domains
SetHeaders();
header('Content-Type: application/json; charset=utf-8');
$response = new stdClass();
$gameName = $_GET["gameName"];
if (!IsGameNameValid($gameName)) {
$response->errorMessage = ("Invalid game name.");
echo (json_encode($response));
exit;
}
$playerID = TryGet("playerID", 3);
if (!is_numeric($playerID)) {
$response->errorMessage = ("Invalid player ID.");
echo(json_encode($response));
exit;
}
$authKey = TryGet("authKey", "");
if(($playerID == 1 || $playerID == 2) && $authKey == "") {
if(isset($_COOKIE["lastAuthKey"])) $authKey = $_COOKIE["lastAuthKey"];
}
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
$lastUpdate = 0;
$response->message = "update";
$response->padding = str_pad("",4096);
ob_start();
// Loop until the client close the stream
$count = 0;
while(true) {
++$count;
if($count % 100 == 0) {
if(!file_exists("Games/" . $gameName . "/GameFile.txt")) {
exit;
}
}
$cacheVal = intval(GetCachePiece($gameName, 1));
if($cacheVal > $lastUpdate)
{
$lastUpdate = $cacheVal;
echo("data: " . json_encode($response));
ob_flush();
flush();
set_time_limit(120);//Reset script time limit
}
// Wait 100ms to check again
usleep(100000); //100 milliseconds
}
ob_end_flush();
?>