Ejemplo n.º 1
0
        static void ZoneAddCallback(Player player, Vector3I[] marks, object tag)
        {
            World playerWorld = player.World;

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

            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;
                    //case SecurityCheckResult.RankTooHigh:
                }
            }

            Zone zone  = (Zone)tag;
            var  zones = player.WorldMap.Zones;

            lock (zones.SyncRoot) {
                Zone dupeZone = zones.FindExact(zone.Name);
                if (dupeZone != null)
                {
                    player.Message("A zone named \"{0}\" has just been created by {1}",
                                   dupeZone.Name, dupeZone.CreatedBy);
                    return;
                }

                zone.Create(new BoundingBox(marks[0], marks[1]), player.Info);

                player.Message("Zone \"{0}\" created, {1} blocks total.",
                               zone.Name, zone.Bounds.Volume);
                Logger.Log(LogType.UserActivity,
                           "Player {0} created a new zone \"{1}\" containing {2} blocks.",
                           player.Name,
                           zone.Name,
                           zone.Bounds.Volume);

                zones.Add(zone);
            }
        }
Ejemplo n.º 2
0
        public override bool Prepare(Vector3I[] marks)
        {
            if (Player.World == null && !Player.IsSuper)
            {
                PlayerOpException.ThrowNoWorld(Player);
            }
            if (!base.Prepare(marks))
            {
                return(false);
            }

            BlocksTotalEstimate = Bounds.Volume;
            Coords = Bounds.MinVertex;

            Context |= BlockChangeContext.Cut;
            return(true);
        }
Ejemplo n.º 3
0
        public override bool Prepare(Vector3I[] marks)
        {
            if (Player.World == null)
            {
                PlayerOpException.ThrowNoWorld(Player);
            }
            if (!base.Prepare(marks))
            {
                return(false);
            }

            BlocksTotalEstimate = Bounds.Volume;
            Coords = Bounds.MinVertex;

            // remember dimensions and orientation
            CopyState copyInfo = new CopyState(marks[0], marks[1]);

            for (int x = Bounds.XMin; x <= Bounds.XMax; x++)
            {
                for (int y = Bounds.YMin; y <= Bounds.YMax; y++)
                {
                    for (int z = Bounds.ZMin; z <= Bounds.ZMax; z++)
                    {
                        copyInfo.Buffer[x - Bounds.XMin, y - Bounds.YMin, z - Bounds.ZMin] = Map.GetBlock(x, y, z);
                    }
                }
            }
            copyInfo.OriginWorld = Player.World.Name;
            copyInfo.CopyTime    = DateTime.UtcNow;
            Player.SetCopyInformation(copyInfo);

            Player.Message("{0} blocks cut into slot #{1}. You can now &H/Paste",
                           Bounds.Volume, Player.CopySlot + 1);
            Player.Message("Origin at {0} {1}{2} corner.",
                           (copyInfo.Orientation.X == 1 ? "bottom" : "top"),
                           (copyInfo.Orientation.Y == 1 ? "south" : "north"),
                           (copyInfo.Orientation.Z == 1 ? "east" : "west"));

            Context |= BlockChangeContext.Cut;
            return(true);
        }
Ejemplo n.º 4
0
        static void ZoneRenameHandler(Player player, Command cmd)
        {
            World playerWorld = player.World;

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

            // make sure that both parameters are given
            string oldName = cmd.Next();
            string newName = cmd.Next();

            if (oldName == null || newName == null)
            {
                CdZoneRename.PrintUsage(player);
                return;
            }

            // make sure that the new name is valid
            if (!World.IsValidName(newName))
            {
                player.Message("\"{0}\" is not a valid zone name", newName);
                return;
            }

            // find the old zone
            var  zones   = player.WorldMap.Zones;
            Zone oldZone = zones.Find(oldName);

            if (oldZone == null)
            {
                player.MessageNoZone(oldName);
                return;
            }

            // Check if a zone with "newName" name already exists
            Zone newZone = zones.FindExact(newName);

            if (newZone != null && newZone != oldZone)
            {
                player.Message("A zone with the name \"{0}\" already exists.", newName);
                return;
            }

            // check if any change is needed
            string fullOldName = oldZone.Name;

            if (fullOldName == newName)
            {
                player.Message("The zone is already named \"{0}\"", fullOldName);
                return;
            }

            // actually rename the zone
            zones.Rename(oldZone, newName);

            // announce the rename
            playerWorld.Players.Message("&SZone \"{0}\" was renamed to \"{1}&S\" by {2}", 0,
                                        fullOldName, oldZone.ClassyName, player.ClassyName);
            Logger.Log(LogType.UserActivity,
                       "Player {0} renamed zone \"{1}\" to \"{2}\" on world {3}",
                       player.Name, fullOldName, newName, playerWorld.Name);
        }
Ejemplo n.º 5
0
        static void ZoneAddHandler(Player player, Command 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;
                    //case SecurityCheckResult.RankTooHigh:
                }
            }

            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("Zone: Creating a {0}+&S zone for player {1}&S.",
                               newZone.Controller.MinRank.ClassyName, info.ClassyName);
            }
            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)
                {
                    string name;
                    while ((name = cmd.Next()) != null)
                    {
                        if (name.Length == 0)
                        {
                            continue;
                        }

                        if (name.ToLower().StartsWith("msg="))
                        {
                            newZone.Message = name.Substring(4) + " " + (cmd.NextAll() ?? "");
                            player.Message("Zone: Custom denied messaged changed to '" + newZone.Message + "'");
                            break;
                        }

                        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;
                }
                else
                {
                    player.MessageNoRank(rankName);
                    return;
                }
            }
            player.Message("Zone " + newZone.ClassyName + "&S: Place a block or type &H/Mark&S to use your location.");
            player.SelectionStart(2, ZoneAddCallback, newZone, CdZoneAdd.Permissions);
        }