X11: Fix renaming at player selection

Due to the new player selection dialog I did, it was possible
to rename your character - but this didn't rename the lock files
and tried to load a save from the wrong name.

This is a bit of a hack, but seems to work and didn't seem to
cause problems for the tty.
This commit is contained in:
Pasi Kallinen
2017-10-31 21:18:24 +02:00
parent 72978d69fa
commit fe9762d1cc
6 changed files with 47 additions and 27 deletions
+1
View File
@@ -191,6 +191,7 @@ struct instance_flags {
* behaviour of various NetHack functions and probably warrant * behaviour of various NetHack functions and probably warrant
* a structure of their own elsewhere some day. * a structure of their own elsewhere some day.
*/ */
boolean defer_plname; /* X11 hack: askname() might not set plname */
boolean herecmd_menu; /* use menu when mouseclick on yourself */ boolean herecmd_menu; /* use menu when mouseclick on yourself */
boolean invis_goldsym; /* gold symbol is ' '? */ boolean invis_goldsym; /* gold symbol is ' '? */
int parse_config_file_src; /* hack for parse_config_line() */ int parse_config_file_src; /* hack for parse_config_line() */
+2 -2
View File
@@ -1714,7 +1714,7 @@ plnamesuffix()
do { do {
if (!*plname) if (!*plname)
askname(); /* fill plname[] if necessary */ askname(); /* fill plname[] if necessary, or set defer_plname */
/* Look for tokens delimited by '-' */ /* Look for tokens delimited by '-' */
if ((eptr = index(plname, '-')) != (char *) 0) if ((eptr = index(plname, '-')) != (char *) 0)
@@ -1735,7 +1735,7 @@ plnamesuffix()
else if ((i = str2align(sptr)) != ROLE_NONE) else if ((i = str2align(sptr)) != ROLE_NONE)
flags.initalign = i; flags.initalign = i;
} }
} while (!*plname); } while (!*plname && !iflags.defer_plname);
/* commas in the plname confuse the record file, convert to spaces */ /* commas in the plname confuse the record file, convert to spaces */
for (sptr = plname; *sptr; sptr++) { for (sptr = plname; *sptr; sptr++) {
+1 -1
View File
@@ -20,7 +20,7 @@ VARDIR = $(HACKDIR)
POSTINSTALL= cp -n sys/unix/sysconf $(INSTDIR)/sysconf; $(CHOWN) $(GAMEUID) $(INSTDIR)/sysconf; $(CHGRP) $(GAMEGRP) $(INSTDIR)/sysconf; chmod $(VARFILEPERM) $(INSTDIR)/sysconf; POSTINSTALL= cp -n sys/unix/sysconf $(INSTDIR)/sysconf; $(CHOWN) $(GAMEUID) $(INSTDIR)/sysconf; $(CHGRP) $(GAMEGRP) $(INSTDIR)/sysconf; chmod $(VARFILEPERM) $(INSTDIR)/sysconf;
POSTINSTALL+= bdftopcf win/X11/nh10.bdf > $(INSTDIR)/nh10.pcf; (cd $(INSTDIR); mkfontdir); POSTINSTALL+= bdftopcf win/X11/nh10.bdf > $(INSTDIR)/nh10.pcf; (cd $(INSTDIR); mkfontdir);
CFLAGS=-O -I../include -DNOTPARMDECL CFLAGS=-g -O -I../include -DNOTPARMDECL
CFLAGS+=-DSYSCF -DSYSCF_FILE=\"$(HACKDIR)/sysconf\" CFLAGS+=-DSYSCF -DSYSCF_FILE=\"$(HACKDIR)/sysconf\"
CFLAGS+=-DCOMPRESS=\"/bin/gzip\" -DCOMPRESS_EXTENSION=\".gz\" CFLAGS+=-DCOMPRESS=\"/bin/gzip\" -DCOMPRESS_EXTENSION=\".gz\"
CFLAGS+=-DX11_GRAPHICS -DDEFAULT_WINDOW_SYS=\"X11\" -DNOTTYGRAPHICS CFLAGS+=-DX11_GRAPHICS -DDEFAULT_WINDOW_SYS=\"X11\" -DNOTTYGRAPHICS
+26 -16
View File
@@ -55,6 +55,7 @@ char *argv[];
#endif #endif
boolean exact_username; boolean exact_username;
boolean resuming = FALSE; /* assume new game */ boolean resuming = FALSE; /* assume new game */
boolean plsel_once = FALSE;
sys_early_init(); sys_early_init();
@@ -237,19 +238,6 @@ char *argv[];
(void) signal(SIGQUIT, SIG_IGN); (void) signal(SIGQUIT, SIG_IGN);
(void) signal(SIGINT, SIG_IGN); (void) signal(SIGINT, SIG_IGN);
} }
/*
* getlock() complains and quits if there is already a game
* in progress for current character name (when locknum == 0)
* or if there are too many active games (when locknum > 0).
* When proceeding, it creates an empty <lockname>.0 file to
* designate the current game.
* getlock() constructs <lockname> based on the character
* name (for !locknum) or on first available of alock, block,
* clock, &c not currently in use in the playground directory
* (for locknum > 0).
*/
getlock();
program_state.preserve_locks = 0; /* after getlock() */
dlb_init(); /* must be before newgame() */ dlb_init(); /* must be before newgame() */
@@ -266,7 +254,24 @@ char *argv[];
* We'll return here if new game player_selection() renames the hero. * We'll return here if new game player_selection() renames the hero.
*/ */
attempt_restore: attempt_restore:
if ((fd = restore_saved_game()) >= 0) {
/*
* getlock() complains and quits if there is already a game
* in progress for current character name (when locknum == 0)
* or if there are too many active games (when locknum > 0).
* When proceeding, it creates an empty <lockname>.0 file to
* designate the current game.
* getlock() constructs <lockname> based on the character
* name (for !locknum) or on first available of alock, block,
* clock, &c not currently in use in the playground directory
* (for locknum > 0).
*/
if (*plname) {
getlock();
program_state.preserve_locks = 0; /* after getlock() */
}
if (*plname && (fd = restore_saved_game()) >= 0) {
const char *fq_save = fqname(SAVEF, SAVEPREFIX, 1); const char *fq_save = fqname(SAVEF, SAVEPREFIX, 1);
(void) chmod(fq_save, 0); /* disallow parallel restores */ (void) chmod(fq_save, 0); /* disallow parallel restores */
@@ -297,12 +302,17 @@ attempt_restore:
} }
if (!resuming) { if (!resuming) {
boolean neednewlock = (!*plname);
/* new game: start by choosing role, race, etc; /* new game: start by choosing role, race, etc;
player might change the hero's name while doing that, player might change the hero's name while doing that,
in which case we try to restore under the new name in which case we try to restore under the new name
and skip selection this time if that didn't succeed */ and skip selection this time if that didn't succeed */
if (!iflags.renameinprogress) { if (!iflags.renameinprogress || iflags.defer_plname || neednewlock) {
player_selection(); if (!plsel_once)
player_selection();
plsel_once = TRUE;
if (neednewlock && *plname)
goto attempt_restore;
if (iflags.renameinprogress) { if (iflags.renameinprogress) {
/* player has renamed the hero while selecting role; /* player has renamed the hero while selecting role;
if locking alphabetically, the existing lock file if locking alphabetically, the existing lock file
+1 -8
View File
@@ -1474,18 +1474,11 @@ X11_askname()
{ {
Widget popup, dialog; Widget popup, dialog;
Arg args[1]; Arg args[1];
char *defplname = (char *)0;
#ifdef UNIX
defplname = get_login_name();
#endif
(void) strncpy(plname, defplname ? defplname : "Mumbles",
sizeof plname - 1);
plname[sizeof plname - 1] = '\0';
if (iflags.wc_player_selection == VIA_DIALOG) { if (iflags.wc_player_selection == VIA_DIALOG) {
/* X11_player_selection_dialog() handles name query */ /* X11_player_selection_dialog() handles name query */
plsel_ask_name = TRUE; plsel_ask_name = TRUE;
iflags.defer_plname = TRUE;
return; return;
} /* else iflags.wc_player_selection == VIA_PROMPTS */ } /* else iflags.wc_player_selection == VIA_PROMPTS */
+16
View File
@@ -352,8 +352,13 @@ plsel_dialog_acceptvalues()
XtSetArg(args[0], nhStr(XtNstring), &s); XtSetArg(args[0], nhStr(XtNstring), &s);
XtGetValues(plsel_name_input, args, ONE); XtGetValues(plsel_name_input, args, ONE);
(void) strncpy(plname, (char *) s, sizeof plname - 1); (void) strncpy(plname, (char *) s, sizeof plname - 1);
plname[sizeof plname - 1] = '\0'; plname[sizeof plname - 1] = '\0';
(void) mungspaces(plname);
if (strlen(plname) < 1)
(void) strcpy(plname, "Mumbles");
iflags.renameinprogress = FALSE;
} }
/* ARGSUSED */ /* ARGSUSED */
@@ -1553,6 +1558,17 @@ void
X11_player_selection() X11_player_selection()
{ {
if (iflags.wc_player_selection == VIA_DIALOG) { if (iflags.wc_player_selection == VIA_DIALOG) {
if (!*plname) {
#ifdef UNIX
char *defplname = get_login_name();
#else
char *defplname = (char *)0;
#endif
(void) strncpy(plname, defplname ? defplname : "Mumbles",
sizeof plname - 1);
plname[sizeof plname - 1] = '\0';
iflags.renameinprogress = TRUE;
}
X11_player_selection_dialog(); X11_player_selection_dialog();
} else { /* iflags.wc_player_selection == VIA_PROMPTS */ } else { /* iflags.wc_player_selection == VIA_PROMPTS */
X11_player_selection_prompts(); X11_player_selection_prompts();