renamed and moved function to sanitize player name
authorHolger Schemel <info@artsoft.org>
Tue, 20 Oct 2020 22:34:16 +0000 (00:34 +0200)
committerHolger Schemel <info@artsoft.org>
Sun, 13 Dec 2020 23:57:59 +0000 (00:57 +0100)
src/files.c
src/libgame/misc.c
src/libgame/misc.h

index 0a674b4ce7ac2441415f211f113d2882f0559ec3..8cb6ec6e3bb879214a56dccee9813f17db73645b 100644 (file)
@@ -9175,27 +9175,12 @@ static struct TokenInfo options_setup_tokens[] =
   },
 };
 
-static char *get_corrected_player_name(char *login_name)
-{
-  // needed because player name must be a fixed length string
-  char *login_name_new = checked_malloc(MAX_PLAYER_NAME_LEN + 1);
-
-  strncpy(login_name_new, login_name, MAX_PLAYER_NAME_LEN);
-  login_name_new[MAX_PLAYER_NAME_LEN] = '\0';
-
-  if (strlen(login_name) > MAX_PLAYER_NAME_LEN)                // name has been cut
-    if (strchr(login_name_new, ' '))
-      *strchr(login_name_new, ' ') = '\0';
-
-  return login_name_new;
-}
-
 static void setSetupInfoToDefaults(struct SetupInfo *si)
 {
   char *player_name = (user.nr == 0 ? getLoginName() : EMPTY_PLAYER_NAME);
   int i;
 
-  si->player_name = get_corrected_player_name(player_name);
+  si->player_name = getFixedUserName(player_name);
 
   si->multiple_users = TRUE;
 
@@ -9683,7 +9668,7 @@ void LoadUserNames(void)
     {
       char *player_name = getHashEntry(setup_file_hash, "player_name");
 
-      global.user_names[i] = get_corrected_player_name(player_name);
+      global.user_names[i] = getFixedUserName(player_name);
 
       freeSetupFileHash(setup_file_hash);
     }
@@ -9716,7 +9701,7 @@ static void LoadSetup_SpecialPostProcessing(void)
   char *player_name_new;
 
   // needed to work around problems with fixed length strings
-  player_name_new = get_corrected_player_name(setup.player_name);
+  player_name_new = getFixedUserName(setup.player_name);
   free(setup.player_name);
   setup.player_name = player_name_new;
 
index 217895c035dfddb4b9adb8e46f9cb62b8bcd040c..a6bef9b878af3869cedb0d7272927584606c7093 100644 (file)
@@ -888,6 +888,21 @@ char *getRealName(void)
   return real_name;
 }
 
+char *getFixedUserName(char *name)
+{
+  // needed because player name must be a fixed length string
+  char *name_new = checked_malloc(MAX_PLAYER_NAME_LEN + 1);
+
+  strncpy(name_new, name, MAX_PLAYER_NAME_LEN);
+  name_new[MAX_PLAYER_NAME_LEN] = '\0';
+
+  if (strlen(name) > MAX_PLAYER_NAME_LEN)              // name has been cut
+    if (strchr(name_new, ' '))
+      *strchr(name_new, ' ') = '\0';
+
+  return name_new;
+}
+
 time_t getFileTimestampEpochSeconds(char *filename)
 {
   struct stat file_status;
index 5d6084f13e04b33f1792ad23700e21cdb4927e48..159b393a27d0fdb9041c273a04aa5c56997f9d0d 100644 (file)
@@ -143,6 +143,7 @@ char *getUnixHomeDir(void);
 
 char *getLoginName(void);
 char *getRealName(void);
+char *getFixedUserName(char *);
 
 time_t getFileTimestampEpochSeconds(char *);