FindByPartialNameOrPrintMatches() private method

private FindByPartialNameOrPrintMatches ( [ player, [ partialName ) : PlayerInfo
player [
partialName [
return PlayerInfo
        static void InfoSwapHandler(Player player, CommandReader cmd)
        {
            string p1Name = cmd.Next();
            string p2Name = cmd.Next();

            if (p1Name == null || p2Name == null)
            {
                CdInfoSwap.PrintUsage(player);
                return;
            }

            PlayerInfo p1 = PlayerDB.FindByPartialNameOrPrintMatches(player, p1Name);

            if (p1 == null)
            {
                return;
            }
            PlayerInfo p2 = PlayerDB.FindByPartialNameOrPrintMatches(player, p2Name);

            if (p2 == null)
            {
                return;
            }

            if (p1 == p2)
            {
                player.Message("InfoSwap: Please specify 2 different players.");
                return;
            }

            if (p1.IsOnline || p2.IsOnline)
            {
                player.Message("InfoSwap: Both players must be offline to swap info.");
                return;
            }

            if (!cmd.IsConfirmed)
            {
                player.Confirm(cmd, "InfoSwap: Swap stats of players {0}&S and {1}&S?", p1.ClassyName, p2.ClassyName);
            }
            else
            {
                PlayerDB.SwapPlayerInfo(p1, p2);
                player.Message("InfoSwap: Stats of {0}&S and {1}&S have been swapped.",
                               p1.ClassyName, p2.ClassyName);
            }
        }
Example #2
0
        static void IgnoreHandler(Player player, CommandReader cmd)
        {
            string name = cmd.Next();

            if (name != null)
            {
                if (cmd.HasNext)
                {
                    CdIgnore.PrintUsage(player);
                    return;
                }
                PlayerInfo targetInfo = PlayerDB.FindByPartialNameOrPrintMatches(player, name);
                if (targetInfo == null)
                {
                    return;
                }

                if (targetInfo == player.Info)
                {
                    player.MessageNow("You cannot ignore yourself.");
                    return;
                }

                if (player.Ignore(targetInfo))
                {
                    player.MessageNow("You are now ignoring {0}", targetInfo.ClassyName);
                }
                else
                {
                    player.MessageNow("You are already ignoring {0}", targetInfo.ClassyName);
                }
            }
            else
            {
                PlayerInfo[] ignoreList = player.IgnoreList;
                if (ignoreList.Length > 0)
                {
                    player.MessageNow("Ignored players: {0}", ignoreList.JoinToClassyString());
                }
                else
                {
                    player.MessageNow("You are not currently ignoring anyone.");
                }
            }
        }
Example #3
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;

                    //case SecurityCheckResult.RankTooHigh: // TODO
                }
            }

            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.FindByPartialNameOrPrintMatches(player, givenZoneName);
                if (info == null)
                {
                    return;
                }
                givenZoneName = info.Name;

                // 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 = givenZoneName;
                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. Place a block or type /Mark to use your location.",
                               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)
                {
                    string name;
                    while ((name = cmd.Next()) != null)
                    {
                        if (name.Length == 0)
                        {
                            continue;
                        }

                        PlayerInfo info = PlayerDB.FindByPartialNameOrPrintMatches(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("Zone: Place a block or type &H/Mark&S to use your location.");
                }
                else
                {
                    player.MessageNoRank(rankName);
                }
            }
        }
        static void SetInfoHandler(Player player, CommandReader cmd)
        {
            string targetName   = cmd.Next();
            string propertyName = cmd.Next();
            string valName      = cmd.NextAll();

            if (targetName == null || propertyName == null)
            {
                CdSetInfo.PrintUsage(player);
                return;
            }

            PlayerInfo info = PlayerDB.FindByPartialNameOrPrintMatches(player, targetName);

            if (info == null)
            {
                return;
            }

            switch (propertyName.ToLower())
            {
            case "banreason":
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (SetPlayerInfoField(player, "BanReason", info, info.BanReason, valName))
                {
                    info.BanReason = valName;
                }
                break;

            case "displayedname":
                string oldDisplayedName = info.DisplayedName;
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (valName == info.DisplayedName)
                {
                    if (valName == null)
                    {
                        player.Message("SetInfo: DisplayedName for {0} is not set.",
                                       info.Name);
                    }
                    else
                    {
                        player.Message("SetInfo: DisplayedName for {0} is already set to \"{1}&S\"",
                                       info.Name,
                                       valName);
                    }
                    break;
                }
                info.DisplayedName = valName;

                if (oldDisplayedName == null)
                {
                    player.Message("SetInfo: DisplayedName for {0} set to \"{1}&S\"",
                                   info.Name,
                                   valName);
                }
                else if (valName == null)
                {
                    player.Message("SetInfo: DisplayedName for {0} was reset (was \"{1}&S\")",
                                   info.Name,
                                   oldDisplayedName);
                }
                else
                {
                    player.Message("SetInfo: DisplayedName for {0} changed from \"{1}&S\" to \"{2}&S\"",
                                   info.Name,
                                   oldDisplayedName,
                                   valName);
                }
                break;

            case "kickreason":
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (SetPlayerInfoField(player, "KickReason", info, info.LastKickReason, valName))
                {
                    info.LastKickReason = valName;
                }
                break;

            case "name":
                if (valName.Equals(info.Name, StringComparison.OrdinalIgnoreCase))
                {
                    player.Message("SetInfo: You may change capitalization of player's real name. " +
                                   "If you'd like to make other changes to the way player's name is displayed, " +
                                   "use &H/SetInfo <Name> DisplayedName <NewName>");
                    break;
                }
                string oldName = info.Name;
                if (oldName != valName)
                {
                    info.Name = valName;
                    player.Message("Name capitalization changed from \"{0}\" to \"{1}\"",
                                   oldName, valName);
                }
                else
                {
                    player.Message("Name capitalization is already \"{0}\"", oldName);
                }
                break;

            case "previousrank":
                Rank newPreviousRank;
                if (valName.Length > 0)
                {
                    newPreviousRank = RankManager.FindRank(valName);
                    if (newPreviousRank == null)
                    {
                        player.MessageNoRank(valName);
                        break;
                    }
                }
                else
                {
                    newPreviousRank = null;
                }

                Rank oldPreviousRank = info.PreviousRank;

                if (newPreviousRank == oldPreviousRank)
                {
                    if (newPreviousRank == null)
                    {
                        player.Message("SetInfo: PreviousRank for {0}&S is not set.",
                                       info.ClassyName);
                    }
                    else
                    {
                        player.Message("SetInfo: PreviousRank for {0}&S is already set to {1}",
                                       info.ClassyName,
                                       newPreviousRank.ClassyName);
                    }
                    break;
                }
                info.PreviousRank = newPreviousRank;

                if (oldPreviousRank == null)
                {
                    player.Message("SetInfo: PreviousRank for {0}&S set to {1}&",
                                   info.ClassyName,
                                   newPreviousRank.ClassyName);
                }
                else if (newPreviousRank == null)
                {
                    player.Message("SetInfo: PreviousRank for {0}&S was reset (was {1}&S)",
                                   info.ClassyName,
                                   oldPreviousRank.ClassyName);
                }
                else
                {
                    player.Message("SetInfo: PreviousRank for {0}&S changed from {1}&S to {2}",
                                   info.ClassyName,
                                   oldPreviousRank.ClassyName,
                                   newPreviousRank.ClassyName);
                }
                break;

            case "rankchangetype":
                RankChangeType oldType = info.RankChangeType;
                try {
                    info.RankChangeType = (RankChangeType)Enum.Parse(typeof(RankChangeType), valName, true);
                } catch (ArgumentException) {
                    player.Message("SetInfo: Could not parse RankChangeType. Allowed values: {0}",
                                   String.Join(", ", Enum.GetNames(typeof(RankChangeType))));
                    break;
                }
                player.Message("SetInfo: RankChangeType for {0}&S changed from {1} to {2}",
                               info.ClassyName,
                               oldType,
                               info.RankChangeType);
                break;

            case "rankreason":
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (SetPlayerInfoField(player, "RankReason", info, info.RankChangeReason, valName))
                {
                    info.RankChangeReason = valName;
                }
                break;

            case "timeskicked":
                int oldTimesKicked = info.TimesKicked;
                if (ValidateInt(valName, 0, 9999))
                {
                    info.TimesKicked = Int32.Parse(valName);
                    player.Message("SetInfo: TimesKicked for {0}&S changed from {1} to {2}",
                                   info.ClassyName,
                                   oldTimesKicked,
                                   info.TimesKicked);
                }
                else
                {
                    player.Message("SetInfo: TimesKicked value out of range (Acceptable value range: 0-9999)");
                }
                break;

            case "totaltime":
                TimeSpan newTotalTime;
                TimeSpan oldTotalTime = info.TotalTime;
                if (valName.TryParseMiniTimespan(out newTotalTime))
                {
                    if (newTotalTime > DateTimeUtil.MaxTimeSpan)
                    {
                        player.MessageMaxTimeSpan();
                        break;
                    }
                    info.TotalTime = newTotalTime;
                    player.Message("SetInfo: TotalTime for {0}&S changed from {1} ({2}) to {3} ({4})",
                                   info.ClassyName,
                                   oldTotalTime.ToMiniString(),
                                   oldTotalTime.ToCompactString(),
                                   info.TotalTime.ToMiniString(),
                                   info.TotalTime.ToCompactString());
                }
                else
                {
                    player.Message("SetInfo: Could not parse value given for TotalTime.");
                }
                break;

            case "unbanreason":
                if (valName.Length == 0)
                {
                    valName = null;
                }
                if (SetPlayerInfoField(player, "UnbanReason", info, info.UnbanReason, valName))
                {
                    info.UnbanReason = valName;
                }
                break;

            default:
                player.Message("Only the following properties are editable: " +
                               "TimesKicked, PreviousRank, TotalTime, RankChangeType, " +
                               "BanReason, UnbanReason, RankReason, KickReason, DisplayedName");
                return;
            }
        }
Example #5
0
        static void ZoneEditHandler(Player player, CommandReader cmd)
        {
            bool   changesWereMade = false;
            string zoneName        = cmd.Next();

            if (zoneName == null)
            {
                player.Message("No zone name specified. See &H/Help ZEdit");
                return;
            }

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

            if (zone == null)
            {
                player.MessageNoZone(zoneName);
                return;
            }

            string nextToken;

            while ((nextToken = cmd.Next()) != null)
            {
                // Clear whitelist
                if (nextToken.Equals("-*"))
                {
                    PlayerInfo[] oldWhitelist = zone.Controller.ExceptionList.Included;
                    if (oldWhitelist.Length > 0)
                    {
                        zone.Controller.ResetIncludedList();
                        player.Message("Whitelist of zone {0}&S cleared: {1}",
                                       zone.ClassyName, oldWhitelist.JoinToClassyString());
                        Logger.Log(LogType.UserActivity,
                                   "Player {0} cleared whitelist of zone {1} on world {2}: {3}",
                                   player.Name, zone.Name, player.World.Name,
                                   oldWhitelist.JoinToString(pi => pi.Name));
                    }
                    else
                    {
                        player.Message("Whitelist of zone {0}&S is empty.",
                                       zone.ClassyName);
                    }
                    continue;
                }

                // Clear blacklist
                if (nextToken.Equals("+*"))
                {
                    PlayerInfo[] oldBlacklist = zone.Controller.ExceptionList.Excluded;
                    if (oldBlacklist.Length > 0)
                    {
                        zone.Controller.ResetExcludedList();
                        player.Message("Blacklist of zone {0}&S cleared: {1}",
                                       zone.ClassyName, oldBlacklist.JoinToClassyString());
                        Logger.Log(LogType.UserActivity,
                                   "Player {0} cleared blacklist of zone {1} on world {2}: {3}",
                                   player.Name, zone.Name, player.World.Name,
                                   oldBlacklist.JoinToString(pi => pi.Name));
                    }
                    else
                    {
                        player.Message("Blacklist of zone {0}&S is empty.",
                                       zone.ClassyName);
                    }
                    continue;
                }

                if (nextToken.StartsWith("+"))
                {
                    PlayerInfo info = PlayerDB.FindByPartialNameOrPrintMatches(player, nextToken.Substring(1));
                    if (info == null)
                    {
                        return;
                    }

                    // prevent players from whitelisting themselves to bypass protection
                    if (!player.Info.Rank.AllowSecurityCircumvention && player.Info == info)
                    {
                        switch (zone.Controller.CheckDetailed(info))
                        {
                        case SecurityCheckResult.BlackListed:
                            player.Message("You are not allowed to remove yourself from the blacklist of zone {0}",
                                           zone.ClassyName);
                            continue;

                        case SecurityCheckResult.RankTooLow:
                            player.Message("You must be {0}+&S to add yourself to the whitelist of zone {1}",
                                           zone.Controller.MinRank.ClassyName, zone.ClassyName);
                            continue;
                        }
                    }

                    switch (zone.Controller.Include(info))
                    {
                    case PermissionOverride.Deny:
                        player.Message("{0}&S is no longer excluded from zone {1}",
                                       info.ClassyName, zone.ClassyName);
                        changesWereMade = true;
                        break;

                    case PermissionOverride.None:
                        player.Message("{0}&S is now included in zone {1}",
                                       info.ClassyName, zone.ClassyName);
                        changesWereMade = true;
                        break;

                    case PermissionOverride.Allow:
                        player.Message("{0}&S is already included in zone {1}",
                                       info.ClassyName, zone.ClassyName);
                        break;
                    }
                }
                else if (nextToken.StartsWith("-"))
                {
                    PlayerInfo info = PlayerDB.FindByPartialNameOrPrintMatches(player, nextToken.Substring(1));
                    if (info == null)
                    {
                        return;
                    }

                    switch (zone.Controller.Exclude(info))
                    {
                    case PermissionOverride.Deny:
                        player.Message("{0}&S is already excluded from zone {1}",
                                       info.ClassyName, zone.ClassyName);
                        break;

                    case PermissionOverride.None:
                        player.Message("{0}&S is now excluded from zone {1}",
                                       info.ClassyName, zone.ClassyName);
                        changesWereMade = true;
                        break;

                    case PermissionOverride.Allow:
                        player.Message("{0}&S is no longer included in zone {1}",
                                       info.ClassyName, zone.ClassyName);
                        changesWereMade = true;
                        break;
                    }
                }
                else
                {
                    Rank minRank = RankManager.FindRank(nextToken);

                    if (minRank != null)
                    {
                        // prevent players from lowering rank so bypass protection
                        if (!player.Info.Rank.AllowSecurityCircumvention &&
                            zone.Controller.MinRank > player.Info.Rank && minRank <= player.Info.Rank)
                        {
                            player.Message("You are not allowed to lower the zone's rank.");
                            continue;
                        }

                        if (zone.Controller.MinRank != minRank)
                        {
                            zone.Controller.MinRank = minRank;
                            player.Message("Permission for zone \"{0}\" changed to {1}+",
                                           zone.Name,
                                           minRank.ClassyName);
                            changesWereMade = true;
                        }
                    }
                    else
                    {
                        player.MessageNoRank(nextToken);
                    }
                }

                if (changesWereMade)
                {
                    zone.Edit(player.Info);
                }
                else
                {
                    player.Message("No changes were made to the zone.");
                }
            }
        }