yet more wizard mode handling (trunk only)

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.
This commit is contained in:
nethack.rankin
2007-02-17 05:25:36 +00:00
parent 1659dd5634
commit 43f72cc357
8 changed files with 55 additions and 98 deletions
+8 -1
View File
@@ -988,6 +988,10 @@ E int FDECL(macwrite, (int,void *,unsigned));
E long FDECL(macseek, (int,long,short)); E long FDECL(macseek, (int,long,short));
E int FDECL(macunlink, (const char *)); E int FDECL(macunlink, (const char *));
/* ### macmain.c ### */
E boolean NDECL(authorize_wizard_mode);
/* ### macsnd.c ### */ /* ### macsnd.c ### */
E void FDECL(mac_speaker, (struct obj *,char *)); 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 void FDECL(parsesymbols, (char *));
E struct symparse *FDECL(match_sym, (char *)); E struct symparse *FDECL(match_sym, (char *));
#endif #endif
E void NDECL(set_playmode);
/* ### pager.c ### */ /* ### pager.c ### */
@@ -1592,6 +1597,7 @@ E int FDECL(do_look, (int, coord *));
# ifdef CHDIR # ifdef CHDIR
E void FDECL(chdirx, (char *,BOOLEAN_P)); E void FDECL(chdirx, (char *,BOOLEAN_P));
# endif /* CHDIR */ # endif /* CHDIR */
E boolean NDECL(authorize_wizard_mode);
#endif /* MICRO || WIN32 */ #endif /* MICRO || WIN32 */
/* ### pcsys.c ### */ /* ### pcsys.c ### */
@@ -2280,9 +2286,9 @@ E int FDECL(flash_hits_mon, (struct monst *,struct obj *));
E void NDECL(port_help); E void NDECL(port_help);
# endif # endif
E void FDECL(sethanguphandler, (void (*)(int))); E void FDECL(sethanguphandler, (void (*)(int)));
E boolean NDECL(authorize_wizard_mode);
#endif /* UNIX */ #endif /* UNIX */
/* ### unixtty.c ### */ /* ### unixtty.c ### */
#if defined(UNIX) || defined(__BEOS__) #if defined(UNIX) || defined(__BEOS__)
@@ -2409,6 +2415,7 @@ E int FDECL(main, (int, char **));
E void FDECL(chdirx, (const char *,BOOLEAN_P)); E void FDECL(chdirx, (const char *,BOOLEAN_P));
# endif /* CHDIR */ # endif /* CHDIR */
E void FDECL(sethanguphandler, (void (*)(int))); E void FDECL(sethanguphandler, (void (*)(int)));
E boolean NDECL(authorize_wizard_mode);
/* ### vmsmisc.c ### */ /* ### vmsmisc.c ### */
+20
View File
@@ -4485,6 +4485,26 @@ char *op;
return 1; 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 */ #endif /* OPTION_LISTS_ONLY */
/*options.c*/ /*options.c*/
+6 -7
View File
@@ -546,13 +546,12 @@ unsigned int *stuckid, *steedid; /* STEED */
/* wizard and discover are actually flags.debug and flags.explore; /* wizard and discover are actually flags.debug and flags.explore;
player might be overriding the save file values for them */ player might be overriding the save file values for them */
if (newgameflags.explore) discover = TRUE; if (newgameflags.explore) discover = TRUE;
if (newgameflags.debug) wizard = TRUE; if (newgameflags.debug) {
if (wizard) { /* authorized by startup code; wizard mode exists and is allowed */
#ifdef WIZARD wizard = TRUE, discover = FALSE;
discover = FALSE; } else if (wizard) {
#else /* specified by save file; check authorization now */
discover = TRUE, wizard = FALSE; set_playmode();
#endif
} }
#ifdef SYSFLAGS #ifdef SYSFLAGS
newgamesysflags = sysflags; newgamesysflags = sysflags;
+4 -17
View File
@@ -11,8 +11,6 @@ static void process_options(int argc, char **argv);
static void chdirx(const char *dir); static void chdirx(const char *dir);
static void getlock(void); static void getlock(void);
static void NDECL(set_playmode);
#ifdef __begui__ #ifdef __begui__
#define MAIN nhmain #define MAIN nhmain
int nhmain(int argc, char **argv); int nhmain(int argc, char **argv);
@@ -238,26 +236,15 @@ void getlock(void)
} }
/* validate wizard mode if player has requested access to it */ /* validate wizard mode if player has requested access to it */
static void boolean
set_playmode() authorize_wizard_mode()
{ {
if (wizard) {
#ifdef WIZARD #ifdef WIZARD
/* other ports validate user name or character name here */ /* other ports validate user name or character name here */
return TRUE;
#else #else
wizard = FALSE; return FALSE;
#endif #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 */
} }
#ifndef __begui__ #ifndef __begui__
+4 -17
View File
@@ -24,8 +24,6 @@
#include <fcntl.h> #include <fcntl.h>
#endif #endif
static void NDECL(set_playmode);
static void finder_file_request(void); static void finder_file_request(void);
int main(void); int main(void);
@@ -271,26 +269,15 @@ finder_file_request(void)
} }
/* validate wizard mode if player has requested access to it */ /* validate wizard mode if player has requested access to it */
static void boolean
set_playmode() authorize_wizard_mode()
{ {
if (wizard) {
#ifdef WIZARD #ifdef WIZARD
/* other ports validate user name or character name here */ /* other ports validate user name or character name here */
return TRUE;
#else #else
wizard = FALSE; return FALSE;
#endif #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 */
} }
/*macmain.c*/ /*macmain.c*/
+4 -19
View File
@@ -66,8 +66,6 @@ extern int redirect_stdout; /* from sys/share/pcsys.c */
extern void NDECL(mswin_destroy_reg); extern void NDECL(mswin_destroy_reg);
#endif #endif
STATIC_DCL void NDECL(set_playmode);
#ifdef EXEPATH #ifdef EXEPATH
STATIC_DCL char *FDECL(exepath,(char *)); STATIC_DCL char *FDECL(exepath,(char *));
#endif #endif
@@ -697,26 +695,13 @@ port_help()
#endif #endif
/* validate wizard mode if player has requested access to it */ /* validate wizard mode if player has requested access to it */
STATIC_OVL void boolean
set_playmode() authorize_wizard_mode()
{ {
if (wizard) {
#ifdef WIZARD #ifdef WIZARD
if (strcmp(plname, WIZARD_NAME)) wizard = FALSE; if (!strcmp(plname, WIZARD_NAME)) return TRUE;
#else
wizard = FALSE;
#endif #endif
return FALSE;
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 */
} }
#ifdef EXEPATH #ifdef EXEPATH
+5 -19
View File
@@ -39,7 +39,6 @@ extern void NDECL(check_linux_console);
extern void NDECL(init_linux_cons); extern void NDECL(init_linux_cons);
#endif #endif
static void NDECL(set_playmode);
static void NDECL(wd_message); static void NDECL(wd_message);
static boolean wiz_error_flag = FALSE; static boolean wiz_error_flag = FALSE;
@@ -507,10 +506,9 @@ port_help()
#endif #endif
/* validate wizard mode if player has requested access to it */ /* validate wizard mode if player has requested access to it */
static void boolean
set_playmode() authorize_wizard_mode()
{ {
if (wizard) {
#ifdef WIZARD #ifdef WIZARD
char *user; char *user;
int uid; int uid;
@@ -532,21 +530,9 @@ set_playmode()
pw = getpwuid(uid); pw = getpwuid(uid);
} }
} }
if (!pw || strcmp(pw->pw_name, WIZARD_NAME)) wizard = FALSE; if (pw && !strcmp(pw->pw_name, WIZARD_NAME)) return TRUE;
#else /* !WIZARD */ #endif /* WIZARD */
wizard = FALSE; return 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 */
} }
static void static void
+4 -18
View File
@@ -22,7 +22,6 @@ static vms_handler_type FDECL(vms_handler, (genericptr_t,genericptr_t));
#include <ssdef.h> /* system service status codes */ #include <ssdef.h> /* system service status codes */
#endif #endif
static void NDECL(set_playmode);
static void NDECL(wd_message); static void NDECL(wd_message);
static boolean wiz_error_flag = FALSE; 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 */ to match it, avoiding need to test which one to use in string ops */
/* validate wizard mode if player has requested access to it */ /* validate wizard mode if player has requested access to it */
static void boolean
set_playmode() authorize_wizard_mode()
{ {
if (wizard) {
#ifdef WIZARD #ifdef WIZARD
if (strcmpi(nh_getenv("USER"), WIZARD_NAME)) wizard = FALSE; if (!strcmpi(nh_getenv("USER"), WIZARD_NAME)) return TRUE;
#else
wizard = FALSE;
#endif #endif
return FALSE;
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 */
} }
static void static void