diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 55d281c31..c56a5b9fb 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -39,6 +39,8 @@ You should have received a copy of the GNU General Public License using Terraria.DataStructures; using Terraria.GameContent.Creative; +using static TShockAPI.Utils; + namespace TShockAPI { public delegate void CommandDelegate(CommandArgs args); @@ -815,9 +817,9 @@ private static void AttemptLogin(CommandArgs args) args.Player.SendMessage($"{Specifier}login - Logs in using your UUID and character name.", Color.White); if (TShock.Config.Settings.AllowLoginAnyUsername) - args.Player.SendMessage($"{Specifier}login {"username".Color(Utils.GreenHighlight)} {"password".Color(Utils.BoldHighlight)} - Logs in using your username and password.", Color.White); + args.Player.SendMessage($"{Specifier}login {Highlight("username", GreenHighlight)} {Highlight("password", BlueHighlight)} - Logs in using your username and password.", Color.White); else - args.Player.SendMessage($"{Specifier}login {"password".Color(Utils.BoldHighlight)} - Logs in using your password and character name.", Color.White); + args.Player.SendMessage($"{Specifier}login {Highlight("password", BlueHighlight)} - Logs in using your password and character name.", Color.White); args.Player.SendWarningMessage("If you forgot your password, there is no way to recover it."); return; @@ -1005,9 +1007,9 @@ private static void RegisterUser(CommandArgs args) args.Player.SendMessage($"Type {Specifier}login to sign in to your account using your UUID.", Color.White); if (TShock.Config.Settings.AllowLoginAnyUsername) - args.Player.SendMessage($"Type {Specifier}login \"{account.Name.Color(Utils.GreenHighlight)}\" {echoPassword.Color(Utils.BoldHighlight)} to sign in to your account.", Color.White); + args.Player.SendMessage($"Type {Specifier}login \"{Highlight(account.Name, GreenHighlight)}\" {Highlight(echoPassword, BlueHighlight)} to sign in to your account.", Color.White); else - args.Player.SendMessage($"Type {Specifier}login {echoPassword.Color(Utils.BoldHighlight)} to sign in to your account.", Color.White); + args.Player.SendMessage($"Type {Specifier}login {Highlight(echoPassword, BlueHighlight)} to sign in to your account.", Color.White); TShock.UserAccounts.AddUserAccount(account); TShock.Log.ConsoleInfo("{0} registered an account: \"{1}\".", args.Player.Name, account.Name); @@ -1297,20 +1299,6 @@ private static void Kick(CommandArgs args) private static void Ban(CommandArgs args) { - //Ban syntax: - // ban add [reason] [duration] [flags (default: -a -u -ip)] - // Duration is in the format 0d0h0m0s. Any part can be ignored. E.g., 1s is a valid ban time, as is 1d1s, etc. If no duration is specified, ban is permanent - // Valid flags: -a (ban account name), -u (ban UUID), -n (ban character name), -ip (ban IP address), -e (exact, ban the identifier provided as 'target') - // Unless -e is passed to the command, is assumed to be a player or player index. - // ban del - // Target is expected to be a ban Unique ID - // ban list [page] - // Displays a paginated list of bans - // ban details - // Target is expected to be a ban Unique ID - //ban help [command] - // Provides extended help on specific ban commands - void Help() { if (args.Parameters.Count > 1) @@ -1321,12 +1309,12 @@ void Help() args.Player.SendMessage("TShock Ban Help", Color.White); args.Player.SendMessage("Available Ban commands:", Color.White); - args.Player.SendMessage($"ban {"add".Color(Utils.RedHighlight)} [Flags]", Color.White); - args.Player.SendMessage($"ban {"del".Color(Utils.RedHighlight)} ", Color.White); - args.Player.SendMessage($"ban {"list".Color(Utils.RedHighlight)}", Color.White); - args.Player.SendMessage($"ban {"details".Color(Utils.RedHighlight)} ", Color.White); - args.Player.SendMessage($"Quick usage: {"ban add".Color(Utils.BoldHighlight)} {args.Player.Name.Color(Utils.RedHighlight)} \"Griefing\"", Color.White); - args.Player.SendMessage($"For more info, use {"ban help".Color(Utils.BoldHighlight)} {"command".Color(Utils.RedHighlight)} or {"ban help".Color(Utils.BoldHighlight)} {"examples".Color(Utils.RedHighlight)}", Color.White); + args.Player.SendMessage($"ban {Highlight("add", RedHighlight)} [Flags]", Color.White); + args.Player.SendMessage($"ban {Highlight("del", RedHighlight)} ", Color.White); + args.Player.SendMessage($"ban {Highlight("list", RedHighlight)}", Color.White); + args.Player.SendMessage($"ban {Highlight("details", RedHighlight)} ", Color.White); + args.Player.SendMessage($"Quick usage: {Highlight("ban add", BlueHighlight)} {Highlight(args.Player.Name, RedHighlight)} \"Griefing\"", Color.White); + args.Player.SendMessage($"For more info, use {Highlight("ban help", BlueHighlight)} {Highlight("command", RedHighlight)} or {Highlight("ban help", BlueHighlight)} {Highlight("examples", RedHighlight)}", Color.White); } void MoreHelp(string cmd) @@ -1336,38 +1324,39 @@ void MoreHelp(string cmd) case "add": args.Player.SendMessage("", Color.White); args.Player.SendMessage("Ban Add Syntax", Color.White); - args.Player.SendMessage($"{"ban add".Color(Utils.BoldHighlight)} <{"Target".Color(Utils.RedHighlight)}> [{"Reason".Color(Utils.BoldHighlight)}] [{"Duration".Color(Utils.PinkHighlight)}] [{"Flags".Color(Utils.GreenHighlight)}]", Color.White); - args.Player.SendMessage($"- {"Duration".Color(Utils.PinkHighlight)}: uses the format {"0d0m0s".Color(Utils.PinkHighlight)} to determine the length of the ban.", Color.White); - args.Player.SendMessage($" Eg a value of {"10d30m0s".Color(Utils.PinkHighlight)} would represent 10 days, 30 minutes, 0 seconds.", Color.White); + args.Player.SendMessage($"{Highlight("ban add", BlueHighlight)} <{Highlight("Target", RedHighlight)}> [{Highlight("Reason", BlueHighlight)}] [{Highlight("Duration", PinkHighlight)}] [{Highlight("Flags", GreenHighlight)}]", Color.White); + args.Player.SendMessage($"- {Highlight("Duration", PinkHighlight)}: uses the format {Highlight("0d0m0s", PinkHighlight)} to determine the length of the ban.", Color.White); + args.Player.SendMessage($" Eg a value of {Highlight("10d30m0s", PinkHighlight)} would represent 10 days, 30 minutes, 0 seconds.", Color.White); args.Player.SendMessage($" If no duration is provided, the ban will be permanent.", Color.White); - args.Player.SendMessage($"- {"Flags".Color(Utils.GreenHighlight)}: -a (account name), -u (UUID), -n (character name), -ip (IP address), -e (exact, {"Target".Color(Utils.RedHighlight)} will be treated as identifier)", Color.White); - args.Player.SendMessage($" Unless {"-e".Color(Utils.GreenHighlight)} is passed to the command, {"Target".Color(Utils.RedHighlight)} is assumed to be a player or player index", Color.White); - args.Player.SendMessage($" If no {"Flags".Color(Utils.GreenHighlight)} are specified, the command uses {"-a -u -ip".Color(Utils.GreenHighlight)} by default.", Color.White); - args.Player.SendMessage($"Example usage: {"ban add".Color(Utils.BoldHighlight)} {args.Player.Name.Color(Utils.RedHighlight)} {"\"Cheating\"".Color(Utils.BoldHighlight)} {"10d30m0s".Color(Utils.PinkHighlight)} {"-a -u -ip".Color(Utils.GreenHighlight)}", Color.White); + args.Player.SendMessage($"- {Highlight("Flags", GreenHighlight)}: -a (account name), -u (UUID), -n (character name), -ip (IP address)", Color.White); + args.Player.SendMessage($" -e (exact, {Highlight("Target", RedHighlight)} will be treated as a raw identifier)", Color.White); + args.Player.SendMessage($" -o (offline, {Highlight("Target", RedHighlight)} will be treated as a username)", Color.White); + args.Player.SendMessage($" If no {Highlight("Flags", GreenHighlight)} are specified, the command uses {Highlight("-a -u -ip", GreenHighlight)} by default.", Color.White); + args.Player.SendMessage($"Example usage: {Highlight("ban add", BlueHighlight)} {Highlight(args.Player.Name, RedHighlight)} {Highlight("\"Cheating\"", BlueHighlight)} {Highlight("10d30m0s", PinkHighlight)} {Highlight("-a -u -ip", GreenHighlight)}", Color.White); break; case "del": args.Player.SendMessage("", Color.White); args.Player.SendMessage("Ban Del Syntax", Color.White); - args.Player.SendMessage($"{"ban del".Color(Utils.BoldHighlight)} <{"Ticket Number".Color(Utils.RedHighlight)}>", Color.White); - args.Player.SendMessage($"- {"Ticket Numbers".Color(Utils.RedHighlight)} are provided when you add a ban, and can also be viewed with the {"ban list".Color(Utils.BoldHighlight)} command.", Color.White); - args.Player.SendMessage($"Example usage: {"ban del".Color(Utils.BoldHighlight)} {"12345".Color(Utils.RedHighlight)}", Color.White); + args.Player.SendMessage($"{Highlight("ban del", BlueHighlight)} <{Highlight("Ticket Number", RedHighlight)}>", Color.White); + args.Player.SendMessage($"- {Highlight("Ticket Numbers", RedHighlight)} are provided when you add a ban, and can also be viewed with the {Highlight("ban list", BlueHighlight)} command.", Color.White); + args.Player.SendMessage($"Example usage: {Highlight("ban del", BlueHighlight)} {Highlight("12345", RedHighlight)}", Color.White); break; case "list": args.Player.SendMessage("", Color.White); args.Player.SendMessage("Ban List Syntax", Color.White); - args.Player.SendMessage($"{"ban list".Color(Utils.BoldHighlight)} [{"Page".Color(Utils.PinkHighlight)}]", Color.White); + args.Player.SendMessage($"{Highlight("ban list", BlueHighlight)} [{Highlight("Page", PinkHighlight)}]", Color.White); args.Player.SendMessage("- Lists active bans. Color trends towards green as the ban approaches expiration", Color.White); - args.Player.SendMessage($"Example usage: {"ban list".Color(Utils.BoldHighlight)}", Color.White); + args.Player.SendMessage($"Example usage: {Highlight("ban list", BlueHighlight)}", Color.White); break; case "details": args.Player.SendMessage("", Color.White); args.Player.SendMessage("Ban Details Syntax", Color.White); - args.Player.SendMessage($"{"ban details".Color(Utils.BoldHighlight)} <{"Ticket Number".Color(Utils.RedHighlight)}>", Color.White); - args.Player.SendMessage($"- {"Ticket Numbers".Color(Utils.RedHighlight)} are provided when you add a ban, and can be found with the {"ban list".Color(Utils.BoldHighlight)} command.", Color.White); - args.Player.SendMessage($"Example usage: {"ban details".Color(Utils.BoldHighlight)} {"12345".Color(Utils.RedHighlight)}", Color.White); + args.Player.SendMessage($"{Highlight("ban details", BlueHighlight)} <{Highlight("Ticket Number", RedHighlight)}>", Color.White); + args.Player.SendMessage($"- {Highlight("Ticket Numbers", RedHighlight)} are provided when you add a ban, and can be found with the {Highlight("ban list", BlueHighlight)} command.", Color.White); + args.Player.SendMessage($"Example usage: {Highlight("ban details", BlueHighlight)} {Highlight("12345", RedHighlight)}", Color.White); break; case "identifiers": @@ -1378,7 +1367,7 @@ void MoreHelp(string cmd) } var idents = from ident in Identifier.Available - select $"{ident.Color(Utils.RedHighlight)} - {ident.Description}"; + select $"{Highlight(ident, RedHighlight)} - {ident.Description}"; args.Player.SendMessage("", Color.White); PaginationTools.SendPage(args.Player, pageNumber, idents.ToList(), @@ -1396,44 +1385,44 @@ void MoreHelp(string cmd) args.Player.SendMessage("", Color.White); args.Player.SendMessage("Ban Usage Examples", Color.White); args.Player.SendMessage("- Ban an offline player by account name", Color.White); - args.Player.SendMessage($" {Specifier}{"ban add".Color(Utils.BoldHighlight)} \"{"acc:".Color(Utils.RedHighlight)}{args.Player.Account.Color(Utils.RedHighlight)}\" {"\"Multiple accounts are not allowed\"".Color(Utils.BoldHighlight)} {"-e".Color(Utils.GreenHighlight)} (Permanently bans this account name)", Color.White); + args.Player.SendMessage($" {Specifier}{Highlight("ban add", BlueHighlight)} \"{Highlight("acc:", RedHighlight)}{Highlight(args.Player.Account, RedHighlight)}\" {Highlight("\"Multiple accounts are not allowed\"", BlueHighlight)} {Highlight("-e", GreenHighlight)} (Permanently bans this account name)", Color.White); args.Player.SendMessage("- Ban an offline player by IP address", Color.White); - args.Player.SendMessage($" {Specifier}{"ai".Color(Utils.BoldHighlight)} \"{args.Player.Account.Color(Utils.RedHighlight)}\" (Find the IP associated with the offline target's account)", Color.White); - args.Player.SendMessage($" {Specifier}{"ban add".Color(Utils.BoldHighlight)} {"ip:".Color(Utils.RedHighlight)}{args.Player.IP.Color(Utils.RedHighlight)} {"\"Griefing\"".Color(Utils.BoldHighlight)} {"-e".Color(Utils.GreenHighlight)} (Permanently bans this IP address)", Color.White); + args.Player.SendMessage($" {Specifier}{Highlight("ai", BlueHighlight)} \"{Highlight(args.Player.Account, RedHighlight)}\" (Find the IP associated with the offline target's account)", Color.White); + args.Player.SendMessage($" {Specifier}{Highlight("ban add", BlueHighlight)} {Highlight("ip:", RedHighlight)}{Highlight(args.Player.IP, RedHighlight)} {Highlight("\"Griefing\"", BlueHighlight)} {Highlight("-e", GreenHighlight)} (Permanently bans this IP address)", Color.White); args.Player.SendMessage($"- Ban an online player by index (Useful for hard to type names)", Color.White); - args.Player.SendMessage($" {Specifier}{"who".Color(Utils.BoldHighlight)} {"-i".Color(Utils.GreenHighlight)} (Find the player index for the target)", Color.White); - args.Player.SendMessage($" {Specifier}{"ban add".Color(Utils.BoldHighlight)} {"tsi:".Color(Utils.RedHighlight)}{args.Player.Index.Color(Utils.RedHighlight)} {"\"Trolling\"".Color(Utils.BoldHighlight)} {"-a -u -ip".Color(Utils.GreenHighlight)} (Permanently bans the online player by Account, UUID, and IP)", Color.White); + args.Player.SendMessage($" {Specifier}{Highlight("who", BlueHighlight)} {Highlight("-i", GreenHighlight)} (Find the player index for the target)", Color.White); + args.Player.SendMessage($" {Specifier}{Highlight("ban add", BlueHighlight)} {Highlight("tsi:", RedHighlight)}{Highlight(args.Player.Index, RedHighlight)} {Highlight("\"Trolling\"", BlueHighlight)} {Highlight("-a -u -ip", GreenHighlight)} (Permanently bans the online player by Account, UUID, and IP)", Color.White); // Ban by account ID when? break; default: - args.Player.SendMessage($"Unknown ban command. Try {"ban help".Color(Utils.BoldHighlight)} {"add".Color(Utils.RedHighlight)}, {"del".Color(Utils.RedHighlight)}, {"list".Color(Utils.RedHighlight)}, {"details".Color(Utils.RedHighlight)}, {"identifiers".Color(Utils.RedHighlight)}, or {"examples".Color(Utils.RedHighlight)}.", Color.White); break; + args.Player.SendMessage($"Unknown ban command. Try {Highlight("ban help", BlueHighlight)} {Highlight("add", RedHighlight)}, {Highlight("del", RedHighlight)}, {Highlight("list", RedHighlight)}, {Highlight("details", RedHighlight)}, {Highlight("identifiers", RedHighlight)}, or {Highlight("examples", RedHighlight)}.", Color.White); break; } } void DisplayBanDetails(Ban ban) { - args.Player.SendMessage($"{"Ban Details".Color(Utils.BoldHighlight)} - Ticket Number: {ban.TicketNumber.Color(Utils.GreenHighlight)}", Color.White); - args.Player.SendMessage($"{"Identifier:".Color(Utils.BoldHighlight)} {ban.Identifier}", Color.White); - args.Player.SendMessage($"{"Reason:".Color(Utils.BoldHighlight)} {ban.Reason}", Color.White); - args.Player.SendMessage($"{"Banned by:".Color(Utils.BoldHighlight)} {ban.BanningUser.Color(Utils.GreenHighlight)} on {ban.BanDateTime.ToString("yyyy/MM/dd").Color(Utils.RedHighlight)} ({ban.GetPrettyTimeSinceBanString().Color(Utils.YellowHighlight)} ago)", Color.White); + args.Player.SendMessage($"{Highlight("Ban Details", BlueHighlight)} - Ticket Number: {Highlight(ban.TicketNumber, GreenHighlight)}", Color.White); + args.Player.SendMessage($"{Highlight("Identifier:", BlueHighlight)} {ban.Identifier}", Color.White); + args.Player.SendMessage($"{Highlight("Reason:", BlueHighlight)} {ban.Reason}", Color.White); + args.Player.SendMessage($"{Highlight("Banned by:", BlueHighlight)} {Highlight(ban.BanningUser, GreenHighlight)} on {Highlight(ban.BanDateTime.ToString("yyyy/MM/dd"), RedHighlight)} ({Highlight(ban.GetPrettyTimeSinceBanString(), YellowHighlight)} ago)", Color.White); if (ban.ExpirationDateTime < DateTime.UtcNow) { - args.Player.SendMessage($"{"Ban expired:".Color(Utils.BoldHighlight)} {ban.ExpirationDateTime.ToString("yyyy/MM/dd").Color(Utils.RedHighlight)} ({ban.GetPrettyExpirationString().Color(Utils.YellowHighlight)} ago)", Color.White); + args.Player.SendMessage($"{Highlight("Ban expired:", BlueHighlight)} {Highlight(ban.ExpirationDateTime.ToString("yyyy/MM/dd"), RedHighlight)} ({Highlight(ban.GetPrettyExpirationString(), YellowHighlight)} ago)", Color.White); } else { string remaining; if (ban.ExpirationDateTime == DateTime.MaxValue) { - remaining = "Never".Color(Utils.YellowHighlight); + remaining = Highlight("Never", YellowHighlight); } else { - remaining = $"{ban.GetPrettyExpirationString().Color(Utils.YellowHighlight)} remaining"; + remaining = $"{Highlight(ban.GetPrettyExpirationString(), YellowHighlight)} remaining"; } - args.Player.SendMessage($"{"Ban expires:".Color(Utils.BoldHighlight)} {ban.ExpirationDateTime.ToString("yyyy/MM/dd").Color(Utils.RedHighlight)} ({remaining})", Color.White); + args.Player.SendMessage($"{Highlight("Ban expires:", BlueHighlight)} {Highlight(ban.ExpirationDateTime.ToString("yyyy/MM/dd"), RedHighlight)} ({remaining})", Color.White); } } @@ -1442,11 +1431,11 @@ AddBanResult DoBan(string ident, string reason, DateTime expiration) AddBanResult banResult = TShock.Bans.InsertBan(ident, reason, args.Player.Account.Name, DateTime.UtcNow, expiration); if (banResult.Ban != null) { - args.Player.SendSuccessMessage($"Ban added. Ticket Number {banResult.Ban.TicketNumber.Color(Utils.GreenHighlight)} was created for identifier {ident.Color(Utils.WhiteHighlight)}."); + args.Player.SendSuccessMessage($"Ban added. Ticket Number {Highlight(banResult.Ban.TicketNumber, GreenHighlight)} was created for identifier {Highlight(ident, WhiteHighlight)}."); } else { - args.Player.SendWarningMessage($"Failed to add ban for identifier: {ident.Color(Utils.WhiteHighlight)}"); + args.Player.SendWarningMessage($"Failed to add ban for identifier: {Highlight(ident, WhiteHighlight)}"); args.Player.SendWarningMessage($"Reason: {banResult.Message}"); } @@ -1457,7 +1446,7 @@ void AddBan() { if (!args.Parameters.TryGetValue(1, out string target)) { - args.Player.SendMessage($"Invalid Ban Add syntax. Refer to {"ban help add".Color(Utils.BoldHighlight)} for details on how to use the {"ban add".Color(Utils.BoldHighlight)} command", Color.White); + args.Player.SendMessage($"Invalid Ban Add syntax. Refer to {Highlight("ban help add", BlueHighlight)} for details on how to use the {Highlight("ban add", BlueHighlight)} command", Color.White); return; } @@ -1466,8 +1455,9 @@ void AddBan() bool banUuid = args.Parameters.Any(p => p == "-u"); bool banName = args.Parameters.Any(p => p == "-n"); bool banIp = args.Parameters.Any(p => p == "-ip"); + bool banOffline = args.Parameters.Any(p => p == "-o"); - List flags = new List() { "-e", "-a", "-u", "-n", "-ip" }; + List flags = new List() { "-e", "-a", "-u", "-n", "-ip", "-o" }; string reason = "Banned."; string duration = null; @@ -1518,6 +1508,18 @@ void AddBan() return; } + if (banOffline) + { + UserAccount account = TShock.UserAccounts.GetUserAccountByName(target); + if (account == null) + { + args.Player.SendErrorMessage("Could not find the account target specified. Check that you have the correct spelling."); + return; + } + + + } + var players = TSPlayer.FindByNameOrID(target); if (players.Count > 1) @@ -1529,59 +1531,47 @@ void AddBan() if (players.Count < 1) { args.Player.SendErrorMessage("Could not find the target specified. Check that you have the correct spelling."); + args.Player.SendInfoMessage($"To ban an offline user, please use the {Highlight("-o", GreenHighlight)} flag."); return; } var player = players[0]; - AddBanResult banResult = null; - - if (banAccount) - { - if (player.Account != null) - { - banResult = DoBan($"{Identifier.Account}{player.Account.Name}", reason, expiration); - } - } - - if (banUuid) - { - banResult = DoBan($"{Identifier.UUID}{player.UUID}", reason, expiration); - } - - if (banName) - { - banResult = DoBan($"{Identifier.Name}{player.Name}", reason, expiration); - } - - if (banIp) + IEnumerable banResults = TShock.Bans.DoPlayerBan(player, new BanAction { - banResult = DoBan($"{Identifier.IP}{player.IP}", reason, expiration); - } + BanAccount = banAccount, + BanIp = banIp, + BanName = banName, + BanUuid = banUuid, + ExecutingUser = args.Player, + Expiration = expiration, + Reason = reason + }); - if (banResult?.Ban != null) + //TODO: group bans better. Display parent ban ID to user + /*if (banResult?.Ban != null) { player.Disconnect($"#{banResult.Ban.TicketNumber} - You have been banned: {banResult.Ban.Reason}."); - } + }*/ } void DelBan() { if (!args.Parameters.TryGetValue(1, out string target)) { - args.Player.SendMessage($"Invalid Ban Del syntax. Refer to {"ban help del".Color(Utils.BoldHighlight)} for details on how to use the {"ban del".Color(Utils.BoldHighlight)} command", Color.White); + args.Player.SendMessage($"Invalid Ban Del syntax. Refer to {Highlight("ban help del", BlueHighlight)} for details on how to use the {Highlight("ban del", BlueHighlight)} command", Color.White); return; } if (!int.TryParse(target, out int banId)) { - args.Player.SendMessage($"Invalid Ticket Number. Refer to {"ban help del".Color(Utils.BoldHighlight)} for details on how to use the {"ban del".Color(Utils.BoldHighlight)} command", Color.White); + args.Player.SendMessage($"Invalid Ticket Number. Refer to {Highlight("ban help del", BlueHighlight)} for details on how to use the {Highlight("ban del", BlueHighlight)} command", Color.White); return; } if (TShock.Bans.RemoveBan(banId)) { TShock.Log.ConsoleInfo($"Ban {banId} has been revoked by {args.Player.Account.Name}."); - args.Player.SendSuccessMessage($"Ban {banId.Color(Utils.GreenHighlight)} has now been marked as expired."); + args.Player.SendSuccessMessage($"Ban {Highlight(banId, GreenHighlight)} has now been marked as expired."); } else { @@ -1605,14 +1595,14 @@ string PickColorForBan(Ban ban) if (!PaginationTools.TryParsePageNumber(args.Parameters, 1, args.Player, out int pageNumber)) { - args.Player.SendMessage($"Invalid Ban List syntax. Refer to {"ban help list".Color(Utils.BoldHighlight)} for details on how to use the {"ban list".Color(Utils.BoldHighlight)} command", Color.White); + args.Player.SendMessage($"Invalid Ban List syntax. Refer to {Highlight("ban help list", BlueHighlight)} for details on how to use the {Highlight("ban list", BlueHighlight)} command", Color.White); return; } var bans = from ban in TShock.Bans.Bans where ban.Value.ExpirationDateTime > DateTime.UtcNow orderby ban.Value.ExpirationDateTime ascending - select $"[{ban.Key.Color(Utils.GreenHighlight)}] {ban.Value.Identifier.Color(PickColorForBan(ban.Value))}"; + select $"[{Highlight(ban.Key, GreenHighlight)}] {Highlight(ban.Value.Identifier, PickColorForBan(ban.Value))}"; PaginationTools.SendPage(args.Player, pageNumber, bans.ToList(), new PaginationTools.Settings @@ -1627,13 +1617,13 @@ void BanDetails() { if (!args.Parameters.TryGetValue(1, out string target)) { - args.Player.SendMessage($"Invalid Ban Details syntax. Refer to {"ban help details".Color(Utils.BoldHighlight)} for details on how to use the {"ban details".Color(Utils.BoldHighlight)} command", Color.White); + args.Player.SendMessage($"Invalid Ban Details syntax. Refer to {Highlight("ban help details", BlueHighlight)} for details on how to use the {Highlight("ban details", BlueHighlight)} command", Color.White); return; } if (!int.TryParse(target, out int banId)) { - args.Player.SendMessage($"Invalid Ticket Number. Refer to {"ban help details".Color(Utils.BoldHighlight)} for details on how to use the {"ban details".Color(Utils.BoldHighlight)} command", Color.White); + args.Player.SendMessage($"Invalid Ticket Number. Refer to {Highlight("ban help details", BlueHighlight)} for details on how to use the {Highlight("ban details", BlueHighlight)} command", Color.White); return; } diff --git a/TShockAPI/DB/BanManager.cs b/TShockAPI/DB/BanManager.cs index 220d778ec..5d27c4912 100644 --- a/TShockAPI/DB/BanManager.cs +++ b/TShockAPI/DB/BanManager.cs @@ -259,6 +259,38 @@ internal void BanAddedCheck(object sender, BanPreAddEventArgs args) } } + public IEnumerable DoPlayerBan(TSPlayer bannedUser, BanAction banAction) + { + if (banAction.BanAccount) + { + if (bannedUser.Account != null) + { + yield return TShock.Bans.InsertBan($"{Identifier.Account}{bannedUser.Account.Name}", banAction.Reason, banAction.ExecutingUser.Account.Name, DateTime.UtcNow, banAction.Expiration); + } + } + + if (banAction.BanUuid) + { + yield return TShock.Bans.InsertBan($"{Identifier.UUID}{bannedUser.UUID}", banAction.Reason, banAction.ExecutingUser.Account.Name, DateTime.UtcNow, banAction.Expiration); + } + + if (banAction.BanName) + { + yield return TShock.Bans.InsertBan($"{Identifier.Name}{bannedUser.Name}", banAction.Reason, banAction.ExecutingUser.Account.Name, DateTime.UtcNow, banAction.Expiration); + } + + if (banAction.BanIp) + { + yield return TShock.Bans.InsertBan($"{Identifier.Name}{bannedUser.IP}", banAction.Reason, banAction.ExecutingUser.Account.Name, DateTime.UtcNow, banAction.Expiration); + } + } + + public IEnumerable DoAccountBan(UserAccount bannedAccount, BanAction banAction) + { + yield return TShock.Bans.InsertBan($"{Identifier.UUID}{bannedAccount.UUID}", banAction.Reason, banAction.ExecutingUser.Account.Name, DateTime.UtcNow, banAction.Expiration); + yield return TShock.Bans.InsertBan($"{Identifier.Account}{bannedAccount.Name}", banAction.Reason, banAction.ExecutingUser.Account.Name, DateTime.UtcNow, banAction.Expiration); + } + /// /// Adds a new ban for the given identifier. Returns a Ban object if the ban was added, else null /// @@ -676,6 +708,17 @@ public static Identifier Register(string prefix, string description) } } + public class BanAction + { + public TSPlayer ExecutingUser { get; set; } + public string Reason { get; set; } + public DateTime Expiration { get; set; } + public bool BanAccount { get; set; } + public bool BanUuid { get; set; } + public bool BanName { get; set; } + public bool BanIp { get; set; } + } + /// /// Model class that represents a ban entry in the TShock database. /// diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 92d452991..5a4c05c61 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -41,7 +41,7 @@ public class Utils /// /// Hex code for a blue pastel color /// - public const string BoldHighlight = "AAAAFF"; + public const string BlueHighlight = "AAAAFF"; /// /// Hex code for a red pastel color /// @@ -63,6 +63,18 @@ public class Utils /// public const string WhiteHighlight = "FFFFFF"; + /// + /// Converts an object to its string representation and wraps it in a Terraria color block + /// using the provided hex color code + /// + /// + /// + /// + public static string Highlight(object obj, string color) + { + return $"[c/{color}:{obj}]"; + } + /// /// The lowest id for a prefix. ///