GetCPA() public static method

public static GetCPA ( PropertyInfo p ) : Server.CommandPropertyAttribute
p System.Reflection.PropertyInfo
return Server.CommandPropertyAttribute
示例#1
0
        public bool HasAccess(Type type)
        {
            if (type != null)
            {
                PropertyInfo[] allProps = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

                foreach (PropertyInfo prop in allProps)
                {
                    CPA attr = Properties.GetCPA(prop);
                    if (attr != null && ((prop.CanRead && m_From.AccessLevel < attr.ReadLevel) || (prop.CanWrite && m_From.AccessLevel < attr.WriteLevel)))
                    {
                        m_From.SendMessage("The item {0} contains the property {1}, which you do not have access to.", type.Name, prop.Name);
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
示例#2
0
        public static int BuildObjects(Mobile from, Type type, Point3D start, Point3D end, string[] args, string[,] props, ArrayList packs)
        {
            Utility.FixPoints(ref start, ref end);

            PropertyInfo[] realProps = null;

            if (props != null)
            {
                realProps = new PropertyInfo[props.GetLength(0)];

                PropertyInfo[] allProps = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

                for (int i = 0; i < realProps.Length; ++i)
                {
                    PropertyInfo thisProp = null;

                    string propName = props[i, 0];

                    for (int j = 0; thisProp == null && j < allProps.Length; ++j)
                    {
                        if (Insensitive.Equals(propName, allProps[j].Name))
                        {
                            thisProp = allProps[j];
                        }
                    }

                    if (thisProp == null)
                    {
                        from.SendMessage("Property not found: {0}", propName);
                    }
                    else
                    {
                        CPA attr = Properties.GetCPA(thisProp);

                        if (attr == null)
                        {
                            from.SendMessage("Property ({0}) not found.", propName);
                        }
                        else if (from.AccessLevel < attr.WriteLevel)
                        {
                            from.SendMessage("Setting this property ({0}) requires at least {1} access level.", propName, Mobile.GetAccessLevelName(attr.WriteLevel));
                        }
                        else if (!thisProp.CanWrite)
                        {
                            from.SendMessage("Property ({0}) is read only.", propName);
                        }
                        else
                        {
                            realProps[i] = thisProp;
                        }
                    }
                }
            }

            ConstructorInfo[] ctors = type.GetConstructors();

            for (int i = 0; i < ctors.Length; ++i)
            {
                ConstructorInfo ctor = ctors[i];

                if (!IsConstructable(ctor))
                {
                    continue;
                }

                ParameterInfo[] paramList = ctor.GetParameters();

                if (args.Length == paramList.Length)
                {
                    object[] paramValues = ParseValues(paramList, args);

                    if (paramValues == null)
                    {
                        continue;
                    }

                    int built = Build(from, start, end, ctor, paramValues, props, realProps, packs);

                    if (built > 0)
                    {
                        return(built);
                    }
                }
            }

            return(0);
        }
示例#3
0
        /// <summary>
        /// Primary dupe method. Will be called recursively.
        /// </summary>
        /// <param name="from">Caller of the dupe command</param>
        /// <param name="toDupe">Item to be duped</param>
        /// <param name="recursionDepth">Recursions left</param>
        /// <param name="itemList">List of items created so far</param>
        /// <param name="mobileList">List of mobiles created so far</param>
        /// <param name="serialMapping">Mapping of serials of duped items and their copied counterparts</param>
        /// <returns>Duplicated entity</returns>
        public static object Dupe(Mobile from, object toDupe, int recursionDepth, List <Item> itemList, List <Mobile> mobileList, Dictionary <int, int> serialMapping)
        {
            object toReturn = null;

            Type type = toDupe.GetType();

            // Getting all properties
            PropertyInfo[] allProps = type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

            // Checking if the caller's AccessLevel is high enough to write those
            foreach (PropertyInfo thisProp in allProps)
            {
                CPA attr = Properties.GetCPA(thisProp);
                if (attr != null && (from.AccessLevel < attr.ReadLevel || from.AccessLevel < attr.WriteLevel))
                {
                    // Ignoring all properties declared by BaseCreature and Mobile
                    if (thisProp.DeclaringType != typeof(BaseCreature) && thisProp.DeclaringType != typeof(Mobile))
                    {
                        throw new AccessLevelTooLowException("Your AccessLevel is too low to dupe this: " + thisProp.Name);
                    }
                }
            }

            MemoryStream stream = new MemoryStream();
            DupeWriter   writer = new DupeWriter(stream, recursionDepth);
            DupeReader   reader = new DupeReader(stream, from, itemList, mobileList, serialMapping);

            try
            {
                if (toDupe is Item)
                {
                    Item item = (Item)toDupe;
                    item.Serialize(writer);
                }
                else
                {
                    Mobile mobile = (Mobile)toDupe;
                    mobile.Serialize(writer);
                }

                // YAY! If we arrived here we are allowed to duplicate the item and have collected all necessary data
                writer.Flush();
                reader.Seek(0, SeekOrigin.Begin);                   // Reset position of the reader

                // Fetch constructor with serial as parameter
                ConstructorInfo ctor = type.GetConstructor(new Type[] { typeof(Serial) });

                if (toDupe is Item)
                {
                    Item item = (Item)ctor.Invoke(new object[] { Serial.NewItem });
                    World.AddItem(item);                       // We don't want duplicate serials so we add it to the world right away to block its serial.
                    serialMapping.Add(((Item)toDupe).Serial, item.Serial);
                    itemList.Insert(0, item);                  // Insert at the beginning to reverse the recursive order

                    item.Deserialize(reader);                  // Deserialize calls Dupe again if it reaches a reference.
                    toReturn = item;
                }
                else if (toDupe is Mobile)
                {
                    // Konstruktor mit Serial aufrufen
                    Mobile mobile = (Mobile)ctor.Invoke(new object[] { Serial.NewMobile });
                    World.AddMobile(mobile);                       // We don't want duplicate serials so we add it to the world right away to block its serial.
                    serialMapping.Add(((Mobile)toDupe).Serial, mobile.Serial);
                    mobileList.Insert(0, mobile);                  // Insert at the beginning to reverse the recursive order

                    mobile.Deserialize(reader);                    // Deserialize calls Dupe again if it reaches a reference.
                    toReturn = mobile;
                }

                if (!reader.End())
                {
                    // The stream is not empty?
                    throw new DeserializeException("Cannot dupe " + toReturn.GetType().Name + ". Serialize/Deserialize is either broken or uses hacks.");
                }

                if (itemList.Count + mobileList.Count > DupeCommand.MAX_ENTITIES)
                {
                    throw new EntitiesExceededException("Cannot dupe more than " + DupeCommand.MAX_ENTITIES + " Items/Mobiles!");
                }
            }
            finally
            {
                writer.Close();
                reader.Close();
                stream.Close();
            }

            return(toReturn);
        }
示例#4
0
        public static int BuildObjects(
            Mobile from, Type type, Point3D start, Point3D end, string[] args, string[,] props,
            List <Container> packs, bool outline = false, bool mapAvg = false
            )
        {
            Utility.FixPoints(ref start, ref end);

            PropertyInfo[] realProps = null;

            if (props != null)
            {
                realProps = new PropertyInfo[props.GetLength(0)];

                var allProps =
                    type.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

                for (var i = 0; i < realProps.Length; ++i)
                {
                    PropertyInfo thisProp = null;

                    var propName = props[i, 0];

                    for (var j = 0; thisProp == null && j < allProps.Length; ++j)
                    {
                        if (propName.InsensitiveEquals(allProps[j].Name))
                        {
                            thisProp = allProps[j];
                        }
                    }

                    if (thisProp == null)
                    {
                        from.SendMessage("Property not found: {0}", propName);
                    }
                    else
                    {
                        var attr = Properties.GetCPA(thisProp);

                        if (attr == null)
                        {
                            from.SendMessage("Property ({0}) not found.", propName);
                        }
                        else if (from.AccessLevel < attr.WriteLevel)
                        {
                            from.SendMessage(
                                "Setting this property ({0}) requires at least {1} access level.",
                                propName,
                                Mobile.GetAccessLevelName(attr.WriteLevel)
                                );
                        }
                        else if (!thisProp.CanWrite || attr.ReadOnly)
                        {
                            from.SendMessage("Property ({0}) is read only.", propName);
                        }
                        else
                        {
                            realProps[i] = thisProp;
                        }
                    }
                }
            }

            var ctors = type.GetConstructors();

            for (var i = 0; i < ctors.Length; ++i)
            {
                var ctor = ctors[i];

                if (!IsConstructible(ctor, from.AccessLevel))
                {
                    continue;
                }

                // Handle optional constructors
                var paramList   = ctor.GetParameters();
                var totalParams = 0;
                for (var j = 0; j < paramList.Length; j++)
                {
                    if (!paramList[j].HasDefaultValue)
                    {
                        totalParams++;
                    }
                }

                if (args.Length >= totalParams && args.Length <= paramList.Length)
                {
                    var paramValues = ParseValues(paramList, args);

                    if (paramValues == null)
                    {
                        continue;
                    }

                    var built = Build(from, start, end, ctor, paramValues, props, realProps, packs, outline, mapAvg);

                    if (built > 0)
                    {
                        return(built);
                    }
                }
            }

            return(0);
        }