Add optional auto-save/restore feature using -a <filename> option

To enable use with online Bulletin Board Systems (BBSes) where users
may be disconnected unexpectedly, but would naturally want to resume
playing their same game, added support for an optional save game
path/filename to be specified on the command-line (very similar to
"-r <filename>"), except this save/restore file is:
1. automatically loaded/restored if it exists
2. automatically created when starting a new game
3. automatically updated when exiting a game for any reason
4. cannot be changed to a different path/filename by the user

Since a BBS server program can be expected to send a SIGHUP or SIGTERM
to the game process upon user disconnection (or timeout), those
signals are caught and a graceful termination will occur which saves
the current game state.

Build with ADVENT_AUTOSAVE defined to enable this option.

BUG:
The 'info' command still reports the save/suspend/pause commands as
valid, though they are not when this build option is used (same is
true of ADVENT_NOSAVE, and that doesn't apparently bother anyone).
This commit is contained in:
Rob Swindell (on Debian Linux) 2023-03-02 19:44:47 -08:00
parent 426684fec2
commit dfff80faa8
5 changed files with 57 additions and 6 deletions

View file

@ -62,7 +62,7 @@ int suspend(void)
* battles or to start over after learning zzword).
* If ADVENT_NOSAVE is defined, do nothing instead. */
#ifdef ADVENT_NOSAVE
#if defined ADVENT_NOSAVE || defined ADVENT_AUTOSAVE
return GO_UNKNOWN;
#endif
FILE *fp = NULL;
@ -93,7 +93,7 @@ int resume(void)
/* Resume. Read a suspended game back from a file.
* If ADVENT_NOSAVE is defined, do nothing instead. */
#ifdef ADVENT_NOSAVE
#if defined ADVENT_NOSAVE || defined ADVENT_AUTOSAVE
return GO_UNKNOWN;
#endif
FILE *fp = NULL;