]> granicus.if.org Git - nethack/commitdiff
yet more wizard mode handling (trunk only)
authornethack.rankin <nethack.rankin>
Sat, 17 Feb 2007 05:25:36 +0000 (05:25 +0000)
committernethack.rankin <nethack.rankin>
Sat, 17 Feb 2007 05:25:36 +0000 (05:25 +0000)
     Reorganize the recent wizard mode control:  move set_playmode() from
xxxmain.c to the core, and have it call new authorize_wizard_mode() to do
the port-specific part.  If the set_playmode() call during startup doesn't
result in running in wizard mode (either because not allowed or user
didn't request it), it will be called again during restore if the save
file is from a wizard mode game.

     For ports which check character name for authorization, players will
have to use `nethack -u whatever -D' (or options for name and playmode) to
restore a wizard mode save file if WIZARD has been changed from "wizard".
plname[] from a wizard mode saved game will always have that value, so if
it's not the right one players will need to get authorized by the startup
code before loading the save file.

include/extern.h
src/options.c
src/restore.c
sys/be/bemain.c
sys/mac/macmain.c
sys/share/pcmain.c
sys/unix/unixmain.c
sys/vms/vmsmain.c

index 4a3320078b48e46aa6bc4ee21fac81ea44576f45..a878d569c3a80486984591e9bd8086047fa6677a 100644 (file)
@@ -988,6 +988,10 @@ E int FDECL(macwrite, (int,void *,unsigned));
 E long FDECL(macseek, (int,long,short));
 E int FDECL(macunlink, (const char *));
 
+/* ### macmain.c ### */
+
+E boolean NDECL(authorize_wizard_mode);
+
 /* ### macsnd.c ### */
 
 E void FDECL(mac_speaker, (struct obj *,char *));
@@ -1574,6 +1578,7 @@ E int FDECL(load_symset, (const char *,int));
 E void FDECL(parsesymbols, (char *));
 E struct symparse *FDECL(match_sym, (char *));
 #endif
+E void NDECL(set_playmode);
 
 /* ### pager.c ### */
 
@@ -1592,6 +1597,7 @@ E int FDECL(do_look, (int, coord *));
 # ifdef CHDIR
 E void FDECL(chdirx, (char *,BOOLEAN_P));
 # endif /* CHDIR */
+E boolean NDECL(authorize_wizard_mode);
 #endif /* MICRO || WIN32 */
 
 /* ### pcsys.c ### */
@@ -2280,9 +2286,9 @@ E int FDECL(flash_hits_mon, (struct monst *,struct obj *));
 E void NDECL(port_help);
 # endif
 E void FDECL(sethanguphandler, (void (*)(int)));
+E boolean NDECL(authorize_wizard_mode);
 #endif /* UNIX */
 
-
 /* ### unixtty.c ### */
 
 #if defined(UNIX) || defined(__BEOS__)
@@ -2409,6 +2415,7 @@ E int FDECL(main, (int, char **));
 E void FDECL(chdirx, (const char *,BOOLEAN_P));
 # endif /* CHDIR */
 E void FDECL(sethanguphandler, (void (*)(int)));
+E boolean NDECL(authorize_wizard_mode);
 
 /* ### vmsmisc.c ### */
 
index e3e8e9c358f4dfab1be1d6d80fe5b8942370d550..ed39ac0e7ec5a7731b4784941d6f7e550fe162d2 100644 (file)
@@ -4485,6 +4485,26 @@ char *op;
        return 1;
 }
 
+/* set up for wizard mode if player or save file has requested to it;
+   called from port-specific startup code to handle `nethack -D' or
+   OPTIONS=playmode:debug, or from dorecover()'s restgamestate() if
+   restoring a game which was saved in wizard mode */
+void
+set_playmode()
+{
+    if (wizard) {
+#ifdef WIZARD
+       if (authorize_wizard_mode())
+           Strcpy(plname, "wizard");
+       else
+#endif
+           wizard = FALSE;     /* not allowed or not available */
+       /* force explore mode if we didn't make it into wizard mode */
+       discover = !wizard;
+    }
+    /* don't need to do anything special for explore mode or normal play */
+}
+
 #endif /* OPTION_LISTS_ONLY */
 
 /*options.c*/
index 39dc2def9ce806096c76991efba661cc45de1a31..ed50634e18d600b4768125ba5840e0360867684d 100644 (file)
@@ -546,13 +546,12 @@ unsigned int *stuckid, *steedid;  /* STEED */
        /* wizard and discover are actually flags.debug and flags.explore;
           player might be overriding the save file values for them */
        if (newgameflags.explore) discover = TRUE;
-       if (newgameflags.debug) wizard = TRUE;
-       if (wizard) {
-#ifdef WIZARD
-           discover = FALSE;
-#else
-           discover = TRUE, wizard = FALSE;
-#endif
+       if (newgameflags.debug) {
+           /* authorized by startup code; wizard mode exists and is allowed */
+           wizard = TRUE, discover = FALSE;
+       } else if (wizard) {
+           /* specified by save file; check authorization now */
+           set_playmode();
        }
 #ifdef SYSFLAGS
        newgamesysflags = sysflags;
index bae1c1e3c30d73cc4e85c2a6ccbb22354e67b664..4050d10fbea262d7c617abbd10bd688727dfcdbc 100644 (file)
@@ -11,8 +11,6 @@ static void process_options(int argc, char **argv);
 static void chdirx(const char *dir);
 static void getlock(void);
 
-static void NDECL(set_playmode);
-
 #ifdef __begui__
        #define MAIN nhmain
        int nhmain(int argc, char **argv);
@@ -238,26 +236,15 @@ void getlock(void)
 }
 
 /* validate wizard mode if player has requested access to it */
-static void
-set_playmode()
+boolean
+authorize_wizard_mode()
 {
-    if (wizard) {
 #ifdef WIZARD
        /* other ports validate user name or character name here */
+       return TRUE;
 #else
-       wizard = FALSE;
-#endif
-
-       if (!wizard) {
-           discover = TRUE; 
-#ifdef WIZARD
-       } else {
-           discover = FALSE;   /* paranoia */
-           Strcpy(plname, "wizard");
+       return FALSE;
 #endif
-       }
-    }
-    /* don't need to do anything special for explore mode or normal play */
 }
 
 #ifndef __begui__
index 051118d73a8543b226c4c19c9f5d9f777870f696..976352b438a62a3e5511b67b5909d6e15f8f0b7f 100644 (file)
@@ -24,8 +24,6 @@
 #include <fcntl.h>
 #endif
 
-static void NDECL(set_playmode);
-
 static void finder_file_request(void);
 int main(void);
 
@@ -271,26 +269,15 @@ finder_file_request(void)
 }
 
 /* validate wizard mode if player has requested access to it */
-static void
-set_playmode()
+boolean
+authorize_wizard_mode()
 {
-    if (wizard) {
 #ifdef WIZARD
        /* other ports validate user name or character name here */
+       return TRUE;
 #else
-       wizard = FALSE;
-#endif
-
-       if (!wizard) {
-           discover = TRUE; 
-#ifdef WIZARD
-       } else {
-           discover = FALSE;   /* paranoia */
-           Strcpy(plname, "wizard");
+       return FALSE;
 #endif
-       }
-    }
-    /* don't need to do anything special for explore mode or normal play */
 }
 
 /*macmain.c*/
index d970dab487c4da5ae5cb2896135d8a583deadec4..9cf9390046e78b76ef9942b36529357cbfd934f1 100644 (file)
@@ -66,8 +66,6 @@ extern int redirect_stdout;           /* from sys/share/pcsys.c */
 extern void NDECL(mswin_destroy_reg);
 #endif
 
-STATIC_DCL void NDECL(set_playmode);
-
 #ifdef EXEPATH
 STATIC_DCL char *FDECL(exepath,(char *));
 #endif
@@ -697,26 +695,13 @@ port_help()
 #endif
 
 /* validate wizard mode if player has requested access to it */
-STATIC_OVL void
-set_playmode()
+boolean
+authorize_wizard_mode()
 {
-    if (wizard) {
 #ifdef WIZARD
-       if (strcmp(plname, WIZARD_NAME)) wizard = FALSE;
-#else
-       wizard = FALSE;
+       if (!strcmp(plname, WIZARD_NAME)) return TRUE;
 #endif
-
-       if (!wizard) {
-           discover = TRUE; 
-#ifdef WIZARD
-       } else {
-           discover = FALSE;   /* paranoia */
-           Strcpy(plname, "wizard");
-#endif
-       }
-    }
-    /* don't need to do anything special for explore mode or normal play */
+       return FALSE;
 }
 
 #ifdef EXEPATH
index 2ab066e3964b445e61c3c89fe3d962c0abd7f0b1..5d40e5f02dc7b948139de78751671a7f1f149698 100644 (file)
@@ -39,7 +39,6 @@ extern void NDECL(check_linux_console);
 extern void NDECL(init_linux_cons);
 #endif
 
-static void NDECL(set_playmode);
 static void NDECL(wd_message);
 static boolean wiz_error_flag = FALSE;
 
@@ -507,10 +506,9 @@ port_help()
 #endif
 
 /* validate wizard mode if player has requested access to it */
-static void
-set_playmode()
+boolean
+authorize_wizard_mode()
 {
-    if (wizard) {
 #ifdef WIZARD
        char *user;
        int uid;
@@ -532,21 +530,9 @@ set_playmode()
                pw = getpwuid(uid);
            }
        }
-       if (!pw || strcmp(pw->pw_name, WIZARD_NAME)) wizard = FALSE;
-#else  /* !WIZARD */
-       wizard = FALSE;
-#endif /* ?WIZARD */
-
-       if (!wizard) {
-           discover = wiz_error_flag = TRUE; 
-#ifdef WIZARD
-       } else {
-           discover = FALSE;   /* paranoia */
-           Strcpy(plname, "wizard");
-#endif
-       }
-    }
-    /* don't need to do anything special for explore mode or normal play */
+       if (pw && !strcmp(pw->pw_name, WIZARD_NAME)) return TRUE;
+#endif /* WIZARD */
+       return FALSE;
 }
 
 static void
index 9af7b859fdf3f64b9e26a965a5bf2b87e1658751..3bdb5dcb0f6f24ec6fd2ce3c5c188501207b6b3d 100644 (file)
@@ -22,7 +22,6 @@ static vms_handler_type FDECL(vms_handler, (genericptr_t,genericptr_t));
 #include <ssdef.h>     /* system service status codes */
 #endif
 
-static void NDECL(set_playmode);
 static void NDECL(wd_message);
 static boolean wiz_error_flag = FALSE;
 
@@ -435,26 +434,13 @@ port_help()
    to match it, avoiding need to test which one to use in string ops */
 
 /* validate wizard mode if player has requested access to it */
-static void
-set_playmode()
+boolean
+authorize_wizard_mode()
 {
-    if (wizard) {
-#ifdef WIZARD
-       if (strcmpi(nh_getenv("USER"), WIZARD_NAME)) wizard = FALSE;
-#else
-       wizard = FALSE;
-#endif
-
-       if (!wizard) {
-           discover = wiz_error_flag = TRUE; 
 #ifdef WIZARD
-       } else {
-           discover = FALSE;   /* paranoia */
-           Strcpy(plname, "wizard");
+       if (!strcmpi(nh_getenv("USER"), WIZARD_NAME)) return TRUE;
 #endif
-       }
-    }
-    /* don't need to do anything special for explore mode or normal play */
+       return FALSE;
 }
 
 static void