rogue4: prevent changing name or save file when using system savedir
This commit is contained in:
parent
18a08fce7e
commit
f433b66dc8
2 changed files with 48 additions and 3 deletions
|
|
@ -34,6 +34,8 @@ struct optstruct {
|
|||
|
||||
typedef struct optstruct OPTION;
|
||||
|
||||
int allowchange(OPTION *opt);
|
||||
|
||||
int put_bool(), get_bool(), put_str(), get_str();
|
||||
|
||||
OPTION optlist[] = {
|
||||
|
|
@ -72,9 +74,12 @@ option()
|
|||
*/
|
||||
for (op = optlist; op < &optlist[NUM_OPTS]; op++)
|
||||
{
|
||||
waddstr(hw, op->o_prompt);
|
||||
(*op->o_putfunc)(op->o_opt);
|
||||
waddch(hw, '\n');
|
||||
if (allowchange(op))
|
||||
{
|
||||
waddstr(hw, op->o_prompt);
|
||||
(*op->o_putfunc)(op->o_opt);
|
||||
waddch(hw, '\n');
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Set values
|
||||
|
|
@ -82,10 +87,14 @@ option()
|
|||
wmove(hw, 0, 0);
|
||||
for (op = optlist; op < &optlist[NUM_OPTS]; op++)
|
||||
{
|
||||
if (!allowchange(op))
|
||||
continue;
|
||||
waddstr(hw, op->o_prompt);
|
||||
if ((retval = (*op->o_getfunc)(op->o_opt, hw)))
|
||||
{
|
||||
if (retval == QUIT)
|
||||
break;
|
||||
#if 0 /* disable MINUS */
|
||||
else if (op > optlist) { /* MINUS */
|
||||
wmove(hw, (op - optlist) - 1, 0);
|
||||
op -= 2;
|
||||
|
|
@ -96,6 +105,10 @@ option()
|
|||
wmove(hw, 0, 0);
|
||||
op--;
|
||||
}
|
||||
#else
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Switch back to original screen
|
||||
|
|
@ -301,6 +314,11 @@ register char *str;
|
|||
* Look it up and deal with it
|
||||
*/
|
||||
for (op = optlist; op < &optlist[NUM_OPTS]; op++)
|
||||
{
|
||||
/* If using system savefiles, changing your name or the
|
||||
save file is not allowed. */
|
||||
if (!allowchange(op))
|
||||
continue;
|
||||
if (EQSTR(str, op->o_name, len))
|
||||
{
|
||||
if (op->o_putfunc == put_bool) /* if option is a boolean */
|
||||
|
|
@ -340,6 +358,7 @@ register char *str;
|
|||
*(bool *)op->o_opt = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* skip to start of next option name
|
||||
|
|
@ -368,3 +387,16 @@ register int len;
|
|||
}
|
||||
*s1 = '\0';
|
||||
}
|
||||
|
||||
/* Tells whether the player is allowed to change the option. */
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ STAT sbuf;
|
|||
* save_game:
|
||||
* Implement the "save game" command
|
||||
*/
|
||||
/* This has to be cleaned up, these goto's are annoying. */
|
||||
save_game()
|
||||
{
|
||||
register FILE *savef;
|
||||
|
|
@ -67,6 +68,14 @@ over:
|
|||
}
|
||||
}
|
||||
|
||||
if (use_savedir)
|
||||
{
|
||||
/* You can't change the savefile if you're using the system
|
||||
savedir, because that means you have privileges. */
|
||||
msg("");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
mpos = 0;
|
||||
|
|
@ -102,7 +111,11 @@ gotfile:
|
|||
}
|
||||
strcpy(file_name, buf);
|
||||
if ((savef = fopen(file_name, "w")) == NULL)
|
||||
{
|
||||
msg(strerror(errno)); /* fake perror() */
|
||||
if (use_savedir)
|
||||
return FALSE;
|
||||
}
|
||||
} while (savef == NULL);
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue