/fCraft/Commands/ModerationCommands.cs
C# | 3299 lines | 2850 code | 362 blank | 87 comment | 625 complexity | 0e6de37676c89544b295c56f0c87daf7 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- // Copyright 2009-2012 Matvei Stefarov <me@matvei.org>
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using fCraft.Events;
- using JetBrains.Annotations;
- using System.IO;
- namespace fCraft {
- /// <summary>
- /// Most commands for server moderation - kick, ban, rank change, etc - are here.
- /// </summary>
- static class ModerationCommands {
- const string BanCommonHelp = "Ban information can be viewed with &H/BanInfo";
- internal static void Init() {
- CdBan.Help += BanCommonHelp;
- CdBanIP.Help += BanCommonHelp;
- CdBanAll.Help += BanCommonHelp;
- CdUnban.Help += BanCommonHelp;
- CdUnbanIP.Help += BanCommonHelp;
- CdUnbanAll.Help += BanCommonHelp;
- CommandManager.RegisterCommand( CdBan );
- CommandManager.RegisterCommand( CdBanIP );
- CommandManager.RegisterCommand( CdUnban );
- CommandManager.RegisterCommand( CdUnbanIP );
- CommandManager.RegisterCommand( CdUnbanAll );
- CommandManager.RegisterCommand( CdBanEx );
- CommandManager.RegisterCommand( CdKick );
- CommandManager.RegisterCommand( CdRank );
- CommandManager.RegisterCommand( CdHide );
- CommandManager.RegisterCommand( CdUnhide );
- CommandManager.RegisterCommand( CdSetSpawn );
- CommandManager.RegisterCommand( CdFreeze );
- CommandManager.RegisterCommand( CdUnfreeze );
- CommandManager.RegisterCommand( CdTP );
- CommandManager.RegisterCommand( CdBring );
- CommandManager.RegisterCommand( CdWorldBring );
- CommandManager.RegisterCommand( CdBringAll );
- CommandManager.RegisterCommand( CdPatrol );
- CommandManager.RegisterCommand( CdSpecPatrol );
- CommandManager.RegisterCommand( CdMute );
- CommandManager.RegisterCommand( CdUnmute );
- CommandManager.RegisterCommand( CdSpectate );
- CommandManager.RegisterCommand( CdUnspectate );
- CommandManager.RegisterCommand( CdSlap );
- CommandManager.RegisterCommand( CdTPZone );
- CommandManager.RegisterCommand( CdBasscannon );
- CommandManager.RegisterCommand( CdKill );
- CommandManager.RegisterCommand( CdTempBan );
- CommandManager.RegisterCommand( CdWarn );
- CommandManager.RegisterCommand( CdUnWarn );
- CommandManager.RegisterCommand( CdDisconnect );
- CommandManager.RegisterCommand( CdImpersonate );
- CommandManager.RegisterCommand( CdImmortal );
- CommandManager.RegisterCommand( CdTitle );
-
- CommandManager.RegisterCommand( CdMuteAll );
- CommandManager.RegisterCommand( CdAssassinate );
- CommandManager.RegisterCommand( CdPunch );
- CommandManager.RegisterCommand( CdBanAll );
- CommandManager.RegisterCommand( CdEconomy );
- CommandManager.RegisterCommand( CdPay );
- CommandManager.RegisterCommand(CdBanGrief);
- CommandManager.RegisterCommand(CdStealthKick);
- CommandManager.RegisterCommand(CdBeatDown);
- CommandManager.RegisterCommand(CdLastCommand);
- CommandManager.RegisterCommand(CdFreezeBring);
- CommandManager.RegisterCommand(CdTempRank);
- CommandManager.RegisterCommand(CdSetClickDistance);
- CommandManager.RegisterCommand(CdAutoRank);
- CommandManager.RegisterCommand(CdAnnounce);
- CommandManager.RegisterCommand(CdForceHold);
- CommandManager.RegisterCommand(CdGetBlock);
- //CommandManager.RegisterCommand(CdTPA);
- }
- #region LegendCraft
- /* Copyright (c) <2012-2014> <LeChosenOne, DingusBungus>
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.*/
- static readonly CommandDescriptor CdGetBlock = new CommandDescriptor
- {
- Name = "GetBlock",
- IsConsoleSafe = true,
- Category = CommandCategory.Moderation,
- Permissions = new[] { Permission.Spectate },
- Help = "&SReturns the block that the player is currently holding.",
- Usage = "&S/GetBlock [player]",
- Handler = GetBlockHandler
- };
- private static void GetBlockHandler(Player player, Command cmd)
- {
- string target = cmd.Next();
- if (String.IsNullOrEmpty(target))
- {
- CdGetBlock.PrintUsage(player);
- return;
- }
- Player targetPlayer = Server.FindPlayerOrPrintMatches(player, target, false, true);
- if (targetPlayer == null)
- {
- return;
- }
- player.Message("{0} is currently holding {1}.", targetPlayer.Name, targetPlayer.Info.HeldBlock.ToString() );
- }
- static readonly CommandDescriptor CdForceHold = new CommandDescriptor
- {
- Name = "ForceHold",
- IsConsoleSafe = false,
- Category = CommandCategory.Moderation,
- Permissions = new[] { Permission.Spectate },
- Help = "&SForces a player to hold a certain block. Only use when needed!",
- Usage = "&S/ForceHold [player] [block]",
- Handler = FHHandler
- };
- private static void FHHandler(Player player, Command cmd)
- {
- if (!Heartbeat.ClassiCube() || !player.ClassiCube)
- {
- player.Message("This is a ClassiCube only command!");
- return;
- }
- string target = cmd.Next();
- if (String.IsNullOrEmpty(target))
- {
- CdForceHold.PrintUsage(player);
- return;
- }
- Player p = Server.FindPlayerOrPrintMatches(player, target, false, true);
- if (p == null)
- {
- return;
- }
- string blockStr = cmd.Next();
- if (String.IsNullOrEmpty(blockStr))
- {
- CdForceHold.PrintUsage(player);
- return;
- }
- //format blockname to be "Stone" instead of "STONE" or "stone"
- blockStr = blockStr.Substring(0, 1).ToUpper() + blockStr.Substring(1).ToLower();
- Block block;
- try
- {
- block = (Block)Enum.Parse(typeof(Block), blockStr);
- }
- catch
- {
- player.Message("Sorry, that was not a valid block name!");
- return;
- }
- p.Send(PacketWriter.MakeHoldThis((byte)block, false));
- }
- static readonly CommandDescriptor CdAnnounce = new CommandDescriptor //todo: make this work lol
- {
- Name = "Announce",
- IsConsoleSafe = true,
- Category = CommandCategory.Moderation,
- Permissions = new[] { Permission.Say },
- Help = "&SAnnounces a message at the top of every player's screen on a specified world. To send a server-wide announcement, use /Announce all [message].",
- Usage = "&S/Announce [world] [message]",
- Handler = AnnounceHandler
- };
- private static void AnnounceHandler(Player player, Command cmd)
- {
- if (!Heartbeat.ClassiCube() || !player.ClassiCube)
- {
- player.Message("This is a ClassiCube only command!");
- return;
- }
- Player[] targetPlayers;
- string world = cmd.Next();
- if(string.IsNullOrEmpty(world))
- {
- CdAnnounce.PrintUsage(player);
- return;
- }
- if (world == "all")
- {
- targetPlayers = Server.Players;
- }
- else
- {
- World[] targetWorlds = WorldManager.FindWorlds(player, world);
- if (targetWorlds.Length > 1)
- {
- player.MessageManyMatches("world", targetWorlds);
- return;
- }
- else if (targetWorlds.Length == 1)
- {
- targetPlayers = targetWorlds[0].Players;
- }
- else
- {
- player.Message("No worlds found matching {0}! Please check your spelling.", world);
- return;
- }
- }
- string message = cmd.Next();
- if (string.IsNullOrEmpty(message))
- {
- CdAnnounce.PrintUsage(player);
- return;
- }
- Packet packet = PacketWriter.MakeSpecialMessage(100, message);
- foreach (Player p in targetPlayers)
- {
- p.Send(packet);
- }
- }
- static readonly CommandDescriptor CdAutoRank = new CommandDescriptor
- {
- Name = "AutoRank",
- IsConsoleSafe = true,
- Category = CommandCategory.Moderation,
- Permissions = new[] { Permission.EditPlayerDB },
- Help = "&SManagement commands for running Autorank. Type '/help AutoRank [option]' for details.",
- Usage = "&S/AutoRank [enable/disable/force/exempt/unexempt]",
- HelpSections = new Dictionary<string, string>{
- { "enable", "&H/AutoRank enable\n&S" +
- "Enables the autorank system on the server." },
- { "disable", "&H/AutoRank disable\n&S" +
- "Disables the autorank system on the server." },
- { "force", "&H/AutoRank force\n&S" +
- "Forces the server to check all online players if they are due for an autorank. Works even if autorank is disabled."},
- { "exempt", "&H/AutoRank exempt [player]\n&S" +
- "Exempts a player from autorank. Even if the player is due for an autorank promotion or demotion, they will not be ranked."},
- { "unexempt", "&H/AutoRank unexempt [player]\n&S" +
- "Lifts the exemption on the target player. Target player can now be autoranked." },
- },
- Handler = AutoRankHandler
- };
- private static void AutoRankHandler(Player player, Command cmd)
- {
- string option = cmd.Next();
- if (string.IsNullOrEmpty(option))
- {
- CdAutoRank.PrintUsage(player);
- return;
- }
- switch (option)
- {
- case "enable":
- if (Server.AutoRankEnabled)
- {
- player.Message("AutoRank is already enabled!");
- break;
- }
- Server.AutoRankEnabled = true;
- player.Message("AutoRank is now enabled on {0}!", ConfigKey.ServerName.GetString());
- break;
- case "disable":
- if (!Server.AutoRankEnabled)
- {
- player.Message("AutoRank is already disabled!");
- break;
- }
- Server.AutoRankEnabled = false;
- player.Message("AutoRank is now disabled on {0}!", ConfigKey.ServerName.GetString());
- break;
- case "force":
- player.Message("Checking for online players to force autorank...");
- //refresh xml incase host updated autorank script, and then check each player
- AutoRank.AutoRankManager.Load();
- foreach (Player p in Server.Players)
- {
- AutoRank.AutoRankManager.Check(p);
- }
- player.Message("AutoRank force check finished.");
- break;
- case "exempt":
- string target = cmd.Next();
- if (string.IsNullOrEmpty(target))
- {
- CdAutoRank.PrintUsage(player);
- break;
- }
- Player targetPlayer = Server.FindPlayerOrPrintMatches(player, target, false, true);
- if (targetPlayer == null)
- {
- return;
- }
- targetPlayer.IsAutoRankExempt = true;
- player.Message("{0} is now exempt from autorank rank changes.", targetPlayer.Name);
- break;
- case "unexempt":
- string target_ = cmd.Next();
- if (string.IsNullOrEmpty(target_))
- {
- CdAutoRank.PrintUsage(player);
- break;
- }
- Player targetPlayer_ = Server.FindPlayerOrPrintMatches(player, target_, false, true);
- if (targetPlayer_ == null)
- {
- return;
- }
- targetPlayer_.IsAutoRankExempt = true;
- player.Message("{0} is now unexempt from autorank rank changes.", targetPlayer_.Name);
- break;
- default:
- CdAutoRank.PrintUsage(player);
- break;
- }
- }
- static readonly CommandDescriptor CdSetClickDistance = new CommandDescriptor
- {
- Name = "SetClickDistance",
- Aliases = new[] { "setclick", "clickdistance", "click", "scd" },
- IsConsoleSafe = false,
- Category = CommandCategory.Moderation,
- Permissions = new[] { Permission.Promote },
- Help = "&SSets the clicking distance of a player. NOTE: Block distances are approximate (+/- 1)",
- Usage = "&S/SetClick (number of blocks)",
- Handler = SetClickHandler
- };
- private static void SetClickHandler(Player player, Command cmd)
- {
- string targetName = cmd.Next();
- if (String.IsNullOrEmpty(targetName))
- {
- CdSetClickDistance.PrintUsage(player);
- return;
- }
- Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
- if (target == null)
- {
- player.MessageNoPlayer(targetName);
- return;
- }
- if (!target.ClassiCube)
- {
- player.Message("Click distance can only be changed for people playing on ClassiCube");
- return;
- }
- string number = cmd.Next();
- if (number == "normal")
- {
- target.Send(PacketWriter.MakeSetClickDistance(160));
- player.Message("Player {0}&s's click distance was set to normal.", target.ClassyName);
- target.hasCustomClickDistance = false;
- return;
- }
- int distance;
- if (String.IsNullOrEmpty(number) || !Int32.TryParse(number, out distance))
- {
- CdSetClickDistance.PrintUsage(player);
- return;
- }
- if (distance > 20 || distance < 1)
- {
- player.Message("Accepted values are between 1 and 20!");
- return;
- }
- int adjustedDistance = (32 * distance);
- target.Send(PacketWriter.MakeSetClickDistance(adjustedDistance));
- target.hasCustomClickDistance = true;
- player.Message("Player {0}&s's click distance was set to {1} blocks.", target.ClassyName, distance);
- }
-
-
- static readonly CommandDescriptor CdTempRank = new CommandDescriptor
- {
- Name = "TempRank",
- Aliases = new[] { "tRank"},
- IsConsoleSafe = true,
- Category = CommandCategory.Moderation,
- Permissions = new[] { Permission.Promote },
- Help = "&SRanks a player for a limited amount of time. Tempranks are reset upon server restart or shutdown.",
- Usage = "&S/TempRank [player] [rank] [duration] [reason]",
- Handler = TempRankHandler
- };
- static void TempRankHandler(Player player, Command cmd)
- {
- string target = cmd.Next();
- string rank = cmd.Next();
- string rankTime = cmd.Next();
- TimeSpan rankDuration;
- string reason = cmd.Next();
- if(String.IsNullOrEmpty(target))
- {
- player.Message("&SPlease input a player's name to temprank.");
- return;
- }
- if (String.IsNullOrEmpty(rank))
- {
- player.Message("&SPlease input your desired rank.");
- return;
- }
- if (String.IsNullOrEmpty(rankTime))
- {
- player.Message("&SPlease input the duration of the temprank.");
- return;
- }
- if (String.IsNullOrEmpty(reason))
- {
- player.Message("&SPlease input the reason for the temprank.");
- return;
- }
- if (!rankTime.TryParseMiniTimespan(out rankDuration) || rankDuration <= TimeSpan.Zero)
- {
- player.Message("&SThe time must be an integer greater than 0!");
- return;
- }
- Rank targetRank = RankManager.FindRank(rank);
- if (targetRank == null)
- {
- player.MessageNoRank(rank);
- return;
- }
-
- PlayerInfo targetInfo = PlayerDB.FindPlayerInfoExact(target);
- if (targetInfo == null)
- {
- player.Message("&SThe player, {0}&S could not be found. Please check the spelling of the player.", target);
- }
- targetInfo.ChangeRank(player, targetRank, "TempRank(" + rankTime + "): " + reason , true, true, false);
- targetInfo.isTempRanked = true;
- targetInfo.tempRankTime = rankDuration;
- }
- static readonly CommandDescriptor CdTPA = new CommandDescriptor
- {
- Name = "TPA",
- Aliases = new[] { "TeleportAsk"},
- IsConsoleSafe = false,
- Category = CommandCategory.Moderation,
- Permissions = new[] { Permission.TPA },
- Help = "&SAsks a player permission to teleport to them before teleporting.",
- Usage = "&S/Tpa player",
- Handler = TPAHandler
- };
- static void TPAHandler(Player player, Command cmd)
- {
- string name = cmd.Next();
- Player player_ = player;
- if (String.IsNullOrEmpty(name))
- {
- CdTPA.PrintUsage(player);
- return;
- }
- Player target = Server.FindPlayerOrPrintMatches(player, name, false, true);
- if (target == null)
- {
- return;
- }
- else
- {
- if (!cmd.IsConfirmed)
- {
- target.Confirm(cmd, player.ClassyName + "&S would like to teleport to you.");
- }
- else
- {
- //Big error here. Both of the following messages are sent to the target, and the target teleports towards itself.
- player.Message("&STeleporting you to {0}...", name);
- target.ParseMessage("/tp " + name, false, false);
- return;
- }
- }
- }
- static readonly CommandDescriptor CdFreezeBring = new CommandDescriptor
- {
- Name = "FreezeBring",
- Aliases = new[] { "fBring" , "fSummon", "fb" },
- IsConsoleSafe = false,
- Category = CommandCategory.Moderation,
- Permissions = new[] { Permission.Freeze },
- Help = "&SFreezes and summons a player to your location. Usefull for griefers.",
- Usage = "&S/FreezeBring player",
- Handler = FBHandler
- };
- static void FBHandler(Player player, Command cmd)
- {
- string name = cmd.Next();
- if (String.IsNullOrEmpty(name))
- {
- CdFreezeBring.PrintUsage(player);
- return;
- }
- else
- {
- Player target = Server.FindPlayerOrPrintMatches(player, name, false, true);
- if (target == null)
- {
- return;
- }
- else
- {
- player.ParseMessage("/summon " + name, false, false); //to lazy to change target's coords, so ill just summon
- target.Info.IsFrozen = true;
- target.Message("&SYou have been frozen by {0}", player.ClassyName);
- return;
- }
- }
- }
- static readonly CommandDescriptor CdLastCommand = new CommandDescriptor
- {
- Name = "LastCommand",
- Aliases = new[] { "LastCmd", "last" },
- IsConsoleSafe = true,
- Category = CommandCategory.Moderation,
- Permissions = new[] { Permission.Spectate },
- Help = "Checks the last command used by a player. Leave the player parameter blank for your last command.",
- Usage = "/LastCommand (player)",
- Handler = LastCommandHandler
- };
- static void LastCommandHandler(Player player, Command cmd) //allows the user to see the last command a target player has used
- {
- string target = cmd.Next();
- if (String.IsNullOrEmpty(target))
- {
- if (player.LastCommand == null)
- {
- player.Message("You do not have a last command");
- CdLastCommand.PrintUsage(player);
- return;
- }
- string sub = player.LastCommand.ToString().Split('"')[1].Split('"')[0];
- player.Message("Your last command used was: " + sub);
- return;
- }
- Player targetName = Server.FindPlayerOrPrintMatches(player, target, false, true);
- if (targetName == null)
- {
- player.Message("No player found matching " + target);
- return;
- }
- else
- {
- string sub = targetName.LastCommand.ToString().Split('"')[1].Split('"')[0];
- player.Message(targetName.Name + "'s last command was " + sub);
- return;
- }
- }
- static readonly CommandDescriptor CdBeatDown = new CommandDescriptor
- {
- Name = "Beatdown",
- IsConsoleSafe = true,
- NotRepeatable = true,
- Aliases = new[] { "ground", "bd", "pummel" },
- Category = CommandCategory.Moderation | CommandCategory.Fun,
- Permissions = new[] { Permission.Basscannon },
- Help = "Pummels a player into the ground. " +
- "Available items are: dog, hammer, sack, pistol, curb and soap.",
- Usage = "/Beatdown <playername> [item]",
- Handler = BeatDownHandler
- };
- static void BeatDownHandler(Player player, Command cmd) //a more brutal /slap cmd, sends the player underground to the bottom of the world
- {
- string name = cmd.Next();
- string item = cmd.Next();
- if (name == null)
- {
- player.Message("Please enter a name");
- return;
- }
- Player target = Server.FindPlayerOrPrintMatches(player, name, false, true);
- if (target == null) return;
- if (target.Immortal)
- {
- player.Message("&SYou failed to beatdown {0}&S, they are immortal", target.ClassyName);
- return;
- }
- if (target == player)
- {
- player.Message("&sYou can't pummel yourself.... What's wrong with you???");
- return;
- }
- double time = (DateTime.Now - player.Info.LastUsedBeatDown).TotalSeconds;
- double timeLeft = Math.Round(20 - time);
- if (time < 20)
- {
- player.Message("&WYou can use /BeatDown again in " + timeLeft + " seconds.");
- return;
- }
- string aMessage;
- if (player.Can(Permission.Basscannon, target.Info.Rank))
- {
- Position pummeled = new Position(target.Position.X, target.Position.Y, (target.World.Map.Bounds.ZMin) * 32);
- target.previousLocation = target.Position;
- target.previousWorld = null;
- target.TeleportTo(pummeled);
- if (string.IsNullOrEmpty(item))
- {
- Server.Players.CanSee(target).Union(target).Message("{0} &Swas pummeled into the ground by {1}", target.ClassyName, player.ClassyName);
- target.Message("Do &a/Spawn&s to get back above ground.");
- IRC.PlayerSomethingMessage(player, "beat down", target, null);
- player.Info.LastUsedBeatDown = DateTime.Now;
- return;
- }
- else if (item.ToLower() == "hammer")
- aMessage = String.Format("{1}&S Beat Down {0}&S with a Hammer", target.ClassyName, player.ClassyName);
- else if (item.ToLower() == "sack")
- aMessage = String.Format("{1}&s pummeled {0}&S with a Sack of Potatoes", target.ClassyName, player.ClassyName);
- else if (item.ToLower() == "soap")
- aMessage = String.Format("{1}&S pummeled {0}&s with Socks Full of Soap", target.ClassyName, player.ClassyName);
- else if (item.ToLower() == "pistol")
- aMessage = String.Format("{1}&S Pistol-Whipped {0}", target.ClassyName, player.ClassyName);
- else if (item.ToLower() == "curb")
- aMessage = String.Format("{1}&S Curb-Stomped {0}", target.ClassyName, player.ClassyName);
- else if (item.ToLower() == "dog")
- aMessage = String.Format("{1}&S Beat Down {0}&S like a dog", target.ClassyName, player.ClassyName);
- else
- {
- Server.Players.CanSee(target).Union(target).Message("{0} &Swas pummeled into the ground by {1}", target.ClassyName, player.ClassyName);
- target.Message("Do &a/Spawn&s to get back above ground.");
- IRC.PlayerSomethingMessage(player, "beat down", target, null);
- player.Info.LastUsedBeatDown = DateTime.Now;
- return;
- }
- Server.Players.CanSee(target).Union(target).Message(aMessage);
- target.Message("Do &a/Spawn&s to get back above ground.");
- IRC.PlayerSomethingMessage(player, "beat down", target, null);
- player.Info.LastUsedBeatDown = DateTime.Now;
- return;
- }
- else
- {
- player.Message("&sYou can only Beat Down players ranked {0}&S or lower",
- player.Info.Rank.GetLimit(Permission.Basscannon).ClassyName);
- player.Message("{0}&S is ranked {1}", target.ClassyName, target.Info.Rank.ClassyName);
- }
- }
-
- static readonly CommandDescriptor CdStealthKick = new CommandDescriptor
- {
- Name = "StealthKick",
- Aliases = new[] { "sk", "stealthk" },
- Category = CommandCategory.Moderation,
- IsConsoleSafe = true,
- Permissions = new[] { Permission.Gtfo },
- Usage = "/StealthKick (playername)",
- Help = "&SKicks a player stealthily. The kick will say the player disconnected and will not save to the playerDB.",
- Handler = StealthKickHandler
- };
- internal static void StealthKickHandler(Player player, Command cmd)
- {
- string name = cmd.Next();
- if (name == null)
- {
- player.Message("Please enter a name");
- return;
- }
- Player target = Server.FindPlayerOrPrintMatches(player, name, false, true);
- if (target == null) return;
- if (target == player)
- {
- player.Message("You cannot StealthKick yourself.");
- return;
- }
- if (cmd.HasNext)
- {
- player.Message("A reason does not need to be specified when using StealthKick.");
- }
- if (player.Can(Permission.Gtfo, target.Info.Rank))
- {
- Player targetPlayer = target;
- target.Send(PacketWriter.MakeDisconnect("You've lost connection to the server."));
- }
- else
- {
- player.Message("You can only StealthKick players ranked {0}&S or lower",
- player.Info.Rank.GetLimit(Permission.Gtfo).ClassyName);
- player.Message("{0}&S is ranked {1}", target.ClassyName, target.Info.Rank.ClassyName);
- }
- }
-
- static CommandDescriptor CdBanGrief = new CommandDescriptor
- {
- Name = "BanGrief",
- Category = CommandCategory.Moderation,
- Aliases = new[] { "Bg" },
- IsConsoleSafe = true,
- Permissions = new[] { Permission.Ban },
- NotRepeatable = true,
- Usage = "/BanGrief Playername",
- Help = "Bans the player with the reason \"Grief, appeal at <website>\"",
- Handler = BanGriefHandler
- };
- static void BanGriefHandler(Player player, Command cmd)
- {
- string targetName = cmd.Next();
- if (targetName == null)
- {
- CdBanGrief.PrintUsage(player);
- return;
- }
- PlayerInfo target = PlayerDB.FindPlayerInfoOrPrintMatches(player, targetName);
- if (target == null) return;
- string reason = "Grief, appeal at " + ConfigKey.WebsiteURL.GetString();
- try
- {
- Player targetPlayer = target.PlayerObject;
- target.Ban(player, reason, true, true);
- WarnIfOtherPlayersOnIP(player, target, targetPlayer);
- }
- catch (PlayerOpException ex)
- {
- player.Message(ex.MessageColored);
- if (ex.ErrorCode == PlayerOpExceptionCode.ReasonRequired)
- {
- FreezeIfAllowed(player, target);
- }
- }
- }
- #region Economy
- static readonly CommandDescriptor CdPay = new CommandDescriptor
- {
- Name = "Pay",
- Aliases = new[] { "Purchase" },
- Category = CommandCategory.Moderation,
- IsConsoleSafe = false,
- Permissions = new[] { Permission.Economy },
- Usage = "/pay player amount",
- Help = "&SUsed to pay a certain player an amount of bits.",
- Handler = PayHandler
- };
- static void PayHandler(Player player, Command cmd)
- {
- string targetName = cmd.Next();
- string amount = cmd.Next();
- int amountnum;
- //lotsa idiot proofing in this one ^.^
- if (targetName == null)
- {
- player.Message("&ePlease type in a player's name to pay bits towards.");
- return;
- }
- Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
- if (target == player)
- {
- player.Message("You can't pay yourself >.> Doesn't work like that.");
- return;
- }
- if (target == null)
- {
- return;
- }
- else
- {
- if (!int.TryParse(amount, out amountnum))
- {
- player.Message("&eThe amount must be a positive whole number!");
- return;
- }
- if (amountnum < 1)
- {
- player.Message("&eThe amount must be a positive whole number!");
- return;
- }
- if (cmd.IsConfirmed)
- {
- if (amountnum > player.Info.Money)
- {
- player.Message("You don't have that many bits!");
- return;
- }
- else
- {
- //show him da monai
- int pNewMoney = player.Info.Money - amountnum;
- int tNewMoney = target.Info.Money + amountnum;
- player.Message("&eYou have paid &C{1}&e to {0}&e.", target.ClassyName, amountnum);
- target.Message("&e{0} &ehas paid you {1} &ebit(s).", player.ClassyName, amountnum);
- Server.Players.Except(target).Except(player).Message("&e{0} &ewas paid {1} &ebit(s) 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} &ebits?", target.ClassyName, amountnum);
- return;
- }
- }
- }
- static readonly CommandDescriptor CdEconomy = new CommandDescriptor
- {
- Name = "Economy",
- Aliases = new[] { "Money", "Econ" },
- Category = CommandCategory.Moderation,
- IsConsoleSafe = false,
- Permissions = new[] { Permission.Economy },
- Usage = "/Economy [give/take/show/pay] [playername] [pay/give/take: amount]",
- Help = "&SEconomy commands for LegendCraft. Show will show you the amount of money a player has" +
- "and give/take will give or take bits from or to a player. WARNING, give and take will change your server's inflation.",
- Handler = EconomyHandler
- };
- 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("You do not have the required permisions to use that command!");
- return;
- }
- Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
- if (targetName == null)
- {
- player.Message("&ePlease type in a player's name to give bits towards.");
- return;
- }
- if (target == null)
- {
- return;
- }
- else
- {
- if (!int.TryParse(amount, out amountnum))
- {
- player.Message("&ePlease select from a whole number.");
- return;
- }
- if (cmd.IsConfirmed)
- {
- //actually give the player the money
- int tNewMoney = target.Info.Money + amountnum;
- player.Message("&eYou have given {0} &C{1} &ebit(s).", target.ClassyName, amountnum);
- target.Message("&e{0} &ehas given you {1} &ebit(s).", player.ClassyName, amountnum);
- Server.Players.Except(target).Except(player).Message("&e{0} &ewas given {1} &ebit(s) from {2}&e.", target.ClassyName, amountnum, player.ClassyName);
- target.Info.Money = tNewMoney;
- return;
- }
- else
- {
- player.Confirm(cmd, "&eAre you sure you want to give {0} &C{1} &ebits?&s", target.ClassyName, amountnum);
- return;
- }
- }
- }
- if (option == "take")
- {
- if (!player.Can(Permission.ManageEconomy))
- {
- player.Message("You do not have the required permisions to use that command!");
- return;
- }
- Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
- if (targetName == null)
- {
- player.Message("&ePlease type in a player's name to take bits away from.");
- 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 > target.Info.Money)
- {
- player.Message("{0}&e doesn't have that many bits!", target.ClassyName);
- return;
- }
- else
- {
- //actually give the player the money
- int tNewMoney = target.Info.Money - amountnum;
- player.Message("&eYou have taken &c{1}&e from {0}.", target.ClassyName, amountnum);
- target.Message("&e{0} &ehas taken {1} &ebit(s) from you.", player.ClassyName, amountnum);
- Server.Players.Except(target).Except(player).Message("&e{0} &etook {1} &ebit(s) 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} &ebits from {0}&e?&s", 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 bits towards.");
- return;
- }
- Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
- if (target == player)
- {
- player.Message("You can't pay yourself >.> Doesn't work like that.");
- return;
- }
- if (target == null)
- {
- return;
- }
- else
- {
- if (!int.TryParse(amount, out amountnum))
- {
- player.Message("&eThe amount must be a positive whole number!");
- return;
- }
- if (amountnum < 1)
- {
- player.Message("&eThe amount must be a positive whole number!");
- return;
- }
- if (cmd.IsConfirmed)
- {
- if (amountnum > player.Info.Money)
- {
- player.Message("You don't have that many bits!");
- return;
- }
- else
- {
- //show him da monai
- int pNewMoney = player.Info.Money - amountnum;
- int tNewMoney = target.Info.Money + amountnum;
- player.Message("&eYou have paid &C{1}&e to {0}&e.", target.ClassyName, amountnum);
- target.Message("&e{0} &ehas paid you {1} &ebit(s).", player.ClassyName, amountnum);
- Server.Players.Except(target).Except(player).Message("&e{0} &ewas paid {1} &ebit(s) 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} &ebits?&s", target.ClassyName, amountnum);
- return;
- }
- }
- }
- else if (option == "show")
- {
- Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
- if (targetName == null)
- {
- player.Message("&ePlease type in a player's name to see how many bits they have.");
- return;
- }
- if (target == null)
- {
- return;
- }
- else
- {
- //actually show how much money that person has
- player.Message("&e{0}&e has &C{1}&e bits currently!", target.ClassyName, target.Info.Money);
- }
- }
- else
- {
- player.Message("&eValid choices are '/economy take', '/economy give', '/economy show' and '/econ pay'.");
- return;
- }
- }
- catch (ArgumentNullException)
- {
- CdEconomy.PrintUsage(player);
- }
- }
- #endregion
- static readonly CommandDescriptor CdBanAll = new CommandDescriptor
- {
- Name = "BanAll",
- Category = CommandCategory.Moderation,
- IsConsoleSafe = true,
- Permissions = new[] { Permission.Ban, Permission.BanIP, Permission.BanAll },
- Usage = "/BanAll PlayerName|IPAddress [Reason]",
- Help = "&SBans the player's name, IP, and all other names associated with the IP. " +
- "UndoAll's the playername. If player is not online, " +
- "the last known IP associated with the name is used. " +
- "You can also type in the IP address directly. " +
- "Any text after PlayerName/IP will be saved as a memo. ",
- Handler = BanAllHandler
- };
- static void BanAllHandler(Player player, Command cmd)
- {
- string targetNameOrIP = cmd.Next();
- if (targetNameOrIP == null)
- {
- CdBanAll.PrintUsage(player);
- return;
- }
- string reason = cmd.NextAll();
- IPAddress targetAddress;
- if (Server.IsIP(targetNameOrIP) && IPAddress.TryParse(targetNameOrIP, out targetAddress))
- {
- try
- {
- targetAddress.BanAll(player, reason, true, true);
- }
- catch (PlayerOpException ex)
- {
- player.Message(ex.MessageColored);
- }
- }
- else
- {
- PlayerInfo target = PlayerDB.FindPlayerInfoOrPrintMatches(player, targetNameOrIP);
- if (target == null) return;
- try
- {
- if (target.LastIP.Equals(IPAddress.Any) || target.LastIP.Equals(IPAddress.None))
- {
- target.Ban(player, reason, true, true);
- }
- else
- {
- target.BanAll(player, reason, true, true);
- BuildingCommands.UndoAllHandler(player, new Command("/UndoAll " + target.Name));
- }
- }
- catch (PlayerOpException ex)
- {
- player.Message(ex.MessageColored);
- if (ex.ErrorCode == PlayerOpExceptionCode.ReasonRequired)
- {
- FreezeIfAllowed(player, target);
- }
- }
- }
- }
- static readonly CommandDescriptor CdAssassinate = new CommandDescriptor
- {
- Name = "Assasinate",
- Category = CommandCategory.Fun | CommandCategory.Fun,
- Aliases = new[] { "Snipe", "Assassinate" },
- IsConsoleSafe = true,
- Permissions = new[] { Permission.Kill },
- Help = "Silently kills a player.",
- NotRepeatable = true,
- Usage = "/assassinate playername",
- Handler = AssassinateHandler
- };
- internal static void AssassinateHandler(Player player, Command cmd)
- {
- string name = cmd.Next();
- if (name == null)
- {
- player.Message("Please enter a name.");
- return;
- }
- if (!player.Info.IsHidden)
- {
- player.Message("You can only assassinate while hidden silly head.");
- return;
- }
- else
- {
- Player target = Server.FindPlayerOrPrintMatches(player, name, false, true);
- if (target == null) return;
- if (target.Immortal)
- {
- player.Message("&SYou can't assassinate {0}&S, they're immortal.", target.ClassyName);
- return;
- }
- if (player.Can(Permission.Kill, target.Info.Rank))
- {
- target.TeleportTo(player.World.Map.Spawn);
- target.Message("&8You were just assassinated!");
- player.Message("&8Successfully assassinated {0}.", target.ClassyName);
- }
- if (target == player)
- {
- Server.Message("{0} killed itself in confusion!", player.ClassyName);
- return;
- }
- if (target == null)
- {
- player.Message("Please enter a victim's name.");
- return;
- }
- else
- {
- if (player.Can(Permission.Kill, target.Info.Rank))
- {
- target.TeleportTo(player.World.Map.Spawn);
- }
- else
- {
- player.Message("You can only assassinate players ranked {0}&S or lower.",
- player.Info.Rank.GetLimit(Permission.Kill).ClassyName);
- player.Message("{0}&S is ranked {1}.", target.ClassyName, target.Info.Rank.ClassyName);
- }
- }
- }
- }
- static readonly CommandDescriptor CdPunch = new CommandDescriptor
- {
- Name = "Punch",
- Aliases = new string[] { "Pu" },
- Category = CommandCategory.Chat | Comman…
Large files files are truncated, but you can click here to view the full file