Exemple #1
0
        /// <summary> Checks how zones affect the given player's ability to affect
        /// a block at given coordinates. </summary>
        /// <param name="coords"> Block coordinates. </param>
        /// <param name="player"> Player to check. </param>
        /// <returns> None if no zones affect the coordinate.
        /// Allow if ALL affecting zones allow the player.
        /// Deny if ANY affecting zone denies the player. </returns>
        /// <exception cref="ArgumentNullException"> player is null. </exception>
        public PermissionOverride Check(Vector3I coords, [NotNull] Player player)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }

            PermissionOverride result = PermissionOverride.None;

            if (Cache.Length == 0)
            {
                return(result);
            }

            Zone[] zoneListCache = Cache;
            for (int i = 0; i < zoneListCache.Length; i++)
            {
                if (zoneListCache[i].Bounds.Contains(coords))
                {
                    if (zoneListCache[i].Controller.Check(player.Info))
                    {
                        result = PermissionOverride.Allow;
                    }
                    else
                    {
                        return(PermissionOverride.Deny);
                    }
                }
            }
            return(result);
        }
Exemple #2
0
        public PermissionOverride CheckZones(int x, int y, int h, Player player)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            PermissionOverride result = PermissionOverride.None;

            Zone[] zoneListCache = ZoneList;
            for (int i = 0; i < zoneListCache.Length; i++)
            {
                if (zoneListCache[i].Bounds.Contains(x, y, h))
                {
                    if (zoneListCache[i].Controller.Check(player.Info))
                    {
                        result = PermissionOverride.Allow;
                    }
                    else
                    {
                        return(PermissionOverride.Deny);
                    }
                }
            }
            return(result);
        }
        /// <summary> Checks how zones affect the given player's ability to affect
        /// a block at given coordinates. </summary>
        /// <param name="coords"> Block coordinates. </param>
        /// <param name="player"> Player to check. </param>
        /// <returns> None if no zones affect the coordinate.
        /// Allow if ALL affecting zones allow the player.
        /// Deny if ANY affecting zone denies the player. </returns>
        /// <exception cref="ArgumentNullException"> If player is null. </exception>
        public PermissionOverride Check(Vector3I coords, [NotNull] Player player)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }

            PermissionOverride result = PermissionOverride.None;

            if (Cache.Length == 0)
            {
                return(result);
            }

            Zone[] zoneListCache = Cache;
            bool   anyDeny       = false;

            for (int i = 0; i < zoneListCache.Length; i++)
            {
                Zone zone = zoneListCache[i];
                if (!zone.Bounds.Contains(coords))
                {
                    continue;
                }
                // want to be able to interact with special zones, even if can't affect zoned region
                if (SpecialZone.IsSpecialAffect(zone.Name))
                {
                    return(PermissionOverride.Allow);
                }

                if (zone.Controller.Check(player.Info))
                {
                    result = PermissionOverride.Allow;
                }
                else
                {
                    anyDeny = true;
                }
            }
            return(anyDeny ? PermissionOverride.Deny : result);
        }
Exemple #4
0
        public CanPlaceResult CanPlace(int x, int y, int h, Block newBlock, bool isManual)
        {
            CanPlaceResult result;
            Block          block = World.Map.GetBlock(x, y, h);

            // check special blocktypes
            if (newBlock == Block.Admincrete && !Can(Permission.PlaceAdmincrete))
            {
                result = CanPlaceResult.BlocktypeDenied;
                goto eventCheck;
            }
            else if ((newBlock == Block.Water || newBlock == Block.StillWater) && !Can(Permission.PlaceWater))
            {
                result = CanPlaceResult.BlocktypeDenied;
                goto eventCheck;
            }
            else if ((newBlock == Block.Lava || newBlock == Block.StillLava) && !Can(Permission.PlaceLava))
            {
                result = CanPlaceResult.BlocktypeDenied;
                goto eventCheck;
            }

            // check deleting admincrete
            if (block == Block.Admincrete && !Can(Permission.DeleteAdmincrete))
            {
                result = CanPlaceResult.BlocktypeDenied;
                goto eventCheck;
            }

            // check zones & world permissions
            PermissionOverride zoneCheckResult = World.Map.CheckZones(x, y, h, this);

            if (zoneCheckResult == PermissionOverride.Allow)
            {
                result = CanPlaceResult.Allowed;
                goto eventCheck;
            }
            else if (zoneCheckResult == PermissionOverride.Deny)
            {
                result = CanPlaceResult.ZoneDenied;
                goto eventCheck;
            }

            // Check world permissions
            switch (World.BuildSecurity.CheckDetailed(Info))
            {
            case SecurityCheckResult.Allowed:
                // Check rank permissions
                if ((Can(Permission.Build) || newBlock == Block.Air) &&
                    (Can(Permission.Delete) || block == Block.Air))
                {
                    result = CanPlaceResult.Allowed;
                    goto eventCheck;
                }
                else
                {
                    result = CanPlaceResult.RankDenied;
                    goto eventCheck;
                }

            case SecurityCheckResult.WhiteListed:
                result = CanPlaceResult.Allowed;
                goto eventCheck;

            default:
                result = CanPlaceResult.WorldDenied;
                goto eventCheck;
            }

eventCheck:
            return(Server.RaisePlayerPlacingBlockEvent(this, (short)x, (short)y, (short)h, block, newBlock, isManual, result));
        }