Add -n option and system savedir functionality
This commit is contained in:
parent
4662bbf65b
commit
265ac56d38
5 changed files with 65 additions and 22 deletions
|
|
@ -39,7 +39,7 @@ MISC = Makefile $(MISC_C) LICENSE.TXT $(PROGRAM).sln $(PROGRAM).vcproj $(DOCS)\
|
||||||
CC = gcc
|
CC = gcc
|
||||||
ROPTS =
|
ROPTS =
|
||||||
COPTS = -O3
|
COPTS = -O3
|
||||||
CFLAGS= $(COPTS) $(ROPTS) -DSCOREFILE=\"rogue36.scr\"
|
CFLAGS= $(COPTS) $(ROPTS) -DSCOREFILE=\"/usr/local/games/roguelike/rogue3.scr\" -DSAVEDIR=\"/usr/local/games/roguelike/rogue3save/\"
|
||||||
LIBS = -lcurses
|
LIBS = -lcurses
|
||||||
RM = rm -f
|
RM = rm -f
|
||||||
LD = $(CC)
|
LD = $(CC)
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
int playing = TRUE, running = FALSE, wizard = FALSE;
|
int playing = TRUE, running = FALSE, wizard = FALSE;
|
||||||
int notify = TRUE, fight_flush = FALSE, terse = FALSE, door_stop = FALSE;
|
int notify = TRUE, fight_flush = FALSE, terse = FALSE, door_stop = FALSE;
|
||||||
int jump = FALSE, slow_invent = FALSE, firstmove = FALSE, askme = FALSE;
|
int jump = FALSE, slow_invent = FALSE, firstmove = FALSE, askme = FALSE;
|
||||||
|
int use_savedir = FALSE;
|
||||||
int amulet = FALSE;
|
int amulet = FALSE;
|
||||||
int in_shell = FALSE;
|
int in_shell = FALSE;
|
||||||
struct linked_list *lvl_obj = NULL, *mlist = NULL;
|
struct linked_list *lvl_obj = NULL, *mlist = NULL;
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,6 @@ char **envp;
|
||||||
|
|
||||||
open_score();
|
open_score();
|
||||||
|
|
||||||
/*
|
|
||||||
* Drop setuid/setgid after opening the scoreboard file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
md_normaluser();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check for print-score option
|
* check for print-score option
|
||||||
*/
|
*/
|
||||||
|
|
@ -64,20 +58,40 @@ char **envp;
|
||||||
argc--;
|
argc--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Are we using the system savefile directory? */
|
||||||
* get home and options from environment
|
#ifdef SAVEDIR
|
||||||
*/
|
if (argc >= 3 && !strcmp(argv[1], "-n"))
|
||||||
strcpy(home, md_gethomedir());
|
{
|
||||||
|
strncpy(whoami, argv[2], 79);
|
||||||
if (strlen(home) > PATH_MAX - strlen("rogue.save") - 1)
|
whoami[79] = '\0';
|
||||||
*home = 0;
|
use_savedir = TRUE;
|
||||||
|
/* look for savefile at SAVEDIR/UIDplayername.r3sav */
|
||||||
strcpy(file_name, home);
|
if (snprintf(file_name, 80, "%s%d%.10s.r3sav", SAVEDIR, md_getuid(), whoami) >= 80)
|
||||||
strcat(file_name, "rogue.save");
|
{
|
||||||
|
/* this shouldn't happen */
|
||||||
|
strcpy(file_name, "rogue3.save");
|
||||||
|
use_savedir = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (use_savedir == FALSE)
|
||||||
|
{
|
||||||
|
md_normaluser();
|
||||||
|
/* because we don't need to create a file in the common savedir,
|
||||||
|
* and the scorefile is already open */
|
||||||
|
strcpy(home, md_gethomedir());
|
||||||
|
|
||||||
|
if (strlen(home) > PATH_MAX - strlen("rogue3.save") - 1)
|
||||||
|
*home = 0;
|
||||||
|
|
||||||
|
strcpy(file_name, home);
|
||||||
|
strcat(file_name, "rogue3.save");
|
||||||
|
}
|
||||||
|
|
||||||
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'))
|
||||||
strucpy(whoami, md_getusername(), strlen(md_getusername()));
|
strucpy(whoami, md_getusername(), strlen(md_getusername()));
|
||||||
if (env == NULL || fruit[0] == '\0')
|
if (env == NULL || fruit[0] == '\0')
|
||||||
strcpy(fruit, "slime-mold");
|
strcpy(fruit, "slime-mold");
|
||||||
|
|
@ -89,11 +103,29 @@ char **envp;
|
||||||
vowelstr(fruit), fruit);
|
vowelstr(fruit), fruit);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 2)
|
/* now start the game */
|
||||||
|
if (use_savedir)
|
||||||
|
{
|
||||||
|
/* Try to restore from file_name which we just set up. */
|
||||||
|
if (!restore(file_name, envp))
|
||||||
|
exit(1);
|
||||||
|
/* If restore() returns true, the system savefile doesn't exist.
|
||||||
|
So we'll start a new game. */
|
||||||
|
}
|
||||||
|
else if (argc == 2)
|
||||||
if (!restore(argv[1], envp)) /* Note: restore will never return */
|
if (!restore(argv[1], envp)) /* Note: restore will never return */
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
|
/* If we reach this point, either
|
||||||
|
* 1. A system savefile was specified and doesn't exist.
|
||||||
|
* 2. No savefile was specified.
|
||||||
|
* Either way, start a new game.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!use_savedir)
|
||||||
|
md_normaluser();
|
||||||
|
|
||||||
time(&now);
|
time(&now);
|
||||||
lowtime = (int) now;
|
lowtime = (int) now;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -492,6 +492,7 @@ extern int take; /* Thing the rogue is taking */
|
||||||
extern int terse; /* True if we should be int */
|
extern int terse; /* True if we should be int */
|
||||||
extern struct magic_item things[NUMTHINGS]; /* Chances for each type of item */
|
extern struct magic_item things[NUMTHINGS]; /* Chances for each type of item */
|
||||||
extern int total; /* Total dynamic memory bytes */
|
extern int total; /* Total dynamic memory bytes */
|
||||||
|
extern int use_savedir; /* True if using system savedir */
|
||||||
extern char * w_names[MAXWEAPONS]; /* Names of the various weapons */
|
extern char * w_names[MAXWEAPONS]; /* Names of the various weapons */
|
||||||
extern char wand_mons[27];
|
extern char wand_mons[27];
|
||||||
extern int waswizard; /* Was a wizard sometime */
|
extern int waswizard; /* Was a wizard sometime */
|
||||||
|
|
|
||||||
|
|
@ -143,8 +143,17 @@ restore(char *file, char **envp)
|
||||||
|
|
||||||
if ((inf = fopen(file, "r")) == NULL)
|
if ((inf = fopen(file, "r")) == NULL)
|
||||||
{
|
{
|
||||||
perror(file);
|
if (use_savedir && errno == ENOENT)
|
||||||
return FALSE;
|
{
|
||||||
|
/* We're using the system savefile and it doesn't exist.
|
||||||
|
* This isn't a fatal error, we'll just start a new game. */
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
perror(file);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue