Ticket #2420: sendNetworkMessagesAtGameEnd_v1.patch

File sendNetworkMessagesAtGameEnd_v1.patch, 2.7 KB (added by Michael, 10 years ago)

Ends sending the messages for the current turn and flushs them when the game is ended.

  • source/network/NetClient.cpp

     
    147147    SAFE_DELETE(m_Session);
    148148}
    149149
     150void CNetClient::OnGameEnd()
     151{
     152    // send network messages of current frame before connection get's destroyed
     153    if (m_ClientTurnManager)
     154    {
     155        m_ClientTurnManager->OnDestroyConnection(); // end sending commands for scheduled turn
     156        Flush(); // make sure the messages are send
     157    }
     158}
     159
    150160void CNetClient::Poll()
    151161{
    152162    if (m_Session)
  • source/network/NetClient.h

     
    164164    void LoadFinished();
    165165
    166166    void SendChatMessage(const std::wstring& text);
     167   
     168    /**
     169     * sends the commands of the current turn to the server and tells the server that there will be no more messages in this turn.
     170     * should only be called once before the client disconnects
     171     * (putting this in destructor  is too late)
     172     */
     173    void OnGameEnd();
    167174
    168175private:
    169176    // Net message / FSM transition handlers
  • source/network/NetTurnManager.cpp

     
    419419    m_NetClient.SendMessage(&msg);
    420420}
    421421
     422void CNetClientTurnManager::OnDestroyConnection()
     423{
     424    NotifyFinishedOwnCommands(m_CurrentTurn + COMMAND_DELAY);
     425}
     426
    422427void CNetClientTurnManager::OnSimulationMessage(CSimulationMessage* msg)
    423428{
    424429    // Command received from the server - store it for later execution
  • source/network/NetTurnManager.h

     
    200200    virtual void OnSimulationMessage(CSimulationMessage* msg);
    201201
    202202    virtual void PostCommand(CScriptValRooted data);
     203   
     204    /**
     205     * notifiy the server that all commands for the scheduled turn are send before the connection is destroyed
     206     */
     207    void OnDestroyConnection();
    203208
    204209protected:
    205210    virtual void NotifyFinishedOwnCommands(u32 turn);
  • source/ps/GameSetup/GameSetup.cpp

     
    654654
    655655void EndGame()
    656656{
     657    // make sure that the messages last messages are sent
     658    if (g_NetClient)
     659        g_NetClient->OnGameEnd();
     660       
    657661    SAFE_DELETE(g_NetServer);
    658662    SAFE_DELETE(g_NetClient);
    659663    SAFE_DELETE(g_Game);