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
|
|
@ -38,12 +38,6 @@ char **envp;
|
|||
|
||||
open_score();
|
||||
|
||||
/*
|
||||
* Drop setuid/setgid after opening the scoreboard file.
|
||||
*/
|
||||
|
||||
md_normaluser();
|
||||
|
||||
/*
|
||||
* check for print-score option
|
||||
*/
|
||||
|
|
@ -64,20 +58,40 @@ char **envp;
|
|||
argc--;
|
||||
}
|
||||
|
||||
/*
|
||||
* get home and options from environment
|
||||
*/
|
||||
strcpy(home, md_gethomedir());
|
||||
|
||||
if (strlen(home) > PATH_MAX - strlen("rogue.save") - 1)
|
||||
*home = 0;
|
||||
|
||||
strcpy(file_name, home);
|
||||
strcat(file_name, "rogue.save");
|
||||
/* Are we using the system savefile directory? */
|
||||
#ifdef SAVEDIR
|
||||
if (argc >= 3 && !strcmp(argv[1], "-n"))
|
||||
{
|
||||
strncpy(whoami, argv[2], 79);
|
||||
whoami[79] = '\0';
|
||||
use_savedir = TRUE;
|
||||
/* look for savefile at SAVEDIR/UIDplayername.r3sav */
|
||||
if (snprintf(file_name, 80, "%s%d%.10s.r3sav", SAVEDIR, md_getuid(), whoami) >= 80)
|
||||
{
|
||||
/* 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)
|
||||
parse_opts(env);
|
||||
if (env == NULL || whoami[0] == '\0')
|
||||
if (!use_savedir && (env == NULL || whoami[0] == '\0'))
|
||||
strucpy(whoami, md_getusername(), strlen(md_getusername()));
|
||||
if (env == NULL || fruit[0] == '\0')
|
||||
strcpy(fruit, "slime-mold");
|
||||
|
|
@ -89,11 +103,29 @@ char **envp;
|
|||
vowelstr(fruit), fruit);
|
||||
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 */
|
||||
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);
|
||||
lowtime = (int) now;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue