From: Holger Schemel Date: Sun, 18 Oct 2020 00:29:54 +0000 (+0200) Subject: added support for loading list of all user names X-Git-Tag: 4.2.1.0~46 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=5e30707f778ec0ce59045e9f19b0af45aa4cf693;p=rocksndiamonds.git added support for loading list of all user names --- diff --git a/src/files.c b/src/files.c index ed885a43..cb4e6d41 100644 --- a/src/files.c +++ b/src/files.c @@ -9657,6 +9657,43 @@ static void decodeSetupFileHash_EditorCascade(SetupFileHash *setup_file_hash) editor_cascade_setup_tokens[i].text)); } +void LoadUserNames(void) +{ + int last_user_nr = user.nr; + int i; + + if (global.user_names != NULL) + { + for (i = 0; i < MAX_PLAYER_NAMES; i++) + checked_free(global.user_names[i]); + + checked_free(global.user_names); + } + + global.user_names = checked_calloc(MAX_PLAYER_NAMES * sizeof(char *)); + + for (i = 0; i < MAX_PLAYER_NAMES; i++) + { + user.nr = i; + + SetupFileHash *setup_file_hash = loadSetupFileHash(getSetupFilename()); + + if (setup_file_hash) + { + char *player_name = getHashEntry(setup_file_hash, "player_name"); + + global.user_names[i] = get_corrected_login_name(player_name); + + freeSetupFileHash(setup_file_hash); + } + + if (global.user_names[i] == NULL) + global.user_names[i] = getStringCopy(EMPTY_PLAYER_NAME); + } + + user.nr = last_user_nr; +} + void LoadSetupFromFilename(char *filename) { SetupFileHash *setup_file_hash = loadSetupFileHash(filename); diff --git a/src/files.h b/src/files.h index bf0df60c..b82c89e5 100644 --- a/src/files.h +++ b/src/files.h @@ -61,6 +61,8 @@ boolean SaveTapeChecked_LevelSolved(int); void LoadScore(int); void SaveScore(int); +void LoadUserNames(void); + void LoadSetupFromFilename(char *); void LoadSetup(void); void SaveSetup(void); diff --git a/src/init.c b/src/init.c index 38142326..bae10aff 100644 --- a/src/init.c +++ b/src/init.c @@ -4912,6 +4912,8 @@ static void InitGlobal(void) global.anim_status = global.anim_status_next = GAME_MODE_LOADING; global.use_envelope_request = FALSE; + + global.user_names = NULL; } static void Execute_Command(char *command) @@ -5184,6 +5186,7 @@ static void Execute_Command(char *command) static void InitSetup(void) { + LoadUserNames(); // global user names LoadUserSetup(); // global user number LoadSetup(); // global setup info diff --git a/src/main.h b/src/main.h index f0e559a5..467b5d1b 100644 --- a/src/main.h +++ b/src/main.h @@ -3253,6 +3253,8 @@ struct GlobalInfo int anim_status_next; boolean use_envelope_request; + + char **user_names; }; struct ElementChangeInfo