From: Holger Schemel Date: Sat, 3 Jul 2021 11:45:20 +0000 (+0200) Subject: added command to upload existing tapes to server X-Git-Tag: 4.3.0.0~109 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=aeffe316860a47217d9b5074ade03cebda8730c9;p=rocksndiamonds.git added command to upload existing tapes to server --- diff --git a/src/init.c b/src/init.c index 0a44e0e5..0dc8ea0d 100644 --- a/src/init.c +++ b/src/init.c @@ -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); diff --git a/src/main.h b/src/main.h index 58e6c59a..fe41a2c5 100644 --- a/src/main.h +++ b/src/main.h @@ -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 diff --git a/src/tape.c b/src/tape.c index 82792fe1..7403be0f 100644 --- a/src/tape.c +++ b/src/tape.c @@ -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)