summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-02-11 23:20:35 +0000
committerrubidium <rubidium@openttd.org>2011-02-11 23:20:35 +0000
commitd8cada7563228809936c0a2b21c5c098848636eb (patch)
tree333bca95298c90933452c0036a4d09c5e832cd58 /src
parent1dc5ba22105bc12ab13e79f3a8a22952d82f7c8e (diff)
downloadopenttd-d8cada7563228809936c0a2b21c5c098848636eb.tar.xz
(svn r22064) -Fix [FS#4497] (r21399): crash when disconnecting and reconnecting while the server is still saving the savegame
Diffstat (limited to 'src')
-rw-r--r--src/network/network_server.cpp11
-rw-r--r--src/saveload/saveload.cpp15
2 files changed, 19 insertions, 7 deletions
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index be27d75a6..ffd295008 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -69,7 +69,6 @@ struct PacketWriter : SaveFilter {
/** Make sure everything is cleaned up. */
~PacketWriter()
{
-
/* Prevent double frees. */
if (this->cs != NULL) {
if (this->cs->savegame_mutex != NULL) this->cs->savegame_mutex->BeginCritical();
@@ -99,7 +98,8 @@ struct PacketWriter : SaveFilter {
/* virtual */ void Write(byte *buf, size_t size)
{
- if (this->cs == NULL) return;
+ /* We want to abort the saving when the socket is closed. */
+ if (this->cs == NULL) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
if (this->current == NULL) this->current = new Packet(PACKET_SERVER_MAP_DATA);
@@ -125,7 +125,8 @@ struct PacketWriter : SaveFilter {
/* virtual */ void Finish()
{
- if (this->cs == NULL) return;
+ /* We want to abort the saving when the socket is closed. */
+ if (this->cs == NULL) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
if (this->cs->savegame_mutex != NULL) this->cs->savegame_mutex->BeginCritical();
@@ -181,6 +182,10 @@ ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler()
if (this->savegame != NULL) this->savegame->cs = NULL;
if (this->savegame_mutex != NULL) this->savegame_mutex->EndCritical();
+
+ /* Make sure the saving is completely cancelled. */
+ if (this->savegame != NULL) WaitTillSaved();
+
delete this->savegame_mutex;
}
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 62c0ff9f5..bff6b05d7 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -2382,13 +2382,20 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded)
} catch (...) {
ClearSaveLoadState();
- /* Skip the "colour" character */
- DEBUG(sl, 0, "%s", GetSaveLoadErrorString() + 3);
+ AsyncSaveFinishProc asfp = SaveFileDone;
+
+ /* We don't want to shout when saving is just
+ * cancelled due to a client disconnecting. */
+ if (_sl.error_str != STR_NETWORK_ERROR_LOSTCONNECTION) {
+ /* Skip the "colour" character */
+ DEBUG(sl, 0, "%s", GetSaveLoadErrorString() + 3);
+ asfp = SaveFileError;
+ }
if (threaded) {
- SetAsyncSaveFinish(SaveFileError);
+ SetAsyncSaveFinish(asfp);
} else {
- SaveFileError();
+ asfp();
}
return SL_ERROR;
}