Send messages in queue before closing connection, patch by boeseRaupe. Fixes #2420

This was SVN commit r14732.
This commit is contained in:
JoshuaJB 2014-02-05 02:44:25 +00:00
parent 035078c317
commit fa85527baf
4 changed files with 17 additions and 1 deletions

View file

@ -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);
}

View file

@ -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

View file

@ -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);

View file

@ -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();