From f0d13f61d10e16ed9513e977ac6354e1af69db9d Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 5 Sep 2016 09:47:04 +1000 Subject: [PATCH] Validate the name in RankCmd.FindName too, also do the same thing for /ban. --- Commands/Moderation/CmdBan.cs | 25 +++++++++++++------------ Commands/Moderation/RankCmd.cs | 7 ++++--- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Commands/Moderation/CmdBan.cs b/Commands/Moderation/CmdBan.cs index a980a53a6..3081159c0 100644 --- a/Commands/Moderation/CmdBan.cs +++ b/Commands/Moderation/CmdBan.cs @@ -27,26 +27,27 @@ namespace MCGalaxy.Commands.Moderation { public override void Use(Player p, string message) { if (message == "") { Help(p); return; } - bool stealth = false; - if (message[0] == '#') { - message = message.Remove(0, 1).Trim(); - stealth = true; + bool stealth = message[0] == '#'; + if (stealth) { + message = message.Remove(0, 1); Server.s.Log("Stealth ban Attempted by " + (p == null ? "Console" : p.ColoredName)); } - string[] args = message.SplitSpaces(2); - string reason = args.Length > 1 ? args[1] : Server.defaultBanMessage; + string reason = args.Length > 1 ? args[1] : ""; + + string target = RankCmd.FindName(p, "ban", "", args[0], ref reason); + if (target == null) return; + Player who = PlayerInfo.FindExact(target); + + if (reason == "") reason = Server.defaultBanMessage; if (reason == "-") reason = "&c-"; reason = GetReason(p, reason); - if (reason == null) return; - string banReason = reason == "-" ? "" : " (" + reason + ")"; - Player who = PlayerInfo.Find(args[0]); - string target = who == null ? args[0] : who.name; - if (!Formatter.ValidName(p, target, "player")) return; + if (reason == null) return; Group group = who == null ? Group.findPlayerGroup(args[0]) : who.group; if (!CheckPerms(target, group, p)) return; - + + string banReason = reason == "-" ? "" : " (" + reason + ")"; string banner = p == null ? "(console)" : p.ColoredName; string banMsg = null; if (who == null) { diff --git a/Commands/Moderation/RankCmd.cs b/Commands/Moderation/RankCmd.cs index 9f1a412f6..3fe140445 100644 --- a/Commands/Moderation/RankCmd.cs +++ b/Commands/Moderation/RankCmd.cs @@ -45,19 +45,20 @@ namespace MCGalaxy.Commands.Moderation { internal static string FindName(Player p, string action, string cmdArgs, string name, ref string reason) { + if (!Formatter.ValidName(p, name, "player")) return null; string match = MatchName(p, ref name); string confirmed = IsConfirmed(reason); - if (confirmed != null) reason = confirmed; + if (confirmed != null) reason = confirmed; if (match != null) { if (match.CaselessEq(name)) return match; - // Not an exact match, may be wanting to ban an offline account + // Not an exact match, may be wanting to ban a non-existent account Player.Message(p, "1 player matches \"{0}\": {1}", name, match); } if (confirmed != null) return name; string msgReason = String.IsNullOrEmpty(reason) ? "" : " " + reason; - Player.Message(p, "If you still want to {0} {1}, use %T/{0} {1}{2} confirm {3}", + Player.Message(p, "If you still want to {0} \"{1}\", use %T/{0} {1}{2} confirm {3}", action, name, cmdArgs, msgReason); return null; }