Index: src/saveload.cpp =================================================================== --- src/saveload.cpp (revision 11498) +++ src/saveload.cpp (working copy) @@ -1595,6 +1595,9 @@ _next_offs = 0; + /* Perform Player Password Save/Load */ + SaveLoadPlayerPasswords(filename, mode); + /* Load a TTDLX or TTDPatch game */ if (mode == SL_OLD_LOAD) { InitializeGame(IG_DATE_RESET, 256, 256); // set a mapsize of 256x256 for TTDPatch games or it might get confused @@ -1744,6 +1747,55 @@ SaveOrLoad("exit.sav", SL_SAVE, AUTOSAVE_DIR); } +/** + * Function to save company passwords on Network Server + * @param filename The name of the savegame being created/loaded + * @param mode Save or load. true when Saving, false when Loading + */ +void SaveLoadPlayerPasswords(const char *filename, int mode) +{ + if(_network_server) { + char password_filename[MAX_PATH] = ""; + FILE *f; + char pass_string[NETWORK_PASSWORD_LENGTH * MAX_PLAYERS*2] = ""; + int index1 = 0; + + NetworkPopulateCompanyInfo(); + /*Create Filename for Saving Passwords to */ + ttd_strlcat(password_filename, filename, lengthof(password_filename)); + ttd_strlcat(password_filename, ".pw", lengthof(password_filename)); + + if(mode == SL_SAVE) { //Are We Saving?? + f = FioFOpenFile(password_filename, "wb", NO_DIRECTORY); + if (f) { + char pass_string[NETWORK_PASSWORD_LENGTH * MAX_PLAYERS*2] = ""; + int index2 = 0; + for (int i = 0; i != NETWORK_PASSWORD_LENGTH; i++) { + for(int j = 0; j != MAX_PLAYERS; j++) { + pass_string[index1++] = _network_player_info[j].password[i]; + pass_string[index1++] = filename[index2++]; + if (!filename[index2]) index2 = 0; + } + } + fwrite(pass_string, lengthof(pass_string), 1, f); + fclose(f); + } + } else if (mode == SL_LOAD){ // Or Loading?? + f = FioFOpenFile(password_filename, "rb", NO_DIRECTORY); + if (f) { + fread(pass_string, NETWORK_PASSWORD_LENGTH * MAX_PLAYERS*2, 1, f); + for (int i = 0; i != NETWORK_PASSWORD_LENGTH; i++) { + for(int j=0; j != MAX_PLAYERS; j++) { + _network_player_info[j].password[i] = pass_string[index1++]; + index1++; + } + } + fclose(f); + } + } + } +} + #if 0 /** * Function to get the type of the savegame by looking at the file header. Index: src/saveload.h =================================================================== --- src/saveload.h (revision 11498) +++ src/saveload.h (working copy) @@ -320,4 +320,6 @@ void SaveFileStart(); void SaveFileDone(); void SaveFileError(); + +void SaveLoadPlayerPasswords(const char *filename, int mode); #endif /* SAVELOAD_H */