renamed and moved function to sanitize player name
[rocksndiamonds.git] / src / libgame / misc.c
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;