From 7fd163f5a448c2f3a3ad1978a46ef3a84c6497b1 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 21 Oct 2020 00:37:43 +0200 Subject: [PATCH] added function to get default player name --- src/files.c | 3 +-- src/libgame/misc.c | 15 +++++++++++++++ src/libgame/misc.h | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/files.c b/src/files.c index 8cb6ec6e..bb08277e 100644 --- a/src/files.c +++ b/src/files.c @@ -9177,10 +9177,9 @@ static struct TokenInfo options_setup_tokens[] = static void setSetupInfoToDefaults(struct SetupInfo *si) { - char *player_name = (user.nr == 0 ? getLoginName() : EMPTY_PLAYER_NAME); int i; - si->player_name = getFixedUserName(player_name); + si->player_name = getStringCopy(getDefaultUserName(user.nr)); si->multiple_users = TRUE; diff --git a/src/libgame/misc.c b/src/libgame/misc.c index a6bef9b8..d3ce6940 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -903,6 +903,21 @@ char *getFixedUserName(char *name) return name_new; } +char *getDefaultUserName(int nr) +{ + static char *user_name[MAX_PLAYER_NAMES] = { NULL }; + + nr = MIN(MAX(0, nr), MAX_PLAYER_NAMES - 1); + + if (user_name[nr] == NULL) + { + user_name[nr] = (nr == 0 ? getLoginName() : EMPTY_PLAYER_NAME); + user_name[nr] = getFixedUserName(user_name[nr]); + } + + return user_name[nr]; +} + time_t getFileTimestampEpochSeconds(char *filename) { struct stat file_status; diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 159b393a..e48d21ef 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -144,6 +144,7 @@ char *getUnixHomeDir(void); char *getLoginName(void); char *getRealName(void); char *getFixedUserName(char *); +char *getDefaultUserName(int); time_t getFileTimestampEpochSeconds(char *); -- 2.34.1