added command to upload existing tapes to server
authorHolger Schemel <info@artsoft.org>
Sat, 3 Jul 2021 11:45:20 +0000 (13:45 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 3 Jul 2021 11:45:20 +0000 (13:45 +0200)
src/init.c
src/main.h
src/tape.c

index 0a44e0e5436906ad45913498a50d3a487f3545b5..0dc8ea0ddfb9a47b717c9cd35f03a368958a4915 100644 (file)
@@ -5069,6 +5069,7 @@ static void Execute_Command(char *command)
           strPrefix(command, "autowarp ") ||
           strPrefix(command, "autotest ") ||
           strPrefix(command, "autosave ") ||
+          strPrefix(command, "autoupload ") ||
           strPrefix(command, "autofix "))
   {
     char *arg_ptr = strchr(command, ' ');
@@ -5080,6 +5081,7 @@ static void Execute_Command(char *command)
        strPrefix(command, "autowarp") ? AUTOPLAY_MODE_WARP :
        strPrefix(command, "autotest") ? AUTOPLAY_MODE_TEST :
        strPrefix(command, "autosave") ? AUTOPLAY_MODE_SAVE :
+       strPrefix(command, "autoupload") ? AUTOPLAY_MODE_UPLOAD :
        strPrefix(command, "autofix")  ? AUTOPLAY_MODE_FIX :
        AUTOPLAY_MODE_NONE);
 
index 58e6c59adf6bcfed6f47a855ba66ac107325248b..fe41a2c5887a878c843391c3b8597b8822e2aedd 100644 (file)
@@ -2656,7 +2656,8 @@ enum
 #define AUTOPLAY_WARP                  (1 << 2)
 #define AUTOPLAY_TEST                  (1 << 3)
 #define AUTOPLAY_SAVE                  (1 << 4)
-#define AUTOPLAY_FIX                   (1 << 5)
+#define AUTOPLAY_UPLOAD                        (1 << 5)
+#define AUTOPLAY_FIX                   (1 << 6)
 #define AUTOPLAY_WARP_NO_DISPLAY       AUTOPLAY_TEST
 
 #define AUTOPLAY_MODE_NONE             0
@@ -2665,6 +2666,7 @@ enum
 #define AUTOPLAY_MODE_WARP             (AUTOPLAY_MODE_FFWD | AUTOPLAY_WARP)
 #define AUTOPLAY_MODE_TEST             (AUTOPLAY_MODE_WARP | AUTOPLAY_TEST)
 #define AUTOPLAY_MODE_SAVE             (AUTOPLAY_MODE_TEST | AUTOPLAY_SAVE)
+#define AUTOPLAY_MODE_UPLOAD           (AUTOPLAY_MODE_TEST | AUTOPLAY_UPLOAD)
 #define AUTOPLAY_MODE_FIX              (AUTOPLAY_MODE_TEST | AUTOPLAY_FIX)
 #define AUTOPLAY_MODE_WARP_NO_DISPLAY  AUTOPLAY_MODE_TEST
 
index 82792fe116b922a4cd1f30062c38129dedfe1547..7403be0f042dd7af216ed8c226cff5c919713be3 100644 (file)
@@ -1459,6 +1459,8 @@ void AutoPlayTapes(void)
     PrintLine("=", 79);
     if (global.autoplay_mode == AUTOPLAY_MODE_FIX)
       Print("Automatically fixing level tapes\n");
+    else if (global.autoplay_mode == AUTOPLAY_MODE_UPLOAD)
+      Print("Automatically uploading level tapes\n");
     else
       Print("Automatically playing level tapes\n");
     PrintLine("-", 79);
@@ -1586,6 +1588,61 @@ void AutoPlayTapes(void)
       }
     }
 
+    if (global.autoplay_mode == AUTOPLAY_MODE_UPLOAD)
+    {
+      // set unique basename for score tape (for uploading to score server)
+      strcpy(tape.score_tape_basename, getScoreTapeBasename(setup.player_name));
+
+      // store score in first score entry
+      scores.last_added = 0;
+
+      struct ScoreEntry *entry = &scores.entry[scores.last_added];
+
+      strncpy(entry->tape_basename, tape.score_tape_basename, MAX_FILENAME_LEN);
+      strncpy(entry->name, setup.player_name, MAX_PLAYER_NAME_LEN);
+
+      entry->score = 0;
+      entry->time = 0;
+
+      Print("Tape %03d:\n", level_nr);
+      PrintNoLog("- uploading score tape to score server ... ");
+
+      server_scores.uploaded = FALSE;
+
+      if (tape_filename == NULL)
+       tape_filename = (options.mytapes ? getTapeFilename(level_nr) :
+                        getSolutionTapeFilename(level_nr));
+
+      SaveServerScoreFromFile(level_nr, tape_filename);
+
+      // required for uploading multiple tapes
+      tape_filename = NULL;
+
+      unsigned int upload_delay = 0;
+      unsigned int upload_delay_value = 10000;
+
+      ResetDelayCounter(&upload_delay);
+
+      // wait for score tape to be successfully uploaded (and fail on timeout)
+      while (!server_scores.uploaded)
+      {
+       if (DelayReached(&upload_delay, upload_delay_value))
+       {
+         PrintNoLog("\r");
+         Print("- uploading score tape to score server - TIMEOUT.\n");
+
+         Fail("cannot upload score tape to score server");
+       }
+
+       Delay(20);
+      }
+
+      PrintNoLog("\r");
+      Print("- uploading score tape to score server - uploaded.\n");
+
+      continue;
+    }
+
     InitCounter();
 
     if (options.tape_log_filename != NULL)