3 * Generate the apps list + other information available at
4 * http://l2.gamestickservices.net/api/rest/connect/stick/stick/xxx/view.json
6 header('HTTP/1.0 500 Internal Server Error');
8 $rootDir = dirname(__FILE__, 4);
9 require_once $rootDir . '/config.php';
11 $cacheDir = $rootDir . '/cache/';
13 $nowMilli = time() * 1000;
15 if (!isset($_GET['hwid'])) {
16 header('HTTP/1.0 400 Bad Request');
17 header('Content-Type: text/plain');
18 echo "Hardware ID is missing\n";
21 $hwId = strtolower($_GET['hwid']);
23 if (count($GLOBALS['whitelistedHardwareIds'])
24 && array_search($hwId, $GLOBALS['whitelistedHardwareIds']) === false
26 header('HTTP/1.0 403 Forbidden');
27 header('Content-Type: text/plain');
28 echo "Gamestick with this hardware ID may not use this server\n";
33 if (isset($_GET['jsessionid'])) {
34 $sessionId = $_GET['jsessionid'];
35 } else if (isset($_COOKIE['JSESSIONID'])) {
36 $sessionId = $_COOKIE['JSESSIONID'];
39 require $rootDir . '/src/ProfileDb.php';
40 $profileDb = new ProfileDb();
41 $profile = $profileDb->getProfileByHardwareId($hwId);
43 if ($profile === null || !$profile->complete()) {
44 //unregistered gamestick
45 if ($profile === null) {
46 $profile = $profileDb->createProfile($hwId);
50 'sid' => $profile->sessionId,
51 'time' => (string) $nowMilli,
53 'status' => 'CONNECTION_IN_PROGRESS',
54 'registrationCode' => ($GLOBALS['verificationCodePrefix'] ?? '')
55 . $profile->verificationCode,
58 $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
59 header('HTTP/1.0 200 OK');
60 header('Content-Type: application/json');
67 'sid' => $profile->sessionId,
68 'time' => (string) $nowMilli,
69 'lastaccessed' => $nowMilli,
70 'x-forwarded-for' => null,
71 'created' => $nowMilli,
74 'remoteaddr' => '1.2.3.4',
77 'status' => 'CONNECTED',
79 'apps' => 'FIXME_APPS',
91 'ages' => 'FIXME_AGES',
98 $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
102 $appsCacheFile = $cacheDir . 'connect-apps.min.json';
103 if (!file_exists($appsCacheFile)) {
104 header('Content-Type: text/plain');
105 echo "Cache file missing: connect-apps.min.json\n";
108 $json = str_replace('"FIXME_APPS"', file_get_contents($appsCacheFile), $json);
111 //inject featured apps
112 $featuredAgesCacheFile = $cacheDir . 'connect-featured-ages.min.json';
113 if (!file_exists($featuredAgesCacheFile)) {
114 header('Content-Type: text/plain');
115 echo "Cache file missing: connect-featured-ages.min.json\n";
118 $json = str_replace('"FIXME_AGES"', file_get_contents($featuredAgesCacheFile), $json);
121 header('HTTP/1.0 200 OK');
122 header('Content-Type: application/json');