Show failure reason in message box when network savegame load fails

See: #412
This commit is contained in:
Jonathan G Rennison
2022-08-27 22:34:28 +01:00
parent edd8b29794
commit 7c78b22c48
3 changed files with 17 additions and 5 deletions

View File

@@ -646,7 +646,8 @@ bool ClientNetworkGameSocketHandler::IsConnected()
* DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p
************/
extern bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = nullptr);
extern bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir,
struct LoadFilter *lf = nullptr, std::string *error_detail = nullptr);
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p)
{
@@ -941,14 +942,20 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
/* The map is done downloading, load it */
ClearErrorMessages();
bool load_success = SafeLoad({}, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, lf);
std::string error_detail;
bool load_success = SafeLoad({}, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, lf, &error_detail);
/* Long savegame loads shouldn't affect the lag calculation! */
this->last_packet = std::chrono::steady_clock::now();
if (!load_success) {
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
ShowErrorMessage(STR_NETWORK_ERROR_SAVEGAMEERROR, INVALID_STRING_ID, WL_CRITICAL);
StringID detail = INVALID_STRING_ID;
if (!error_detail.empty()) {
detail = STR_JUST_RAW_STRING;
SetDParamStr(0, error_detail.c_str());
}
ShowErrorMessage(STR_NETWORK_ERROR_SAVEGAMEERROR, detail, WL_CRITICAL);
return NETWORK_RECV_STATUS_SAVEGAME;
}
/* If the savegame has successfully loaded, ALL windows have been removed,