Skip to content

Commit

Permalink
ADD: restore open windows when rejoining a networkgame
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11331 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
prissi committed Jul 8, 2024
1 parent 989fdc8 commit 0935b5f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions simutrans/history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
FIX: overflow in bits in private way sign could allow/deny unexpectant players
FIX: loading pak from savegame again (so only savegame needed on commandline)
CHG: Activate input field if chat is active or after sending message
ADD: restore open windows when rejoining a networkgame


Release of 124.1 (r11272 on 3-June-2024):
Expand Down
22 changes: 21 additions & 1 deletion src/simutrans/simmain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ int simu_main(int argc, char** argv)
}
}

if( scen == NULL && (loadgame=="" || !welt->load(loadgame.c_str())) ) {
if( scen == NULL && (loadgame=="" || !welt->load(loadgame.c_str())) ) {
// create a default map
DBG_MESSAGE("simu_main()", "Init with default map (failing will be a pak error!)");

Expand Down Expand Up @@ -1539,6 +1539,26 @@ int simu_main(int argc, char** argv)
}

tool_t::toolbar_tool[0]->init(welt->get_active_player());

if (env_t::networkmode) {
// try to restore windows
loadsave_t file;
std::string name("autosave-");
name.append(env_t::pak_name);
name.erase(name.length() - 1);
name.append(".net.sve");
dr_remove("temp-load.sve"); // we load under tempary name if there was a crash => no reloading next time
if (!dr_rename(name.c_str(),"temp-load.sve") && file.rd_open("temp-load.sve") == loadsave_t::FILE_STATUS_OK) {
uint8 pn;
intr_disable();
file.rdwr_byte(pn);
welt->switch_active_player(pn, true);
rdwr_all_win(&file);
intr_enable();
}
// rename back, so we could get the same windows after a desync (when using the commandline to join)
dr_rename( "temp-load.sve", name.c_str() );
}
}

welt->set_fast_forward(false);
Expand Down
3 changes: 2 additions & 1 deletion src/simutrans/sys/simsys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ int dr_rename(const char *existing_utf8, const char *new_utf8)
DWORD error = GetLastError();
if (error == ERROR_FILE_NOT_FOUND) {
errno = ENOENT;
} else if(error == ERROR_ACCESS_DENIED) {
}
else if(error == ERROR_ACCESS_DENIED) {
errno = EACCES;
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/simutrans/world/simworld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5676,6 +5676,17 @@ void karte_t::stop(bool exit_game)
FILE *f = dr_fopen(pak_name.c_str(), "w");
fputs(settings.get_filename(), f);
fclose(f);

// save windows
loadsave_t file;
pak_name.append(".sve");
if (file.wr_open(pak_name.c_str(), loadsave_t::autosave_mode, loadsave_t::autosave_level, env_t::pak_name.c_str(), SAVEGAME_VER_NR) == loadsave_t::FILE_STATUS_OK) {
// we could open for writing
file.rdwr_byte(active_player_nr);
// save all open windows
rdwr_all_win(&file);
}

}
else {
// save current game, if not online
Expand Down

0 comments on commit 0935b5f

Please sign in to comment.