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;
|
typedef struct optstruct OPTION;
|
||||||
|
|
||||||
|
int allowchange(OPTION *opt);
|
||||||
|
|
||||||
int put_bool(), get_bool(), put_str(), get_str();
|
int put_bool(), get_bool(), put_str(), get_str();
|
||||||
|
|
||||||
OPTION optlist[] = {
|
OPTION optlist[] = {
|
||||||
|
|
@ -71,21 +73,28 @@ option()
|
||||||
* Display current values of options
|
* Display current values of options
|
||||||
*/
|
*/
|
||||||
for (op = optlist; op < &optlist[NUM_OPTS]; op++)
|
for (op = optlist; op < &optlist[NUM_OPTS]; op++)
|
||||||
|
{
|
||||||
|
if (allowchange(op))
|
||||||
{
|
{
|
||||||
waddstr(hw, op->o_prompt);
|
waddstr(hw, op->o_prompt);
|
||||||
(*op->o_putfunc)(op->o_opt);
|
(*op->o_putfunc)(op->o_opt);
|
||||||
waddch(hw, '\n');
|
waddch(hw, '\n');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Set values
|
* Set values
|
||||||
*/
|
*/
|
||||||
wmove(hw, 0, 0);
|
wmove(hw, 0, 0);
|
||||||
for (op = optlist; op < &optlist[NUM_OPTS]; op++)
|
for (op = optlist; op < &optlist[NUM_OPTS]; op++)
|
||||||
{
|
{
|
||||||
|
if (!allowchange(op))
|
||||||
|
continue;
|
||||||
waddstr(hw, op->o_prompt);
|
waddstr(hw, op->o_prompt);
|
||||||
if ((retval = (*op->o_getfunc)(op->o_opt, hw)))
|
if ((retval = (*op->o_getfunc)(op->o_opt, hw)))
|
||||||
|
{
|
||||||
if (retval == QUIT)
|
if (retval == QUIT)
|
||||||
break;
|
break;
|
||||||
|
#if 0 /* disable MINUS */
|
||||||
else if (op > optlist) { /* MINUS */
|
else if (op > optlist) { /* MINUS */
|
||||||
wmove(hw, (op - optlist) - 1, 0);
|
wmove(hw, (op - optlist) - 1, 0);
|
||||||
op -= 2;
|
op -= 2;
|
||||||
|
|
@ -96,6 +105,10 @@ option()
|
||||||
wmove(hw, 0, 0);
|
wmove(hw, 0, 0);
|
||||||
op--;
|
op--;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Switch back to original screen
|
* Switch back to original screen
|
||||||
|
|
@ -301,6 +314,11 @@ register char *str;
|
||||||
* Look it up and deal with it
|
* Look it up and deal with it
|
||||||
*/
|
*/
|
||||||
for (op = optlist; op < &optlist[NUM_OPTS]; op++)
|
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 (EQSTR(str, op->o_name, len))
|
||||||
{
|
{
|
||||||
if (op->o_putfunc == put_bool) /* if option is a boolean */
|
if (op->o_putfunc == put_bool) /* if option is a boolean */
|
||||||
|
|
@ -340,6 +358,7 @@ register char *str;
|
||||||
*(bool *)op->o_opt = FALSE;
|
*(bool *)op->o_opt = FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* skip to start of next option name
|
* skip to start of next option name
|
||||||
|
|
@ -368,3 +387,16 @@ register int len;
|
||||||
}
|
}
|
||||||
*s1 = '\0';
|
*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:
|
* save_game:
|
||||||
* Implement the "save game" command
|
* Implement the "save game" command
|
||||||
*/
|
*/
|
||||||
|
/* This has to be cleaned up, these goto's are annoying. */
|
||||||
save_game()
|
save_game()
|
||||||
{
|
{
|
||||||
register FILE *savef;
|
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
|
do
|
||||||
{
|
{
|
||||||
mpos = 0;
|
mpos = 0;
|
||||||
|
|
@ -102,7 +111,11 @@ gotfile:
|
||||||
}
|
}
|
||||||
strcpy(file_name, buf);
|
strcpy(file_name, buf);
|
||||||
if ((savef = fopen(file_name, "w")) == NULL)
|
if ((savef = fopen(file_name, "w")) == NULL)
|
||||||
|
{
|
||||||
msg(strerror(errno)); /* fake perror() */
|
msg(strerror(errno)); /* fake perror() */
|
||||||
|
if (use_savedir)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
} while (savef == NULL);
|
} while (savef == NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue