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:
parent
e35502804b
commit
283506baf9
2 changed files with 52 additions and 7 deletions
|
|
@ -51,6 +51,9 @@ int put_bool(),
|
||||||
put_quest(),
|
put_quest(),
|
||||||
get_default();
|
get_default();
|
||||||
|
|
||||||
|
int get_str_prot(char *opt, WINDOW *win);
|
||||||
|
bool allowchange(OPTION *op);
|
||||||
|
|
||||||
OPTION optlist[] = {
|
OPTION optlist[] = {
|
||||||
{"terse", "Terse output: ",
|
{"terse", "Terse output: ",
|
||||||
(int *) &terse, put_bool, get_bool },
|
(int *) &terse, put_bool, get_bool },
|
||||||
|
|
@ -67,11 +70,11 @@ OPTION optlist[] = {
|
||||||
{"overlay", "Overlay menu: ",
|
{"overlay", "Overlay menu: ",
|
||||||
(int *) &menu_overlay, put_bool, get_bool },
|
(int *) &menu_overlay, put_bool, get_bool },
|
||||||
{"name", "Name: ",
|
{"name", "Name: ",
|
||||||
(int *) whoami, put_str, get_str },
|
(int *) whoami, put_str, get_str_prot },
|
||||||
{"file", "Save file: ",
|
{"file", "Save file: ",
|
||||||
(int *) file_name, put_str, get_str },
|
(int *) file_name, put_str, get_str_prot },
|
||||||
{"score", "Score file: ",
|
{"score", "Score file: ",
|
||||||
(int *) score_file, put_str, get_str },
|
(int *) score_file, put_str, get_str_prot },
|
||||||
{"class", "Character type: ",
|
{"class", "Character type: ",
|
||||||
(int *) &char_type, put_abil, get_abil },
|
(int *) &char_type, put_abil, get_abil },
|
||||||
{"quest", "Quest item: ",
|
{"quest", "Quest item: ",
|
||||||
|
|
@ -407,8 +410,10 @@ register char *str;
|
||||||
strucpy(start, str, (char *) sp - str);
|
strucpy(start, str, (char *) sp - str);
|
||||||
|
|
||||||
/* Put the value into the option field */
|
/* Put the value into the option field */
|
||||||
if (op->o_putfunc != put_abil)
|
if (op->o_putfunc != put_abil) {
|
||||||
strcpy((char *)op->o_opt, value);
|
if (allowchange(op))
|
||||||
|
strcpy((char *)op->o_opt, value);
|
||||||
|
}
|
||||||
|
|
||||||
else if (*op->o_opt == -1) { /* Only init ability once */
|
else if (*op->o_opt == -1) { /* Only init ability once */
|
||||||
register int len = strlen(value);
|
register int len = strlen(value);
|
||||||
|
|
@ -500,3 +505,32 @@ WINDOW *win;
|
||||||
waddstr(win, str);
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,10 @@ save_game()
|
||||||
mpos = 0;
|
mpos = 0;
|
||||||
if (file_name[0] != '\0')
|
if (file_name[0] != '\0')
|
||||||
{
|
{
|
||||||
msg("Save file (%s)? ", file_name);
|
if (use_savedir)
|
||||||
|
msg("Save game? ");
|
||||||
|
else
|
||||||
|
msg("Save file (%s)? ", file_name);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
c = wgetch(cw);
|
c = wgetch(cw);
|
||||||
|
|
@ -59,6 +62,11 @@ save_game()
|
||||||
else
|
else
|
||||||
goto gotfile; /* must save to file restored from */
|
goto gotfile; /* must save to file restored from */
|
||||||
|
|
||||||
|
if (use_savedir) {
|
||||||
|
msg("");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
msg("File name: ");
|
msg("File name: ");
|
||||||
|
|
@ -72,8 +80,11 @@ save_game()
|
||||||
strcpy(file_name, buf);
|
strcpy(file_name, buf);
|
||||||
gotfile:
|
gotfile:
|
||||||
|
|
||||||
if ((savef = fopen(file_name, "wb")) == NULL)
|
if ((savef = fopen(file_name, "wb")) == NULL) {
|
||||||
msg(strerror(errno));
|
msg(strerror(errno));
|
||||||
|
if (use_savedir)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
} while (savef == NULL);
|
} while (savef == NULL);
|
||||||
|
|
||||||
msg("");
|
msg("");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue