changeset 112:ee250e3646fd

Don't truncate player name in savefile name or log message. The player name is stored in whoami[], which is length 80 in most games (1024 in rogue5). Only the first 10 chars were used to create file_name, because that buffer is the same length. Increasing the size of file_name to 256 permits using all of whoami. The name is also no longer truncated to 20 chars when writing the log. All games should now be able to handle 79-character names without collisions. Anything more would break save compatibility.
author John "Elwin" Edwards
date Sun, 23 Mar 2014 21:27:14 -0700
parents 7f8f43943b1f
children aa582a02eb5d
files arogue5/main.c arogue5/rip.c arogue5/rogue.c rogue3/init.c rogue3/main.c rogue3/rip.c rogue3/rogue.h rogue4/extern.c rogue4/main.c rogue4/rip.c rogue4/save.c rogue5/main.c rogue5/rip.c srogue/global.c srogue/main.c srogue/rip.c
diffstat 16 files changed, 23 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/arogue5/main.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/arogue5/main.c	Sun Mar 23 21:27:14 2014 -0700
@@ -64,8 +64,8 @@
         use_savedir = TRUE;
         strncpy(whoami, argv[2], LINELEN);
         whoami[LINELEN - 1] = '\0';
-        if (snprintf(file_name, LINELEN, "%s/%d-%.10s.ar5sav", SAVEDIR, 
-                     md_getuid(), whoami) >= LINELEN)
+        if (snprintf(file_name, 256, "%s/%d-%s.ar5sav", SAVEDIR, 
+                     md_getuid(), whoami) >= 256)
         {
             /* The name is too long */
             use_savedir = FALSE;
--- a/arogue5/rip.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/arogue5/rip.c	Sun Mar 23 21:27:14 2014 -0700
@@ -614,7 +614,7 @@
     perror(LOGFILE);
     return;
   }
-  fprintf(logfi, "%d %d %.20s %d %s %d %d %d %c %s\n", time(NULL), amount, 
+  fprintf(logfi, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount, 
           whoami, pstats.s_lvl, class, level, max_level, quest_item, had_quest, 
           fate);
   fclose(logfi);
--- a/arogue5/rogue.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/arogue5/rogue.c	Sun Mar 23 21:27:14 2014 -0700
@@ -84,7 +84,7 @@
 char *ws_guess[MAXSTICKS];		/* Players guess at what wand is */
 char *m_guess[MAXMM];			/* Players guess at what MM is */
 char *ws_type[MAXSTICKS];		/* Is it a wand or a staff */
-char file_name[LINELEN];		/* Save file name */
+char file_name[256];			/* Save file name */
 char score_file[LINELEN];		/* Score file name */
 char home[LINELEN];			/* User's home directory */
 WINDOW *cw;				/* Window that the player sees */
--- a/rogue3/init.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/rogue3/init.c	Sun Mar 23 21:27:14 2014 -0700
@@ -63,7 +63,7 @@
 char *r_guess[MAXRINGS];         /* Players guess at what ring is */
 char *ws_guess[MAXSTICKS];               /* Players guess at what wand is */
 char *ws_type[MAXSTICKS];                /* Is it a wand or a staff */
-char file_name[80];                      /* Save file name */
+char file_name[256];                      /* Save file name */
 char home[PATH_MAX];                     /* User's home directory */
 unsigned char prbuf[80];                 /* Buffer for sprintfs */
 int max_hp;                              /* Player's max hit points */
--- a/rogue3/main.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/rogue3/main.c	Sun Mar 23 21:27:14 2014 -0700
@@ -71,7 +71,7 @@
         whoami[79] = '\0';
         use_savedir = TRUE;
         /* look for savefile at SAVEDIR/UID-playername.r3sav */
-        if (snprintf(file_name, 80, "%s/%d-%.10s.r3sav", SAVEDIR, md_getuid(), whoami) >= 80)
+        if (snprintf(file_name, 256, "%s/%d-%s.r3sav", SAVEDIR, md_getuid(), whoami) >= 256)
         {
             /* this shouldn't happen */
             strcpy(file_name, "rogue3.save");
--- a/rogue3/rip.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/rogue3/rip.c	Sun Mar 23 21:27:14 2014 -0700
@@ -308,13 +308,13 @@
 
 void writelog(int amount, int flags, int monst)
 {
-    char logmessage[160], ltemp[80];
+    char logmessage[220], ltemp[80];
     char *killer;
     
     if (waswizard)
         return;
 #ifdef LOGFILE
-    sprintf(logmessage, "%d %d %.20s %d ", time(NULL), amount, whoami, 
+    sprintf(logmessage, "%d %d %s %d ", time(NULL), amount, whoami, 
             pstats.s_lvl);
     if (flags == 0) /* died */
     {
--- a/rogue3/rogue.h	Wed Jan 08 16:44:16 2014 -0500
+++ b/rogue3/rogue.h	Sun Mar 23 21:27:14 2014 -0700
@@ -428,7 +428,7 @@
 extern int                   door_stop;			/* Stop running when we pass a door */
 extern struct delayed_action d_list[20];
 extern int                   fight_flush;		/* True if toilet input */
-extern char                  file_name[80];		/* Save file name */
+extern char                  file_name[256];		/* Save file name */
 extern int                   firstmove;			/* First move after setting door_stop */
 extern int                   food_left;			/* Amount of food in hero's stomach */
 extern char                  fruit[80];			/* Favorite fruit */
--- a/rogue4/extern.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/rogue4/extern.c	Sun Mar 23 21:27:14 2014 -0700
@@ -77,7 +77,7 @@
 char *r_guess[MAXRINGS];		/* Players guess at what ring is */
 char *ws_guess[MAXSTICKS];		/* Players guess at what wand is */
 char *ws_type[MAXSTICKS];		/* Is it a wand or a staff */
-char file_name[MAXSTR];			/* Save file name */
+char file_name[256];			/* Save file name */
 char home[MAXSTR];			/* User's home directory */
 char _level[MAXLINES*MAXCOLS];		/* Level map */
 char _flags[MAXLINES*MAXCOLS];		/* Flags for each space on the map */
--- a/rogue4/main.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/rogue4/main.c	Sun Mar 23 21:27:14 2014 -0700
@@ -78,8 +78,8 @@
         whoami[MAXSTR - 1] = '\0'; /* insurance */
         use_savedir = TRUE;
         /* look for savefile at SAVEDIR/UID-playername.r4sav */
-        if (snprintf(file_name, MAXSTR, "%s/%d-%.10s.r4sav", SAVEDIR, 
-            md_getuid(), whoami) >= MAXSTR)
+        if (snprintf(file_name, 256, "%s/%d-%s.r4sav", SAVEDIR, 
+            md_getuid(), whoami) >= 256)
         {
             /* Name is too long- this shouldn't happen */
             strcpy(file_name, "rogue4.save");
--- a/rogue4/rip.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/rogue4/rip.c	Sun Mar 23 21:27:14 2014 -0700
@@ -239,7 +239,7 @@
 void writelog(int amount, int flags, char monst)
 {
     FILE *logfi;
-    char logmessage[160], ltemp[80];
+    char logmessage[220], ltemp[80];
     char *killer;
     if (noscore)
         return;
@@ -251,7 +251,7 @@
     if (logfi == NULL)
         return;
     /* otherwise writing should work */
-    sprintf(logmessage, "%d %d %.20s %d ", time(NULL), amount, whoami, 
+    sprintf(logmessage, "%d %d %s %d ", time(NULL), amount, whoami, 
             pstats.s_lvl);
     if (flags == 0) /* died */
     {
--- a/rogue4/save.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/rogue4/save.c	Sun Mar 23 21:27:14 2014 -0700
@@ -37,7 +37,7 @@
 {
     register FILE *savef;
     register int c;
-    char buf[MAXSTR];
+    char buf[256];
 
     /*
      * get file name
--- a/rogue5/main.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/rogue5/main.c	Sun Mar 23 21:27:14 2014 -0700
@@ -49,7 +49,7 @@
         use_savedir = TRUE;
         strncpy(whoami, argv[2], MAXSTR);
         whoami[MAXSTR-1] = '\0';
-        snprintf(file_name, MAXSTR, "%s/%d-%.10s.r5sav", SAVEDIR, 
+        snprintf(file_name, MAXSTR, "%s/%d-%.80s.r5sav", SAVEDIR, 
                  md_getuid(), whoami);
     }
 #endif
--- a/rogue5/rip.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/rogue5/rip.c	Sun Mar 23 21:27:14 2014 -0700
@@ -226,7 +226,7 @@
 void writelog(int amount, int flags, int monst)
 {
 #ifdef LOGFILE
-    char logmessage[160], ltemp[80];
+    char logmessage[220], ltemp[80];
 
     if (logfi == NULL)
         return;
@@ -237,7 +237,7 @@
         return;
     }
 #endif
-    sprintf(logmessage, "%d %d %.20s %d ", time(NULL), amount, whoami, 
+    sprintf(logmessage, "%d %d %.80s %d ", time(NULL), amount, whoami, 
             pstats.s_lvl);
     if (flags == 0) /* dead */
     {
--- a/srogue/global.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/srogue/global.c	Sun Mar 23 21:27:14 2014 -0700
@@ -62,7 +62,7 @@
 char whoami[LINLEN];		/* Name of player */
 char fruit[LINLEN];			/* Favorite fruit */
 char huh[LINLEN];			/* The last message printed */
-char file_name[LINLEN];		/* Save file name */
+char file_name[256];		/* Save file name */
 char scorefile[LINLEN];		/* place for scorefile */
 char home[LINLEN];			/* User's home directory */
 char outbuf[BUFSIZ];		/* Output buffer for stdout */
--- a/srogue/main.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/srogue/main.c	Sun Mar 23 21:27:14 2014 -0700
@@ -119,8 +119,8 @@
 		strncpy(whoami, argv[2], LINLEN);
 		whoami[LINLEN - 1] = '\0';
 		use_savedir = TRUE;
-		if (snprintf(file_name, LINLEN, "%s/%d-%.10s.srsav", SAVEDIR, 
-			playuid, whoami) >= LINLEN) {
+		if (snprintf(file_name, 256, "%s/%d-%s.srsav", SAVEDIR, 
+			playuid, whoami) >= 256) {
 			/* Just in case it doesn't fit */
 			strcpy(file_name, "srogue.save");
 			use_savedir = FALSE;
--- a/srogue/rip.c	Wed Jan 08 16:44:16 2014 -0500
+++ b/srogue/rip.c	Sun Mar 23 21:27:14 2014 -0700
@@ -223,14 +223,14 @@
 
 void writelog(int amount, int aflag, char monst)
 {
-	char logmessage[160], ltemp[80], mlev[40];
+	char logmessage[220], ltemp[80], mlev[40];
 	char *killer;
 	FILE *logfi;
 
 	if (waswizard)
 		return;
 #ifdef LOGFILE
-	sprintf(logmessage, "%d %d %.20s %d ", time(NULL), amount, whoami,
+	sprintf(logmessage, "%d %d %s %d ", time(NULL), amount, whoami,
 		him->s_lvl);
 	if (amulet)
 		sprintf(mlev, " [max %d] with the Amulet", max_level);