Ticket #3551: t3551_prohibit_all_cheats_for_rated_games_v2.patch

File t3551_prohibit_all_cheats_for_rated_games_v2.patch, 3.9 KB (added by elexis, 4 years ago)

No more ugliness as we save the rated-setting in the GuiInterface instead of the Player component.

  • binaries/data/mods/public/simulation/components/GuiInterface.js

    GuiInterface.prototype.Init = function() 
    2525{
    2626    this.placementEntity = undefined; // = undefined or [templateName, entityID]
    2727    this.placementWallEntities = undefined;
    2828    this.placementWallLastAngle = 0;
    2929    this.notifications = [];
     30    this.ratingEnabled = false;
    3031    this.renamedEntities = [];
    3132    this.miragedEntities = [];
    3233    this.timeNotificationID = 1;
    3334    this.timeNotifications = [];
    3435    this.entsRallyPointsDisplayed = [];
    GuiInterface.prototype.GetSimulationStat 
    157158    }
    158159
    159160    return ret;
    160161};
    161162
     163GuiInterface.prototype.IsRatedGame = function()
     164{
     165    return this.ratingEnabled;
     166}
     167
     168GuiInterface.prototype.SetRatedGame = function(enabled)
     169{
     170    this.ratingEnabled = enabled;
     171}
     172
    162173/**
    163174 * Returns global information about the current game state, plus statistics.
    164175 * This is used by the GUI at the end of a game, in the summary screen.
    165176 * Note: Amongst statistics, the team exploration map percentage is computed from
    166177 * scratch, so the extended simulation state should not be requested too often.
  • binaries/data/mods/public/simulation/helpers/Commands.js

    var commands = { 
    9898        data.cmpPlayer.TributeResource(cmd.player, cmd.amounts);
    9999    },
    100100
    101101    "control-all": function(player, cmd, data)
    102102    {
     103        var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     104        if (cmpGuiInterface.IsRatedGame())
     105            return;
     106
    103107        data.cmpPlayer.SetControlAllUnits(cmd.flag);
    104108    },
    105109
    106110    "reveal-map": function(player, cmd, data)
    107111    {
     112        var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     113        if (cmpGuiInterface.IsRatedGame())
     114            return;
     115
    108116        // Reveal the map for all players, not just the current player,
    109117        // primarily to make it obvious to everyone that the player is cheating
    110118        var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    111119        cmpRangeManager.SetLosRevealAll(-1, cmd.enable);
    112120    },
    var commands = { 
    552560        });
    553561    },
    554562
    555563    "promote": function(player, cmd, data)
    556564    {
    557         // No need to do checks here since this is a cheat anyway
    558565        var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     566        if (cmpGuiInterface.IsRatedGame())
     567            return;
     568
    559569        cmpGuiInterface.PushNotification({"type": "chat", "players": [player], "message": "(Cheat - promoted units)"});
    560570
    561571        for each (var ent in cmd.entities)
    562572        {
    563573            var cmpPromotion = Engine.QueryInterface(ent, IID_Promotion);
  • binaries/data/mods/public/simulation/helpers/InitGame.js

    function InitGame(settings) 
    3939        let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    4040        for (let i = 1; i < settings.PlayerData.length; ++i)
    4141            cmpRangeManager.ExploreAllTiles(i);
    4242    }
    4343
     44    // TODO: cheats should also be saved in the GuiInterface instead of the Player component
     45    let cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     46    cmpGuiInterface.SetRatedGame(settings.RatingEnabled);
     47
    4448    let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
    4549    let cmpAIManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AIManager);
    4650    for (let i = 1; i < settings.PlayerData.length; ++i)
    4751    {
    4852        let cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(i), IID_Player);