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

View 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 ### */

View 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*/

View 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;

View 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;
return FALSE;
#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__

View 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;
return FALSE;
#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*/

View 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

View 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

View 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;
if (!strcmpi(nh_getenv("USER"), WIZARD_NAME)) return TRUE;
#endif
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 */
return FALSE;
}
static void