added option to write tape log file (for high score server)
authorHolger Schemel <info@artsoft.org>
Tue, 29 Jun 2021 10:20:21 +0000 (12:20 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 29 Jun 2021 10:20:21 +0000 (12:20 +0200)
src/libgame/misc.c
src/libgame/system.h
src/tape.c

index 5f9c009afd39875560ed9b9f6ee846ceb0fabdd8..ed4c2606e81026f94c307d9da347eab39f3db3b8 100644 (file)
@@ -1262,6 +1262,7 @@ void GetOptions(int argc, char *argv[],
   options.conf_directory     = getPath2(base_path, CONF_DIRECTORY);
 
   options.execute_command = NULL;
+  options.tape_log_filename = NULL;
   options.special_flags = NULL;
   options.debug_mode = NULL;
 
@@ -1428,6 +1429,15 @@ void GetOptions(int argc, char *argv[],
       // when doing batch processing, always enable verbose mode (warnings)
       options.verbose = TRUE;
     }
+    else if (strncmp(option, "-tape_logfile", option_len) == 0)
+    {
+      if (option_arg == NULL)
+       FailWithHelp("option '%s' requires an argument", option_str);
+
+      options.tape_log_filename = getStringCopy(option_arg);
+      if (option_arg == next_option)
+       options_left++;
+    }
 #if defined(PLATFORM_MACOSX)
     else if (strPrefix(option, "-psn"))
     {
index 40f3436b219d07055b0e767547c87c9890e47791..bd3f4b8fd6f3bf30629574dc161275b157a0d1d7 100644 (file)
@@ -1050,6 +1050,7 @@ struct OptionInfo
   char *conf_directory;
 
   char *execute_command;
+  char *tape_log_filename;
 
   char *special_flags;
   char *debug_mode;
index 14bf45bcb383c975baa0780776272284cb42e107..0c99d6802582ae5376635c932f585a5da959045f 100644 (file)
@@ -512,6 +512,27 @@ static void PrintTapeReplayProgress(boolean replay_finished)
   }
 }
 
+static FILE *tape_log_file;
+
+static void OpenTapeLogfile(void)
+{
+  if (!(tape_log_file = fopen(options.tape_log_filename, MODE_WRITE)))
+    Warn("cannot write tape logfile '%s'", options.tape_log_filename);
+}
+
+static void WriteTapeLogfile(byte action[MAX_TAPE_ACTIONS])
+{
+  int i;
+
+  for (i = 0; i < MAX_TAPE_ACTIONS; i++)
+    putFile8Bit(tape_log_file, action[i]);
+}
+
+static void CloseTapeLogfile(void)
+{
+  fclose(tape_log_file);
+}
+
 
 // ============================================================================
 // tape control functions
@@ -936,6 +957,9 @@ byte *TapePlayAction(void)
   if (tape.auto_play)
     PrintTapeReplayProgress(FALSE);
 
+  if (options.tape_log_filename != NULL)
+    WriteTapeLogfile(action);
+
   return action;
 }
 
@@ -1313,6 +1337,9 @@ void AutoPlayTapes(void)
     // just finished auto-playing tape
     PrintTapeReplayProgress(TRUE);
 
+    if (options.tape_log_filename != NULL)
+      CloseTapeLogfile();
+
     if (global.autoplay_mode == AUTOPLAY_MODE_SAVE &&
        tape.auto_play_level_solved)
     {
@@ -1549,6 +1576,9 @@ void AutoPlayTapes(void)
 
     InitCounter();
 
+    if (options.tape_log_filename != NULL)
+      OpenTapeLogfile();
+
     TapeStartGamePlaying();
     TapeStartWarpForward(global.autoplay_mode);