Sleep a bit to prevent being too fast
[gamestick-pjgsapi.git] / www / api / rest / connect.php
index d6881655ef87d949d4dcab9dd920516e29af4ee3..783684f3c5610f254776d013e8dd833943f9b122 100644 (file)
@@ -51,7 +51,8 @@ if ($profile === null || !$profile->complete()) {
         'time' => (string) $nowMilli,
         'body' => [
             'status'           => 'CONNECTION_IN_PROGRESS',
-            'registrationCode' => $profile->verificationCode,
+            'registrationCode' => ($GLOBALS['verificationCodePrefix'] ?? '')
+                . $profile->verificationCode,
         ]
     ];
     $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
@@ -68,26 +69,24 @@ $data = [
     'lastaccessed'    => $nowMilli,
     'x-forwarded-for' => null,
     'created'         => $nowMilli,
-    'accessCount'     => 0,
+    'accessCount'     => 1,
     'addr'            => '1.2.3.4',
     'remoteaddr'      => '1.2.3.4',
 
     'body' => [
         'status' => 'CONNECTED',
+        'verificationCode' => 'd7d987',
         'config' => [
-            'apps'   => 'FIXME_APPS',
+            'apps'   => 'PLACEHOLDER_APPS',
             'global' => [
                 'defaults' => [
                     'images'   => [],
                     'currency' => null,
                     'social'   => [],
                 ],
-                'uitranslation' => [
-                    'version' => 0,
-                    'country' => [],
-                ],
+                'uitranslation' => 'PLACEHOLDER_UITRANSLATION',
                 'newfeatured' => [
-                    'ages' => 'FIXME_AGES',
+                    'ages' => 'PLACEHOLDER_AGES',
                 ],
             ],
         ]
@@ -97,25 +96,26 @@ $data = [
 $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
 
 
-//inject apps
-$appsCacheFile = $cacheDir . 'connect-apps.min.json';
-if (!file_exists($appsCacheFile)) {
-    header('Content-Type: text/plain');
-    echo "Cache file missing: connect-apps.min.json\n";
-    exit(1);
-}
-$json = str_replace('"FIXME_APPS"', file_get_contents($appsCacheFile), $json);
-
-
-//inject featured apps
-$featuredAgesCacheFile = $cacheDir . 'connect-featured-ages.min.json';
-if (!file_exists($featuredAgesCacheFile)) {
-    header('Content-Type: text/plain');
-    echo "Cache file missing: connect-featured-ages.min.json\n";
-    exit(1);
+$placeholderFiles = [
+    'PLACEHOLDER_APPS'          => $cacheDir . 'connect-apps.min.json',
+    'PLACEHOLDER_AGES'          => $cacheDir . 'connect-featured-ages.min.json',
+    'PLACEHOLDER_UITRANSLATION' => $cacheDir . 'connect-uitranslation.min.json',
+];
+foreach ($placeholderFiles as $placeholder => $cacheFile) {
+    //inject apps
+    if (!file_exists($cacheFile)) {
+        header('Content-Type: text/plain');
+        echo "Cache file missing: $cacheFile\n";
+        exit(1);
+    }
+    $json = str_replace(
+        '"' . $placeholder . '"',
+        trim(file_get_contents($cacheFile)),
+        $json
+    );
 }
-$json = str_replace('"FIXME_AGES"', file_get_contents($featuredAgesCacheFile), $json);
 
+sleep(2);//prevent error "Failed to duplicate connect data for console"
 
 header('HTTP/1.0 200 OK');
 header('Content-Type: application/json');