rogue5: add savedir, logfile, bugfixes

This commit is contained in:
John "Elwin" Edwards 2010-05-24 20:16:15 +00:00
parent 3741c4867d
commit 53a15a3e2e
13 changed files with 2124 additions and 1397 deletions

View file

@ -52,9 +52,15 @@ SED = @SED@
#SCOREFILE=rogue54.scr
SCOREFILE = @SCOREFILE@
#LOGFILE=rogue54.log
LOGFILE = @LOGFILE@
#LOCKFILE=rogue54.lck
LOCKFILE = @LOCKFILE@
#SAVEDIR=rogue5save
SAVEDIR = @SAVEDIR@
#GROUPOWNER=games
GROUPOWNER = @GROUPOWNER@
@ -193,12 +199,20 @@ dist: clean $(PROGRAM)
install: $(PROGRAM)
-$(TOUCH) test
-if test ! -f $(DESTDIR)$(SCOREFILE) ; then $(INSTALL) -m 0664 test $(DESTDIR)$(SCOREFILE) ; fi
-if test "x$(LOGFILE)" != "x" -a ! -f $(DESTDIR)$(LOGFILE) ; then \
$(INSTALL) -m 0664 test $(DESTDIR)$(LOGFILE) ; fi
-if test "x$(SAVEDIR)" != "x" -a ! -f $(DESTDIR)$(SAVEDIR) ; then \
$(MKDIR) -p $(DESTDIR)$(SAVEDIR) ; fi
-$(INSTALL) -m 0755 $(PROGRAM) $(DESTDIR)$(bindir)/$(PROGRAM)
-if test "x$(GROUPOWNER)" != "x" ; then \
$(CHGRP) $(GROUPOWNER) $(DESTDIR)$(SCOREFILE) ; \
$(CHGRP) $(GROUPOWNER) $(DESTDIR)$(LOGFILE) ; \
$(CHGRP) $(GROUPOWNER) $(DESTDIR)$(bindir)/$(PROGRAM) ; \
$(CHGRP) $(GROUPOWNER) $(DESTDIR)$(SAVEDIR) ; \
$(CHMOD) 02755 $(DESTDIR)$(bindir)/$(PROGRAM) ; \
$(CHMOD) 0464 $(DESTDIR)$(SCOREFILE) ; \
$(CHMOD) 0464 $(DESTDIR)$(LOGFILE) ; \
$(CHMOD) 0775 $(DESTDIR)$(SAVEDIR) ; \
fi
-if test -d $(man6dir) ; then $(INSTALL) -m 0644 rogue.6 $(DESTDIR)$(man6dir)/$(PROGRAM).6 ; fi
-if test ! -d $(man6dir) ; then $(INSTALL) -m 0644 rogue.6 $(DESTDIR)$(mandir)/$(PROGRAM).6 ; fi

View file

@ -189,6 +189,9 @@
/* Define to file to use for scoreboard lockfile */
#undef LOCKFILE
/* Define to file to use for log */
#undef LOGFILE
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
slash. */
#undef LSTAT_FOLLOWS_SLASHED_SYMLINK
@ -233,6 +236,9 @@
/* Define as the return type of signal handlers (`int' or `void'). */
#undef RETSIGTYPE
/* Define to systemwide directory for storing saved games */
#undef SAVEDIR
/* Define to file to use for scoreboard */
#undef SCOREFILE

3253
rogue5/configure vendored

File diff suppressed because it is too large Load diff

View file

@ -86,6 +86,27 @@ fi
AC_SUBST(SCOREFILE)
AC_ARG_ENABLE([logfile],[AC_HELP_STRING([--enable-logfile=LOGFILE], [enable logfile with given filename])],[],[])
AC_MSG_CHECKING([for log file])
if test "x$enable_logfile" = "xno" ; then
LOGFILE=
elif test "x$enable_logfile" = "xyes" ; then
LOGFILE=$progname.log
elif test "x$enable_logfile" = "x" ; then
LOGFILE=$progname.log
else
LOGFILE=$enable_logfile
fi
if test "x$LOGFILE" != "x" ; then
AC_DEFINE_UNQUOTED([LOGFILE], ["$LOGFILE"], [Define to file to use for log])
AC_MSG_RESULT([$LOGFILE])
else
AC_MSG_RESULT([disabled])
fi
AC_SUBST(LOGFILE)
AC_ARG_ENABLE([lockfile],[AC_HELP_STRING([--enable-lockfile=LOCKFILE], [enable scoreboard lockfile with given filename])],[],[])
AC_MSG_CHECKING([for scoreboard lockfile file])
if test "x$enable_lockfile" = "xno" ; then
@ -107,6 +128,27 @@ fi
AC_SUBST(LOCKFILE)
AC_ARG_ENABLE([savedir],[AC_HELP_STRING([--enable-savedir=SAVEDIR], [enable systemwide location for saved games])],[],[])
AC_MSG_CHECKING([for save directory])
if test "x$enable_savedir" = "xno" ; then
SAVEDIR=
elif test "x$enable_savedir" = "xyes" ; then
SAVEDIR=$progname/
elif test "x$enable_savedir" = "x" ; then
SAVEDIR=$progname/
else
SAVEDIR=$enable_savedir
fi
if test "x$SAVEDIR" != "x" ; then
AC_DEFINE_UNQUOTED([SAVEDIR], ["$SAVEDIR"], [Define to systemwide directory for storing saved games])
AC_MSG_RESULT([$SAVEDIR])
else
AC_MSG_RESULT([disabled])
fi
AC_SUBST(SAVEDIR)
AC_ARG_ENABLE([wizardmode],[AC_HELP_STRING([--enable-wizardmode], [enable availability of wizard mode @<:@default=no@:>@])],[],[])
AC_MSG_CHECKING([if wizard mode is enabled])
if test "x$enable_wizardmode" = "xno" ; then

View file

@ -42,6 +42,7 @@ int stat_msg = FALSE; /* Should status() print as a msg() */
int terse = FALSE; /* True if we should be short */
int to_death = FALSE; /* Fighting is to the death! */
int tombstone = TRUE; /* Print out tombstone at end */
int use_savedir = FALSE; /* True if using system savefile dir */
#ifdef MASTER
int wizard = FALSE; /* True if allows wizard commands */
#endif
@ -111,6 +112,7 @@ const int a_class[MAXARMORS] = { /* Armor class for each armor type */
int count = 0; /* Number of times to repeat command */
FILE *scoreboard = NULL; /* File descriptor for score file */
FILE *logfi = NULL; /* The log file */
int food_left; /* Amount of food in hero's stomach */
int lastscore = -1; /* Score before this turn */
int no_command = 0; /* Number of turns asleep */

View file

@ -127,9 +127,11 @@ extern int wizard;
extern char fruit[], prbuf[], whoami[];
extern int orig_dsusp;
extern FILE *scoreboard;
extern FILE *logfi;
extern int numscores;
extern char *Numname;
extern int allscore;
extern int use_savedir;
/*
* Function types

View file

@ -129,6 +129,21 @@ open_score(void)
#endif
}
void
open_log(void)
{
#ifdef LOGFILE
logfi = fopen(LOGFILE, "a");
if (logfi == NULL)
{
fprintf(stderr, "Could not open %s for appending: %s\n", LOGFILE,
strerror(errno));
fflush(stderr);
}
#endif
return;
}
/*
* getltchars:
* Get the local tty chars for later use
@ -163,6 +178,7 @@ setup(void)
raw(); /* Raw mode */
noecho(); /* Echo off */
nonl();
keypad(stdscr,1);
getltchars(); /* get the local tty chars */
}

View file

@ -42,21 +42,40 @@ main(int argc, char **argv)
#endif
/* Check to see if savefiles should be stored in the system location */
#ifdef SAVEDIR
if (argc >= 3 && !strcmp(argv[1], "-n"))
{
use_savedir = TRUE;
strncpy(whoami, argv[2], MAXSTR);
whoami[MAXSTR-1] = '\0';
snprintf(file_name, MAXSTR, "%s/%d-%.10s.r5sav", SAVEDIR,
md_getuid(), whoami);
}
#endif
open_score();
open_log();
/*
* get home and options from environment
*/
strcpy(home, md_gethomedir());
if (strlen(home) > MAXSTR - strlen("rogue.save") - 1)
if (strlen(home) > MAXSTR - strlen("rogue5.save") - 1)
*home = 0;
strcpy(file_name, home);
strcat(file_name, "rogue.save");
if (!use_savedir)
{
md_normaluser();
strcpy(file_name, home);
strcat(file_name, "rogue5.save");
}
if ((env = getenv("ROGUEOPTS")) != NULL)
parse_opts(env);
if (env == NULL || whoami[0] == '\0')
if (!use_savedir && (env == NULL || whoami[0] == '\0'))
strucpy(whoami, md_getusername(), strlen(md_getusername()));
lowtime = time(NULL);
if (getenv("SEED") != NULL)
@ -68,20 +87,10 @@ main(int argc, char **argv)
dnum = (unsigned int) lowtime + md_getpid();
seed = dnum;
open_score();
/*
* Drop setuid/setgid after opening the scoreboard file.
*/
md_normaluser();
/*
* check for print-score option
*/
md_normaluser(); /* we drop any setgid/setuid priveldges here */
if (argc == 2)
{
if (strcmp(argv[1], "-s") == 0)
@ -105,15 +114,23 @@ main(int argc, char **argv)
}
init_check(); /* check for legal startup */
if (argc == 2)
if (use_savedir)
{
/* If there is a saved game, restore() will not return. If it
* returns 1, there isn't a game, so start one. If 0, there was
* an error. */
if (!restore(file_name))
my_exit(1);
}
else if (argc == 2)
if (!restore(argv[1])) /* Note: restore will never return */
my_exit(1);
#ifdef MASTER
if (wizard)
printf("Hello %s, welcome to dungeon #%d", whoami, dnum);
printf("Hello %s, welcome to dungeon #%d\n", whoami, dnum);
else
#endif
printf("Hello %s, just a moment while I dig the dungeon...", whoami);
printf("Hello %s, just a moment while I dig the dungeon...\n", whoami);
fflush(stdout);
initscr(); /* Start up cursor package */
@ -235,6 +252,7 @@ tstp(int ignored)
md_tstpresume();
raw();
noecho();
nonl();
keypad(stdscr,1);
playltchars();
clearok(curscr, TRUE);
@ -311,6 +329,7 @@ quit(int sig)
mvprintw(LINES - 2, 0, "You quit with %d gold pieces", purse);
move(LINES - 1, 0);
refresh();
writelog(purse, 1, 0);
score(purse, 1, 0);
my_exit(0);
}
@ -377,6 +396,7 @@ shell(void)
noecho();
raw();
nonl();
keypad(stdscr,1);
playltchars();
in_shell = FALSE;

View file

@ -448,7 +448,10 @@ md_getusername(void)
pw = getpwuid(getuid());
l = pw->pw_name;
if (pw != NULL)
l = pw->pw_name;
else
l = NULL;
#endif
if ((l == NULL) || (*l == '\0'))
@ -479,7 +482,10 @@ md_gethomedir(void)
struct passwd *pw;
pw = getpwuid(getuid());
h = pw->pw_dir;
if (pw != NULL)
h = pw->pw_dir;
else
h = NULL;
if (strcmp(h,"/") == 0)
h = NULL;
@ -543,7 +549,8 @@ md_getshell(void)
char *def = "/bin/sh";
struct passwd *pw;
pw = getpwuid(getuid());
s = pw->pw_shell;
if (pw != NULL)
s = pw->pw_shell;
#endif
if ((s == NULL) || (*s == '\0'))
if ( (s = getenv("COMSPEC")) == NULL)

View file

@ -38,6 +38,7 @@ struct optstruct {
typedef struct optstruct OPTION;
void pr_optname(const OPTION *op);
int allowchange(const OPTION *op);
static const OPTION optlist[] = {
{"terse", "Terse output",
@ -79,9 +80,12 @@ option(void)
*/
for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
{
pr_optname(op);
(*op->o_putfunc)(op->o_opt);
waddch(hw, '\n');
if (allowchange(op))
{
pr_optname(op);
(*op->o_putfunc)(op->o_opt);
waddch(hw, '\n');
}
}
/*
* Set values
@ -89,12 +93,16 @@ option(void)
wmove(hw, 0, 0);
for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
{
if (!allowchange(op))
continue;
pr_optname(op);
retval = (*op->o_getfunc)(op->o_opt, hw);
if (retval)
{
if (retval == QUIT)
break;
#if 0
/* Support for MINUS removed until this section is rewritten. */
else if (op > optlist) { /* MINUS */
wmove(hw, (int)(op - optlist) - 1, 0);
op -= 2;
@ -105,6 +113,9 @@ option(void)
wmove(hw, 0, 0);
op--;
}
#else
break;
#endif
}
}
/*
@ -418,6 +429,9 @@ parse_opts(char *str)
* Look it up and deal with it
*/
for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++)
{
if (!allowchange(op))
continue;
if (EQSTR(str, op->o_name, len))
{
if (op->o_putfunc == put_bool) /* if option is a boolean */
@ -471,6 +485,7 @@ parse_opts(char *str)
*(int *)op->o_opt = FALSE; /* NOSTRICT */
break;
}
}
/*
* skip to start of next option name
@ -499,3 +514,16 @@ strucpy(char *s1, const char *s2, size_t len)
}
*s1 = '\0';
}
/* Tells whether the user is allowed to change the option. */
int
allowchange(const OPTION *opt)
{
if (!use_savedir)
return TRUE;
if (!strcmp(opt->o_name, "name"))
return FALSE;
if (!strcmp(opt->o_name, "file"))
return FALSE;
return TRUE;
}

View file

@ -223,6 +223,62 @@ score(int amount, int flags, int monst)
}
}
void writelog(int amount, int flags, int monst)
{
#ifdef LOGFILE
char logmessage[160], ltemp[80];
if (logfi == NULL)
return;
#ifdef MASTER
if (wizard)
{
fclose(logfi);
return;
}
#endif
sprintf(logmessage, "%d %d %.20s %d ", time(NULL), amount, whoami,
pstats.s_lvl);
if (flags == 0) /* dead */
{
sprintf(ltemp, "killed by %s on level %d\n", killname(monst, TRUE),
level);
strcat(logmessage, ltemp);
}
else if (flags == 1) /* quit */
{
if (amulet)
sprintf(ltemp, "quit on level %d [max %d] with the Amulet\n",
level, max_level);
else
sprintf(ltemp, "quit on level %d\n", level);
strcat(logmessage, ltemp);
}
else if (flags == 2) /* won */
{
sprintf(ltemp, "escaped with the Amulet [deepest level: %d]\n",
max_level);
strcat(logmessage, ltemp);
}
else if (flags == 3) /* killed with Amulet */
{
strcat(logmessage, "killed by ");
strcat(logmessage, killname(monst, TRUE));
sprintf(ltemp, " on level %d [max %d] with the Amulet\n",
level, max_level);
strcat(logmessage, ltemp);
}
else
{
fclose(logfi);
return;
}
fprintf(logfi, "%s", logmessage);
fclose(logfi);
#endif
return;
}
/*
* death:
* Do something really fun when he dies
@ -271,7 +327,12 @@ death(int monst)
}
move(LINES - 1, 0);
refresh();
writelog(purse, amulet ? 3 : 0, monst);
score(purse, amulet ? 3 : 0, monst);
/* Make sure the output gets through. */
printf("[Press return to exit]\n");
fflush(NULL);
getchar();
my_exit(0);
}
@ -382,6 +443,7 @@ total_winner(void)
}
printw(" %5d Gold Pieces ", oldpurse);
refresh();
writelog(purse, 2, ' ');
score(purse, 2, ' ');
my_exit(0);
}

View file

@ -672,6 +672,7 @@ const char *nullstr(const THING *ignored);
const char *num(int n1, int n2, int type);
void numpass(int y, int x);
void option(void);
void open_log(void);
void open_score(void);
int pack_char(void);
int pack_room(int from_floor, THING *obj);
@ -775,4 +776,5 @@ void wear(void);
void whatis(int insist, int type);
void wield(void);
int wreadchar(WINDOW *win);
void writelog(int amount, int flags, int monst);

View file

@ -41,7 +41,10 @@ over:
{
for (;;)
{
msg("save file (%s)? ", file_name);
if (use_savedir)
msg("Save game? ");
else
msg("Save file (%s)? ", file_name);
c = readchar();
mpos = 0;
if (c == ESCAPE)
@ -63,6 +66,8 @@ over:
}
}
if (use_savedir) /* User chose N, changing location isn't allowed. */
goto quit_it;
do
{
mpos = 0;
@ -79,7 +84,7 @@ gotfile:
/*
* test to see if the file exists
*/
if (stat(buf, &sbuf) >= 0)
if (stat(buf, &sbuf) >= 0 && !use_savedir)
{
for (;;)
{
@ -99,7 +104,11 @@ gotfile:
}
strcpy(file_name, buf);
if ((savef = fopen(file_name, "w")) == NULL)
{
msg(strerror(errno));
if (use_savedir)
return;
}
} while (savef == NULL);
msg("");
save_file(savef);
@ -138,13 +147,14 @@ save_file(FILE *savef)
putchar('\n');
endwin();
resetltchars();
md_chmod(file_name, 0400);
md_chmod(file_name, 0644);
encwrite(version, strlen(version)+1, savef);
sprintf(buf,"%d x %d\n", LINES, COLS);
encwrite(buf,80,savef);
rs_save_file(savef);
fflush(savef);
fclose(savef);
printf("See you soon, %s!\n", whoami);
exit(0);
}
@ -167,8 +177,11 @@ restore(const char *file)
md_tstphold();
if ((inf = fopen(file,"r")) == NULL)
if ((inf = fopen(file,"r")) == NULL)
{
/* If a system savefile doesn't exist, start a new game. */
if (use_savedir && errno == ENOENT)
return TRUE;
perror(file);
return FALSE;
}