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(string $gamesDir): array
42 $gamesDir = str_replace('//', '/', $gamesDir . '/');
45 foreach (glob($gamesDir . '*.json') as $gameFile) {
46 $gameData = json_decode(file_get_contents($gameFile));
47 if ($gameData === null) {
48 throw new \Exception('Cannot load game file: ' . $gameFile);
50 $games[$gameData->package] = $gameData;
56 * Convert a meta data game info into a structure that is suitable
57 * for http://l2.gamestickservices.net/api/rest/connect/stick/stick/xxx/view.json
59 function convertGameDataForConnect(object $gameData, array $popular): array
61 $userCurrency = 'EUR';
64 'id' => $gameData->id,
65 'package' => $gameData->package,
66 'name' => $gameData->name,
67 'description' => $gameData->description,
69 //FIXME: use original value once changing age works on the server
70 'minAge' => 3,//$gameData->minAge,
71 'genre' => current($gameData->genres),
82 'popular' => $popular[$gameData->package] ?? 0,
86 'downloadedfree' => false,
88 'isfree' => $gameData->prices->buy->$userCurrency->amount == 0,
91 'price' => $userCurrency . ' '
92 . $gameData->prices->buy->$userCurrency->amount,
105 'companyname' => $gameData->companyname,
106 'companylogofile' => '',
107 'companyiconsize' => 0,
111 foreach ($gameData->genres as $genre) {
112 $connectData['genres'][] = [
118 foreach ($gameData->prices->buy as $currencySymbol => $price) {
119 $connectData['multipricing']['buy'][] = [
120 'amount' => $price->amount,
121 'isocurrency' => $currencySymbol,
122 'symbol' => $price->symbol,
123 'symbolpostindex' => $price->symbolpostindex,
124 'formattedcurrency' => $price->formattedcurrency,
129 $highestVersionCode = 0;
130 $highestVersionKey = null;
131 foreach ($gameData->releases as $releaseKey => $release) {
132 if (isset($release->broken) && $release->broken === true) {
135 if ($release->versionCode > $highestVersionCode) {
136 $highestVersionKey = $releaseKey;
139 if ($highestVersionKey !== null) {
140 $release = $gameData->releases[$highestVersionKey];
141 $connectData['version'] = $release->uuid;
142 $connectData['gameversion'] = $release->gsName ?? $release->name;
143 $connectData['size'] = round($release->size / 1024 / 1024 * 1000);
144 $connectData['download'] = [
145 'url' => $release->url,
146 'version' => $release->gsVersion,
149 $connectData['name'] = '!! ' . $connectData['name'];
152 foreach ($gameData->videos as $videoNum => $video) {
153 $connectData['videos'][] = [
154 'version' => $video->version,
155 'url' => $video->url,
157 $connectData['images'][] = [
160 'url' => $video->thumb,
164 'name' => 'STICK_VIDEO' . ($videoNum + 1) . '_SCREENSHOT',
172 'name' => 'STICK_THUMBNAIL1',
177 'name' => 'STICK_THUMBNAIL2',
182 'name' => 'STICK_THUMBNAIL3',
187 'name' => 'STICK_THUMBNAIL4',
192 'name' => 'STICK_THUMBNAIL1_1080',
197 'name' => 'STICK_THUMBNAIL2_1080',
202 'name' => 'STICK_THUMBNAIL3_1080',
207 'name' => 'STICK_THUMBNAIL4_1080',
211 'icon-registration' => [
212 'name' => 'STICK_REGISTRATION_GAME_ICON',
217 'name' => 'STICK_ICON',
222 'name' => 'STICK_SCREENSHOT',
226 'screenshots-big' => [
227 'name' => 'STICK_SCREENSHOT_1080',
232 foreach ($gameData->images as $imageKey => $imageData) {
233 if (!isset($imageNameMap[$imageKey])) {
234 throw new \Exception('Unknown image key: ' . $imageKey);
236 if ($imageData === null) {
240 'name' => $imageNameMap[$imageKey]['name'],
241 'width' => $imageNameMap[$imageKey]['width'],
242 'height' => $imageNameMap[$imageKey]['height'],
244 $urls = (array) $imageData;
245 foreach ($urls as $imageUrl) {
246 $connectImage['urls'][] = [
251 $connectData['images'][] = $connectImage;
259 * @param array $featured Array keys are the ages, values
260 * are array of "package name => height"
262 * @return array Suitable for
263 * http://l2.gamestickservices.net/api/rest/connect/stick/stick/xxx/view.json
265 function buildFeaturedMenu(array $featured, array $games)
268 foreach ($featured as $age => $packages) {
277 foreach ($packages as $package => $height) {
278 if ($heightSum + $height > 6) {
282 $connectAge['entries'][] = $columnData;
285 'column' => $columnNum,
286 'columnentries' => [],
289 if (!isset($games[$package])) {
290 throw new \Exception('Unknown featured game: ' . $package);
292 $columnData['columnentries'][] = [
293 'gameID' => $games[$package]->id,
294 'thumbnail' => $height,
295 'column' => $columnNum,
297 $heightSum += $height;
299 if (count($columnData['columnentries'])) {
300 $connectAge['entries'][] = $columnData;
303 $connectMenu[] = $connectAge;