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 require_once dirname(__FILE__, 7) . '/config.php';
10 $cacheDir = dirname(__FILE__, 7) . '/cache/';
12 $nowMilli = time() * 1000;
15 'time' => (string) $nowMilli,
16 'lastaccessed' => $nowMilli,
17 'x-forwarded-for' => null,
18 'created' => $nowMilli,
21 'remoteaddr' => '1.2.3.4',
24 'status' => 'CONNECTED',
26 'apps' => 'FIXME_APPS',
38 'ages' => 'FIXME_AGES',
45 if (isset($_GET['jsessionid'])) {
46 $data['sid'] = $_GET['jsessionid'];
47 } else if (isset($_COOKIE['JSESSIONID'])) {
48 $data['sid'] = $_COOKIE['JSESSIONID'];
50 //FIXME: map hwid to user sid
51 $data['sid'] = 'dummy';
52 // header('HTTP/1.0 400 Bad Request');
53 // header('Content-Type: text/plain');
54 // echo "jsessionid GET parameter or JSESSIONID cookie missing\n";
58 if (!isset($_GET['hwid'])) {
59 header('HTTP/1.0 400 Bad Request');
60 header('Content-Type: text/plain');
61 echo "Hardware ID is missing\n";
64 if (count($GLOBALS['whitelistedHardwareIds'])
65 && array_search($_GET['hwid'], $GLOBALS['whitelistedHardwareIds']) === false
67 header('HTTP/1.0 403 Forbidden');
68 header('Content-Type: text/plain');
69 echo "Gamestick with this hardware ID may not use this server\n";
74 $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
78 $appsCacheFile = $cacheDir . 'connect-apps.min.json';
79 if (!file_exists($appsCacheFile)) {
80 header('Content-Type: text/plain');
81 echo "Cache file missing: connect-apps.min.json\n";
84 $json = str_replace('"FIXME_APPS"', file_get_contents($appsCacheFile), $json);
87 //inject featured apps
88 $featuredAgesCacheFile = $cacheDir . 'connect-featured-ages.min.json';
89 if (!file_exists($featuredAgesCacheFile)) {
90 header('Content-Type: text/plain');
91 echo "Cache file missing: connect-featured-ages.min.json\n";
94 $json = str_replace('"FIXME_AGES"', file_get_contents($featuredAgesCacheFile), $json);
97 header('HTTP/1.0 200 OK');
98 header('Content-Type: application/json');