Remove savefilefmt from config file; backing up the savefile
can now be done with per-game commands. git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@392 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
parent
24cb396d16
commit
0d509576d8
1
config.l
1
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; }
|
||||
|
|
9
config.y
9
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";
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue