Avoid performing emergency network save more than once
This commit is contained in:
@@ -136,6 +136,7 @@ void ClientNetworkEmergencySave()
|
|||||||
{
|
{
|
||||||
if (!_settings_client.gui.autosave_on_network_disconnect) return;
|
if (!_settings_client.gui.autosave_on_network_disconnect) return;
|
||||||
if (!_networking) return;
|
if (!_networking) return;
|
||||||
|
if (!ClientNetworkGameSocketHandler::EmergencySavePossible()) return;
|
||||||
|
|
||||||
const char *filename = "netsave.sav";
|
const char *filename = "netsave.sav";
|
||||||
DEBUG(net, 0, "Client: Performing emergency save (%s)", filename);
|
DEBUG(net, 0, "Client: Performing emergency save (%s)", filename);
|
||||||
@@ -344,6 +345,14 @@ void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus res)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */ bool ClientNetworkGameSocketHandler::EmergencySavePossible()
|
||||||
|
{
|
||||||
|
if (!my_client) return false;
|
||||||
|
if (my_client->emergency_save_done) return false;
|
||||||
|
my_client->emergency_save_done = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Our client's connection. */
|
/** Our client's connection. */
|
||||||
ClientNetworkGameSocketHandler * ClientNetworkGameSocketHandler::my_client = nullptr;
|
ClientNetworkGameSocketHandler * ClientNetworkGameSocketHandler::my_client = nullptr;
|
||||||
|
@@ -40,6 +40,7 @@ private:
|
|||||||
|
|
||||||
FILE *desync_log_file = nullptr;
|
FILE *desync_log_file = nullptr;
|
||||||
std::string server_desync_log;
|
std::string server_desync_log;
|
||||||
|
bool emergency_save_done = false;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend void NetworkExecuteLocalCommandQueue();
|
friend void NetworkExecuteLocalCommandQueue();
|
||||||
@@ -111,6 +112,8 @@ public:
|
|||||||
static void Send();
|
static void Send();
|
||||||
static bool Receive();
|
static bool Receive();
|
||||||
static bool GameLoop();
|
static bool GameLoop();
|
||||||
|
|
||||||
|
static bool EmergencySavePossible();
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Helper to make the code look somewhat nicer. */
|
/** Helper to make the code look somewhat nicer. */
|
||||||
|
Reference in New Issue
Block a user