From: Holger Schemel Date: Sat, 16 Oct 2021 14:03:44 +0000 (+0200) Subject: added sending flag for locally saved tape to score server X-Git-Tag: 4.3.0.0~15 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=91b5e8017245999d9f72b5cd8089597eb827666e;p=rocksndiamonds.git added sending flag for locally saved tape to score server --- diff --git a/src/files.c b/src/files.c index 78a505dd..11eba8f4 100644 --- a/src/files.c +++ b/src/files.c @@ -9432,11 +9432,13 @@ static char *get_file_base64(char *filename) struct ApiAddScoreThreadData { int level_nr; + boolean tape_saved; char *score_tape_filename; struct ScoreEntry score_entry; }; -static void *CreateThreadData_ApiAddScore(int nr, char *score_tape_filename) +static void *CreateThreadData_ApiAddScore(int nr, boolean tape_saved, + char *score_tape_filename) { struct ApiAddScoreThreadData *data = checked_malloc(sizeof(struct ApiAddScoreThreadData)); @@ -9446,6 +9448,7 @@ static void *CreateThreadData_ApiAddScore(int nr, char *score_tape_filename) score_tape_filename = getScoreTapeFilename(score_entry->tape_basename, nr); data->level_nr = nr; + data->tape_saved = tape_saved; data->score_entry = *score_entry; data->score_tape_filename = getStringCopy(score_tape_filename); @@ -9466,6 +9469,7 @@ static boolean SetRequest_ApiAddScore(struct HttpRequest *request, struct ApiAddScoreThreadData *data = data_raw; struct ScoreEntry *score_entry = &data->score_entry; char *score_tape_filename = data->score_tape_filename; + boolean tape_saved = data->tape_saved; int level_nr = data->level_nr; request->hostname = setup.api_server_hostname; @@ -9519,6 +9523,7 @@ static boolean SetRequest_ApiAddScore(struct HttpRequest *request, " \"score\": \"%d\",\n" " \"time\": \"%d\",\n" " \"tape_basename\": \"%s\",\n" + " \"tape_saved\": \"%d\",\n" " \"tape\": \"%s\"\n" "}\n", getPasswordJSON(setup.api_server_password), @@ -9539,6 +9544,7 @@ static boolean SetRequest_ApiAddScore(struct HttpRequest *request, score_entry->score, score_entry->time, score_entry->tape_basename, + tape_saved, tape_base64); checked_free(tape_base64); @@ -9671,30 +9677,32 @@ static int ApiAddScoreThread(void *data_raw) return 0; } -static void ApiAddScoreAsThread(int nr, char *score_tape_filename) +static void ApiAddScoreAsThread(int nr, boolean tape_saved, + char *score_tape_filename) { struct ApiAddScoreThreadData *data = - CreateThreadData_ApiAddScore(nr, score_tape_filename); + CreateThreadData_ApiAddScore(nr, tape_saved, score_tape_filename); ExecuteAsThread(ApiAddScoreThread, "ApiAddScore", data, "upload score to server"); } -void SaveServerScore(int nr) +void SaveServerScore(int nr, boolean tape_saved) { if (!runtime.use_api_server) return; - ApiAddScoreAsThread(nr, NULL); + ApiAddScoreAsThread(nr, tape_saved, NULL); } -void SaveServerScoreFromFile(int nr, char *score_tape_filename) +void SaveServerScoreFromFile(int nr, boolean tape_saved, + char *score_tape_filename) { if (!runtime.use_api_server) return; - ApiAddScoreAsThread(nr, score_tape_filename); + ApiAddScoreAsThread(nr, tape_saved, score_tape_filename); } void LoadLocalAndServerScore(int nr, boolean download_score) diff --git a/src/files.h b/src/files.h index 596c24a6..e32fcd80 100644 --- a/src/files.h +++ b/src/files.h @@ -68,8 +68,8 @@ void LoadScore(int); void SaveScore(int); void LoadServerScore(int, boolean); -void SaveServerScore(int); -void SaveServerScoreFromFile(int, char *); +void SaveServerScore(int, boolean); +void SaveServerScoreFromFile(int, boolean, char *); void LoadLocalAndServerScore(int, boolean); diff --git a/src/game.c b/src/game.c index c3dc82cc..89e9e7fa 100644 --- a/src/game.c +++ b/src/game.c @@ -1106,7 +1106,7 @@ void ContinueMoving(int, int); void Bang(int, int); void InitMovDir(int, int); void InitAmoebaNr(int, int); -void NewHighScore(int); +void NewHighScore(int, boolean); void TestIfGoodThingHitsBadThing(int, int, int); void TestIfBadThingHitsGoodThing(int, int, int); @@ -4965,6 +4965,7 @@ void GameEnd(void) { // used instead of "level_nr" (needed for network games) int last_level_nr = levelset.level_nr; + boolean tape_saved = FALSE; game.LevelSolved_GameEnd = TRUE; @@ -4974,7 +4975,8 @@ void GameEnd(void) if (!global.use_envelope_request) CloseDoor(DOOR_CLOSE_1); - SaveTapeChecked_LevelSolved(tape.level_nr); // ask to save tape + // ask to save tape + tape_saved = SaveTapeChecked_LevelSolved(tape.level_nr); // set unique basename for score tape (also saved in high score table) strcpy(tape.score_tape_basename, getScoreTapeBasename(setup.player_name)); @@ -5009,7 +5011,7 @@ void GameEnd(void) } // save score and score tape before potentially erasing tape below - NewHighScore(last_level_nr); + NewHighScore(last_level_nr, tape_saved); if (setup.increment_levels && level_nr < leveldir_current->last_level && @@ -5117,7 +5119,7 @@ static int addScoreEntry(struct ScoreInfo *list, struct ScoreEntry *new_entry, return -1; } -void NewHighScore(int level_nr) +void NewHighScore(int level_nr, boolean tape_saved) { struct ScoreEntry new_entry = {{ 0 }}; // (prevent warning from GCC bug 53119) boolean one_per_name = FALSE; @@ -5143,7 +5145,7 @@ void NewHighScore(int level_nr) if (game.LevelSolved_SaveTape) { SaveScoreTape(level_nr); - SaveServerScore(level_nr); + SaveServerScore(level_nr, tape_saved); } } diff --git a/src/tape.c b/src/tape.c index 38bc0166..793bf0ce 100644 --- a/src/tape.c +++ b/src/tape.c @@ -1540,7 +1540,7 @@ static int AutoPlayTapesExt(boolean initialize) // * solution tape may have native format (like Supaplex solution files) SaveScoreTape(level_nr); - SaveServerScore(level_nr); + SaveServerScore(level_nr, TRUE); AutoPlayTapes_WaitForUpload(); } @@ -1832,7 +1832,7 @@ static int AutoPlayTapesExt(boolean initialize) } } - SaveServerScoreFromFile(level_nr, autoplay.tape_filename); + SaveServerScoreFromFile(level_nr, TRUE, autoplay.tape_filename); boolean success = AutoPlayTapes_WaitForUpload();