Пример #1
1
        static void PayHandler(Player player, Command cmd)
        {
            string targetName = cmd.Next();
            string money = cmd.Next();
            int amount;

            if (money == null)
            {
                player.Message("&ePlease select the amount of bits you wish to send.");
                return;
            }

            Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
            if (target == null)
            {
                player.Message("&ePlease select a player to pay bits towards.");
                return;
            }

            if (!int.TryParse(money, out amount))
            {
                player.Message("&ePlease select from a whole number.");
                return;
            }

            PayHandler(player, new Command("/economy pay " + target + " " + money));
        }
Пример #2
0
        internal static void PokeHandler(Player player, Command cmd)
        {
            string targetName = cmd.Next();

            if (targetName == null)
            {
                CdPoke.PrintUsage(player);
                return;
            }
            Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);

            if (target == null)
            {
                return;
            }
            if (target.Immortal)
            {
                player.Message("&SYou cannot poke {0}&S because they are immortal.", target.ClassyName);
                return;
            }
            if (target == player)
            {
                player.Message("&SYou cannot poke yourself.");
                return;
            }
            if (!Player.IsValidName(targetName))
            {
                return;
            }
            target.Message("&8You were just poked by {0}&8.",
                           player.ClassyName);
            player.Message("&8You poked {0}&8.", target.ClassyName);
        }
Пример #3
0
        internal static void High5Handler(Player player, Command cmd)
        {
            string targetName = cmd.Next();

            if (targetName == null)
            {
                CdHighFive.PrintUsage(player);
                return;
            }
            Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);

            if (target == null)
            {
                return;
            }
            if (target == player)
            {
                player.Message("&WYou cannot high five yourself.");
                return;
            }
            Server.Players.CanSee(target)
            .Except(target)
            .Message("{0}&S was just &chigh fived &Sby {1}&S.", target.ClassyName, player.ClassyName);
            IRC.PlayerSomethingMessage(player, "high fived", target, null);
            target.Message("{0}&S high fived you.", player.ClassyName);
        }
Пример #4
0
        private static void VoteKickCheck()
        {
            if (VoteIsOn)
            {
                Server.Players.Message(
                    "{0}&S wanted to get {1} kicked. Reason: {2} \n&SResults are in! Yes: &A{3} &SNo: &C{4}",
                    VoteStarter,
                    TargetName, VoteKickReason, VotedYes, VotedNo);

                Player target = null;

                try
                {
                    target = Server.FindPlayerOrPrintMatches(Player.Console, TargetName, true, true);
                }
                catch (Exception ex)
                {
                    // Log exception
                    Logger.Log(LogType.Error, ex.Message);

                    // Notify users
                    Server.Message("Unexpected error while trying to execute votekick");

                    // Unable to find target so quit.
                    VoteIsOn   = false;
                    TargetName = null;
                    return;
                }

                if (target == null)
                {
                    Server.Message("{0}&S is offline", target.ClassyName);
                    return;
                }
                else if (VotedYes > VotedNo)
                {
                    Scheduler.NewTask(
                        t =>
                        target.Kick(Player.Console, "VoteKick by: " + VoteStarter + " - " + VoteKickReason,
                                    LeaveReason.Kick, false, true, false)).RunOnce(TimeSpan.FromSeconds(3));
                    Server.Players.Message("{0}&S was kicked from the server", target.ClassyName);
                }
                else
                {
                    Server.Players.Message("{0} &Sdid not get kicked from the server", target.ClassyName);
                }
                VoteIsOn   = false;
                TargetName = null;
                foreach (Player V in Voted)
                {
                    V.HasVoted = false;
                }
            }
        }
Пример #5
0
        private static void UnpossessHandler(Player player, Command cmd)
        {
            string targetName = cmd.Next();

            if (targetName == null)
            {
                CdUnpossess.PrintUsage(player);
                return;
            }
            Player target = Server.FindPlayerOrPrintMatches(player, targetName, true, true);

            if (target == null)
            {
                return;
            }

            if (!player.StopPossessing(target))
            {
                player.Message("You are not currently possessing anyone.");
            }
        }
Пример #6
0
        private static void PossessHandler(Player player, Command cmd)
        {
            string targetName = cmd.Next();

            if (targetName == null)
            {
                CdPossess.PrintUsage(player);
                return;
            }
            Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);

            if (target == null)
            {
                return;
            }
            if (target.Immortal)
            {
                player.Message("You cannot possess {0}&S, they are immortal", target.ClassyName);
                return;
            }
            if (target == player)
            {
                player.Message("You cannot possess yourself.");
                return;
            }

            if (!player.Can(Permission.Possess, target.Info.Rank))
            {
                player.Message("You may only possess players ranked {0}&S or lower.",
                               player.Info.Rank.GetLimit(Permission.Possess).ClassyName);
                player.Message("{0}&S is ranked {1}",
                               target.ClassyName, target.Info.Rank.ClassyName);
                return;
            }

            if (!player.Possess(target))
            {
                player.Message("Already possessing {0}", target.ClassyName);
            }
        }
Пример #7
0
        internal static void Where(Player player, Command cmd)
        {
            string name = cmd.Next();

            Player target = player;

            if (name != null)
            {
                target = Server.FindPlayerOrPrintMatches(player, name, false);
                if (target == null)
                {
                    return;
                }
            }
            else if (player.World == null)
            {
                player.Message("When called form console, &H/where&S requires a player name.");
                return;
            }

            player.Message("Player {0}&S is on world {1}&S:",
                           target.GetClassyName(),
                           target.World.GetClassyName());


            int offset = (int)(target.Position.R / 255f * 64f) + 32;

            player.Message("{0}({1},{2},{3}) - {4}[{5}{6}{7}{4}{8}]",
                           Color.Silver,
                           target.Position.X / 32,
                           target.Position.Y / 32,
                           target.Position.H / 32,
                           Color.White,
                           Compass.Substring(offset - 12, 11),
                           Color.Red,
                           Compass.Substring(offset - 1, 3),
                           Compass.Substring(offset + 2, 11));
        }
Пример #8
0
        public static void VoteParams(Player player, Command cmd)
        {
            string option = cmd.Next();

            if (option == null)
            {
                player.Message("Invalid param");
                return;
            }
            switch (option)
            {
            default:
                if (VoteIsOn)
                {
                    if (VoteKickReason == null)
                    {
                        player.Message("Last Question: {0}&C asked: {1}", VoteStarter, Question);
                        player.Message(Usage);
                        return;
                    }
                    else
                    {
                        player.Message("Last VoteKick: &CA VoteKick has started for {0}&C, reason: {1}", TargetName,
                                       VoteKickReason);
                    }
                    player.Message(Usage);
                    return;
                }
                else
                {
                    player.Message(option);
                }
                break;

            case "abort":
            case "stop":
                if (!VoteIsOn)
                {
                    player.Message("No vote is currently running");
                    return;
                }

                if (!player.Can(Permission.MakeVotes))
                {
                    player.Message("You do not have Permission to abort votes");
                    return;
                }
                VoteIsOn = false;
                foreach (Player V in Voted)
                {
                    if (V.HasVoted)
                    {
                        V.HasVoted = false;
                    }
                    V.Message("Your vote was cancelled");
                }
                Voted.Clear();
                TargetName = null;
                Server.Players.Message("{0} &Saborted the vote.", player.ClassyName);
                break;

            case "yes":
                if (!VoteIsOn)
                {
                    player.Message("No vote is currently running");
                    return;
                }

                if (player.HasVoted)
                {
                    player.Message("&CYou have already voted");
                    return;
                }
                Voted.Add(player);
                VotedYes++;
                player.HasVoted = true;
                player.Message("&8You have voted for 'Yes'");
                break;

            case "kick":
                string toKick = cmd.Next();
                string Reason = cmd.NextAll();
                VoteKickReason = Reason;
                if (toKick == null)
                {
                    player.Message("Target cannot be empty. " + Usage);
                    return;
                }

                Player target = Server.FindPlayerOrPrintMatches(player, toKick, false, true);

                if (target == null)
                {
                    // FIX: Target is null when no such player is online, this caused crashes
                    return;
                }

                if (!Player.IsValidName(target.Name))
                {
                    return;
                }

                if (!player.Can(Permission.MakeVoteKicks))
                {
                    player.Message("You do not have permissions to start a VoteKick");
                    return;
                }

                if (VoteIsOn)
                {
                    player.Message("A vote has already started. Each vote lasts 1 minute.");
                    return;
                }

                if (VoteKickReason.Length < 3)
                {
                    player.Message("Invalid reason");
                    return;
                }

                if (target == player)
                {
                    player.Message("You cannot VoteKick yourself, lol");
                    return;
                }

                VoteThread = new Thread(new ThreadStart(delegate
                {
                    TargetName = target.Name;
                    if (!Player.IsValidName(TargetName))
                    {
                        player.Message("Invalid name");
                        return;
                    }
                    NewVote();
                    VoteStarter = player.ClassyName;
                    Server.Players.Message("{0}&S started a VoteKick for player: {1}", player.ClassyName,
                                           target.ClassyName);
                    Server.Players.Message("&WReason: {0}", VoteKickReason);
                    Server.Players.Message("&9Vote now! &S/Vote &AYes &Sor /Vote &CNo");
                    VoteIsOn = true;
                    Logger.Log(LogType.SystemActivity, "{0} started a votekick on player {1} reason: {2}",
                               player.Name, target.Name, VoteKickReason);
                    Thread.Sleep(60000);
                    VoteKickCheck();
                }));
                VoteThread.Start();
                break;

            case "no":
                if (!VoteIsOn)
                {
                    player.Message("No vote is currently running");
                    return;
                }
                if (player.HasVoted)
                {
                    player.Message("&CYou have already voted");
                    return;
                }
                VotedNo++;
                Voted.Add(player);
                player.HasVoted = true;
                player.Message("&8You have voted for 'No'");
                break;

            case "1":
                if (PropHunt.IsOn)
                {
                    if (!PropHunt.VoteIsOn)
                    {
                        player.Message("Voting has not yet started.");
                        return;
                    }

                    if (player.HasVoted)
                    {
                        player.Message("&CYou have already voted.");
                        return;
                    }
                    PropHunt.Voted.Add(player);
                    PropHunt.Voted1++;
                    player.HasVoted = true;
                    player.Message("&8You have voted for {0}.", PropHunt.World1.ClassyName);
                }
                break;

            case "2":
                if (PropHunt.IsOn)
                {
                    if (!PropHunt.VoteIsOn)
                    {
                        player.Message("Voting has not yet started.");
                        return;
                    }

                    if (player.HasVoted)
                    {
                        player.Message("&CYou have already voted.");
                        return;
                    }
                    PropHunt.Voted.Add(player);
                    PropHunt.Voted2++;
                    player.HasVoted = true;
                    player.Message("&8You have voted for {0}.", PropHunt.World2.ClassyName);
                }
                break;

            case "3":
                if (PropHunt.IsOn)
                {
                    if (!PropHunt.VoteIsOn)
                    {
                        player.Message("Voting has not yet started.");
                        return;
                    }

                    if (player.HasVoted)
                    {
                        player.Message("&CYou have already voted.");
                        return;
                    }
                    PropHunt.Voted.Add(player);
                    PropHunt.Voted3++;
                    player.HasVoted = true;
                    player.Message("&8You have voted for {0}.", PropHunt.World3.ClassyName);
                }
                break;

            case "ask":
                string AskQuestion = cmd.NextAll();
                Question = AskQuestion;
                if (!player.Can(Permission.MakeVotes))
                {
                    player.Message("You do not have permissions to ask a question");
                    return;
                }
                if (VoteIsOn)
                {
                    player.Message("A vote has already started. Each vote lasts 1 minute.");
                    return;
                }
                if (Question.Length < 5)
                {
                    player.Message("Invalid question");
                    return;
                }

                VoteThread = new Thread(new ThreadStart(delegate
                {
                    NewVote();
                    VoteStarter = player.ClassyName;
                    Server.Players.Message("{0}&S Asked: {1}", player.ClassyName, Question);
                    Server.Players.Message("&9Vote now! &S/Vote &AYes &Sor /Vote &CNo");
                    VoteIsOn = true;
                    Thread.Sleep(60000);
                    VoteCheck();
                }));
                VoteThread.Start();
                break;
            }
        }
Пример #9
0
        static void EconomyHandler(Player player, Command cmd)
        {
            try
            {
                string option = cmd.Next();
                string targetName = cmd.Next();
                string amount = cmd.Next();
                int amountnum;
                if (option == null)
                {
                    CdEconomy.PrintUsage(player);
                }
                if (option == "give")
                {
                    if (!player.Can(Permission.ManageEconomy))
                    {
                        player.Message("&cYou do not have permission to use that command!");
                        return;
                    }
                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to give coins to.");
                        return;
                    }
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);

                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        if (!int.TryParse(amount, out amountnum))
                        {
                            player.Message("&eThe amount must be a number without any decimals!");
                            return;
                        }
                        if (cmd.IsConfirmed)
                        {
                            //actually give the player the money
                            int tNewMoney = target.Info.Money + amountnum;

                            if (amountnum == 1)
                            {
                                player.Message("&eYou have given {0} &C{1} &ecoin.", target.ClassyName, amountnum);
                                target.Message("&e{0} &ehas given you {1} &ecoin.", player.ClassyName, amountnum);
                                Server.Players.Except(target).Except(player).Message("&e{0} &ewas given {1} &ecoin by {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                            }
                            else
                            {
                                player.Message("&eYou have given {0} &C{1} &ecoins.", target.ClassyName, amountnum);
                                target.Message("&e{0} &ehas given you {1} &ecoins.", player.ClassyName, amountnum);
                                Server.Players.Except(target).Except(player).Message("&e{0} &ewas given {1} &ecoins by {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                            }

                            target.Info.Money = tNewMoney;
                            return;
                        }
                        else
                        {
                            if (amountnum == 1) {
                            player.Confirm(cmd, "&eAre you sure you want to give {0} &C{1} &ecoin?", target.ClassyName, amountnum);
                            return;
                        }
                        else {
                            player.Confirm(cmd, "&eAre you sure you want to give {0} &C{1} &ecoins?", target.ClassyName, amountnum);
                            return;
                        }
                        }

                    }
                }
                if (option == "take")
                {
                    if (!player.Can(Permission.ManageEconomy))
                    {
                        player.Message("&cYou do not have permission to use that command.");
                        return;
                    }
                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to take coins away from.");
                        return;
                    }
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);

                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        if (!int.TryParse(amount, out amountnum))
                        {
                            player.Message("&eThe amount must be a number!");
                            return;
                        }

                        if (cmd.IsConfirmed)
                        {
                            if (amountnum > target.Info.Money)
                            {
                                player.Message("{0}&e doesn't have that many coins!", target.ClassyName);
                                return;
                            }
                            else
                            {
                                //actually give the player the money
                                int tNewMoney = target.Info.Money - amountnum;
                                if (amountnum == 1)
                                {
                                    player.Message("&eYou have taken &c{1}&e coin from {0}.", target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas taken {1} &ecoin from you.", player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &etook {1} &ecoin from {2}&e.", player.ClassyName, amountnum, target.ClassyName);
                                }
                                else
                                {
                                    player.Message("&eYou have taken &c{1}&e coins from {0}.", target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas taken {1} &ecoins from you.", player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &etook {1} &ecoins from {2}&e.", player.ClassyName, amountnum, target.ClassyName);
                                }
                                target.Info.Money = tNewMoney;
                                return;
                            }
                        }
                        else
                        {
                            player.Confirm(cmd, "&eAre you sure you want to take &c{1} &ecoins from {0}?", target.ClassyName, amountnum);
                            return;
                        }

                    }


                }
                if (option == "pay")
                {
                    //lotsa idiot proofing in this one ^.^

                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to pay.");
                        return;
                    }
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
                    if (target == player)
                    {
                        player.Message("You cannot pay youself.");
                        return;
                    }

                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        if (!int.TryParse(amount, out amountnum))
                        {
                            player.Message("&eThe amount must be a number!");
                            return;
                        }

                        if (cmd.IsConfirmed)
                        {
                            if (amountnum > player.Info.Money)
                            {
                                player.Message("You don't have enough coins!");
                                return;
                            }
                            else
                            {
                                //show him da monai
                                int pNewMoney = player.Info.Money - amountnum;
                                int tNewMoney = target.Info.Money + amountnum;
                                if (amountnum == 1)
                                {
                                    player.Message("&eYou have paid &C{1}&e coin to {0}.", target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas paid you {1} &ecoin.", player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &ewas paid {1} &ecoin from {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                                }
                                else
                                {
                                    player.Message("&eYou have paid &C{1}&e coins to {0}.", target.ClassyName, amountnum);
                                    target.Message("&e{0} &ehas paid you {1} &ecoins.", player.ClassyName, amountnum);
                                    Server.Players.Except(target).Except(player).Message("&e{0} &ewas paid {1} &ecoins from {2}&e.", target.ClassyName, amountnum, player.ClassyName);
                                }
                                player.Info.Money = pNewMoney;
                                target.Info.Money = tNewMoney;
                                return;
                            }
                        }
                        else
                        {
                            player.Confirm(cmd, "&eAre you sure you want to pay {0}&e {1} &ecoins? Type /ok to continue.", target.ClassyName, amountnum);
                            return;
                        }


                    }
                }


                else if (option == "show")
                {

                    if (targetName == null)
                    {
                        player.Message("&ePlease type in a player's name to see how many coins they have.");
                        return;
                    }
                    Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);

                    if (target == null)
                    {
                        return;
                    }
                    else
                    {
                        //actually show how much money that person has
                        player.Message("&e{0} has &C{1} &ecoins!", target.ClassyName, target.Info.Money);
                    }

                }
                else
                {
                    player.Message("&eOptions are &a/Economy pay&e, &a/Economy take&e, &a/Economy give&e, and &a/Economy show&e.");
                    return;
                }
            }
            catch (ArgumentNullException)
            {
                CdEconomy.PrintUsage(player);
            }
        }
Пример #10
0
        public static PlayerInfo FindPlayerInfoOrPrintMatches([NotNull] Player player, [NotNull] string namePart,
                                                              SearchOptions options)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (namePart == null)
            {
                throw new ArgumentNullException("namePart");
            }
            CheckIfLoaded();

            bool includeSelf = (options & SearchOptions.IncludeSelf) != 0;
            bool returnSelf  = (options & SearchOptions.ReturnSelfIfOnlyMatch) != 0;

            // If name starts with '!', return matches for online players only
            if (namePart.Length > 1 && namePart[0] == '!')
            {
                namePart = namePart.Substring(1);
                Player targetPlayer = Server.FindPlayerOrPrintMatches(player, namePart, options);
                if (targetPlayer != null)
                {
                    return(targetPlayer.Info);
                }
                else
                {
                    player.Message("No online players found matching \"{0}\"", namePart);
                    return(null);
                }
            }

            // Repeat last-used player name
            if (namePart == "-")
            {
                if (player.LastUsedPlayerName != null)
                {
                    namePart = player.LastUsedPlayerName;
                }
                else
                {
                    player.Message("Cannot repeat player name: you haven't used any names yet.");
                    return(null);
                }
            }

            // Make sure player name is valid
            if (!Player.ContainsValidCharacters(namePart))
            {
                player.MessageInvalidPlayerName(namePart);
                return(null);
            }

            // Search for exact matches first
            PlayerInfo target = FindPlayerInfoExact(namePart);

            // If no exact match was found, look for partial matches
            if (target == null || target == player.Info && !includeSelf)
            {
                PlayerInfo[] targets = FindPlayers(namePart);

                if (!includeSelf)
                {
                    // special handling if IncludeSelf flag is not set
                    if (targets.Length > 1)
                    {
                        targets = targets.Where(p => p != player.Info).ToArray();
                    }
                    else if (!returnSelf && targets.Length == 1 && targets[0] == player.Info)
                    {
                        // special handling if ReturnSelfIfOnlyMatch flag is not set
                        targets = new PlayerInfo[0];
                    }
                }

                if (targets.Length == 0)
                {
                    // No matches
                    player.MessageNoPlayer(namePart);
                    return(null);
                }
                else if (targets.Length > 1)
                {
                    // More than one match
                    Array.Sort(targets, new PlayerInfoComparer(player));
                    player.MessageManyMatches("player", targets.Take(MatchesToPrint).ToArray());
                    return(null);
                } // else: one match!
                target = targets[0];
            }

            // If a single name has been found, set it as LastUsedPlayerName
            if (includeSelf || target != player.Info)
            {
                player.LastUsedPlayerName = target.Name;
            }
            return(target);
        }
Пример #11
0
        public static PlayerInfo FindPlayerInfoOrPrintMatches([NotNull] Player player, [NotNull] string partialName)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (partialName == null)
            {
                throw new ArgumentNullException("partialName");
            }
            CheckIfLoaded();

            // If name starts with '!', return matches for online players only
            if (partialName.Length > 1 && partialName[0] == '!')
            {
                partialName = partialName.Substring(1);
                Player targetPlayer = Server.FindPlayerOrPrintMatches(player, partialName, false, true);
                if (targetPlayer != null)
                {
                    return(targetPlayer.Info);
                }
                else
                {
                    player.Message("No online players found matching \"{0}\"", partialName);
                    return(null);
                }
            }

            // Repeat last-used player name
            if (partialName == "-")
            {
                if (player.LastUsedPlayerName != null)
                {
                    partialName = player.LastUsedPlayerName;
                }
                else
                {
                    player.Message("Cannot repeat player name: you haven't used any names yet.");
                    return(null);
                }
            }

            // Make sure player name is valid
            if (!Player.ContainsValidCharacters(partialName))
            {
                player.MessageInvalidPlayerName(partialName);
                return(null);
            }

            // Search for exact matches first
            PlayerInfo target = FindPlayerInfoExact(partialName);

            // If no exact match was found, look for partial matches
            if (target == null)
            {
                PlayerInfo[] targets = FindPlayers(partialName);
                if (targets.Length == 0)
                {
                    // No matches
                    player.MessageNoPlayer(partialName);
                    return(null);
                }
                else if (targets.Length > 1)
                {
                    // More than one match
                    Array.Sort(targets, new PlayerInfoComparer(player));
                    player.MessageManyMatches("player", targets.Take(25).ToArray());
                    return(null);
                } // else: one match!
                target = targets[0];
            }

            // If a single name has been found, set it as LastUsedPlayerName
            player.LastUsedPlayerName = target.Name;
            return(target);
        }