Ejemplo n.º 1
0
        private bool Verify(TagNode parent, TagNode tag, SchemaNode schema)
        {
            if (tag == null)
            {
                return(OnMissingTag(new TagEventArgs(schema.Name)));
            }

            SchemaNodeScaler scaler = schema as SchemaNodeScaler;

            if (scaler != null)
            {
                return(VerifyScaler(tag, scaler));
            }

            SchemaNodeString str = schema as SchemaNodeString;

            if (str != null)
            {
                return(VerifyString(tag, str));
            }

            SchemaNodeArray array = schema as SchemaNodeArray;

            if (array != null)
            {
                return(VerifyArray(tag, array));
            }

            SchemaNodeIntArray intarray = schema as SchemaNodeIntArray;

            if (intarray != null)
            {
                return(VerifyIntArray(tag, intarray));
            }

            SchemaNodeShortArray shortarray = schema as SchemaNodeShortArray;

            if (shortarray != null)
            {
                return(VerifyShortArray(tag, shortarray));
            }

            SchemaNodeList list = schema as SchemaNodeList;

            if (list != null)
            {
                return(VerifyList(tag, list));
            }

            SchemaNodeCompound compound = schema as SchemaNodeCompound;

            if (compound != null)
            {
                return(VerifyCompound(tag, compound));
            }

            return(OnInvalidTagType(new TagEventArgs(schema.Name, tag)));
        }
Ejemplo n.º 2
0
        private bool VerifyList(TagNode tag, SchemaNodeList schema)
        {
            TagNodeList ltag = tag as TagNodeList;

            if (ltag == null)
            {
                if (!OnInvalidTagType(new TagEventArgs(schema, tag)))
                {
                    return(false);
                }
            }
            if (ltag.Count > 0 && ltag.ValueType != schema.Type)
            {
                if (!OnInvalidTagValue(new TagEventArgs(schema, tag)))
                {
                    return(false);
                }
            }
            if (schema.Length > 0 && ltag.Count != schema.Length)
            {
                if (!OnInvalidTagValue(new TagEventArgs(schema, tag)))
                {
                    return(false);
                }
            }

            // Patch up empty lists
            //if (schema.Length == 0) {
            //    tag = new NBT_List(schema.Type);
            //}

            bool pass = true;

            // If a subschema is set, test all items in list against it

            if (schema.SubSchema != null)
            {
                foreach (TagNode v in ltag)
                {
                    pass = Verify(tag, v, schema.SubSchema) && pass;
                }
            }

            return(pass);
        }
Ejemplo n.º 3
0
        private bool VerifyList(TagNode tag, SchemaNodeList schema)
        {
            TagNodeList ltag = tag as TagNodeList;
            if (ltag == null) {
                if (!OnInvalidTagType(new TagEventArgs(schema, tag))) {
                    return false;
                }
            }
            if (ltag.Count > 0 && ltag.ValueType != schema.Type) {
                if (!OnInvalidTagValue(new TagEventArgs(schema, tag))) {
                    return false;
                }
            }
            if (schema.Length > 0 && ltag.Count != schema.Length) {
                if (!OnInvalidTagValue(new TagEventArgs(schema, tag))) {
                    return false;
                }
            }

            // Patch up empty lists
            //if (schema.Length == 0) {
            //    tag = new NBT_List(schema.Type);
            //}

            bool pass = true;

            // If a subschema is set, test all items in list against it

            if (schema.SubSchema != null) {
                foreach (TagNode v in ltag) {
                    pass = Verify(tag, v, schema.SubSchema) && pass;
                }
            }

            return pass;
        }