From 12031e804c77225f2b79c292f093a22e27cd7d5a Mon Sep 17 00:00:00 2001 From: CoderCow Date: Mon, 22 Jul 2013 10:13:44 +0200 Subject: [PATCH 1/8] Added .editorconfig, might cause a bit less identation / line ending mess. It will automatically set the given settings in the used text editor if the Editor Config plugin is installed (available for several text editors), info: http://editorconfig.org/ --- .editorconfig | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..14864433 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +end_of_line = crlf +insert_final_newline = false + +[*.cs] +indent_style = tab +trim_trailing_whitespace = true \ No newline at end of file From dcfdbd1dbdf515511c06ce6f29eeb93118c8e016 Mon Sep 17 00:00:00 2001 From: CoderCow Date: Mon, 22 Jul 2013 10:36:34 +0200 Subject: [PATCH 2/8] Added quick format versions of the Log message methods. --- TShockAPI/Log.cs | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/TShockAPI/Log.cs b/TShockAPI/Log.cs index 9e54c53a..b04bc4c9 100644 --- a/TShockAPI/Log.cs +++ b/TShockAPI/Log.cs @@ -70,6 +70,16 @@ namespace TShockAPI public static void Data(String message) { Write(message, LogLevel.Data); + } + + /// + /// Writes data to the log file. + /// + /// The format of the message to be written. + /// The format arguments. + public static void Data(String format, params String[] args) + { + Data(String.Format(format, args)); } /// @@ -79,6 +89,16 @@ namespace TShockAPI public static void Error(String message) { Write(message, LogLevel.Error); + } + + /// + /// Writes an error to the log file. + /// + /// The format of the message to be written. + /// The format arguments. + public static void Error(String format, params String[] args) + { + Error(String.Format(format, args)); } /// @@ -91,6 +111,16 @@ namespace TShockAPI Console.WriteLine(message); Console.ForegroundColor = ConsoleColor.Gray; Write(message, LogLevel.Error); + } + + /// + /// Writes an error to the log file. + /// + /// The format of the message to be written. + /// The format arguments. + public static void ConsoleError(String format, params String[] args) + { + ConsoleError(String.Format(format, args)); } /// @@ -100,6 +130,16 @@ namespace TShockAPI public static void Warn(String message) { Write(message, LogLevel.Warning); + } + + /// + /// Writes a warning to the log file. + /// + /// The format of the message to be written. + /// The format arguments. + public static void Warn(String format, params String[] args) + { + Warn(String.Format(format, args)); } /// @@ -109,6 +149,16 @@ namespace TShockAPI public static void Info(String message) { Write(message, LogLevel.Info); + } + + /// + /// Writes an informative string to the log file. + /// + /// The format of the message to be written. + /// The format arguments. + public static void Info(String format, params String[] args) + { + Info(String.Format(format, args)); } /// @@ -121,6 +171,16 @@ namespace TShockAPI Console.WriteLine(message); Console.ForegroundColor = ConsoleColor.Gray; Write(message, LogLevel.Info); + } + + /// + /// Writes an informative string to the log file. Also outputs to the console. + /// + /// The format of the message to be written. + /// The format arguments. + public static void ConsoleInfo(String format, params String[] args) + { + ConsoleInfo(String.Format(format, args)); } /// @@ -130,6 +190,16 @@ namespace TShockAPI public static void Debug(String message) { Write(message, LogLevel.Debug); + } + + /// + /// Writes a debug string to the log file. + /// + /// The format of the message to be written. + /// The format arguments. + public static void Debug(String format, params String[] args) + { + Debug(String.Format(format, args)); } /// From 512ec24b57516523924b177805dbb1138f845efd Mon Sep 17 00:00:00 2001 From: CoderCow Date: Mon, 22 Jul 2013 10:45:36 +0200 Subject: [PATCH 3/8] Minor fix of /region info's output. --- TShockAPI/Commands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index a2c925d7..ac8cf231 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -2879,7 +2879,7 @@ namespace TShockAPI args.Player, pageNumber, lines, new PaginationTools.Settings { HeaderFormat = string.Format("Information About Region \"{0}\" ({{0}}/{{1}}):", region.Name), - FooterFormat = "Type /region info {0} for more information." + FooterFormat = string.Format("Type /region info {0} {{0}} for more information.", regionName) } ); From d1f1e422a0776f75b0251c884900a079d7e4eb1a Mon Sep 17 00:00:00 2001 From: CoderCow Date: Mon, 22 Jul 2013 11:28:12 +0200 Subject: [PATCH 4/8] -Ingame log messages are no longer shown to the player who caused them. -Changed ingame log message color to something more unique for better identification. --- TShockAPI/Commands.cs | 4 ++-- TShockAPI/GetDataHandlers.cs | 2 +- TShockAPI/Utils.cs | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index ac8cf231..9db26c72 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -282,7 +282,7 @@ namespace TShockAPI { if (!cmd.CanRun(player)) { - TShock.Utils.SendLogs(string.Format("{0} tried to execute /{1}.", player.Name, cmdText), Color.Red); + TShock.Utils.SendLogs(string.Format("{0} tried to execute /{1}.", player.Name, cmdText), Color.PaleVioletRed, player); player.SendErrorMessage("You do not have access to that command."); } else if (!cmd.AllowServer && !player.RealPlayer) @@ -292,7 +292,7 @@ namespace TShockAPI else { if (cmd.DoLog) - TShock.Utils.SendLogs(string.Format("{0} executed: /{1}.", player.Name, cmdText), Color.Red); + TShock.Utils.SendLogs(string.Format("{0} executed: /{1}.", player.Name, cmdText), Color.PaleVioletRed, player); cmd.Run(cmdText, player, args); } } diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index e8ff6d65..bd77b273 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2922,7 +2922,7 @@ namespace TShockAPI break; } - TShock.Utils.SendLogs(string.Format("{0} summoned {1}", args.Player.Name, boss), Color.Red); + TShock.Utils.SendLogs(string.Format("{0} summoned {1}", args.Player.Name, boss), Color.PaleVioletRed, args.Player); return false; } } diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index f98cb284..5f0d8706 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -218,18 +218,19 @@ namespace TShockAPI } /// - /// Sends message to all users with 'logs' permission. + /// Sends message to all players with 'logs' permission. /// /// Message to send - /// Color of the message - public void SendLogs(string log, Color color) + /// Color of the message + /// The player to not send the message to. + public void SendLogs(string log, Color color, TSPlayer excludedPlayer = null) { Log.Info(log); TSPlayer.Server.SendMessage(log, color); foreach (TSPlayer player in TShock.Players) { - if (player != null && player.Active && player.Group.HasPermission(Permissions.logs) && player.DisplayLogs && - TShock.Config.DisableSpewLogs == false) + if (player != null && player != excludedPlayer && player.Active && player.Group.HasPermission(Permissions.logs) && + player.DisplayLogs && TShock.Config.DisableSpewLogs == false) player.SendMessage(log, color); } } From 5d2be3569095f319c9d73bf3d635dd64fa4d7cee Mon Sep 17 00:00:00 2001 From: CoderCow Date: Mon, 22 Jul 2013 11:41:52 +0200 Subject: [PATCH 5/8] -Made the broadcast color configurable. -Broadcast color defaults to Aquamarine now. --- TShockAPI/Commands.cs | 5 +++-- TShockAPI/ConfigFile.cs | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 9db26c72..238ec52b 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1288,8 +1288,9 @@ namespace TShockAPI { message += " " + args.Parameters[i]; } - - TShock.Utils.Broadcast("(Server Broadcast)" + message, Color.Red); + + Color color = new Color(TShock.Config.BroadcastRGB[0], TShock.Config.BroadcastRGB[1], TShock.Config.BroadcastRGB[2]); + TShock.Utils.Broadcast("(Server Broadcast)" + message, color); return; } diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index dec09a6d..304de298 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -251,7 +251,10 @@ namespace TShockAPI [Description("The path of the directory where logs should be written into.")] public string LogPath = "tshock"; - [Description("Prevents players from placing tiles with an invalid style.")] public bool PreventInvalidPlaceStyle = true; + [Description("Prevents players from placing tiles with an invalid style.")] public bool PreventInvalidPlaceStyle = true; + + [Description("#.#.#. = Red/Blue/Green - RGB Colors for broadcasts. Max value: 255.")] public float[] BroadcastRGB = + {127,255,212}; /// /// Reads a configuration file from a given path From 56d17224b61bc7e8cae63074a3bffa23d8fbfbb4 Mon Sep 17 00:00:00 2001 From: CoderCow Date: Mon, 22 Jul 2013 12:09:09 +0200 Subject: [PATCH 6/8] Added /aliases command used to list aliases of other commands. --- TShockAPI/Commands.cs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 238ec52b..ce231c60 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -244,7 +244,8 @@ namespace TShockAPI add(Permissions.savessi, SaveSSI, "savessi"); add(Permissions.savessi, OverrideSSI, "overridessi", "ossi"); add(Permissions.xmas, ForceXmas, "forcexmas"); - add(Permissions.settempgroup, TempGroup, "tempgroup"); + add(Permissions.settempgroup, TempGroup, "tempgroup"); + add(null, Aliases, "aliases"); //add(null, TestCallbackCommand, "test"); TShockCommands = new ReadOnlyCollection(tshockCommands); @@ -3373,6 +3374,41 @@ namespace TShockAPI args.Player.SendSuccessMessage("Annoying " + ply.Name + " for " + annoy + " seconds."); (new Thread(ply.Whoopie)).Start(annoy); } + } + + private static void Aliases(CommandArgs args) + { + if (args.Parameters.Count < 1) + { + args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /aliases "); + return; + } + + string givenCommandName = string.Join(" ", args.Parameters); + if (string.IsNullOrWhiteSpace(givenCommandName)) { + args.Player.SendErrorMessage("Please enter a proper command name or alias."); + return; + } + + string commandName; + if (givenCommandName[0] == '/') + commandName = givenCommandName.Substring(1); + else + commandName = givenCommandName; + + bool didMatch = false; + foreach (Command matchingCommand in ChatCommands.Where(cmd => cmd.Names.IndexOf(commandName) != -1)) { + if (matchingCommand.Names.Count > 1) + args.Player.SendInfoMessage( + "Aliases of /{0}: /{1}", matchingCommand.Name, string.Join(", /", matchingCommand.Names.Skip(1))); + else + args.Player.SendInfoMessage("/{0} defines no aliases.", matchingCommand.Name); + + didMatch = true; + } + + if (!didMatch) + args.Player.SendErrorMessage("No command or command alias matching \"{0}\" found.", givenCommandName); } #endregion General Commands From f4aa36b8d1469e47dca13c7cb49419b951228e9a Mon Sep 17 00:00:00 2001 From: CoderCow Date: Mon, 22 Jul 2013 12:12:02 +0200 Subject: [PATCH 7/8] Fixed a possible bug causing TSPlayer.StrikeNPC to cause NullReferenceExceptions depending on the calling thread. --- TShockAPI/TSPlayer.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 986d3147..bd13cfd4 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -899,6 +899,10 @@ namespace TShockAPI public void StrikeNPC(int npcid, int damage, float knockBack, int hitDirection) { + // Main.rand is thread static. + if (Main.rand == null) + Main.rand = new Random(); + Main.npc[npcid].StrikeNPC(damage, knockBack, hitDirection); NetMessage.SendData((int) PacketTypes.NpcStrike, -1, -1, "", npcid, damage, knockBack, hitDirection); } From b591b740d1f6c2f2ec50e08df083bd798ac735f1 Mon Sep 17 00:00:00 2001 From: CoderCow Date: Mon, 22 Jul 2013 18:30:08 +0200 Subject: [PATCH 8/8] Fixed .editorconfig final new lines. --- .editorconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index 14864433..598dd721 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,8 +2,8 @@ root = true [*] end_of_line = crlf -insert_final_newline = false +insert_final_newline = true [*.cs] indent_style = tab -trim_trailing_whitespace = true \ No newline at end of file +trim_trailing_whitespace = true