added support for loading list of all user names
authorHolger Schemel <info@artsoft.org>
Sun, 18 Oct 2020 00:29:54 +0000 (02:29 +0200)
committerHolger Schemel <info@artsoft.org>
Sun, 13 Dec 2020 23:57:57 +0000 (00:57 +0100)
src/files.c
src/files.h
src/init.c
src/main.h

index ed885a434bbbaaf99cb00e41d8cb93f5d27dda6d..cb4e6d41820b938085efb01810ef0fd4f6e42362 100644 (file)
@@ -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);
index bf0df60cc16ac199ce641647ca8f2f7d8db4c88c..b82c89e5c7c4c42d0ccb9c989cc75d51638fdb97 100644 (file)
@@ -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);
index 381423265f235032ec96b0415628845eb0c30928..bae10aff54191ef28f82dba28b61dd6c8ea1892c 100644 (file)
@@ -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
index f0e559a5f280c1d652daf6aa7df12b6825bfc5e3..467b5d1b9503c11d9b55a54fb1d8ac8d7e67eca9 100644 (file)
@@ -3253,6 +3253,8 @@ struct GlobalInfo
   int anim_status_next;
 
   boolean use_envelope_request;
+
+  char **user_names;
 };
 
 struct ElementChangeInfo