Server.Property.CheckAccess C# (CSharp) Méthode

CheckAccess() public méthode

public CheckAccess ( Server.Mobile from ) : bool
from Server.Mobile
Résultat bool
		public bool CheckAccess( Mobile from )
		{
			if ( !IsBound )
				throw new NotYetBoundException( this );

			for ( int i = 0; i < m_Chain.Length; ++i )
			{
				PropertyInfo prop = m_Chain[i];

				bool isFinal = ( i == ( m_Chain.Length - 1 ) );

				PropertyAccess access = m_Access;

				if ( !isFinal )
					access |= PropertyAccess.Read;

				CPA security = Properties.GetCPA( prop );

				if ( security == null )
					throw new InternalAccessException( this );

				if ( ( access & PropertyAccess.Read ) != 0 && from.AccessLevel < security.ReadLevel )
					throw new ReadAccessException( this, security.ReadLevel );

				if ( ( access & PropertyAccess.Write ) != 0 && (from.AccessLevel < security.WriteLevel || security.ReadOnly) )
					throw new WriteAccessException( this, security.ReadLevel );
			}

			return true;
		}

Usage Example

Exemple #1
0
		public static ObjectConditional ParseDirect( Mobile from, string[] args, int offset, int size )
		{
			if ( args == null || size == 0 )
				return ObjectConditional.Empty;

			int index = 0;

			Type objectType = ScriptCompiler.FindTypeByName( args[offset + index], true );

			if ( objectType == null )
				throw new Exception( String.Format( "No type with that name ({0}) was found.", args[offset + index] ) );

			++index;

			List<ICondition[]> conditions = new List<ICondition[]>();
			List<ICondition> current = new List<ICondition>();

			current.Add( TypeCondition.Default );

			while ( index < size )
			{
				string cur = args[offset + index];

				bool inverse = false;

				if ( Insensitive.Equals( cur, "not" ) || cur == "!" )
				{
					inverse = true;
					++index;

					if ( index >= size )
						throw new Exception( "Improperly formatted object conditional." );
				}
				else if ( Insensitive.Equals( cur, "or" ) || cur == "||" )
				{
					if ( current.Count > 1 )
					{
						conditions.Add( current.ToArray() );

						current.Clear();
						current.Add( TypeCondition.Default );
					}

					++index;

					continue;
				}

				string binding = args[offset + index];
				index++;

				if ( index >= size )
					throw new Exception( "Improperly formatted object conditional." );

				string oper = args[offset + index];
				index++;

				if ( index >= size )
					throw new Exception( "Improperly formatted object conditional." );

				string val = args[offset + index];
				index++;

				Property prop = new Property( binding );

				prop.BindTo( objectType, PropertyAccess.Read );
				prop.CheckAccess( from );

				ICondition condition = null;

				switch ( oper )
				{
					#region Equality
					case "=":
					case "==":
					case "is":
						condition = new ComparisonCondition( prop, inverse, ComparisonOperator.Equal, val );
						break;

					case "!=":
						condition = new ComparisonCondition( prop, inverse, ComparisonOperator.NotEqual, val );
						break;
					#endregion

					#region Relational
					case ">":
						condition = new ComparisonCondition( prop, inverse, ComparisonOperator.Greater, val );
						break;

					case "<":
						condition = new ComparisonCondition( prop, inverse, ComparisonOperator.Lesser, val );
						break;

					case ">=":
						condition = new ComparisonCondition( prop, inverse, ComparisonOperator.GreaterEqual, val );
						break;

					case "<=":
						condition = new ComparisonCondition( prop, inverse, ComparisonOperator.LesserEqual, val );
						break;
					#endregion

					#region Strings
					case "==~":
					case "~==":
					case "=~":
					case "~=":
					case "is~":
					case "~is":
						condition = new StringCondition( prop, inverse, StringOperator.Equal, val, true );
						break;

					case "!=~":
					case "~!=":
						condition = new StringCondition( prop, inverse, StringOperator.NotEqual, val, true );
						break;

					case "starts":
						condition = new StringCondition( prop, inverse, StringOperator.StartsWith, val, false );
						break;

					case "starts~":
					case "~starts":
						condition = new StringCondition( prop, inverse, StringOperator.StartsWith, val, true );
						break;

					case "ends":
						condition = new StringCondition( prop, inverse, StringOperator.EndsWith, val, false );
						break;

					case "ends~":
					case "~ends":
						condition = new StringCondition( prop, inverse, StringOperator.EndsWith, val, true );
						break;

					case "contains":
						condition = new StringCondition( prop, inverse, StringOperator.Contains, val, false );
						break;

					case "contains~":
					case "~contains":
						condition = new StringCondition( prop, inverse, StringOperator.Contains, val, true );
						break;
					#endregion
				}

				if ( condition == null )
					throw new InvalidOperationException( String.Format( "Unrecognized operator (\"{0}\").", oper ) );

				current.Add( condition );
			}

			conditions.Add( current.ToArray() );

			return new ObjectConditional( objectType, conditions.ToArray() );
		}