3 * Generate the apps list + other information available at
4 * http://l2.gamestickservices.net/api/rest/connect/stick/stick/xxx/view.json
6 #readfile(dirname(__FILE__, 4) . '/alex.json');die();
8 header('HTTP/1.0 500 Internal Server Error');
10 $rootDir = dirname(__FILE__, 4);
11 require_once $rootDir . '/config.php';
13 $cacheDir = $rootDir . '/cache/';
15 $nowMilli = time() * 1000;
17 if (!isset($_GET['hwid'])) {
18 header('HTTP/1.0 400 Bad Request');
19 header('Content-Type: text/plain');
20 echo "Hardware ID is missing\n";
23 $hwId = strtolower($_GET['hwid']);
25 if (count($GLOBALS['whitelistedHardwareIds'])
26 && array_search($hwId, $GLOBALS['whitelistedHardwareIds']) === false
28 header('HTTP/1.0 403 Forbidden');
29 header('Content-Type: text/plain');
30 echo "Gamestick with this hardware ID may not use this server\n";
35 if (isset($_GET['jsessionid'])) {
36 $sessionId = $_GET['jsessionid'];
37 } else if (isset($_COOKIE['JSESSIONID'])) {
38 $sessionId = $_COOKIE['JSESSIONID'];
41 require $rootDir . '/src/ProfileDb.php';
42 $profileDb = new ProfileDb();
43 $profile = $profileDb->getProfileByHardwareId($hwId);
45 if ($profile === null || !$profile->complete()) {
46 //unregistered gamestick
47 if ($profile === null) {
48 $profile = $profileDb->createProfile($hwId);
52 'sid' => $profile->sessionId,
53 'time' => (string) $nowMilli,
55 'status' => 'CONNECTION_IN_PROGRESS',
56 'registrationCode' => ($GLOBALS['verificationCodePrefix'] ?? '')
57 . $profile->verificationCode,
60 $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
61 header('HTTP/1.0 200 OK');
62 header('Content-Type: application/json');
69 'sid' => $profile->sessionId,
70 'time' => (string) $nowMilli,
71 'lastaccessed' => $nowMilli,
72 'x-forwarded-for' => null,
73 'created' => $nowMilli,
76 'remoteaddr' => '1.2.3.4',
79 'status' => 'CONNECTED',
80 'verificationCode' => 'd7d987',
82 'apps' => 'PLACEHOLDER_APPS',
89 'uitranslation' => 'PLACEHOLDER_UITRANSLATION',
91 'ages' => 'PLACEHOLDER_AGES',
98 $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
101 $placeholderFiles = [
102 'PLACEHOLDER_APPS' => $cacheDir . 'connect-apps.min.json',
103 'PLACEHOLDER_AGES' => $cacheDir . 'connect-featured-ages.min.json',
104 'PLACEHOLDER_UITRANSLATION' => $cacheDir . 'connect-uitranslation.min.json',
106 foreach ($placeholderFiles as $placeholder => $cacheFile) {
108 if (!file_exists($cacheFile)) {
109 header('Content-Type: text/plain');
110 echo "Cache file missing: $cacheFile\n";
114 '"' . $placeholder . '"',
115 trim(file_get_contents($cacheFile)),
120 header('HTTP/1.0 200 OK');
121 header('Content-Type: application/json');