xrogue: restrict changes to the save file location.

When using the -n option, disallow changing file_name or whoami via
options or dialogs.
This commit is contained in:
John "Elwin" Edwards 2015-05-02 07:31:14 -04:00
parent e35502804b
commit 283506baf9
2 changed files with 52 additions and 7 deletions

View file

@ -51,6 +51,9 @@ int put_bool(),
put_quest(),
get_default();
int get_str_prot(char *opt, WINDOW *win);
bool allowchange(OPTION *op);
OPTION optlist[] = {
{"terse", "Terse output: ",
(int *) &terse, put_bool, get_bool },
@ -67,11 +70,11 @@ OPTION optlist[] = {
{"overlay", "Overlay menu: ",
(int *) &menu_overlay, put_bool, get_bool },
{"name", "Name: ",
(int *) whoami, put_str, get_str },
(int *) whoami, put_str, get_str_prot },
{"file", "Save file: ",
(int *) file_name, put_str, get_str },
(int *) file_name, put_str, get_str_prot },
{"score", "Score file: ",
(int *) score_file, put_str, get_str },
(int *) score_file, put_str, get_str_prot },
{"class", "Character type: ",
(int *) &char_type, put_abil, get_abil },
{"quest", "Quest item: ",
@ -407,8 +410,10 @@ register char *str;
strucpy(start, str, (char *) sp - str);
/* Put the value into the option field */
if (op->o_putfunc != put_abil)
if (op->o_putfunc != put_abil) {
if (allowchange(op))
strcpy((char *)op->o_opt, value);
}
else if (*op->o_opt == -1) { /* Only init ability once */
register int len = strlen(value);
@ -500,3 +505,32 @@ WINDOW *win;
waddstr(win, str);
}
/* Like get_str, but disallows changes when use_savedir is set. */
int
get_str_prot(char *opt, WINDOW *win)
{
int oy, ox;
if (use_savedir) {
getyx(win, oy, ox);
waddstr(win, opt);
return get_ro(win, oy, ox);
}
else {
return get_str(opt, win);
}
}
bool
allowchange(OPTION *op)
{
if (!use_savedir)
return TRUE;
if (!strcmp(op->o_name, "name"))
return FALSE;
if (!strcmp(op->o_name, "file"))
return FALSE;
if (!strcmp(op->o_name, "score"))
return FALSE;
return TRUE;
}

View file

@ -43,6 +43,9 @@ save_game()
mpos = 0;
if (file_name[0] != '\0')
{
if (use_savedir)
msg("Save game? ");
else
msg("Save file (%s)? ", file_name);
do
{
@ -59,6 +62,11 @@ save_game()
else
goto gotfile; /* must save to file restored from */
if (use_savedir) {
msg("");
return FALSE;
}
do
{
msg("File name: ");
@ -72,8 +80,11 @@ save_game()
strcpy(file_name, buf);
gotfile:
if ((savef = fopen(file_name, "wb")) == NULL)
if ((savef = fopen(file_name, "wb")) == NULL) {
msg(strerror(errno));
if (use_savedir)
return FALSE;
}
} while (savef == NULL);
msg("");