Ticket #2676: 2676-patch-v2.patch

File 2676-patch-v2.patch, 1.5 KB (added by historic_bruno, 6 years ago)
  • source/network/NetServer.cpp

     
    883883    {
    884884        CSimulationMessage* simMessage = static_cast<CSimulationMessage*> (message);
    885885
     886        // Ignore messages sent by one player on behalf of another player
     887        // unless cheating is enabled
     888        bool cheatsEnabled = false;
     889        ScriptInterface& scriptInterface = server.GetScriptInterface();
     890        JSContext* cx = scriptInterface.GetContext();
     891        JSAutoRequest rq(cx);
     892        JS::RootedValue settings(cx);
     893        scriptInterface.GetProperty(server.m_GameAttributes.get(), "settings", &settings);
     894        if (scriptInterface.HasProperty(settings, "CheatsEnabled"))
     895            scriptInterface.GetProperty(settings, "CheatsEnabled", cheatsEnabled);
     896
     897        PlayerAssignmentMap::iterator it = server.m_PlayerAssignments.find(session->GetGUID());
     898        if (!cheatsEnabled && (it == server.m_PlayerAssignments.end() || it->second.m_PlayerID != simMessage->m_Player))
     899            return true;
     900
    886901        // Send it back to all clients immediately
    887902        server.Broadcast(simMessage);
    888903
     
    891906            server.m_SavedCommands.resize(simMessage->m_Turn + 1);
    892907        server.m_SavedCommands[simMessage->m_Turn].push_back(*simMessage);
    893908
    894         // TODO: we should do some validation of ownership (clients can't send commands on behalf of opposing players)
    895 
    896909        // TODO: we shouldn't send the message back to the client that first sent it
    897910    }
    898911    else if (message->GetType() == (uint)NMT_SYNC_CHECK)