Validate the name in RankCmd.FindName too, also do the same thing for /ban.

This commit is contained in:
UnknownShadow200 2016-09-05 09:47:04 +10:00
parent f2a7aafbc2
commit f0d13f61d1
2 changed files with 17 additions and 15 deletions

View File

@ -27,26 +27,27 @@ namespace MCGalaxy.Commands.Moderation {
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
if (message == "") { Help(p); return; } if (message == "") { Help(p); return; }
bool stealth = false; bool stealth = message[0] == '#';
if (message[0] == '#') { if (stealth) {
message = message.Remove(0, 1).Trim(); message = message.Remove(0, 1);
stealth = true;
Server.s.Log("Stealth ban Attempted by " + (p == null ? "Console" : p.ColoredName)); Server.s.Log("Stealth ban Attempted by " + (p == null ? "Console" : p.ColoredName));
} }
string[] args = message.SplitSpaces(2); 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-"; if (reason == "-") reason = "&c-";
reason = GetReason(p, reason); reason = GetReason(p, reason);
if (reason == null) return;
string banReason = reason == "-" ? "" : " (" + reason + ")";
Player who = PlayerInfo.Find(args[0]); if (reason == null) return;
string target = who == null ? args[0] : who.name;
if (!Formatter.ValidName(p, target, "player")) return;
Group group = who == null ? Group.findPlayerGroup(args[0]) : who.group; Group group = who == null ? Group.findPlayerGroup(args[0]) : who.group;
if (!CheckPerms(target, group, p)) return; if (!CheckPerms(target, group, p)) return;
string banReason = reason == "-" ? "" : " (" + reason + ")";
string banner = p == null ? "(console)" : p.ColoredName; string banner = p == null ? "(console)" : p.ColoredName;
string banMsg = null; string banMsg = null;
if (who == null) { if (who == null) {

View File

@ -45,19 +45,20 @@ namespace MCGalaxy.Commands.Moderation {
internal static string FindName(Player p, string action, string cmdArgs, internal static string FindName(Player p, string action, string cmdArgs,
string name, ref string reason) { string name, ref string reason) {
if (!Formatter.ValidName(p, name, "player")) return null;
string match = MatchName(p, ref name); string match = MatchName(p, ref name);
string confirmed = IsConfirmed(reason); string confirmed = IsConfirmed(reason);
if (confirmed != null) reason = confirmed; if (confirmed != null) reason = confirmed;
if (match != null) { if (match != null) {
if (match.CaselessEq(name)) return match; 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); Player.Message(p, "1 player matches \"{0}\": {1}", name, match);
} }
if (confirmed != null) return name; if (confirmed != null) return name;
string msgReason = String.IsNullOrEmpty(reason) ? "" : " " + reason; 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); action, name, cmdArgs, msgReason);
return null; return null;
} }