changeset 14:e7dc81b41168

rogue4: prevent changing name or save file when using system savedir
author edwarj4
date Sat, 31 Oct 2009 13:20:00 +0000
parents 63b9fd7d70ce
children 7ef854484e08
files rogue4/options.c rogue4/save.c
diffstat 2 files changed, 48 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/rogue4/options.c	Sat Oct 31 01:51:52 2009 +0000
+++ b/rogue4/options.c	Sat Oct 31 13:20:00 2009 +0000
@@ -34,6 +34,8 @@
 
 typedef struct optstruct	OPTION;
 
+int allowchange(OPTION *opt);
+
 int	put_bool(), get_bool(), put_str(), get_str();
 
 OPTION	optlist[] = {
@@ -72,9 +74,12 @@
      */
     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 @@
     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 @@
 		wmove(hw, 0, 0);
 		op--;
 	    }
+#else
+            break;
+#endif
+        }
     }
     /*
      * Switch back to original screen
@@ -301,6 +314,11 @@
 	 * 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 @@
 		*(bool *)op->o_opt = FALSE;
 		break;
 	    }
+        }
 
 	/*
 	 * skip to start of next option name
@@ -368,3 +387,16 @@
     }
     *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;
+}
+
--- a/rogue4/save.c	Sat Oct 31 01:51:52 2009 +0000
+++ b/rogue4/save.c	Sat Oct 31 13:20:00 2009 +0000
@@ -32,6 +32,7 @@
  * 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 @@
 	}
     }
 
+    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 @@
 	}
 	strcpy(file_name, buf);
 	if ((savef = fopen(file_name, "w")) == NULL)
+        {
 	    msg(strerror(errno));	/* fake perror() */
+            if (use_savedir)
+                return FALSE;
+        }
     } while (savef == NULL);
 
     /*