Ticket #3551: t3551_prohibit_all_cheats_for_rated_games_v1.patch

File t3551_prohibit_all_cheats_for_rated_games_v1.patch, 3.4 KB (added by elexis, 4 years ago)
  • binaries/data/mods/public/simulation/components/Player.js

    Player.prototype.Init = function() 
    3535    this.startCam = undefined;
    3636    this.controlAllUnits = false;
    3737    this.isAI = false;
    3838    this.gatherRateMultiplier = 1;
    3939    this.cheatsEnabled = false;
     40    this.ratingEnabled = false;
    4041    this.cheatTimeMultiplier = 1;
    4142    this.heroes = [];
    4243    this.resourceNames = {
    4344        "food": markForTranslation("Food"),
    4445        "wood": markForTranslation("Wood"),
    Player.prototype.SetCheatsEnabled = func 
    684685Player.prototype.GetCheatsEnabled = function()
    685686{
    686687    return this.cheatsEnabled;
    687688};
    688689
     690Player.prototype.SetRatingEnabled = function(flag)
     691{
     692    this.ratingEnabled = flag;
     693};
     694
     695Player.prototype.GetRatingEnabled = function()
     696{
     697    return this.ratingEnabled;
     698};
     699
    689700Player.prototype.SetCheatTimeMultiplier = function(time)
    690701{
    691702    this.cheatTimeMultiplier = time;
    692703};
    693704
  • 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        if (data.cmpPlayer.GetRatingEnabled())
     104            return;
     105
    103106        data.cmpPlayer.SetControlAllUnits(cmd.flag);
    104107    },
    105108
    106109    "reveal-map": function(player, cmd, data)
    107110    {
     111        if (data.cmpPlayer.GetRatingEnabled())
     112            return;
     113
    108114        // Reveal the map for all players, not just the current player,
    109115        // primarily to make it obvious to everyone that the player is cheating
    110116        var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    111117        cmpRangeManager.SetLosRevealAll(-1, cmd.enable);
    112118    },
    var commands = { 
    552558        });
    553559    },
    554560
    555561    "promote": function(player, cmd, data)
    556562    {
    557         // No need to do checks here since this is a cheat anyway
     563        if (data.cmpPlayer.GetRatingEnabled())
     564            return;
     565
    558566        var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
    559567        cmpGuiInterface.PushNotification({"type": "chat", "players": [player], "message": "(Cheat - promoted units)"});
    560568
    561569        for each (var ent in cmd.entities)
    562570        {
  • binaries/data/mods/public/simulation/helpers/InitGame.js

    function InitGame(settings) 
    4545    let cmpAIManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AIManager);
    4646    for (let i = 1; i < settings.PlayerData.length; ++i)
    4747    {
    4848        let cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(i), IID_Player);
    4949        cmpPlayer.SetCheatsEnabled(!!settings.CheatsEnabled);
     50        cmpPlayer.SetRatingEnabled(!!settings.RatingEnabled);
    5051        if (settings.PlayerData[i] && settings.PlayerData[i].AI && settings.PlayerData[i].AI != "")
    5152        {
    5253            cmpAIManager.AddPlayer(settings.PlayerData[i].AI, i, +settings.PlayerData[i].AIDiff);
    5354            cmpPlayer.SetAI(true);
    5455            // Sandbox: 50%, very easy: 50%, easy: 66%, Medium: 100%, hard: 133%, very hard: 166%