Ticket #3643: defuse_v2.patch

File defuse_v2.patch, 4.5 KB (added by elexis, 8 years ago)

Not tested yet with the destroy-patch

  • source/network/NetServer.cpp

    bool CNetServerWorker::OnInGame(void* co  
    10641064        // TODO: we shouldn't send the message back to the client that first sent it
    10651065    }
    10661066    else if (message->GetType() == (uint)NMT_SYNC_CHECK)
    10671067    {
    10681068        CSyncCheckMessage* syncMessage = static_cast<CSyncCheckMessage*> (message);
    1069         server.m_ServerTurnManager->NotifyFinishedClientUpdate(session->GetHostID(), session->GetUserName(), syncMessage->m_Turn, syncMessage->m_Hash);
     1069        server.m_ServerTurnManager->NotifyFinishedClientUpdate(session, syncMessage->m_Turn, syncMessage->m_Hash);
    10701070    }
    10711071    else if (message->GetType() == (uint)NMT_END_COMMAND_BATCH)
    10721072    {
    10731073        CEndCommandBatchMessage* endMessage = static_cast<CEndCommandBatchMessage*> (message);
    1074         server.m_ServerTurnManager->NotifyFinishedClientCommands(session->GetHostID(), endMessage->m_Turn);
     1074        server.m_ServerTurnManager->NotifyFinishedClientCommands(session, endMessage->m_Turn);
    10751075    }
    10761076
    10771077    return true;
    10781078}
    10791079
  • source/network/NetTurnManager.cpp

    CNetServerTurnManager::CNetServerTurnMan  
    582582    // so store dummy values into the saved lengths list
    583583    m_SavedTurnLengths.push_back(0);
    584584    m_SavedTurnLengths.push_back(0);
    585585}
    586586
    587 void CNetServerTurnManager::NotifyFinishedClientCommands(int client, u32 turn)
     587void CNetServerTurnManager::NotifyFinishedClientCommands(CNetServerSession* session, u32 turn)
    588588{
     589    int client = session->GetHostID();
     590
    589591    NETTURN_LOG((L"NotifyFinishedClientCommands(client=%d, turn=%d)\n", client, turn));
    590592
    591593    // Must be a client we've already heard of
    592594    ENSURE(m_ClientsReady.find(client) != m_ClientsReady.end());
    593595
    594596    // Clients must advance one turn at a time
    595     ENSURE(turn == m_ClientsReady[client] + 1);
     597    if (turn != m_ClientsSimulated[client] + 1)
     598    {
     599        LOGERROR("NotifyFinishedClientCommands: Client %d (%s) is ready for turn %d, but expected %d",
     600            client,
     601            utf8_from_wstring(session->GetUserName()).c_str(),
     602            turn,
     603            m_ClientsReady[client] + 1
     604        );
     605
     606        session->Disconnect(NDR_UNKNOWN);
     607    }
     608
    596609    m_ClientsReady[client] = turn;
    597610
    598611    // Check whether this was the final client to become ready
    599612    CheckClientsReady();
    600613}
    void CNetServerTurnManager::CheckClients  
    623636    // Save the turn length in case it's needed later
    624637    ENSURE(m_SavedTurnLengths.size() == m_ReadyTurn);
    625638    m_SavedTurnLengths.push_back(m_TurnLength);
    626639}
    627640
    628 void CNetServerTurnManager::NotifyFinishedClientUpdate(int client, const CStrW& playername, u32 turn, const CStr& hash)
     641void CNetServerTurnManager::NotifyFinishedClientUpdate(CNetServerSession* session, u32 turn, const CStr& hash)
    629642{
     643
     644    int client = session->GetHostID();
     645    const CStrW& playername = session->GetUserName();
     646
    630647    // Clients must advance one turn at a time
    631     ENSURE(turn == m_ClientsSimulated[client] + 1);
     648    if (turn != m_ClientsSimulated[client] + 1)
     649    {
     650        LOGERROR("NotifyFinishedClientUpdate: Client %d (%s) is ready for turn %d, but expected %d",
     651            client,
     652            utf8_from_wstring(playername).c_str(),
     653            turn,
     654            m_ClientsReady[client] + 1
     655        );
     656
     657        session->Disconnect(NDR_UNKNOWN);
     658    }
     659
    632660    m_ClientsSimulated[client] = turn;
    633661
    634662    // Check for OOS only if in sync
    635663    if (m_HasSyncError)
    636664        return;
  • source/network/NetTurnManager.h

     
    1919#define INCLUDED_NETTURNMANAGER
    2020
    2121#include "simulation2/helpers/SimulationCommand.h"
    2222#include "lib/os_path.h"
    2323#include "NetMessage.h"
     24#include "NetSession.h"
    2425
    2526#include <list>
    2627#include <map>
    2728#include <vector>
    2829
    class CNetServerTurnManager  
    292293{
    293294    NONCOPYABLE(CNetServerTurnManager);
    294295public:
    295296    CNetServerTurnManager(CNetServerWorker& server);
    296297
    297     void NotifyFinishedClientCommands(int client, u32 turn);
     298    void NotifyFinishedClientCommands(CNetServerSession* session, u32 turn);
    298299
    299     void NotifyFinishedClientUpdate(int client, const CStrW& playername, u32 turn, const CStr& hash);
     300    void NotifyFinishedClientUpdate(CNetServerSession* session, u32 turn, const CStr& hash);
    300301
    301302    /**
    302303     * Inform the turn manager of a new client who will be sending commands.
    303304     */
    304305    void InitialiseClient(int client, u32 turn);