From: Holger Schemel Date: Fri, 24 Sep 2021 23:42:33 +0000 (+0200) Subject: changed API code to use thread data pointer instead of variables X-Git-Tag: 4.3.0.0~38 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=cc3401ea96ba528d5f7d384d9f89444dbebcc432;p=rocksndiamonds.git changed API code to use thread data pointer instead of variables --- diff --git a/src/files.c b/src/files.c index a38c4122..668a697f 100644 --- a/src/files.c +++ b/src/files.c @@ -9096,9 +9096,12 @@ static void FreeThreadData_ApiGetScore(void *data_raw) static void ApiGetScoreExt(struct HttpRequest *request, struct HttpResponse *response, - int level_nr, - char *score_cache_filename) + void *data_raw) { + struct ApiGetScoreThreadData *data = data_raw; + int level_nr = data->level_nr; + char *score_cache_filename = data->score_cache_filename; + request->hostname = setup.api_server_hostname; request->port = API_SERVER_PORT; request->method = API_SERVER_METHOD; @@ -9168,13 +9171,13 @@ static void ApiGetScoreExt(struct HttpRequest *request, server_scores.updated = TRUE; } -static void ApiGetScore(int level_nr, char *score_cache_filename) +static void ApiGetScore(void *data_raw) { struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest)); struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse)); ApiGetScoreExt(request, response, - level_nr, score_cache_filename); + data_raw); checked_free(request); checked_free(response); @@ -9182,10 +9185,7 @@ static void ApiGetScore(int level_nr, char *score_cache_filename) static int ApiGetScoreThread(void *data_raw) { - struct ApiGetScoreThreadData *data = data_raw; - - ApiGetScore(data->level_nr, - data->score_cache_filename); + ApiGetScore(data_raw); FreeThreadData_ApiGetScore(data_raw); @@ -9374,10 +9374,13 @@ static void FreeThreadData_ApiAddScore(void *data_raw) static void ApiAddScoreExt(struct HttpRequest *request, struct HttpResponse *response, - int level_nr, - char *score_tape_filename, - struct ScoreEntry *score_entry) + void *data_raw) { + struct ApiAddScoreThreadData *data = data_raw; + int level_nr = data->level_nr; + char *score_tape_filename = data->score_tape_filename; + struct ScoreEntry *score_entry = &data->score_entry; + request->hostname = setup.api_server_hostname; request->port = API_SERVER_PORT; request->method = API_SERVER_METHOD; @@ -9482,14 +9485,13 @@ static void ApiAddScoreExt(struct HttpRequest *request, server_scores.uploaded = TRUE; } -static void ApiAddScore(int level_nr, char *score_tape_filename, - struct ScoreEntry *score_entry) +static void ApiAddScore(void *data_raw) { struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest)); struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse)); ApiAddScoreExt(request, response, - level_nr, score_tape_filename, score_entry); + data_raw); checked_free(request); checked_free(response); @@ -9497,11 +9499,7 @@ static void ApiAddScore(int level_nr, char *score_tape_filename, static int ApiAddScoreThread(void *data_raw) { - struct ApiAddScoreThreadData *data = data_raw; - - ApiAddScore(data->level_nr, - data->score_tape_filename, - &data->score_entry); + ApiAddScore(data_raw); FreeThreadData_ApiAddScore(data_raw); diff --git a/src/screens.c b/src/screens.c index 46632bc4..3f64b882 100644 --- a/src/screens.c +++ b/src/screens.c @@ -4070,9 +4070,12 @@ static void FreeThreadData_ApiRenamePlayer(void *data_raw) static void ApiRenamePlayerExt(struct HttpRequest *request, struct HttpResponse *response, - char *player_name_raw, - char *player_uuid_raw) + void *data_raw) { + struct ApiRenamePlayerThreadData *data = data_raw; + char *player_name_raw = data->player_name; + char *player_uuid_raw = data->player_uuid; + request->hostname = setup.api_server_hostname; request->port = API_SERVER_PORT; request->method = API_SERVER_METHOD; @@ -4117,12 +4120,12 @@ static void ApiRenamePlayerExt(struct HttpRequest *request, } } -static void ApiRenamePlayer(char *player_name, char *player_uuid) +static void ApiRenamePlayer(void *data_raw) { struct HttpRequest *request = checked_calloc(sizeof(struct HttpRequest)); struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse)); - ApiRenamePlayerExt(request, response, player_name, player_uuid); + ApiRenamePlayerExt(request, response, data_raw); checked_free(request); checked_free(response); @@ -4130,9 +4133,7 @@ static void ApiRenamePlayer(char *player_name, char *player_uuid) static int ApiRenamePlayerThread(void *data_raw) { - struct ApiRenamePlayerThreadData *data = data_raw; - - ApiRenamePlayer(data->player_name, data->player_uuid); + ApiRenamePlayer(data_raw); FreeThreadData_ApiRenamePlayer(data_raw);