From 43730f15f3549ab38f51d667a5db416506674bf2 Mon Sep 17 00:00:00 2001 From: elexis Date: Tue, 5 Jun 2018 14:52:41 +0000 Subject: [PATCH] Fix network FSM errors when a client closes the game during the loading screen or rejoin synchronization stage, fixes #4594, refs 3199. Fix comments claiming to ensure reliability when in reality there is only a small likelihood of the message being received. Broken by fa85527baf / refs #2420 which was a preparation for a3e1c68b9a / refs #2373, which hence didn't actually work and was circumvented by 9b136a45fc without clarification. Might have caused #3643. Differential Revision: https://code.wildfiregames.com/D1557 Reviewed By: Imarok This was SVN commit r21837. --- source/network/NetClient.cpp | 6 +++--- source/network/NetClientTurnManager.cpp | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/source/network/NetClient.cpp b/source/network/NetClient.cpp index eb7802a371..1ce1e541be 100644 --- a/source/network/NetClient.cpp +++ b/source/network/NetClient.cpp @@ -181,11 +181,11 @@ void CNetClient::SetAndOwnSession(CNetClientSession* session) void CNetClient::DestroyConnection() { - // Send network messages from the current frame before connection is destroyed. + // Attempt to send network messages from the current frame before connection is destroyed. if (m_ClientTurnManager) { - m_ClientTurnManager->OnDestroyConnection(); // End sending of commands for scheduled turn. - Flush(); // Make sure the messages are sent. + m_ClientTurnManager->OnDestroyConnection(); + Flush(); } SAFE_DELETE(m_Session); } diff --git a/source/network/NetClientTurnManager.cpp b/source/network/NetClientTurnManager.cpp index 58bd507b1a..d94c75fc4f 100644 --- a/source/network/NetClientTurnManager.cpp +++ b/source/network/NetClientTurnManager.cpp @@ -95,7 +95,10 @@ void CNetClientTurnManager::NotifyFinishedUpdate(u32 turn) void CNetClientTurnManager::OnDestroyConnection() { - NotifyFinishedOwnCommands(m_CurrentTurn + COMMAND_DELAY); + // Attempt to flush messages before leaving. + // Notice the sending is not reliable and rarely makes it to the Server. + if (m_NetClient.GetCurrState() == NCS_INGAME) + NotifyFinishedOwnCommands(m_CurrentTurn + COMMAND_DELAY); } void CNetClientTurnManager::OnSimulationMessage(CSimulationMessage* msg)