diff options
author | Patric Stout <truebrain@openttd.org> | 2021-01-02 20:34:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-02 20:34:55 +0100 |
commit | c288eba81389d07e27b32f28c6dc4dc518824d2b (patch) | |
tree | dc7eddb7a1078e780980adac8b1fa96da5b87b6f /src | |
parent | 46e13e7f0b5b52ad8cf75b42bbf41438adf0f0da (diff) | |
download | openttd-c288eba81389d07e27b32f28c6dc4dc518824d2b.tar.xz |
Fix: prevent clients making emergency saves twice if server disconnects (#8477)
This was clearly overlooked during the initial implementation.
Diffstat (limited to 'src')
-rw-r--r-- | src/network/network_client.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index a66786dad..e083e6c1a 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -211,15 +211,22 @@ void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus res) default: errorno = NETWORK_ERROR_GENERAL; break; } - /* This means we fucked up and the server closed the connection */ - if (res != NETWORK_RECV_STATUS_SERVER_ERROR && res != NETWORK_RECV_STATUS_SERVER_FULL && - res != NETWORK_RECV_STATUS_SERVER_BANNED) { + if (res == NETWORK_RECV_STATUS_SERVER_ERROR || res == NETWORK_RECV_STATUS_SERVER_FULL || + res == NETWORK_RECV_STATUS_SERVER_BANNED) { + /* This means the server closed the connection. Emergency save is + * already created if this was appropriate during handling of the + * disconnect. */ + this->CloseConnection(res); + } else { + /* This means we as client made a boo-boo. */ SendError(errorno); - } - this->CloseConnection(res); - - ClientNetworkEmergencySave(); + /* Close connection before we make an emergency save, as the save can + * take a bit of time; better that the server doesn't stall while we + * are doing the save, and already disconnects us. */ + this->CloseConnection(res); + ClientNetworkEmergencySave(); + } _switch_mode = SM_MENU; _networking = false; |