added support for optional password for score server access
authorHolger Schemel <info@artsoft.org>
Thu, 24 Jun 2021 10:09:34 +0000 (12:09 +0200)
committerHolger Schemel <info@artsoft.org>
Thu, 24 Jun 2021 10:09:52 +0000 (12:09 +0200)
src/files.c
src/libgame/system.h

index 93a4b59724af8d9fb458d2e0f9bdcd27ffae2df5..de9c7e37028ee6d75511011d18c1baf1d7326ab8 100644 (file)
@@ -9016,6 +9016,26 @@ static void ExecuteAsThread(SDL_ThreadFunction function, char *name, void *data,
   Delay(1);
 }
 
+static char *getPasswordJSON(char *password)
+{
+  static char password_json[MAX_FILENAME_LEN] = "";
+  static boolean initialized = FALSE;
+
+  if (!initialized)
+  {
+    if (password != NULL &&
+       !strEqual(password, "") &&
+       !strEqual(password, UNDEFINED_PASSWORD))
+      snprintf(password_json, MAX_FILENAME_LEN,
+              "  \"password\":             \"%s\",\n",
+              setup.api_server_password);
+
+    initialized = TRUE;
+  }
+
+  return password_json;
+}
+
 static void DownloadServerScoreToCacheExt(struct HttpRequest *request,
                                          struct HttpResponse *response,
                                          int level_nr,
@@ -9028,9 +9048,11 @@ static void DownloadServerScoreToCacheExt(struct HttpRequest *request,
 
   snprintf(request->body, MAX_HTTP_BODY_SIZE,
           "{\n"
+          "%s"
           "  \"levelset_identifier\":  \"%s\",\n"
           "  \"level_nr\":             \"%d\"\n"
           "}\n",
+          getPasswordJSON(setup.api_server_password),
           levelset.identifier, level_nr);
 
   ConvertHttpRequestBodyToServerEncoding(request);
@@ -9298,6 +9320,7 @@ static void UploadScoreToServerExt(struct HttpRequest *request,
 
   snprintf(request->body, MAX_HTTP_BODY_SIZE,
           "{\n"
+          "%s"
           "  \"game_version\":         \"%s\",\n"
           "  \"levelset_identifier\":  \"%s\",\n"
           "  \"levelset_name\":        \"%s\",\n"
@@ -9314,6 +9337,7 @@ static void UploadScoreToServerExt(struct HttpRequest *request,
           "  \"tape_basename\":        \"%s\",\n"
           "  \"tape\":                 \"%s\"\n"
           "}\n",
+          getPasswordJSON(setup.api_server_password),
           getProgramRealVersionString(),
           levelset_identifier,
           levelset_name,
@@ -9681,6 +9705,10 @@ static struct TokenInfo global_setup_tokens[] =
     TYPE_STRING,
     &setup.api_server_hostname,                        "api_server_hostname"
   },
+  {
+    TYPE_STRING,
+    &setup.api_server_password,                        "api_server_password"
+  },
   {
     TYPE_STRING,
     &setup.touch.control_type,                 "touch.control_type"
@@ -10317,6 +10345,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
 
   si->api_server = TRUE;
   si->api_server_hostname = getStringCopy(API_SERVER_HOSTNAME);
+  si->api_server_password = getStringCopy(UNDEFINED_PASSWORD);
 
   si->touch.control_type = getStringCopy(TOUCH_CONTROL_DEFAULT);
   si->touch.move_distance = TOUCH_MOVE_DISTANCE_DEFAULT;       // percent
index e59edf837771dc563f77fe2db1912d46394f0ee8..40f3436b219d07055b0e767547c87c9890e47791 100644 (file)
 // default value for undefined levelset
 #define UNDEFINED_LEVELSET     "[NONE]"
 
+// default value for undefined password
+#define UNDEFINED_PASSWORD     "[undefined]"
+
 // default value for undefined parameter
 #define ARG_DEFAULT            "[DEFAULT]"
 
@@ -1490,6 +1493,7 @@ struct SetupInfo
 
   boolean api_server;
   char *api_server_hostname;
+  char *api_server_password;
 
   struct SetupAutoSetupInfo auto_setup;
   struct SetupLevelSetupInfo level_setup;