From: Holger Schemel Date: Tue, 20 Oct 2020 22:37:43 +0000 (+0200) Subject: added function to get default player name X-Git-Tag: 4.2.1.0~16 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=7fd163f5a448c2f3a3ad1978a46ef3a84c6497b1;p=rocksndiamonds.git added function to get default player name --- 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 *);