Ejemplo n.º 1
0
 public ZoneCollection([NotNull] ZoneCollection other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     lock (other.syncRoot) {
         foreach (Zone zone in other.store.Values)
         {
             Add(zone);
         }
     }
 }
Ejemplo n.º 2
0
        private static void ZoneRemoveHandler(Player player, Command cmd)
        {
            string zoneName = cmd.Next();

            if (zoneName == null)
            {
                CdZoneRemove.PrintUsage(player);
                return;
            }

            ZoneCollection zones = player.WorldMap.Zones;
            Zone           zone  = zones.Find(zoneName);

            if (zone != null)
            {
                if (!player.Info.Rank.AllowSecurityCircumvention)
                {
                    switch (zone.Controller.CheckDetailed(player.Info))
                    {
                    case SecurityCheckResult.BlackListed:
                        player.Message("You are not allowed to remove zone {0}: you are blacklisted.",
                                       zone.ClassyName);
                        return;

                    case SecurityCheckResult.RankTooLow:
                        player.Message("You are not allowed to remove zone {0}.", zone.ClassyName);
                        return;
                    }
                }
                if (!cmd.IsConfirmed)
                {
                    player.Confirm(cmd, "Remove zone {0}&S?", zone.ClassyName);
                    return;
                }

                if (zones.Remove(zone.Name))
                {
                    player.Message("Zone \"{0}\" removed.", zone.Name);
                }
            }
            else
            {
                player.MessageNoZone(zoneName);
            }
        }
Ejemplo n.º 3
0
        /// <summary> Creates an empty new map of given dimensions.
        /// Dimensions cannot be changed after creation. </summary>
        /// <param name="world"> World that owns this map. May be null, and may be changed later. </param>
        /// <param name="width"> Width (horizontal, Notch's X). </param>
        /// <param name="length"> Length (horizontal, Notch's Z). </param>
        /// <param name="height"> Height (vertical, Notch's Y). </param>
        /// <param name="initBlockArray"> If true, the Blocks array will be created. </param>
        /// <exception cref="ArgumentOutOfRangeException"> Width, length, or height is not between 16 and 2048. </exception>
        /// <exception cref="ArgumentException"> Map volume exceeds Int32.MaxValue. </exception>
        public Map([CanBeNull] World world, int width, int length, int height, bool initBlockArray)
        {
            if (!IsValidDimension(width))
            {
                throw new ArgumentOutOfRangeException("width", "Invalid map width.");
            }
            if (!IsValidDimension(length))
            {
                throw new ArgumentOutOfRangeException("length", "Invalid map length.");
            }
            if (!IsValidDimension(height))
            {
                throw new ArgumentOutOfRangeException("height", "Invalid map height.");
            }
            if ((long)width * length * height > Int32.MaxValue)
            {
                throw new ArgumentException("Map volume exceeds Int32.MaxValue.");
            }
            DateCreated  = DateTime.UtcNow;
            DateModified = DateCreated;
            Guid         = Guid.NewGuid();

            Metadata          = new MetadataCollection <string>();
            Metadata.Changed += OnMetaOrZoneChange;

            Zones          = new ZoneCollection();
            Zones.Changed += OnMetaOrZoneChange;

            World = world;

            Width  = width;
            Length = length;
            Height = height;
            Bounds = new BoundingBox(Vector3I.Zero, Width, Length, Height);
            Volume = Bounds.Volume;

            if (initBlockArray)
            {
                Blocks = new byte[Volume];
            }

            ResetSpawn();
        }
Ejemplo n.º 4
0
        /// <summary> Creates an empty new map of given dimensions.
        /// Dimensions cannot be changed after creation. </summary>
        /// <param name="world"> World that owns this map. May be null, and may be changed later. </param>
        /// <param name="width"> Width (horizontal, Notch's X). </param>
        /// <param name="length"> Length (horizontal, Notch's Z). </param>
        /// <param name="height"> Height (vertical, Notch's Y). </param>
        /// <param name="initBlockArray"> If true, the Blocks array will be created. </param>
        public Map(World world, int width, int length, int height, bool initBlockArray)
        {
            if (!IsValidDimension(width))
            {
                throw new ArgumentException("Invalid map dimension.", "width");
            }
            if (!IsValidDimension(length))
            {
                throw new ArgumentException("Invalid map dimension.", "length");
            }
            if (!IsValidDimension(height))
            {
                throw new ArgumentException("Invalid map dimension.", "height");
            }
            DateCreated  = DateTime.UtcNow;
            DateModified = DateCreated;
            Guid         = Guid.NewGuid();

            Metadata          = new MetadataCollection <string>();
            Metadata.Changed += OnMetaOrZoneChange;

            Zones          = new ZoneCollection();
            Zones.Changed += OnMetaOrZoneChange;

            World = world;

            Width  = width;
            Length = length;
            Height = height;
            Bounds = new BoundingBox(Vector3I.Zero, Width, Length, Height);
            Volume = Bounds.Volume;

            if (initBlockArray)
            {
                Blocks = new byte[Volume];
            }

            LifeZones = new Dictionary <string, Life2DZone>();

            ResetSpawn();
        }
Ejemplo n.º 5
0
        static void ZoneRemoveHandler(Player player, CommandReader cmd)
        {
            if (player.World == null)
            {
                PlayerOpException.ThrowNoWorld(player);
            }

            string zoneName = cmd.Next();

            if (zoneName == null || cmd.HasNext)
            {
                CdZoneRemove.PrintUsage(player);
                return;
            }

            if (zoneName == "*")
            {
                if (!cmd.IsConfirmed)
                {
                    Logger.Log(LogType.UserActivity,
                               "ZRemove: Asked {0} to confirm removing all zones on world {1}",
                               player.Name, player.World.Name);
                    player.Confirm(cmd,
                                   "&WRemove ALL zones on this world ({0}&W)? This cannot be undone.&S",
                                   player.World.ClassyName);
                    return;
                }
                player.WorldMap.Zones.Clear();
                Logger.Log(LogType.UserActivity,
                           "Player {0} removed all zones on world {1}",
                           player.Name, player.World.Name);
                Server.Message("Player {0}&S removed all zones on world {1}",
                               player.ClassyName, player.World.ClassyName);
                return;
            }

            ZoneCollection zones = player.WorldMap.Zones;
            Zone           zone  = zones.Find(zoneName);

            if (zone != null)
            {
                if (!player.Info.Rank.AllowSecurityCircumvention)
                {
                    switch (zone.Controller.CheckDetailed(player.Info))
                    {
                    case SecurityCheckResult.BlackListed:
                        player.Message("You are not allowed to remove zone {0}: you are blacklisted.", zone.ClassyName);
                        return;

                    case SecurityCheckResult.RankTooLow:
                        player.Message("You are not allowed to remove zone {0}.", zone.ClassyName);
                        return;
                    }
                }
                if (!cmd.IsConfirmed)
                {
                    Logger.Log(LogType.UserActivity,
                               "ZRemove: Asked {0} to confirm removing zone {1} from world {2}",
                               player.Name, zone.Name, player.World.Name);
                    player.Confirm(cmd, "Remove zone {0}&S?", zone.ClassyName);
                    return;
                }

                if (zones.Remove(zone.Name))
                {
                    Logger.Log(LogType.UserActivity,
                               "Player {0} removed zone {1} from world {2}",
                               player.Name, zone.Name, player.World.Name);
                    player.Message("Zone \"{0}\" removed.", zone.Name);
                }
            }
            else
            {
                player.MessageNoZone(zoneName);
            }
        }
Ejemplo n.º 6
0
        static void ZoneAddHandler(Player player, CommandReader cmd)
        {
            World playerWorld = player.World;

            if (playerWorld == null)
            {
                PlayerOpException.ThrowNoWorld(player);
            }

            string givenZoneName = cmd.Next();

            if (givenZoneName == null)
            {
                CdZoneAdd.PrintUsage(player);
                return;
            }

            if (!player.Info.Rank.AllowSecurityCircumvention)
            {
                SecurityCheckResult buildCheck = playerWorld.BuildSecurity.CheckDetailed(player.Info);
                switch (buildCheck)
                {
                case SecurityCheckResult.BlackListed:
                    player.Message("Cannot add zones to world {0}&S: You are barred from building here.",
                                   playerWorld.ClassyName);
                    return;

                case SecurityCheckResult.RankTooLow:
                    player.Message("Cannot add zones to world {0}&S: You are not allowed to build here.",
                                   playerWorld.ClassyName);
                    return;
                }
            }

            Zone           newZone        = new Zone();
            ZoneCollection zoneCollection = player.WorldMap.Zones;

            if (givenZoneName.StartsWith("+"))
            {
                // personal zone (/ZAdd +Name)
                givenZoneName = givenZoneName.Substring(1);

                // Find the target player
                PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, givenZoneName);
                if (info == null)
                {
                    return;
                }

                // Make sure that the name is not taken already.
                // If a zone named after the player already exists, try adding a number after the name (e.g. "Notch2")
                newZone.Name = info.Name;
                for (int i = 2; zoneCollection.Contains(newZone.Name); i++)
                {
                    newZone.Name = givenZoneName + i;
                }

                newZone.Controller.MinRank = info.Rank.NextRankUp ?? info.Rank;
                newZone.Controller.Include(info);
                player.Message("ZoneAdd: Creating a {0}+&S zone for player {1}&S. Click or &H/Mark&S 2 blocks.",
                               newZone.Controller.MinRank.ClassyName, info.ClassyName);
                player.SelectionStart(2, ZoneAddCallback, newZone, CdZoneAdd.Permissions);
            }
            else
            {
                // Adding an ordinary, rank-restricted zone.
                if (!World.IsValidName(givenZoneName))
                {
                    player.Message("\"{0}\" is not a valid zone name", givenZoneName);
                    return;
                }

                if (zoneCollection.Contains(givenZoneName))
                {
                    player.Message("A zone with this name already exists. Use &H/ZEdit&S to edit.");
                    return;
                }

                newZone.Name = givenZoneName;

                string rankName = cmd.Next();
                if (rankName == null)
                {
                    player.Message("No rank was specified. See &H/Help zone");
                    return;
                }

                Rank minRank = RankManager.FindRank(rankName);
                if (minRank == null)
                {
                    player.MessageNoRank(rankName);
                    return;
                }

                string name;
                while ((name = cmd.Next()) != null)
                {
                    if (name.Length < 1)
                    {
                        CdZoneAdd.PrintUsage(player);
                        return;
                    }
                    PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, name.Substring(1));
                    if (info == null)
                    {
                        return;
                    }

                    if (name.StartsWith("+"))
                    {
                        newZone.Controller.Include(info);
                    }
                    else if (name.StartsWith("-"))
                    {
                        newZone.Controller.Exclude(info);
                    }
                }

                newZone.Controller.MinRank = minRank;
                player.SelectionStart(2, ZoneAddCallback, newZone, CdZoneAdd.Permissions);
                player.Message("ZoneAdd: Creating zone {0}&S. Click or &H/Mark&S 2 blocks.",
                               newZone.ClassyName);
            }
        }