srogue: add support for SAVEDIR
This commit is contained in:
parent
ce4b930551
commit
20d469d64f
5 changed files with 91 additions and 22 deletions
|
|
@ -86,6 +86,7 @@ bool waswizard = FALSE; /* Was a wizard sometime */
|
||||||
bool amulet = FALSE; /* He found the amulet */
|
bool amulet = FALSE; /* He found the amulet */
|
||||||
bool in_shell = FALSE; /* True if executing a shell */
|
bool in_shell = FALSE; /* True if executing a shell */
|
||||||
bool nochange = FALSE; /* true if last stat same as now */
|
bool nochange = FALSE; /* true if last stat same as now */
|
||||||
|
bool use_savedir = FALSE; /* true if using system savefiles */
|
||||||
|
|
||||||
bool s_know[MAXSCROLLS]; /* Does he know about a scroll */
|
bool s_know[MAXSCROLLS]; /* Does he know about a scroll */
|
||||||
bool p_know[MAXPOTIONS]; /* Does he know about a potion */
|
bool p_know[MAXPOTIONS]; /* Does he know about a potion */
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,9 @@
|
||||||
|
|
||||||
#include "rogue.ext"
|
#include "rogue.ext"
|
||||||
|
|
||||||
|
#define SCOREFILE "/usr/local/games/roguelike/srogue.scr"
|
||||||
|
#define SAVEDIR "/usr/local/games/roguelike/sroguesave/"
|
||||||
|
|
||||||
struct termios terminal;
|
struct termios terminal;
|
||||||
|
|
||||||
main(argc, argv, envp)
|
main(argc, argv, envp)
|
||||||
|
|
@ -71,12 +74,17 @@ char **envp;
|
||||||
playgid = getgid();
|
playgid = getgid();
|
||||||
|
|
||||||
/* check for print-score option */
|
/* check for print-score option */
|
||||||
|
#ifdef SCOREFILE
|
||||||
|
strncpy(scorefile, SCOREFILE, LINLEN);
|
||||||
|
scorefile[LINLEN - 1] = '\0';
|
||||||
|
#else
|
||||||
|
|
||||||
strcpy(scorefile, homedir);
|
strcpy(scorefile, homedir);
|
||||||
|
|
||||||
if (*scorefile)
|
if (*scorefile)
|
||||||
strcat(scorefile,"/");
|
strcat(scorefile,"/");
|
||||||
strcat(scorefile, "srogue.scr");
|
strcat(scorefile, "srogue.scr");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(argc >= 2 && strcmp(argv[1], "-s") == 0)
|
if(argc >= 2 && strcmp(argv[1], "-s") == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -105,6 +113,20 @@ char **envp;
|
||||||
time(&now);
|
time(&now);
|
||||||
lowtime = (int) now;
|
lowtime = (int) now;
|
||||||
|
|
||||||
|
#ifdef SAVEDIR
|
||||||
|
if (argc >= 3 && !strcmp(argv[1], "-n")) {
|
||||||
|
strncpy(whoami, argv[2], LINLEN);
|
||||||
|
whoami[LINLEN - 1] = '\0';
|
||||||
|
use_savedir = TRUE;
|
||||||
|
if (snprintf(file_name, LINLEN, "%s%d-%.10s.srsav", SAVEDIR,
|
||||||
|
playuid, whoami) >= LINLEN) {
|
||||||
|
/* Just in case it doesn't fit */
|
||||||
|
strcpy(file_name, "srogue.save");
|
||||||
|
use_savedir = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* get home and options from environment */
|
/* get home and options from environment */
|
||||||
|
|
||||||
if ((env = getenv("HOME")) != NULL)
|
if ((env = getenv("HOME")) != NULL)
|
||||||
|
|
@ -120,13 +142,15 @@ char **envp;
|
||||||
if ((strlen(home) > 0) && (home[strlen(home)-1] != '/'))
|
if ((strlen(home) > 0) && (home[strlen(home)-1] != '/'))
|
||||||
strcat(home, "/");
|
strcat(home, "/");
|
||||||
|
|
||||||
|
if (!use_savedir) {
|
||||||
strcpy(file_name, home);
|
strcpy(file_name, home);
|
||||||
strcat(file_name, "srogue.sav");
|
strcat(file_name, "srogue.sav");
|
||||||
|
}
|
||||||
|
|
||||||
if ((env = getenv("ROGUEOPTS")) != NULL)
|
if ((env = getenv("ROGUEOPTS")) != NULL)
|
||||||
parse_opts(env);
|
parse_opts(env);
|
||||||
|
|
||||||
if (env == NULL || whoami[0] == '\0')
|
if (!use_savedir && (env == NULL || whoami[0] == '\0'))
|
||||||
{
|
{
|
||||||
if((pw = getpwuid(playuid)) == NULL)
|
if((pw = getpwuid(playuid)) == NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -140,10 +164,20 @@ char **envp;
|
||||||
if (env == NULL || fruit[0] == '\0')
|
if (env == NULL || fruit[0] == '\0')
|
||||||
strcpy(fruit, "juicy-fruit");
|
strcpy(fruit, "juicy-fruit");
|
||||||
|
|
||||||
if (argc == 2)
|
if (use_savedir)
|
||||||
|
{
|
||||||
|
/* restore() won't return if the restore succeeded. If
|
||||||
|
* file_name doesn't exist, it will return TRUE. In that
|
||||||
|
* case, start a new game. */
|
||||||
|
if (!restore(file_name, envp))
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
else if (argc == 2)
|
||||||
if(!restore(argv[1], envp)) /* NOTE: NEVER RETURNS */
|
if(!restore(argv[1], envp)) /* NOTE: NEVER RETURNS */
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
|
/* START NEW GAME */
|
||||||
|
|
||||||
dnum = (wizard && getenv("SEED") != NULL ?
|
dnum = (wizard && getenv("SEED") != NULL ?
|
||||||
atoi(getenv("SEED")) : lowtime + getpid());
|
atoi(getenv("SEED")) : lowtime + getpid());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,9 @@ char *str;
|
||||||
continue;
|
continue;
|
||||||
len = sp - str;
|
len = sp - str;
|
||||||
for (op = optlist; op < &optlist[NUM_OPTS]; op++) {
|
for (op = optlist; op < &optlist[NUM_OPTS]; op++) {
|
||||||
|
/* For security, some options can't be changed. */
|
||||||
|
if (!allowchange(op))
|
||||||
|
continue;
|
||||||
if (EQSTR(str, op->o_name, len)) {
|
if (EQSTR(str, op->o_name, len)) {
|
||||||
reg char *start;
|
reg char *start;
|
||||||
|
|
||||||
|
|
@ -228,3 +231,14 @@ int len;
|
||||||
}
|
}
|
||||||
*s1 = '\0';
|
*s1 = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int allowchange(OPTION *opt)
|
||||||
|
{
|
||||||
|
if (!use_savedir)
|
||||||
|
return 1;
|
||||||
|
if (!strcmp(opt->o_name, "name"))
|
||||||
|
return 0;
|
||||||
|
if (!strcmp(opt->o_name, "file"))
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ extern void quit(), auto_save(), endit(), byebye(), game_err();
|
||||||
EXTINT prntfile(), unconfuse(), sapem();
|
EXTINT prntfile(), unconfuse(), sapem();
|
||||||
EXTINT noteth(), notregen(), notinvinc(), unsee(), nohaste(), npch();
|
EXTINT noteth(), notregen(), notinvinc(), unsee(), nohaste(), npch();
|
||||||
EXTBOOL running, nochange, after, inwhgt, isfight, firstmove, nlmove;
|
EXTBOOL running, nochange, after, inwhgt, isfight, firstmove, nlmove;
|
||||||
EXTBOOL wizard, waswizard, in_shell, amulet, door_stop, playing;
|
EXTBOOL wizard, waswizard, in_shell, amulet, door_stop, playing, use_savedir;
|
||||||
EXTBOOL notify, ws_know[], p_know[], s_know[], r_know[], inpool;
|
EXTBOOL notify, ws_know[], p_know[], s_know[], r_know[], inpool;
|
||||||
EXTCHAR home[], file_name[], whoami[], fruit[], curpurch[], scorefile[];
|
EXTCHAR home[], file_name[], whoami[], fruit[], curpurch[], scorefile[];
|
||||||
EXTCHAR *r_stones[], *p_colors[], *s_names[], *ws_type[], *ws_made[];
|
EXTCHAR *r_stones[], *p_colors[], *s_names[], *ws_type[], *ws_made[];
|
||||||
|
|
|
||||||
|
|
@ -136,8 +136,11 @@ dosave()
|
||||||
FILE *savef;
|
FILE *savef;
|
||||||
|
|
||||||
ignore();
|
ignore();
|
||||||
|
if (!use_savedir)
|
||||||
|
{
|
||||||
setuid(playuid);
|
setuid(playuid);
|
||||||
setgid(playgid);
|
setgid(playgid);
|
||||||
|
}
|
||||||
umask(022);
|
umask(022);
|
||||||
|
|
||||||
if (file_name[0] != '\0') {
|
if (file_name[0] != '\0') {
|
||||||
|
|
@ -209,9 +212,13 @@ char *file, **envp;
|
||||||
int slines, scols;
|
int slines, scols;
|
||||||
|
|
||||||
if ((inf = open(file, O_RDONLY)) < 0) {
|
if ((inf = open(file, O_RDONLY)) < 0) {
|
||||||
|
if (use_savedir && errno == ENOENT)
|
||||||
|
return TRUE;
|
||||||
|
else {
|
||||||
printf("Cannot read save game %s\n",file);
|
printf("Cannot read save game %s\n",file);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
encread(buf, strlen(version) + 1, inf);
|
encread(buf, strlen(version) + 1, inf);
|
||||||
|
|
||||||
|
|
@ -297,6 +304,8 @@ char *file, **envp;
|
||||||
{
|
{
|
||||||
#ifndef __DJGPP__
|
#ifndef __DJGPP__
|
||||||
endwin();
|
endwin();
|
||||||
|
if (!use_savedir)
|
||||||
|
{
|
||||||
while((pid = fork()) < 0)
|
while((pid = fork()) < 0)
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
|
|
@ -319,6 +328,17 @@ char *file, **envp;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Don't drop privileges, they're needed
|
||||||
|
* for the unlink. */
|
||||||
|
if (unlink(file) < 0)
|
||||||
|
{
|
||||||
|
printf("Cannot unlink file\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if (unlink(file) < 0)
|
if (unlink(file) < 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue