2 function loadConfigPopularTxtFile()
4 if (!$GLOBALS['popuplarTxtFile']) {
8 if (!file_exists($GLOBALS['popuplarTxtFile'])) {
9 throw new \Exception('popuplarTxtFile does not exist');
12 $GLOBALS['popular'] = file(
13 $GLOBALS['popuplarTxtFile'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
17 function loadConfigFeaturedFile()
19 if (!$GLOBALS['featuredFile']) {
23 if (!file_exists($GLOBALS['featuredFile'])) {
24 throw new \Exception('featuredFile does not exist');
27 $featured = json_decode(file_get_contents($GLOBALS['featuredFile']));
28 if ($featured === null) {
29 throw new \Exception('cache/featured.json cannot be loaded');
32 foreach ($featured as $age => $packages) {
33 $GLOBALS['featured'][$age] = $packages;
38 * Load game data files and return them
40 function loadGames(array $gameFiles): array
43 foreach ($gameFiles as $gameFile) {
44 $gameData = json_decode(file_get_contents($gameFile));
45 if ($gameData === null) {
46 throw new \Exception('Cannot load game file: ' . $gameFile);
48 $games[$gameData->package] = $gameData;
54 * Convert a meta data game info into a structure that is suitable
55 * for http://l2.gamestickservices.net/api/rest/connect/stick/stick/xxx/view.json
57 function convertGameDataForConnect(object $gameData, array $popular): ?array
59 $userCurrency = 'EUR';
62 'id' => $gameData->id,
63 'package' => $gameData->package,
64 'name' => $gameData->name,
65 'description' => $gameData->description,
67 'minAge' => $gameData->minAge,
68 'genre' => current($gameData->genres),
79 'popular' => $popular[$gameData->package] ?? 0,
83 'downloadedfree' => false,
85 'isfree' => $gameData->prices->buy->$userCurrency->amount == 0,
88 'price' => $userCurrency . ' '
89 . $gameData->prices->buy->$userCurrency->amount,
102 'companyname' => $gameData->companyname,
103 'companylogofile' => '',
104 'companyiconsize' => 0,
108 foreach ($gameData->genres as $genre) {
109 $connectData['genres'][] = [
115 foreach ($gameData->prices->buy as $currencySymbol => $price) {
116 $connectData['multipricing']['buy'][] = [
117 'amount' => $price->amount,
118 'isocurrency' => $currencySymbol,
119 'symbol' => $price->symbol,
120 'symbolpostindex' => $price->symbolpostindex,
121 'formattedcurrency' => $price->formattedcurrency,
126 $highestVersionCode = 0;
127 $highestVersionKey = null;
128 foreach ($gameData->releases as $releaseKey => $release) {
129 if (isset($release->broken) && $release->broken === true) {
132 if ($release->versionCode > $highestVersionCode) {
133 $highestVersionCode = $release->versionCode;
134 $highestVersionKey = $releaseKey;
137 if ($highestVersionKey !== null) {
138 $release = $gameData->releases[$highestVersionKey];
139 $connectData['version'] = $release->uuid;
140 $connectData['gameversion'] = $release->gsName ?? $release->name;
141 $connectData['size'] = round($release->size / 1024 / 1024 * 1000);
142 $connectData['download'] = [
143 'url' => $release->url,
144 'version' => $release->versionCode,
147 $connectData['name'] = '!! ' . $connectData['name'];
150 foreach ($gameData->videos as $videoNum => $video) {
151 $connectData['videos'][] = [
152 'version' => $video->version,
153 'url' => $video->url,
155 $connectData['images'][] = [
158 'url' => $video->thumb,
162 'name' => 'STICK_VIDEO' . ($videoNum + 1) . '_SCREENSHOT',
170 'name' => 'STICK_THUMBNAIL1',
175 'name' => 'STICK_THUMBNAIL2',
180 'name' => 'STICK_THUMBNAIL3',
185 'name' => 'STICK_THUMBNAIL4',
190 'name' => 'STICK_THUMBNAIL1_1080',
195 'name' => 'STICK_THUMBNAIL2_1080',
200 'name' => 'STICK_THUMBNAIL3_1080',
205 'name' => 'STICK_THUMBNAIL4_1080',
209 'icon-registration' => [
210 'name' => 'STICK_REGISTRATION_GAME_ICON',
215 'name' => 'STICK_ICON',
220 'name' => 'STICK_SCREENSHOT',
224 'screenshots-big' => [
225 'name' => 'STICK_SCREENSHOT_1080',
230 foreach ($gameData->images as $imageKey => $imageData) {
231 if (!isset($imageNameMap[$imageKey])) {
232 throw new \Exception('Unknown image key: ' . $imageKey);
234 if ($imageData === null) {
238 'name' => $imageNameMap[$imageKey]['name'],
239 'width' => $imageNameMap[$imageKey]['width'],
240 'height' => $imageNameMap[$imageKey]['height'],
243 $urls = (array) $imageData;
244 foreach ($urls as $imageUrl) {
245 $connectImage['urls'][] = [
250 $connectData['images'][] = $connectImage;
258 * @param array $featured Array keys are the ages, values
259 * are array of "package name => height"
261 * @return array Suitable for
262 * http://l2.gamestickservices.net/api/rest/connect/stick/stick/xxx/view.json
264 function buildFeaturedMenu(array $featured, array $games)
267 foreach ($featured as $age => $packages) {
276 foreach ($packages as $package => $height) {
277 if ($heightSum + $height > 6) {
281 $connectAge['entries'][] = $columnData;
284 'column' => $columnNum,
285 'columnentries' => [],
288 if (!isset($games[$package])) {
289 throw new \Exception('Unknown featured game: ' . $package);
291 $columnData['columnentries'][] = [
292 'gameID' => $games[$package]->id,
293 'thumbnail' => $height,
294 'column' => $columnNum,
296 $heightSum += $height;
298 if (count($columnData['columnentries'])) {
299 $connectAge['entries'][] = $columnData;
302 $connectMenu[] = $connectAge;