Ticket #3552: t3552_prevent_commands_for_others_in_rated_games_v1.patch

File t3552_prevent_commands_for_others_in_rated_games_v1.patch, 1.6 KB (added by elexis, 4 years ago)
  • source/network/NetServer.cpp

     
    2424#include "NetSession.h"
    2525#include "NetStats.h"
    2626#include "NetTurnManager.h"
    2727
    2828#include "lib/external_libraries/enet.h"
     29#include "lobby/IXmppClient.h"
    2930#include "ps/CLogger.h"
    3031#include "ps/ConfigDB.h"
    3132#include "scriptinterface/ScriptInterface.h"
    3233#include "scriptinterface/ScriptRuntime.h"
    3334#include "simulation2/Simulation2.h"
    bool CNetServerWorker::OnInGame(void* co 
    881882    CNetMessage* message = (CNetMessage*)event->GetParamRef();
    882883    if (message->GetType() == (uint)NMT_SIMULATION_COMMAND)
    883884    {
    884885        CSimulationMessage* simMessage = static_cast<CSimulationMessage*> (message);
    885886
     887        // Clients may not send commands on behalf of others in rated games
     888        if (g_rankedGame && server.m_PlayerAssignments[session->GetGUID()].m_PlayerID != simMessage->m_Player)
     889            return true;
     890
    886891        // Send it back to all clients immediately
    887892        server.Broadcast(simMessage);
    888893
    889894        // Save all the received commands
    890895        if (server.m_SavedCommands.size() < simMessage->m_Turn + 1)
    891896            server.m_SavedCommands.resize(simMessage->m_Turn + 1);
    892897        server.m_SavedCommands[simMessage->m_Turn].push_back(*simMessage);
    893898
    894         // TODO: we should do some validation of ownership (clients can't send commands on behalf of opposing players)
    895 
    896899        // TODO: we shouldn't send the message back to the client that first sent it
    897900    }
    898901    else if (message->GetType() == (uint)NMT_SYNC_CHECK)
    899902    {
    900903        CSyncCheckMessage* syncMessage = static_cast<CSyncCheckMessage*> (message);