]> granicus.if.org Git - nethack/commitdiff
X11: Fix renaming at player selection
authorPasi Kallinen <paxed@alt.org>
Tue, 31 Oct 2017 19:18:21 +0000 (21:18 +0200)
committerPasi Kallinen <paxed@alt.org>
Tue, 31 Oct 2017 19:18:24 +0000 (21:18 +0200)
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.

include/flag.h
src/role.c
sys/unix/hints/linux-x11
sys/unix/unixmain.c
win/X11/winX.c
win/X11/winmisc.c

index 3bccbaa18cfca518b1299171e2a1cf013cdfaead..81630bd2790b0f0520c0547f2e9e6a3319aa732b 100644 (file)
@@ -191,6 +191,7 @@ struct instance_flags {
      * behaviour of various NetHack functions and probably warrant
      * 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 invis_goldsym; /* gold symbol is ' '? */
     int parse_config_file_src;  /* hack for parse_config_line() */
index 5a1a4ab56755ec7f79e873cf1837c18b550be477..fd23f3adbfd8d8df343fe34de0a987515a47a2ef 100644 (file)
@@ -1714,7 +1714,7 @@ plnamesuffix()
 
     do {
         if (!*plname)
-            askname(); /* fill plname[] if necessary */
+            askname(); /* fill plname[] if necessary, or set defer_plname */
 
         /* Look for tokens delimited by '-' */
         if ((eptr = index(plname, '-')) != (char *) 0)
@@ -1735,7 +1735,7 @@ plnamesuffix()
             else if ((i = str2align(sptr)) != ROLE_NONE)
                 flags.initalign = i;
         }
-    } while (!*plname);
+    } while (!*plname && !iflags.defer_plname);
 
     /* commas in the plname confuse the record file, convert to spaces */
     for (sptr = plname; *sptr; sptr++) {
index a0d5552e28b8749738645d6ccc4445b739be9ca0..05d7e7304878c7d3e55c994c492901f42a73a1c1 100644 (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+= 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+=-DCOMPRESS=\"/bin/gzip\" -DCOMPRESS_EXTENSION=\".gz\"
 CFLAGS+=-DX11_GRAPHICS -DDEFAULT_WINDOW_SYS=\"X11\" -DNOTTYGRAPHICS
index 2e8f413302c769b7d7f60d21392285c8892f6f2f..b9ab44526be3daccb621e7c39a243158b08e980d 100644 (file)
@@ -55,6 +55,7 @@ char *argv[];
 #endif
     boolean exact_username;
     boolean resuming = FALSE; /* assume new game */
+    boolean plsel_once = FALSE;
 
     sys_early_init();
 
@@ -237,19 +238,6 @@ char *argv[];
         (void) signal(SIGQUIT, 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() */
 
@@ -266,7 +254,24 @@ char *argv[];
      * We'll return here if new game player_selection() renames the hero.
      */
 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);
 
         (void) chmod(fq_save, 0); /* disallow parallel restores */
@@ -297,12 +302,17 @@ attempt_restore:
     }
 
     if (!resuming) {
+        boolean neednewlock = (!*plname);
         /* new game:  start by choosing role, race, etc;
            player might change the hero's name while doing that,
            in which case we try to restore under the new name
            and skip selection this time if that didn't succeed */
-        if (!iflags.renameinprogress) {
-            player_selection();
+        if (!iflags.renameinprogress || iflags.defer_plname || neednewlock) {
+            if (!plsel_once)
+                player_selection();
+            plsel_once = TRUE;
+            if (neednewlock && *plname)
+                goto attempt_restore;
             if (iflags.renameinprogress) {
                 /* player has renamed the hero while selecting role;
                    if locking alphabetically, the existing lock file
index ff9b0ff51f239dfa6210c9216ab99945cf779c53..6b285a2e550ac901997a3bff20ad0faa4c2abae3 100644 (file)
@@ -1474,18 +1474,11 @@ X11_askname()
 {
     Widget popup, dialog;
     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) {
         /* X11_player_selection_dialog() handles name query */
         plsel_ask_name = TRUE;
+        iflags.defer_plname = TRUE;
         return;
     } /* else iflags.wc_player_selection == VIA_PROMPTS */
 
index 8ddb62a7956fa9a8ea7d50ca61359f9d787d7a7e..945e35fc47288e998812fdc7d21f5212fbe751be 100644 (file)
@@ -352,8 +352,13 @@ plsel_dialog_acceptvalues()
 
     XtSetArg(args[0], nhStr(XtNstring), &s);
     XtGetValues(plsel_name_input, args, ONE);
+
     (void) strncpy(plname, (char *) s, sizeof plname - 1);
     plname[sizeof plname - 1] = '\0';
+    (void) mungspaces(plname);
+    if (strlen(plname) < 1)
+        (void) strcpy(plname, "Mumbles");
+    iflags.renameinprogress = FALSE;
 }
 
 /* ARGSUSED */
@@ -1553,6 +1558,17 @@ void
 X11_player_selection()
 {
     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();
     } else { /* iflags.wc_player_selection == VIA_PROMPTS */
         X11_player_selection_prompts();