From cf07764d802b7eafa64da36558e086515577a9f9 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Thu, 24 Jun 2021 12:09:34 +0200 Subject: [PATCH] added support for optional password for score server access --- src/files.c | 29 +++++++++++++++++++++++++++++ src/libgame/system.h | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/src/files.c b/src/files.c index 93a4b597..de9c7e37 100644 --- a/src/files.c +++ b/src/files.c @@ -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 diff --git a/src/libgame/system.h b/src/libgame/system.h index e59edf83..40f3436b 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -614,6 +614,9 @@ // 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; -- 2.34.1