コード例 #1
0
ファイル: Trigger.cs プロジェクト: areiter/InMemoryFuzzing
        public bool IsTriggered(TriggerEnum trigger, object data)
        {
            if (_triggerFirst && trigger == _trigger && (trigger == TriggerEnum.Start || trigger == TriggerEnum.End))
            {
                _triggerFirst = false;
                _currentCount = 0;
                return true;
            }

            if (trigger == _trigger &&
                (trigger == TriggerEnum.Start || trigger == TriggerEnum.End) &&
                (_currentCount == _triggerCount || _triggerCount == 0))
            {
                return true;
            }

            if (trigger == _trigger &&
                trigger == TriggerEnum.Location &&
                data is UInt64)
            {
                UInt64? address = ((IAddressSpecifier)_data).ResolveAddress ();

                return (address != null && address.Value == (UInt64)data);
            }

            return false;
        }
コード例 #2
0
ファイル: Rule.cs プロジェクト: filipe-silva/FireflyIII.Net
        /// <summary>
        /// Initializes a new instance of the <see cref="Rule" /> class.
        /// </summary>
        /// <param name="title">title (required).</param>
        /// <param name="description">description.</param>
        /// <param name="ruleGroupId">ID of the rule group under which the rule must be stored. Either this field or rule_group_title is mandatory. (required).</param>
        /// <param name="ruleGroupTitle">Title of the rule group under which the rule must be stored. Either this field or rule_group_id is mandatory..</param>
        /// <param name="trigger">Which action is necessary for the rule to fire? Use either store-journal or update-journal. (required).</param>
        /// <param name="active">Whether or not the rule is even active. Default is true..</param>
        /// <param name="strict">If the rule is set to be strict, ALL triggers must hit in order for the rule to fire. Otherwise, just one is enough. Default value is true..</param>
        /// <param name="stopProcessing">If this value is true and the rule is triggered, other rules  after this one in the group will be skipped. Default value is false..</param>
        /// <param name="triggers">triggers (required).</param>
        /// <param name="actions">actions (required).</param>
        public Rule(string title = default(string), string description = default(string), int ruleGroupId = default(int), string ruleGroupTitle = default(string), TriggerEnum trigger = default(TriggerEnum), bool active = default(bool), bool strict = default(bool), bool stopProcessing = default(bool), List <RuleTrigger> triggers = default(List <RuleTrigger>), List <RuleAction> actions = default(List <RuleAction>))
        {
            // to ensure "title" is required (not null)
            if (title == null)
            {
                throw new InvalidDataException("title is a required property for Rule and cannot be null");
            }
            else
            {
                this.Title = title;
            }

            // to ensure "ruleGroupId" is required (not null)
            if (ruleGroupId == 0)
            {
                throw new InvalidDataException("ruleGroupId is a required property for Rule and cannot be null");
            }
            else
            {
                this.RuleGroupId = ruleGroupId;
            }

            this.Trigger = trigger;
            // to ensure "triggers" is required (not null)
            if (triggers == null)
            {
                throw new InvalidDataException("triggers is a required property for Rule and cannot be null");
            }
            else
            {
                this.Triggers = triggers;
            }

            // to ensure "actions" is required (not null)
            if (actions == null)
            {
                throw new InvalidDataException("actions is a required property for Rule and cannot be null");
            }
            else
            {
                this.Actions = actions;
            }

            this.Description    = description;
            this.RuleGroupTitle = ruleGroupTitle;
            this.Active         = active;
            this.Strict         = strict;
            this.StopProcessing = stopProcessing;
        }
コード例 #3
0
ファイル: Trigger.cs プロジェクト: areiter/InMemoryFuzzing
        public Trigger(string trigger, string triggerArgs, ITargetConnector connector)
        {
            _trigger = (TriggerEnum)Enum.Parse (typeof(TriggerEnum), trigger, true);

            if (_trigger == TriggerEnum.Location)
            {
                _data = FuzzDescriptionInfo.ParseRegionAddress (triggerArgs, false, connector);
                /*IBreakpoint myBreakpoint =*/ connector.SetSoftwareBreakpoint (
                    ((IAddressSpecifier)_data).ResolveAddress ().Value, 0, "Trigger at '" + triggerArgs + "'");
            }
            else if (triggerArgs != null && triggerArgs.StartsWith ("!"))
            {
                _triggerFirst = true;
                _triggerCount = Int32.Parse (triggerArgs.Substring (1));
            }
            else if(triggerArgs != null)
                _triggerCount = Int32.Parse (triggerArgs);
        }
コード例 #4
0
ファイル: ProconRulz.cs プロジェクト: Geolim4/ProconRulz
            public string unparsed_rule; // the original string parsed into this rule

            #endregion Fields

            #region Constructors

            public ParsedRule()
            {
                parts = new List<PartClass>();
                comment = false;
                trigger = TriggerEnum.Spawn;
            }
コード例 #5
0
ファイル: ProconRulz.cs プロジェクト: Geolim4/ProconRulz
        //**********************************************************************************************
        //**********************************************************************************************
        //   CHECK THE RULES to see if we should kill, kick, say
        //**********************************************************************************************
        //**********************************************************************************************
        // here is where we scan the rules after a player has joined, spawned or a kill has occurred
        private void scan_rules(TriggerEnum trigger, string name, 
            Dictionary<SubstEnum, string> keywords,
            Inventory inv, Kill k, string item)
        {
            WriteDebugInfo(String.Format("ProconRulz: Scan_rules[{0}] with Event {1}",
                                name,
                                Enum.GetName(typeof(TriggerEnum), trigger)));

            // don't do anything if rulz_enable has been set to false
            if (!rulz_enable) return;

            // CATCH EXCEPTIONS
            try
            {
                // initial population of the 'keywords' dictionary
                assign_initial_keywords(name, ref keywords);

                // loop through the rules
                foreach (ParsedRule rule in parsed_rules)
                {
                    // skip comments
                    if (rule.comment) continue;

                    if (rule.trigger == trigger)
                    {
                        WriteDebugInfo(String.Format("ProconRulz: scan_rules[{0}] [{1}]",
                            name, rule.unparsed_rule));
                        if (process_rule(trigger, rule, name, ref keywords, inv, k, item))
                        {
                            WriteDebugInfo(String.Format("ProconRulz: scan_rules[{0}] [{1}] FIRED",
                                name, rule.unparsed_rule));
                            break; // break if any rule fires
                        }
                    }
                    // else WriteDebugInfo(String.Format("ProconRulz: scan_rules[{0}] skipped", name));
                } // end looping through the rules
            }
            catch (Exception ex)
            {
                WriteConsole("ProconRulz: recoverable exception in scan_rules");
                PrintException(ex);
            }
        }
コード例 #6
0
ファイル: ProconRulz.cs プロジェクト: Geolim4/ProconRulz
        // test a rule (we have already confirmed Spawn or Kill trigger is true)
        // will return 'true' if the rule is applied
        private bool process_rule(TriggerEnum trigger, ParsedRule rule, string player_name, 
            ref Dictionary<SubstEnum, string> keywords,
            Inventory inv, Kill k, string item)
        {
            WriteDebugInfo(String.Format("ProconRulz:   process_rule[{0}] with event {1}",
                                player_name,
                                Enum.GetName(typeof(TriggerEnum), trigger)));

            // CATCH EXCEPTIONS
            try
            {
                List<PartClass> parts = new List<PartClass>(rule.parts);

                if (trigger == TriggerEnum.Say) keywords[SubstEnum.Text] = item;
                // Populate the Counts AS IF THIS RULE SUCCEEDED so conditions can use them
                keywords[SubstEnum.ServerCount] = count_server_rule(rule.id).ToString() + 1;
                keywords[SubstEnum.Count] = count_rule(player_name, rule.id).ToString() + 1;
                keywords[SubstEnum.TeamCount] = count_team_rule(players.team_id(player_name), rule.id).ToString() + 1;

                // populate the 'keywords' dictionary
                assign_keywords(trigger, rule, player_name, ref keywords, inv, k, item);

                if (!process_parts(rule, parts, player_name, ref keywords, k, item))
                {
                    WriteDebugInfo(String.Format("ProconRulz:   process_rule[{0}] in rule [{1}] tests NEGATIVE",
                        player_name, rule.unparsed_rule));
                    return false;
                }

                WriteDebugInfo(String.Format("ProconRulz:   process_rule[{0}] in rule [{1}] all conditions OK",
                    player_name, rule.unparsed_rule));

                // return 'true' to quit rulz checks after this rule
                // if rule contains End, Kill, Kick, TempBan, Ban unless it contains Continue.
                return end_rulz(parts);
            }
            catch (Exception ex)
            {
                WriteConsole("ProconRulz: recoverable exception in test_rule_and_exec(" +
                    rule.unparsed_rule + ")");
                PrintException(ex);
                return false;
            }
        }
コード例 #7
0
ファイル: ProconRulz.cs プロジェクト: Geolim4/ProconRulz
        private void assign_keywords(TriggerEnum trigger, ParsedRule rulex, string player_name,
            ref Dictionary<SubstEnum, string> keywords,
            Inventory inv, Kill k, string item)
        {
            // HERE's WHERE WE UPDATE THE SUBST KEYWORDS (and conditions can as well,
            // e.g. TargetPlayer)
            // this would be more efficient if I only updated the keywords that are
            // actually used in the rulz

            // update player count etc for this rule (for use of %c% parameter
            // or subsequent Count condition)

            if (trigger == TriggerEnum.Spawn)
            {
                keywords[SubstEnum.Kit] = kit_desc(item_key(inv.Kit));
                keywords[SubstEnum.KitKey] = item_key(inv.Kit);
                // keywords[Weaponkey, Weapon, Damage, SpecKey, Spec] all set in OnPlaeyrSpawned
            }
            else if (trigger == TriggerEnum.Kill ||
                trigger == TriggerEnum.TeamKill ||
                trigger == TriggerEnum.Suicide ||
                trigger == TriggerEnum.PlayerBlock
                )
            {
                try
                {
                    // we're in a 'kill' type event here
                    // as far as I can tell, 'k.DamageType' usually contains
                    // weapon key, but sometimes can be null

                    // with BF3, k.Killer.SoldierName can be empty (null or ""?)
                    if (k == null) return;

                    string victim_name = (k.Victim == null) ? "No victim" : k.Victim.SoldierName;
                    keywords[SubstEnum.Victim] = victim_name;

                    string weapon_key = k.DamageType;

                    Weapon weapon_used;
                    try
                    {
                        if (weapon_key == null) weapon_used = null;
                        else weapon_used = weaponDefines[weapon_key];
                    }
                    catch { weapon_used = null; }

                    string weapon_descr = weapon_desc(weapon_key);

                    string damage;
                    try
                    {
                        damage = (weapon_used == null) ? "No damage key" : item_key(weapon_used.Damage);
                    }
                    catch { damage = "No damage key"; }

                    keywords[SubstEnum.Weapon] = weapon_descr;
                    keywords[SubstEnum.WeaponKey] = weapon_key;

                    keywords[SubstEnum.KitKey] = spawned_kit(player_name);
                    keywords[SubstEnum.Kit] = kit_desc(spawned_kit(player_name));

                    keywords[SubstEnum.VictimKit] = kit_desc(spawned_kit(victim_name));
                    keywords[SubstEnum.VictimTeamKey] = players.team_id(victim_name);
                    keywords[SubstEnum.VictimTeam] = team_name(players.team_id(victim_name));

                    keywords[SubstEnum.VictimCountry] = players.cname(victim_name);
                    keywords[SubstEnum.VictimCountryKey] = players.ckey(victim_name);

                    keywords[SubstEnum.Damage] = damage;

                    keywords[SubstEnum.Range] = k.Distance.ToString("0.0");
                    keywords[SubstEnum.Headshot] = k.Headshot ? "Headshot" : "";
                }
                catch (Exception ex)
                {
                    WriteConsole("ProconRulz: recoverable exception in assign_keywords #2");
                    PrintException(ex);
                    return;
                }
            }

            if (trigger == TriggerEnum.PlayerBlock)
            {
                keywords.Add(SubstEnum.BlockedItem, item);
                WriteDebugInfo(String.Format("ProconRulz: test_rule[{0}] is PlayerBlock event for [{1}] OK",
                                    player_name, item));
            }
        }
コード例 #8
0
        private void InvokeFuzzLocations(TriggerEnum triggerType, object triggerData)
        {
            List<IFuzzLocation> fuzzLocationsToRemove = new List<IFuzzLocation> ();
            foreach (IFuzzLocation fuzzLocation in _fuzzDescription.FuzzLocation) {
                if (fuzzLocation.IsFinished)
                    fuzzLocationsToRemove.Add (fuzzLocation); else if (fuzzLocation.IsTriggered (triggerType, triggerData)) {
                    fuzzLocation.Run (this);
                }
            }

            foreach (IFuzzLocation toRemove in fuzzLocationsToRemove)
                _fuzzDescription.FuzzLocation.Remove (toRemove);
        }
コード例 #9
0
        public virtual bool IsTriggered(TriggerEnum triggerType, object data)
        {
            if (_triggers == null)
                return false;
            foreach (ITrigger trigger in _triggers)
            {
                if (trigger.IsTriggered (triggerType, data))
                    return true;
            }

            return false;
        }
コード例 #10
0
 public bool IsTriggered(TriggerEnum trigger, object data)
 {
     _childLocation.ApplyChangeableId (_changeableId);
     return _childLocation.IsTriggered (trigger, data);
 }