Exemplo n.º 1
0
        public virtual bool ParseKey(string key, TomlObject tomlObj, ParseContext ctx)
        {
            switch (key)
            {
            case "+":
                DeclAdd = TomlTools.GetValues <string>(tomlObj);
                if (DeclAdd == null)
                {
                    ctx.Errors.Add("<+> Field has invalid data.");
                }
                return(true);

            case "-":
                DeclDeny = TomlTools.GetValues <string>(tomlObj);
                if (DeclDeny == null)
                {
                    ctx.Errors.Add("<-> Field has invalid data.");
                }
                return(true);

            case "include":
                includeNames = TomlTools.GetValues <string>(tomlObj);
                if (includeNames == null)
                {
                    ctx.Errors.Add("<include> Field has invalid data.");
                }
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 2
0
        public override bool ParseKey(string key, TomlObject tomlObj, ParseContext ctx)
        {
            if (base.ParseKey(key, tomlObj, ctx))
            {
                return(true);
            }

            switch (key)
            {
            case "host":
                var host = TomlTools.GetValues <string>(tomlObj);
                if (host == null)
                {
                    ctx.Errors.Add("<host> Field has invalid data.");
                }
                else
                {
                    MatchHost = new HashSet <string>(host);
                }
                return(true);

            case "groupid":
                var groupid = TomlTools.GetValues <ulong>(tomlObj);
                if (groupid == null)
                {
                    ctx.Errors.Add("<groupid> Field has invalid data.");
                }
                else
                {
                    MatchClientGroupId = new HashSet <ulong>(groupid);
                }
                return(true);

            case "channelgroupid":
                var cgroupid = TomlTools.GetValues <ulong>(tomlObj);
                if (cgroupid == null)
                {
                    ctx.Errors.Add("<channelgroupid> Field has invalid data.");
                }
                else
                {
                    MatchChannelGroupId = new HashSet <ulong>(cgroupid);
                }
                return(true);

            case "useruid":
                var useruid = TomlTools.GetValues <string>(tomlObj);
                if (useruid == null)
                {
                    ctx.Errors.Add("<useruid> Field has invalid data.");
                }
                else
                {
                    MatchClientUid = new HashSet <string>(useruid);
                }
                return(true);

            case "perm":
                var perm = TomlTools.GetValues <string>(tomlObj);
                if (perm == null)
                {
                    ctx.Errors.Add("<perm> Field has invalid data.");
                }
                else
                {
                    MatchPermission = new HashSet <string>(perm);
                }
                return(true);

            case "visibility":
                var visibility = TomlTools.GetValues <TextMessageTargetMode>(tomlObj);
                if (visibility == null)
                {
                    ctx.Errors.Add("<visibility> Field has invalid data.");
                }
                else
                {
                    MatchVisibility = visibility;
                }
                return(true);

            case "rule":
                if (tomlObj.TomlType == TomlObjectType.ArrayOfTables)
                {
                    var childTables = (TomlTableArray)tomlObj;
                    foreach (var childTable in childTables.Items)
                    {
                        var rule = new RightsRule();
                        Children.Add(rule);
                        rule.Parent = this;
                        rule.ParseChilden(childTable, ctx);
                    }
                    return(true);
                }
                else
                {
                    ctx.Errors.Add("Misused key with reserved name \"rule\".");
                    return(false);
                }

            default:
                // group
                if (key.StartsWith("$"))
                {
                    if (tomlObj.TomlType == TomlObjectType.Table)
                    {
                        var childTable = (TomlTable)tomlObj;
                        var group      = new RightsGroup(key);
                        Children.Add(group);
                        group.Parent = this;
                        group.ParseChilden(childTable, ctx);
                        return(true);
                    }
                    else
                    {
                        ctx.Errors.Add($"Misused key for group declaration: {key}.");
                    }
                }
                return(false);
            }
        }