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,
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_THUMBNAIL4',
180 'name' => 'STICK_THUMBNAIL4',
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'],
242 $urls = (array) $imageData;
243 foreach ($urls as $imageUrl) {
244 $connectImage['urls'][] = [
249 $connectData['images'][] = $connectImage;
257 * @param array $featured Array keys are the ages, values
258 * are array of "package name => height"
260 * @return array Suitable for
261 * http://l2.gamestickservices.net/api/rest/connect/stick/stick/xxx/view.json
263 function buildFeaturedMenu(array $featured, array $games)
266 foreach ($featured as $age => $packages) {
275 foreach ($packages as $package => $height) {
276 if ($heightSum + $height > 6) {
280 $connectAge['entries'][] = $columnData;
283 'column' => $columnNum,
284 'columnentries' => [],
287 if (!isset($games[$package])) {
288 throw new \Exception('Unknown featured game: ' . $package);
290 $columnData['columnentries'][] = [
291 'gameID' => $games[$package]->id,
292 'thumbnail' => $height,
293 'column' => $columnNum,
295 $heightSum += $height;
297 if (count($columnData['columnentries'])) {
298 $connectAge['entries'][] = $columnData;
301 $connectMenu[] = $connectAge;