added sending flag for locally saved tape to score server
authorHolger Schemel <info@artsoft.org>
Sat, 16 Oct 2021 14:03:44 +0000 (16:03 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 16 Oct 2021 17:12:33 +0000 (19:12 +0200)
src/files.c
src/files.h
src/game.c
src/tape.c

index 78a505dd4c4699469a0b636b629dc4f26e097e73..11eba8f4b95dd2c3cd72b620d64c9ae8e388381e 100644 (file)
@@ -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)
index 596c24a60b6eeca03287fae4357a79b81c8182ed..e32fcd80c2c82c773d35117b35e090d36057443c 100644 (file)
@@ -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);
 
index c3dc82cc2631d07c03bc56ce83bb4b3e9ddd6e8a..89e9e7fac1c739df6326eb4276d28913d6794795 100644 (file)
@@ -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);
   }
 }
 
index 38bc0166394f487ef64a31a979ad25e4e89b316c..793bf0cec0145eb04ddaea56a01f898092558626 100644 (file)
@@ -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();