PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/fCraft/Commands/ModerationCommands.cs

https://github.com/EpicClowny/LegendCraft
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

  1. // Copyright 2009-2012 Matvei Stefarov <me@matvei.org>
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net;
  6. using fCraft.Events;
  7. using JetBrains.Annotations;
  8. using System.IO;
  9. namespace fCraft {
  10. /// <summary>
  11. /// Most commands for server moderation - kick, ban, rank change, etc - are here.
  12. /// </summary>
  13. static class ModerationCommands {
  14. const string BanCommonHelp = "Ban information can be viewed with &H/BanInfo";
  15. internal static void Init() {
  16. CdBan.Help += BanCommonHelp;
  17. CdBanIP.Help += BanCommonHelp;
  18. CdBanAll.Help += BanCommonHelp;
  19. CdUnban.Help += BanCommonHelp;
  20. CdUnbanIP.Help += BanCommonHelp;
  21. CdUnbanAll.Help += BanCommonHelp;
  22. CommandManager.RegisterCommand( CdBan );
  23. CommandManager.RegisterCommand( CdBanIP );
  24. CommandManager.RegisterCommand( CdUnban );
  25. CommandManager.RegisterCommand( CdUnbanIP );
  26. CommandManager.RegisterCommand( CdUnbanAll );
  27. CommandManager.RegisterCommand( CdBanEx );
  28. CommandManager.RegisterCommand( CdKick );
  29. CommandManager.RegisterCommand( CdRank );
  30. CommandManager.RegisterCommand( CdHide );
  31. CommandManager.RegisterCommand( CdUnhide );
  32. CommandManager.RegisterCommand( CdSetSpawn );
  33. CommandManager.RegisterCommand( CdFreeze );
  34. CommandManager.RegisterCommand( CdUnfreeze );
  35. CommandManager.RegisterCommand( CdTP );
  36. CommandManager.RegisterCommand( CdBring );
  37. CommandManager.RegisterCommand( CdWorldBring );
  38. CommandManager.RegisterCommand( CdBringAll );
  39. CommandManager.RegisterCommand( CdPatrol );
  40. CommandManager.RegisterCommand( CdSpecPatrol );
  41. CommandManager.RegisterCommand( CdMute );
  42. CommandManager.RegisterCommand( CdUnmute );
  43. CommandManager.RegisterCommand( CdSpectate );
  44. CommandManager.RegisterCommand( CdUnspectate );
  45. CommandManager.RegisterCommand( CdSlap );
  46. CommandManager.RegisterCommand( CdTPZone );
  47. CommandManager.RegisterCommand( CdBasscannon );
  48. CommandManager.RegisterCommand( CdKill );
  49. CommandManager.RegisterCommand( CdTempBan );
  50. CommandManager.RegisterCommand( CdWarn );
  51. CommandManager.RegisterCommand( CdUnWarn );
  52. CommandManager.RegisterCommand( CdDisconnect );
  53. CommandManager.RegisterCommand( CdImpersonate );
  54. CommandManager.RegisterCommand( CdImmortal );
  55. CommandManager.RegisterCommand( CdTitle );
  56. CommandManager.RegisterCommand( CdMuteAll );
  57. CommandManager.RegisterCommand( CdAssassinate );
  58. CommandManager.RegisterCommand( CdPunch );
  59. CommandManager.RegisterCommand( CdBanAll );
  60. CommandManager.RegisterCommand( CdEconomy );
  61. CommandManager.RegisterCommand( CdPay );
  62. CommandManager.RegisterCommand(CdBanGrief);
  63. CommandManager.RegisterCommand(CdStealthKick);
  64. CommandManager.RegisterCommand(CdBeatDown);
  65. CommandManager.RegisterCommand(CdLastCommand);
  66. CommandManager.RegisterCommand(CdFreezeBring);
  67. CommandManager.RegisterCommand(CdTempRank);
  68. CommandManager.RegisterCommand(CdSetClickDistance);
  69. CommandManager.RegisterCommand(CdAutoRank);
  70. CommandManager.RegisterCommand(CdAnnounce);
  71. CommandManager.RegisterCommand(CdForceHold);
  72. CommandManager.RegisterCommand(CdGetBlock);
  73. //CommandManager.RegisterCommand(CdTPA);
  74. }
  75. #region LegendCraft
  76. /* Copyright (c) <2012-2014> <LeChosenOne, DingusBungus>
  77. Permission is hereby granted, free of charge, to any person obtaining a copy
  78. of this software and associated documentation files (the "Software"), to deal
  79. in the Software without restriction, including without limitation the rights
  80. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  81. copies of the Software, and to permit persons to whom the Software is
  82. furnished to do so, subject to the following conditions:
  83. The above copyright notice and this permission notice shall be included in
  84. all copies or substantial portions of the Software.
  85. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  86. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  87. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  88. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  89. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  90. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  91. THE SOFTWARE.*/
  92. static readonly CommandDescriptor CdGetBlock = new CommandDescriptor
  93. {
  94. Name = "GetBlock",
  95. IsConsoleSafe = true,
  96. Category = CommandCategory.Moderation,
  97. Permissions = new[] { Permission.Spectate },
  98. Help = "&SReturns the block that the player is currently holding.",
  99. Usage = "&S/GetBlock [player]",
  100. Handler = GetBlockHandler
  101. };
  102. private static void GetBlockHandler(Player player, Command cmd)
  103. {
  104. string target = cmd.Next();
  105. if (String.IsNullOrEmpty(target))
  106. {
  107. CdGetBlock.PrintUsage(player);
  108. return;
  109. }
  110. Player targetPlayer = Server.FindPlayerOrPrintMatches(player, target, false, true);
  111. if (targetPlayer == null)
  112. {
  113. return;
  114. }
  115. player.Message("{0} is currently holding {1}.", targetPlayer.Name, targetPlayer.Info.HeldBlock.ToString() );
  116. }
  117. static readonly CommandDescriptor CdForceHold = new CommandDescriptor
  118. {
  119. Name = "ForceHold",
  120. IsConsoleSafe = false,
  121. Category = CommandCategory.Moderation,
  122. Permissions = new[] { Permission.Spectate },
  123. Help = "&SForces a player to hold a certain block. Only use when needed!",
  124. Usage = "&S/ForceHold [player] [block]",
  125. Handler = FHHandler
  126. };
  127. private static void FHHandler(Player player, Command cmd)
  128. {
  129. if (!Heartbeat.ClassiCube() || !player.ClassiCube)
  130. {
  131. player.Message("This is a ClassiCube only command!");
  132. return;
  133. }
  134. string target = cmd.Next();
  135. if (String.IsNullOrEmpty(target))
  136. {
  137. CdForceHold.PrintUsage(player);
  138. return;
  139. }
  140. Player p = Server.FindPlayerOrPrintMatches(player, target, false, true);
  141. if (p == null)
  142. {
  143. return;
  144. }
  145. string blockStr = cmd.Next();
  146. if (String.IsNullOrEmpty(blockStr))
  147. {
  148. CdForceHold.PrintUsage(player);
  149. return;
  150. }
  151. //format blockname to be "Stone" instead of "STONE" or "stone"
  152. blockStr = blockStr.Substring(0, 1).ToUpper() + blockStr.Substring(1).ToLower();
  153. Block block;
  154. try
  155. {
  156. block = (Block)Enum.Parse(typeof(Block), blockStr);
  157. }
  158. catch
  159. {
  160. player.Message("Sorry, that was not a valid block name!");
  161. return;
  162. }
  163. p.Send(PacketWriter.MakeHoldThis((byte)block, false));
  164. }
  165. static readonly CommandDescriptor CdAnnounce = new CommandDescriptor //todo: make this work lol
  166. {
  167. Name = "Announce",
  168. IsConsoleSafe = true,
  169. Category = CommandCategory.Moderation,
  170. Permissions = new[] { Permission.Say },
  171. 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].",
  172. Usage = "&S/Announce [world] [message]",
  173. Handler = AnnounceHandler
  174. };
  175. private static void AnnounceHandler(Player player, Command cmd)
  176. {
  177. if (!Heartbeat.ClassiCube() || !player.ClassiCube)
  178. {
  179. player.Message("This is a ClassiCube only command!");
  180. return;
  181. }
  182. Player[] targetPlayers;
  183. string world = cmd.Next();
  184. if(string.IsNullOrEmpty(world))
  185. {
  186. CdAnnounce.PrintUsage(player);
  187. return;
  188. }
  189. if (world == "all")
  190. {
  191. targetPlayers = Server.Players;
  192. }
  193. else
  194. {
  195. World[] targetWorlds = WorldManager.FindWorlds(player, world);
  196. if (targetWorlds.Length > 1)
  197. {
  198. player.MessageManyMatches("world", targetWorlds);
  199. return;
  200. }
  201. else if (targetWorlds.Length == 1)
  202. {
  203. targetPlayers = targetWorlds[0].Players;
  204. }
  205. else
  206. {
  207. player.Message("No worlds found matching {0}! Please check your spelling.", world);
  208. return;
  209. }
  210. }
  211. string message = cmd.Next();
  212. if (string.IsNullOrEmpty(message))
  213. {
  214. CdAnnounce.PrintUsage(player);
  215. return;
  216. }
  217. Packet packet = PacketWriter.MakeSpecialMessage(100, message);
  218. foreach (Player p in targetPlayers)
  219. {
  220. p.Send(packet);
  221. }
  222. }
  223. static readonly CommandDescriptor CdAutoRank = new CommandDescriptor
  224. {
  225. Name = "AutoRank",
  226. IsConsoleSafe = true,
  227. Category = CommandCategory.Moderation,
  228. Permissions = new[] { Permission.EditPlayerDB },
  229. Help = "&SManagement commands for running Autorank. Type '/help AutoRank [option]' for details.",
  230. Usage = "&S/AutoRank [enable/disable/force/exempt/unexempt]",
  231. HelpSections = new Dictionary<string, string>{
  232. { "enable", "&H/AutoRank enable\n&S" +
  233. "Enables the autorank system on the server." },
  234. { "disable", "&H/AutoRank disable\n&S" +
  235. "Disables the autorank system on the server." },
  236. { "force", "&H/AutoRank force\n&S" +
  237. "Forces the server to check all online players if they are due for an autorank. Works even if autorank is disabled."},
  238. { "exempt", "&H/AutoRank exempt [player]\n&S" +
  239. "Exempts a player from autorank. Even if the player is due for an autorank promotion or demotion, they will not be ranked."},
  240. { "unexempt", "&H/AutoRank unexempt [player]\n&S" +
  241. "Lifts the exemption on the target player. Target player can now be autoranked." },
  242. },
  243. Handler = AutoRankHandler
  244. };
  245. private static void AutoRankHandler(Player player, Command cmd)
  246. {
  247. string option = cmd.Next();
  248. if (string.IsNullOrEmpty(option))
  249. {
  250. CdAutoRank.PrintUsage(player);
  251. return;
  252. }
  253. switch (option)
  254. {
  255. case "enable":
  256. if (Server.AutoRankEnabled)
  257. {
  258. player.Message("AutoRank is already enabled!");
  259. break;
  260. }
  261. Server.AutoRankEnabled = true;
  262. player.Message("AutoRank is now enabled on {0}!", ConfigKey.ServerName.GetString());
  263. break;
  264. case "disable":
  265. if (!Server.AutoRankEnabled)
  266. {
  267. player.Message("AutoRank is already disabled!");
  268. break;
  269. }
  270. Server.AutoRankEnabled = false;
  271. player.Message("AutoRank is now disabled on {0}!", ConfigKey.ServerName.GetString());
  272. break;
  273. case "force":
  274. player.Message("Checking for online players to force autorank...");
  275. //refresh xml incase host updated autorank script, and then check each player
  276. AutoRank.AutoRankManager.Load();
  277. foreach (Player p in Server.Players)
  278. {
  279. AutoRank.AutoRankManager.Check(p);
  280. }
  281. player.Message("AutoRank force check finished.");
  282. break;
  283. case "exempt":
  284. string target = cmd.Next();
  285. if (string.IsNullOrEmpty(target))
  286. {
  287. CdAutoRank.PrintUsage(player);
  288. break;
  289. }
  290. Player targetPlayer = Server.FindPlayerOrPrintMatches(player, target, false, true);
  291. if (targetPlayer == null)
  292. {
  293. return;
  294. }
  295. targetPlayer.IsAutoRankExempt = true;
  296. player.Message("{0} is now exempt from autorank rank changes.", targetPlayer.Name);
  297. break;
  298. case "unexempt":
  299. string target_ = cmd.Next();
  300. if (string.IsNullOrEmpty(target_))
  301. {
  302. CdAutoRank.PrintUsage(player);
  303. break;
  304. }
  305. Player targetPlayer_ = Server.FindPlayerOrPrintMatches(player, target_, false, true);
  306. if (targetPlayer_ == null)
  307. {
  308. return;
  309. }
  310. targetPlayer_.IsAutoRankExempt = true;
  311. player.Message("{0} is now unexempt from autorank rank changes.", targetPlayer_.Name);
  312. break;
  313. default:
  314. CdAutoRank.PrintUsage(player);
  315. break;
  316. }
  317. }
  318. static readonly CommandDescriptor CdSetClickDistance = new CommandDescriptor
  319. {
  320. Name = "SetClickDistance",
  321. Aliases = new[] { "setclick", "clickdistance", "click", "scd" },
  322. IsConsoleSafe = false,
  323. Category = CommandCategory.Moderation,
  324. Permissions = new[] { Permission.Promote },
  325. Help = "&SSets the clicking distance of a player. NOTE: Block distances are approximate (+/- 1)",
  326. Usage = "&S/SetClick (number of blocks)",
  327. Handler = SetClickHandler
  328. };
  329. private static void SetClickHandler(Player player, Command cmd)
  330. {
  331. string targetName = cmd.Next();
  332. if (String.IsNullOrEmpty(targetName))
  333. {
  334. CdSetClickDistance.PrintUsage(player);
  335. return;
  336. }
  337. Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
  338. if (target == null)
  339. {
  340. player.MessageNoPlayer(targetName);
  341. return;
  342. }
  343. if (!target.ClassiCube)
  344. {
  345. player.Message("Click distance can only be changed for people playing on ClassiCube");
  346. return;
  347. }
  348. string number = cmd.Next();
  349. if (number == "normal")
  350. {
  351. target.Send(PacketWriter.MakeSetClickDistance(160));
  352. player.Message("Player {0}&s's click distance was set to normal.", target.ClassyName);
  353. target.hasCustomClickDistance = false;
  354. return;
  355. }
  356. int distance;
  357. if (String.IsNullOrEmpty(number) || !Int32.TryParse(number, out distance))
  358. {
  359. CdSetClickDistance.PrintUsage(player);
  360. return;
  361. }
  362. if (distance > 20 || distance < 1)
  363. {
  364. player.Message("Accepted values are between 1 and 20!");
  365. return;
  366. }
  367. int adjustedDistance = (32 * distance);
  368. target.Send(PacketWriter.MakeSetClickDistance(adjustedDistance));
  369. target.hasCustomClickDistance = true;
  370. player.Message("Player {0}&s's click distance was set to {1} blocks.", target.ClassyName, distance);
  371. }
  372. static readonly CommandDescriptor CdTempRank = new CommandDescriptor
  373. {
  374. Name = "TempRank",
  375. Aliases = new[] { "tRank"},
  376. IsConsoleSafe = true,
  377. Category = CommandCategory.Moderation,
  378. Permissions = new[] { Permission.Promote },
  379. Help = "&SRanks a player for a limited amount of time. Tempranks are reset upon server restart or shutdown.",
  380. Usage = "&S/TempRank [player] [rank] [duration] [reason]",
  381. Handler = TempRankHandler
  382. };
  383. static void TempRankHandler(Player player, Command cmd)
  384. {
  385. string target = cmd.Next();
  386. string rank = cmd.Next();
  387. string rankTime = cmd.Next();
  388. TimeSpan rankDuration;
  389. string reason = cmd.Next();
  390. if(String.IsNullOrEmpty(target))
  391. {
  392. player.Message("&SPlease input a player's name to temprank.");
  393. return;
  394. }
  395. if (String.IsNullOrEmpty(rank))
  396. {
  397. player.Message("&SPlease input your desired rank.");
  398. return;
  399. }
  400. if (String.IsNullOrEmpty(rankTime))
  401. {
  402. player.Message("&SPlease input the duration of the temprank.");
  403. return;
  404. }
  405. if (String.IsNullOrEmpty(reason))
  406. {
  407. player.Message("&SPlease input the reason for the temprank.");
  408. return;
  409. }
  410. if (!rankTime.TryParseMiniTimespan(out rankDuration) || rankDuration <= TimeSpan.Zero)
  411. {
  412. player.Message("&SThe time must be an integer greater than 0!");
  413. return;
  414. }
  415. Rank targetRank = RankManager.FindRank(rank);
  416. if (targetRank == null)
  417. {
  418. player.MessageNoRank(rank);
  419. return;
  420. }
  421. PlayerInfo targetInfo = PlayerDB.FindPlayerInfoExact(target);
  422. if (targetInfo == null)
  423. {
  424. player.Message("&SThe player, {0}&S could not be found. Please check the spelling of the player.", target);
  425. }
  426. targetInfo.ChangeRank(player, targetRank, "TempRank(" + rankTime + "): " + reason , true, true, false);
  427. targetInfo.isTempRanked = true;
  428. targetInfo.tempRankTime = rankDuration;
  429. }
  430. static readonly CommandDescriptor CdTPA = new CommandDescriptor
  431. {
  432. Name = "TPA",
  433. Aliases = new[] { "TeleportAsk"},
  434. IsConsoleSafe = false,
  435. Category = CommandCategory.Moderation,
  436. Permissions = new[] { Permission.TPA },
  437. Help = "&SAsks a player permission to teleport to them before teleporting.",
  438. Usage = "&S/Tpa player",
  439. Handler = TPAHandler
  440. };
  441. static void TPAHandler(Player player, Command cmd)
  442. {
  443. string name = cmd.Next();
  444. Player player_ = player;
  445. if (String.IsNullOrEmpty(name))
  446. {
  447. CdTPA.PrintUsage(player);
  448. return;
  449. }
  450. Player target = Server.FindPlayerOrPrintMatches(player, name, false, true);
  451. if (target == null)
  452. {
  453. return;
  454. }
  455. else
  456. {
  457. if (!cmd.IsConfirmed)
  458. {
  459. target.Confirm(cmd, player.ClassyName + "&S would like to teleport to you.");
  460. }
  461. else
  462. {
  463. //Big error here. Both of the following messages are sent to the target, and the target teleports towards itself.
  464. player.Message("&STeleporting you to {0}...", name);
  465. target.ParseMessage("/tp " + name, false, false);
  466. return;
  467. }
  468. }
  469. }
  470. static readonly CommandDescriptor CdFreezeBring = new CommandDescriptor
  471. {
  472. Name = "FreezeBring",
  473. Aliases = new[] { "fBring" , "fSummon", "fb" },
  474. IsConsoleSafe = false,
  475. Category = CommandCategory.Moderation,
  476. Permissions = new[] { Permission.Freeze },
  477. Help = "&SFreezes and summons a player to your location. Usefull for griefers.",
  478. Usage = "&S/FreezeBring player",
  479. Handler = FBHandler
  480. };
  481. static void FBHandler(Player player, Command cmd)
  482. {
  483. string name = cmd.Next();
  484. if (String.IsNullOrEmpty(name))
  485. {
  486. CdFreezeBring.PrintUsage(player);
  487. return;
  488. }
  489. else
  490. {
  491. Player target = Server.FindPlayerOrPrintMatches(player, name, false, true);
  492. if (target == null)
  493. {
  494. return;
  495. }
  496. else
  497. {
  498. player.ParseMessage("/summon " + name, false, false); //to lazy to change target's coords, so ill just summon
  499. target.Info.IsFrozen = true;
  500. target.Message("&SYou have been frozen by {0}", player.ClassyName);
  501. return;
  502. }
  503. }
  504. }
  505. static readonly CommandDescriptor CdLastCommand = new CommandDescriptor
  506. {
  507. Name = "LastCommand",
  508. Aliases = new[] { "LastCmd", "last" },
  509. IsConsoleSafe = true,
  510. Category = CommandCategory.Moderation,
  511. Permissions = new[] { Permission.Spectate },
  512. Help = "Checks the last command used by a player. Leave the player parameter blank for your last command.",
  513. Usage = "/LastCommand (player)",
  514. Handler = LastCommandHandler
  515. };
  516. static void LastCommandHandler(Player player, Command cmd) //allows the user to see the last command a target player has used
  517. {
  518. string target = cmd.Next();
  519. if (String.IsNullOrEmpty(target))
  520. {
  521. if (player.LastCommand == null)
  522. {
  523. player.Message("You do not have a last command");
  524. CdLastCommand.PrintUsage(player);
  525. return;
  526. }
  527. string sub = player.LastCommand.ToString().Split('"')[1].Split('"')[0];
  528. player.Message("Your last command used was: " + sub);
  529. return;
  530. }
  531. Player targetName = Server.FindPlayerOrPrintMatches(player, target, false, true);
  532. if (targetName == null)
  533. {
  534. player.Message("No player found matching " + target);
  535. return;
  536. }
  537. else
  538. {
  539. string sub = targetName.LastCommand.ToString().Split('"')[1].Split('"')[0];
  540. player.Message(targetName.Name + "'s last command was " + sub);
  541. return;
  542. }
  543. }
  544. static readonly CommandDescriptor CdBeatDown = new CommandDescriptor
  545. {
  546. Name = "Beatdown",
  547. IsConsoleSafe = true,
  548. NotRepeatable = true,
  549. Aliases = new[] { "ground", "bd", "pummel" },
  550. Category = CommandCategory.Moderation | CommandCategory.Fun,
  551. Permissions = new[] { Permission.Basscannon },
  552. Help = "Pummels a player into the ground. " +
  553. "Available items are: dog, hammer, sack, pistol, curb and soap.",
  554. Usage = "/Beatdown <playername> [item]",
  555. Handler = BeatDownHandler
  556. };
  557. static void BeatDownHandler(Player player, Command cmd) //a more brutal /slap cmd, sends the player underground to the bottom of the world
  558. {
  559. string name = cmd.Next();
  560. string item = cmd.Next();
  561. if (name == null)
  562. {
  563. player.Message("Please enter a name");
  564. return;
  565. }
  566. Player target = Server.FindPlayerOrPrintMatches(player, name, false, true);
  567. if (target == null) return;
  568. if (target.Immortal)
  569. {
  570. player.Message("&SYou failed to beatdown {0}&S, they are immortal", target.ClassyName);
  571. return;
  572. }
  573. if (target == player)
  574. {
  575. player.Message("&sYou can't pummel yourself.... What's wrong with you???");
  576. return;
  577. }
  578. double time = (DateTime.Now - player.Info.LastUsedBeatDown).TotalSeconds;
  579. double timeLeft = Math.Round(20 - time);
  580. if (time < 20)
  581. {
  582. player.Message("&WYou can use /BeatDown again in " + timeLeft + " seconds.");
  583. return;
  584. }
  585. string aMessage;
  586. if (player.Can(Permission.Basscannon, target.Info.Rank))
  587. {
  588. Position pummeled = new Position(target.Position.X, target.Position.Y, (target.World.Map.Bounds.ZMin) * 32);
  589. target.previousLocation = target.Position;
  590. target.previousWorld = null;
  591. target.TeleportTo(pummeled);
  592. if (string.IsNullOrEmpty(item))
  593. {
  594. Server.Players.CanSee(target).Union(target).Message("{0} &Swas pummeled into the ground by {1}", target.ClassyName, player.ClassyName);
  595. target.Message("Do &a/Spawn&s to get back above ground.");
  596. IRC.PlayerSomethingMessage(player, "beat down", target, null);
  597. player.Info.LastUsedBeatDown = DateTime.Now;
  598. return;
  599. }
  600. else if (item.ToLower() == "hammer")
  601. aMessage = String.Format("{1}&S Beat Down {0}&S with a Hammer", target.ClassyName, player.ClassyName);
  602. else if (item.ToLower() == "sack")
  603. aMessage = String.Format("{1}&s pummeled {0}&S with a Sack of Potatoes", target.ClassyName, player.ClassyName);
  604. else if (item.ToLower() == "soap")
  605. aMessage = String.Format("{1}&S pummeled {0}&s with Socks Full of Soap", target.ClassyName, player.ClassyName);
  606. else if (item.ToLower() == "pistol")
  607. aMessage = String.Format("{1}&S Pistol-Whipped {0}", target.ClassyName, player.ClassyName);
  608. else if (item.ToLower() == "curb")
  609. aMessage = String.Format("{1}&S Curb-Stomped {0}", target.ClassyName, player.ClassyName);
  610. else if (item.ToLower() == "dog")
  611. aMessage = String.Format("{1}&S Beat Down {0}&S like a dog", target.ClassyName, player.ClassyName);
  612. else
  613. {
  614. Server.Players.CanSee(target).Union(target).Message("{0} &Swas pummeled into the ground by {1}", target.ClassyName, player.ClassyName);
  615. target.Message("Do &a/Spawn&s to get back above ground.");
  616. IRC.PlayerSomethingMessage(player, "beat down", target, null);
  617. player.Info.LastUsedBeatDown = DateTime.Now;
  618. return;
  619. }
  620. Server.Players.CanSee(target).Union(target).Message(aMessage);
  621. target.Message("Do &a/Spawn&s to get back above ground.");
  622. IRC.PlayerSomethingMessage(player, "beat down", target, null);
  623. player.Info.LastUsedBeatDown = DateTime.Now;
  624. return;
  625. }
  626. else
  627. {
  628. player.Message("&sYou can only Beat Down players ranked {0}&S or lower",
  629. player.Info.Rank.GetLimit(Permission.Basscannon).ClassyName);
  630. player.Message("{0}&S is ranked {1}", target.ClassyName, target.Info.Rank.ClassyName);
  631. }
  632. }
  633. static readonly CommandDescriptor CdStealthKick = new CommandDescriptor
  634. {
  635. Name = "StealthKick",
  636. Aliases = new[] { "sk", "stealthk" },
  637. Category = CommandCategory.Moderation,
  638. IsConsoleSafe = true,
  639. Permissions = new[] { Permission.Gtfo },
  640. Usage = "/StealthKick (playername)",
  641. Help = "&SKicks a player stealthily. The kick will say the player disconnected and will not save to the playerDB.",
  642. Handler = StealthKickHandler
  643. };
  644. internal static void StealthKickHandler(Player player, Command cmd)
  645. {
  646. string name = cmd.Next();
  647. if (name == null)
  648. {
  649. player.Message("Please enter a name");
  650. return;
  651. }
  652. Player target = Server.FindPlayerOrPrintMatches(player, name, false, true);
  653. if (target == null) return;
  654. if (target == player)
  655. {
  656. player.Message("You cannot StealthKick yourself.");
  657. return;
  658. }
  659. if (cmd.HasNext)
  660. {
  661. player.Message("A reason does not need to be specified when using StealthKick.");
  662. }
  663. if (player.Can(Permission.Gtfo, target.Info.Rank))
  664. {
  665. Player targetPlayer = target;
  666. target.Send(PacketWriter.MakeDisconnect("You've lost connection to the server."));
  667. }
  668. else
  669. {
  670. player.Message("You can only StealthKick players ranked {0}&S or lower",
  671. player.Info.Rank.GetLimit(Permission.Gtfo).ClassyName);
  672. player.Message("{0}&S is ranked {1}", target.ClassyName, target.Info.Rank.ClassyName);
  673. }
  674. }
  675. static CommandDescriptor CdBanGrief = new CommandDescriptor
  676. {
  677. Name = "BanGrief",
  678. Category = CommandCategory.Moderation,
  679. Aliases = new[] { "Bg" },
  680. IsConsoleSafe = true,
  681. Permissions = new[] { Permission.Ban },
  682. NotRepeatable = true,
  683. Usage = "/BanGrief Playername",
  684. Help = "Bans the player with the reason \"Grief, appeal at <website>\"",
  685. Handler = BanGriefHandler
  686. };
  687. static void BanGriefHandler(Player player, Command cmd)
  688. {
  689. string targetName = cmd.Next();
  690. if (targetName == null)
  691. {
  692. CdBanGrief.PrintUsage(player);
  693. return;
  694. }
  695. PlayerInfo target = PlayerDB.FindPlayerInfoOrPrintMatches(player, targetName);
  696. if (target == null) return;
  697. string reason = "Grief, appeal at " + ConfigKey.WebsiteURL.GetString();
  698. try
  699. {
  700. Player targetPlayer = target.PlayerObject;
  701. target.Ban(player, reason, true, true);
  702. WarnIfOtherPlayersOnIP(player, target, targetPlayer);
  703. }
  704. catch (PlayerOpException ex)
  705. {
  706. player.Message(ex.MessageColored);
  707. if (ex.ErrorCode == PlayerOpExceptionCode.ReasonRequired)
  708. {
  709. FreezeIfAllowed(player, target);
  710. }
  711. }
  712. }
  713. #region Economy
  714. static readonly CommandDescriptor CdPay = new CommandDescriptor
  715. {
  716. Name = "Pay",
  717. Aliases = new[] { "Purchase" },
  718. Category = CommandCategory.Moderation,
  719. IsConsoleSafe = false,
  720. Permissions = new[] { Permission.Economy },
  721. Usage = "/pay player amount",
  722. Help = "&SUsed to pay a certain player an amount of bits.",
  723. Handler = PayHandler
  724. };
  725. static void PayHandler(Player player, Command cmd)
  726. {
  727. string targetName = cmd.Next();
  728. string amount = cmd.Next();
  729. int amountnum;
  730. //lotsa idiot proofing in this one ^.^
  731. if (targetName == null)
  732. {
  733. player.Message("&ePlease type in a player's name to pay bits towards.");
  734. return;
  735. }
  736. Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
  737. if (target == player)
  738. {
  739. player.Message("You can't pay yourself >.> Doesn't work like that.");
  740. return;
  741. }
  742. if (target == null)
  743. {
  744. return;
  745. }
  746. else
  747. {
  748. if (!int.TryParse(amount, out amountnum))
  749. {
  750. player.Message("&eThe amount must be a positive whole number!");
  751. return;
  752. }
  753. if (amountnum < 1)
  754. {
  755. player.Message("&eThe amount must be a positive whole number!");
  756. return;
  757. }
  758. if (cmd.IsConfirmed)
  759. {
  760. if (amountnum > player.Info.Money)
  761. {
  762. player.Message("You don't have that many bits!");
  763. return;
  764. }
  765. else
  766. {
  767. //show him da monai
  768. int pNewMoney = player.Info.Money - amountnum;
  769. int tNewMoney = target.Info.Money + amountnum;
  770. player.Message("&eYou have paid &C{1}&e to {0}&e.", target.ClassyName, amountnum);
  771. target.Message("&e{0} &ehas paid you {1} &ebit(s).", player.ClassyName, amountnum);
  772. Server.Players.Except(target).Except(player).Message("&e{0} &ewas paid {1} &ebit(s) from {2}&e.", target.ClassyName, amountnum, player.ClassyName);
  773. player.Info.Money = pNewMoney;
  774. target.Info.Money = tNewMoney;
  775. return;
  776. }
  777. }
  778. else
  779. {
  780. player.Confirm(cmd, "&eAre you sure you want to pay {0}&e {1} &ebits?", target.ClassyName, amountnum);
  781. return;
  782. }
  783. }
  784. }
  785. static readonly CommandDescriptor CdEconomy = new CommandDescriptor
  786. {
  787. Name = "Economy",
  788. Aliases = new[] { "Money", "Econ" },
  789. Category = CommandCategory.Moderation,
  790. IsConsoleSafe = false,
  791. Permissions = new[] { Permission.Economy },
  792. Usage = "/Economy [give/take/show/pay] [playername] [pay/give/take: amount]",
  793. Help = "&SEconomy commands for LegendCraft. Show will show you the amount of money a player has" +
  794. "and give/take will give or take bits from or to a player. WARNING, give and take will change your server's inflation.",
  795. Handler = EconomyHandler
  796. };
  797. static void EconomyHandler(Player player, Command cmd)
  798. {
  799. try
  800. {
  801. string option = cmd.Next();
  802. string targetName = cmd.Next();
  803. string amount = cmd.Next();
  804. int amountnum;
  805. if (option == null)
  806. {
  807. CdEconomy.PrintUsage(player);
  808. }
  809. if (option == "give")
  810. {
  811. if (!player.Can(Permission.ManageEconomy))
  812. {
  813. player.Message("You do not have the required permisions to use that command!");
  814. return;
  815. }
  816. Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
  817. if (targetName == null)
  818. {
  819. player.Message("&ePlease type in a player's name to give bits towards.");
  820. return;
  821. }
  822. if (target == null)
  823. {
  824. return;
  825. }
  826. else
  827. {
  828. if (!int.TryParse(amount, out amountnum))
  829. {
  830. player.Message("&ePlease select from a whole number.");
  831. return;
  832. }
  833. if (cmd.IsConfirmed)
  834. {
  835. //actually give the player the money
  836. int tNewMoney = target.Info.Money + amountnum;
  837. player.Message("&eYou have given {0} &C{1} &ebit(s).", target.ClassyName, amountnum);
  838. target.Message("&e{0} &ehas given you {1} &ebit(s).", player.ClassyName, amountnum);
  839. Server.Players.Except(target).Except(player).Message("&e{0} &ewas given {1} &ebit(s) from {2}&e.", target.ClassyName, amountnum, player.ClassyName);
  840. target.Info.Money = tNewMoney;
  841. return;
  842. }
  843. else
  844. {
  845. player.Confirm(cmd, "&eAre you sure you want to give {0} &C{1} &ebits?&s", target.ClassyName, amountnum);
  846. return;
  847. }
  848. }
  849. }
  850. if (option == "take")
  851. {
  852. if (!player.Can(Permission.ManageEconomy))
  853. {
  854. player.Message("You do not have the required permisions to use that command!");
  855. return;
  856. }
  857. Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
  858. if (targetName == null)
  859. {
  860. player.Message("&ePlease type in a player's name to take bits away from.");
  861. return;
  862. }
  863. if (target == null)
  864. {
  865. return;
  866. }
  867. else
  868. {
  869. if (!int.TryParse(amount, out amountnum))
  870. {
  871. player.Message("&eThe amount must be a number!");
  872. return;
  873. }
  874. if (cmd.IsConfirmed)
  875. {
  876. if (amountnum > target.Info.Money)
  877. {
  878. player.Message("{0}&e doesn't have that many bits!", target.ClassyName);
  879. return;
  880. }
  881. else
  882. {
  883. //actually give the player the money
  884. int tNewMoney = target.Info.Money - amountnum;
  885. player.Message("&eYou have taken &c{1}&e from {0}.", target.ClassyName, amountnum);
  886. target.Message("&e{0} &ehas taken {1} &ebit(s) from you.", player.ClassyName, amountnum);
  887. Server.Players.Except(target).Except(player).Message("&e{0} &etook {1} &ebit(s) from {2}&e.", player.ClassyName, amountnum, target.ClassyName);
  888. target.Info.Money = tNewMoney;
  889. return;
  890. }
  891. }
  892. else
  893. {
  894. player.Confirm(cmd, "&eAre you sure you want to take &c{1} &ebits from {0}&e?&s", target.ClassyName, amountnum);
  895. return;
  896. }
  897. }
  898. }
  899. if (option == "pay")
  900. {
  901. //lotsa idiot proofing in this one ^.^
  902. if (targetName == null)
  903. {
  904. player.Message("&ePlease type in a player's name to pay bits towards.");
  905. return;
  906. }
  907. Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
  908. if (target == player)
  909. {
  910. player.Message("You can't pay yourself >.> Doesn't work like that.");
  911. return;
  912. }
  913. if (target == null)
  914. {
  915. return;
  916. }
  917. else
  918. {
  919. if (!int.TryParse(amount, out amountnum))
  920. {
  921. player.Message("&eThe amount must be a positive whole number!");
  922. return;
  923. }
  924. if (amountnum < 1)
  925. {
  926. player.Message("&eThe amount must be a positive whole number!");
  927. return;
  928. }
  929. if (cmd.IsConfirmed)
  930. {
  931. if (amountnum > player.Info.Money)
  932. {
  933. player.Message("You don't have that many bits!");
  934. return;
  935. }
  936. else
  937. {
  938. //show him da monai
  939. int pNewMoney = player.Info.Money - amountnum;
  940. int tNewMoney = target.Info.Money + amountnum;
  941. player.Message("&eYou have paid &C{1}&e to {0}&e.", target.ClassyName, amountnum);
  942. target.Message("&e{0} &ehas paid you {1} &ebit(s).", player.ClassyName, amountnum);
  943. Server.Players.Except(target).Except(player).Message("&e{0} &ewas paid {1} &ebit(s) from {2}&e.", target.ClassyName, amountnum, player.ClassyName);
  944. player.Info.Money = pNewMoney;
  945. target.Info.Money = tNewMoney;
  946. return;
  947. }
  948. }
  949. else
  950. {
  951. player.Confirm(cmd, "&eAre you sure you want to pay {0}&e {1} &ebits?&s", target.ClassyName, amountnum);
  952. return;
  953. }
  954. }
  955. }
  956. else if (option == "show")
  957. {
  958. Player target = Server.FindPlayerOrPrintMatches(player, targetName, false, true);
  959. if (targetName == null)
  960. {
  961. player.Message("&ePlease type in a player's name to see how many bits they have.");
  962. return;
  963. }
  964. if (target == null)
  965. {
  966. return;
  967. }
  968. else
  969. {
  970. //actually show how much money that person has
  971. player.Message("&e{0}&e has &C{1}&e bits currently!", target.ClassyName, target.Info.Money);
  972. }
  973. }
  974. else
  975. {
  976. player.Message("&eValid choices are '/economy take', '/economy give', '/economy show' and '/econ pay'.");
  977. return;
  978. }
  979. }
  980. catch (ArgumentNullException)
  981. {
  982. CdEconomy.PrintUsage(player);
  983. }
  984. }
  985. #endregion
  986. static readonly CommandDescriptor CdBanAll = new CommandDescriptor
  987. {
  988. Name = "BanAll",
  989. Category = CommandCategory.Moderation,
  990. IsConsoleSafe = true,
  991. Permissions = new[] { Permission.Ban, Permission.BanIP, Permission.BanAll },
  992. Usage = "/BanAll PlayerName|IPAddress [Reason]",
  993. Help = "&SBans the player's name, IP, and all other names associated with the IP. " +
  994. "UndoAll's the playername. If player is not online, " +
  995. "the last known IP associated with the name is used. " +
  996. "You can also type in the IP address directly. " +
  997. "Any text after PlayerName/IP will be saved as a memo. ",
  998. Handler = BanAllHandler
  999. };
  1000. static void BanAllHandler(Player player, Command cmd)
  1001. {
  1002. string targetNameOrIP = cmd.Next();
  1003. if (targetNameOrIP == null)
  1004. {
  1005. CdBanAll.PrintUsage(player);
  1006. return;
  1007. }
  1008. string reason = cmd.NextAll();
  1009. IPAddress targetAddress;
  1010. if (Server.IsIP(targetNameOrIP) && IPAddress.TryParse(targetNameOrIP, out targetAddress))
  1011. {
  1012. try
  1013. {
  1014. targetAddress.BanAll(player, reason, true, true);
  1015. }
  1016. catch (PlayerOpException ex)
  1017. {
  1018. player.Message(ex.MessageColored);
  1019. }
  1020. }
  1021. else
  1022. {
  1023. PlayerInfo target = PlayerDB.FindPlayerInfoOrPrintMatches(player, targetNameOrIP);
  1024. if (target == null) return;
  1025. try
  1026. {
  1027. if (target.LastIP.Equals(IPAddress.Any) || target.LastIP.Equals(IPAddress.None))
  1028. {
  1029. target.Ban(player, reason, true, true);
  1030. }
  1031. else
  1032. {
  1033. target.BanAll(player, reason, true, true);
  1034. BuildingCommands.UndoAllHandler(player, new Command("/UndoAll " + target.Name));
  1035. }
  1036. }
  1037. catch (PlayerOpException ex)
  1038. {
  1039. player.Message(ex.MessageColored);
  1040. if (ex.ErrorCode == PlayerOpExceptionCode.ReasonRequired)
  1041. {
  1042. FreezeIfAllowed(player, target);
  1043. }
  1044. }
  1045. }
  1046. }
  1047. static readonly CommandDescriptor CdAssassinate = new CommandDescriptor
  1048. {
  1049. Name = "Assasinate",
  1050. Category = CommandCategory.Fun | CommandCategory.Fun,
  1051. Aliases = new[] { "Snipe", "Assassinate" },
  1052. IsConsoleSafe = true,
  1053. Permissions = new[] { Permission.Kill },
  1054. Help = "Silently kills a player.",
  1055. NotRepeatable = true,
  1056. Usage = "/assassinate playername",
  1057. Handler = AssassinateHandler
  1058. };
  1059. internal static void AssassinateHandler(Player player, Command cmd)
  1060. {
  1061. string name = cmd.Next();
  1062. if (name == null)
  1063. {
  1064. player.Message("Please enter a name.");
  1065. return;
  1066. }
  1067. if (!player.Info.IsHidden)
  1068. {
  1069. player.Message("You can only assassinate while hidden silly head.");
  1070. return;
  1071. }
  1072. else
  1073. {
  1074. Player target = Server.FindPlayerOrPrintMatches(player, name, false, true);
  1075. if (target == null) return;
  1076. if (target.Immortal)
  1077. {
  1078. player.Message("&SYou can't assassinate {0}&S, they're immortal.", target.ClassyName);
  1079. return;
  1080. }
  1081. if (player.Can(Permission.Kill, target.Info.Rank))
  1082. {
  1083. target.TeleportTo(player.World.Map.Spawn);
  1084. target.Message("&8You were just assassinated!");
  1085. player.Message("&8Successfully assassinated {0}.", target.ClassyName);
  1086. }
  1087. if (target == player)
  1088. {
  1089. Server.Message("{0} killed itself in confusion!", player.ClassyName);
  1090. return;
  1091. }
  1092. if (target == null)
  1093. {
  1094. player.Message("Please enter a victim's name.");
  1095. return;
  1096. }
  1097. else
  1098. {
  1099. if (player.Can(Permission.Kill, target.Info.Rank))
  1100. {
  1101. target.TeleportTo(player.World.Map.Spawn);
  1102. }
  1103. else
  1104. {
  1105. player.Message("You can only assassinate players ranked {0}&S or lower.",
  1106. player.Info.Rank.GetLimit(Permission.Kill).ClassyName);
  1107. player.Message("{0}&S is ranked {1}.", target.ClassyName, target.Info.Rank.ClassyName);
  1108. }
  1109. }
  1110. }
  1111. }
  1112. static readonly CommandDescriptor CdPunch = new CommandDescriptor
  1113. {
  1114. Name = "Punch",
  1115. Aliases = new string[] { "Pu" },
  1116. Category = CommandCategory.Chat | Comman

Large files files are truncated, but you can click here to view the full file