]> skyeroc.xyz Git - dgamelaunch/commitdiff
Remove savefilefmt from config file; backing up the savefile
authorPasi Kallinen <paxed@alt.org>
Tue, 1 Jan 2008 17:36:46 +0000 (17:36 +0000)
committerPasi Kallinen <paxed@alt.org>
Tue, 1 Jan 2008 17:36:46 +0000 (17:36 +0000)
can now be done with per-game commands.

git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@392 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

config.l
config.y
dgamelaunch.c
dgamelaunch.h
dgl-common.c
examples/dgamelaunch.conf

index 0340e16e689843b720844af89f462b00b9176073..003d91a13913db04b961b65fdde0b3c125164b23 100644 (file)
--- a/config.l
+++ b/config.l
@@ -77,7 +77,6 @@ COMMENT               ^#.*
 "rc_template"  { return TYPE_PATH_CANNED; }
 "passwd"       { return TYPE_PATH_PASSWD; }
 "lockfile"     { return TYPE_PATH_LOCKFILE; }
-"savefilefmt"  { return TYPE_PATH_SAVEFILEFMT; }
 "inprogressdir" { return TYPE_PATH_INPROGRESS; }
 "game_args"    { return TYPE_GAME_ARGS; }
 "rc_fmt"       { return TYPE_RC_FMT; }
index 4c2fb665db0e63bc37d9f5693d04df85f664ca94..661d5a1e31f2e37668f978d8b26120a1e8b78b44 100644 (file)
--- a/config.y
+++ b/config.y
@@ -37,7 +37,7 @@ static const char* lookup_token (int t);
 %token TYPE_ALLOW_REGISTRATION
 %token TYPE_PATH_GAME TYPE_NAME_GAME TYPE_PATH_DGLDIR TYPE_PATH_SPOOL
 %token TYPE_PATH_BANNER TYPE_PATH_CANNED TYPE_PATH_CHROOT
-%token TYPE_PATH_PASSWD TYPE_PATH_LOCKFILE TYPE_PATH_SAVEFILEFMT
+%token TYPE_PATH_PASSWD TYPE_PATH_LOCKFILE
 %token TYPE_MALSTRING TYPE_PATH_INPROGRESS TYPE_GAME_ARGS TYPE_RC_FMT
 %token TYPE_CMDQUEUE
 %token <s> TYPE_VALUE
@@ -280,11 +280,6 @@ game_definition : TYPE_CMDQUEUE
                myconfig[ncnf]->mkdir = strdup ($3);
                break;
 
-           case TYPE_PATH_SAVEFILEFMT:
-               if (myconfig[ncnf]->savefilefmt) free(myconfig[ncnf]->savefilefmt);
-               myconfig[ncnf]->savefilefmt = strdup($3);
-               break;
-
            case TYPE_RC_FMT:
                if (myconfig[ncnf]->rc_fmt) free(myconfig[ncnf]->rc_fmt);
                myconfig[ncnf]->rc_fmt = strdup($3);
@@ -404,7 +399,6 @@ KeyType : TYPE_SUSER        { $$ = TYPE_SUSER; }
        | TYPE_PATH_CANNED      { $$ = TYPE_PATH_CANNED; }
        | TYPE_PATH_PASSWD      { $$ = TYPE_PATH_PASSWD; }
        | TYPE_PATH_LOCKFILE    { $$ = TYPE_PATH_LOCKFILE; }
-       | TYPE_PATH_SAVEFILEFMT { $$ = TYPE_PATH_SAVEFILEFMT; }
        | TYPE_PATH_INPROGRESS  { $$ = TYPE_PATH_INPROGRESS; }
        | TYPE_GAME_ARGS        { $$ = TYPE_GAME_ARGS; }
        | TYPE_RC_FMT           { $$ = TYPE_RC_FMT; }
@@ -433,7 +427,6 @@ const char* lookup_token (int t)
     case TYPE_PATH_SPOOL: return "spooldir";
     case TYPE_PATH_BANNER: return "banner";
     case TYPE_PATH_CANNED: return "rc_template";
-    case TYPE_PATH_SAVEFILEFMT: return "savefilefmt";
     case TYPE_PATH_INPROGRESS: return "inprogressdir";
     case TYPE_GAME_ARGS: return "game_args";
     case TYPE_RC_FMT: return "rc_fmt";
index d1684af61d0c3c8efa13ec5a3c15e25fba84cd44..2884c5a34578b47de0e991a627f449d6d60d7b7b 100644 (file)
@@ -1581,67 +1581,6 @@ writefile (int requirenew)
 /* ************************************************************* */
 
 
-/*
- * Backup the savefile, if configured.
- * Returns non-zero if successful, otherwise an error message has been
- * given already.
- */
-int
-backup_savefile (int game)
-{
-    /*char buf[1024];*/
-    char *f, *p, *end, *buf;
-  int ispercent = 0, n;
-  int in, out;
-
-  f = myconfig[game]->savefilefmt;
-
-  if (*f == '\0')
-    return 1;
-  if (me == NULL)
-    graceful_exit (147);
-
-  buf = dgl_format_str(game, me, f);
-  p = buf;
-  p += strlen(buf);
-
-  /*fprintf(stderr, "***\n[SAVEFILE=%s]\n***\n", buf);
-  sleep(3);*/
-  in = open (buf, O_RDONLY);
-  if (in == -1)
-    {
-      if (errno == ENOENT)
-        return 1; /* Nothing to back up */
-      else
-        {
-          fprintf (stderr, "Cannot open savefile '%s'\n", buf);
-         perror ("for input");
-          return 0;
-        }
-    }
-  strcpy (p, ".bak");
-  out = open (buf, O_WRONLY | O_CREAT | O_TRUNC, 0666);
-  if (out == -1)
-    {
-      close (in);
-      fprintf (stderr, "Cannot open backup savefile '%s'\n", buf);
-      perror ("for output");
-      return 0;
-    }
-
-  while ((n = read (in, buf, sizeof(buf))) > 0)
-    {
-      n = write (out, buf, n);
-      if (n < 0)
-        break;
-    }
-  close (out);
-  close (in);
-  if (n < 0)
-    perror ("I/O error while backing up savefile");
-  return n >= 0;
-}
-
 int
 purge_stale_locks (int game)
 {
@@ -2130,8 +2069,10 @@ main (int argc, char** argv)
   /* then run the game-specific commands */
   dgl_exec_cmdqueue(myconfig[userchoice]->cmdqueue, userchoice, me);
 
+  /*
   if (!backup_savefile (userchoice))
     graceful_exit (5);
+  */
 
   /* environment */
   if (myconfig[userchoice]->rcfile) {
index 00b646c55167c7ff4021f3062393079ad8ef2535..24abfee0214cc9fa48d02f4b0738e7f39dca25b3 100644 (file)
@@ -71,7 +71,7 @@ struct dg_config
   char* mkdir;
   char* rcfile;
   char* spool;
-  char* savefilefmt;
+    /*char* savefilefmt;*/
   char* inprogressdir;
     int num_args; /* # of bin_args */
     char **bin_args; /* args for game binary */
index 3591f7e78bd2baf06c8d346e7c0171495471317e..f13b60987bdf49b4644c6d120ecbea5f4eac1684 100644 (file)
@@ -35,7 +35,7 @@ struct dg_config defconfig = {
   /* shed_uid = *//* 5,*/
   /* shed_gid = */ /*60,*/ /* games:games in Debian */
   /* max = */ /*64000,*/
-  /* savefilefmt = */ "", /* don't do this by default */
+  /* savefilefmt = */ /*"",*/ /* don't do this by default */
   /* inprogressdir = */ "inprogress/",
   /* num_args = */ 0,
   /* bin_args = */ NULL,
@@ -431,7 +431,7 @@ create_config ()
       if (!myconfig[tmp]->shortname) myconfig[tmp]->shortname = defconfig.shortname;
       if (!myconfig[tmp]->rcfile) myconfig[tmp]->rcfile = defconfig.rcfile;
       if (!myconfig[tmp]->spool) myconfig[tmp]->spool = defconfig.spool;
-      if (!myconfig[tmp]->savefilefmt) myconfig[tmp]->savefilefmt = defconfig.savefilefmt;
+      /*if (!myconfig[tmp]->savefilefmt) myconfig[tmp]->savefilefmt = defconfig.savefilefmt;*/
       if (!myconfig[tmp]->inprogressdir) myconfig[tmp]->inprogressdir = defconfig.inprogressdir;
 
   }
index 6d179b2d29ac697b300ffaa2a00c8207ce1e2907..94289cf77ad6b97f3c986a1dbc36024a16c88c61 100644 (file)
@@ -108,14 +108,6 @@ spooldir = "/var/mail/"
 # From inside the jail, the default .nethackrc that is copied for new users.
 # rc_template = "/dgl-default-rcfile"
 
-
-# From inside the jail, the path to the savefile. %u is replaced by the
-# decimal representation of shed_uid, %n is replaced by the player's
-# user name. Before starting the game, this file is copied to its name
-# with ".bak" appended. Set to an empty string to disable this copying.
-
-savefilefmt = "/var/games/nethack/save/%u%n.gz"
-
 # make sure the inprogress dir actually exists. default is "inprogress/"
 # each game you define here must have it's own.
 inprogressdir = "inprogress-nethackstub/"
@@ -148,9 +140,11 @@ rc_template = "/dgl-default-rcfile"
 # %r == dglroot
 # %n == user name
 rc_fmt = "%rrcfiles/%n.nethackrc"
-savefilefmt = "/var/games/nethack/save/%u%n.gz"
 inprogressdir = "inprogress-nethack/"
 
+# back up savefile
+commands = cp "/var/games/nethack/save/%u%n.gz" "/var/games/nethack/save/%u%n.gz.bak"
+
 }
 
 #