diff --git a/source/network/NetClient.cpp b/source/network/NetClient.cpp index 39dffbae25..6dc208c82f 100644 --- a/source/network/NetClient.cpp +++ b/source/network/NetClient.cpp @@ -144,6 +144,12 @@ void CNetClient::SetAndOwnSession(CNetClientSession* session) void CNetClient::DestroyConnection() { + // 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. + } SAFE_DELETE(m_Session); } diff --git a/source/network/NetTurnManager.cpp b/source/network/NetTurnManager.cpp index a61da4c1bc..70059ecb5c 100644 --- a/source/network/NetTurnManager.cpp +++ b/source/network/NetTurnManager.cpp @@ -419,6 +419,11 @@ void CNetClientTurnManager::NotifyFinishedUpdate(u32 turn) m_NetClient.SendMessage(&msg); } +void CNetClientTurnManager::OnDestroyConnection() +{ + NotifyFinishedOwnCommands(m_CurrentTurn + COMMAND_DELAY); +} + void CNetClientTurnManager::OnSimulationMessage(CSimulationMessage* msg) { // Command received from the server - store it for later execution diff --git a/source/network/NetTurnManager.h b/source/network/NetTurnManager.h index 54805d2088..efe8a2e9f8 100644 --- a/source/network/NetTurnManager.h +++ b/source/network/NetTurnManager.h @@ -200,6 +200,11 @@ public: virtual void OnSimulationMessage(CSimulationMessage* msg); virtual void PostCommand(CScriptValRooted data); + + /** + * Notifiy the server that all commands are sent to prepare the connection for termination. + */ + void OnDestroyConnection(); protected: virtual void NotifyFinishedOwnCommands(u32 turn); diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index ad2f8cf8f1..2ef91ad55a 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -654,8 +654,8 @@ static void ShutdownSDL() void EndGame() { - SAFE_DELETE(g_NetServer); SAFE_DELETE(g_NetClient); + SAFE_DELETE(g_NetServer); SAFE_DELETE(g_Game); ISoundManager::CloseGame();