From 0b98ac5fc141af34e78e598e629e24da907f3acb Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 26 Dec 2017 19:54:21 -0700 Subject: [PATCH 01/10] Remove deprecated motd, color code support --- TShockAPI/TShock.cs | 2 - TShockAPI/Utils.cs | 93 --------------------------------------------- 2 files changed, 95 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index d534d67e..c88fc247 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -886,8 +886,6 @@ namespace TShockAPI Utils.ComputeMaxStyles(); Utils.FixChestStacks(); - Utils.UpgradeMotD(); - if (Config.UseServerName) { Main.worldName = Config.ServerName; diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 82791065..6809710b 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -52,12 +52,6 @@ namespace TShockAPI /// instance - an instance of the utils class private static readonly Utils instance = new Utils(); - /// This regex will look for the old MotD format for colors and replace them with the new chat format. - private Regex motdColorRegex = new Regex(@"\%\s*(?\d{1,3})\s*,\s*(?\d{1,3})\s*,\s*(?\d{1,3})\s*\%(?((?!(\%\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\%)|(\[[a-zA-Z]/[^:]+:[^\]]*\])).)*)"); - - /// Matches the start of a line with our legacy color format - private Regex startOfLineColorRegex = new Regex(@"^\%\s*(?\d{1,3})\s*,\s*(?\d{1,3})\s*,\s*(?\d{1,3})\s*\%"); - /// Utils - Creates a utilities object. private Utils() {} @@ -715,98 +709,11 @@ namespace TShockAPI foo = foo.Replace("%map%", (TShock.Config.UseServerName ? TShock.Config.ServerName : Main.worldName)); foo = foo.Replace("%players%", String.Join(",", GetPlayers(false))); - var legacyColorMatch = startOfLineColorRegex.Match(foo); - if (legacyColorMatch.Success) - { - lineColor = new Color(Int32.Parse(legacyColorMatch.Groups["r"].Value), - Int32.Parse(legacyColorMatch.Groups["g"].Value), - Int32.Parse(legacyColorMatch.Groups["b"].Value)); - foo = foo.Replace(legacyColorMatch.Groups[0].Value, ""); - } - - bool upgraded = false; - string newFoo = ReplaceDeprecatedColorCodes(foo, out upgraded); - if (upgraded && !containsOldFormat) - { - TShock.Log.ConsoleInfo($"You are using an old color format in file {file}."); - TShock.Log.ConsoleInfo("To send coloured text please use Terraria's inbuilt format of: [c/#hex:text]."); - TShock.Log.ConsoleInfo("For example: [c/ff00aa:This is a message!]."); - containsOldFormat = true; - } - foo = newFoo; - player.SendMessage(foo, lineColor); } } } - /// - /// Returns a string with deprecated %###,###,###% formats replaced with the new chat format colors. - /// - /// The input string - /// An out parameter that denotes if this line of text was upgraded. - /// A replaced version of the input with the new chat color format. - private string ReplaceDeprecatedColorCodes(string input, out bool upgradedFormat) - { - String tempString = input; - Match match = null; - bool uFormat = false; - - while ((match = motdColorRegex.Match(tempString)).Success) - { - uFormat = true; - tempString = tempString.Replace(match.Groups[0].Value, String.Format("[c/{0:X2}{1:X2}{2:X2}:{3}]", Int32.Parse(match.Groups["r"].Value), Int32.Parse(match.Groups["g"].Value), Int32.Parse(match.Groups["b"].Value), match.Groups["text"])); - } - - upgradedFormat = uFormat; - return tempString; - } - - /// - /// Upgrades a legacy MotD file to the new terraria chat tags version. - /// - public void UpgradeMotD() - { - string foo = ""; - StringBuilder motd = new StringBuilder(); - bool informedOwner = false; - using (var tr = new StreamReader(FileTools.MotdPath)) - { - Color lineColor; - while ((foo = tr.ReadLine()) != null) - { - lineColor = Color.White; - var legacyColorMatch = startOfLineColorRegex.Match(foo); - if (legacyColorMatch.Success) - { - lineColor = new Color(Int32.Parse(legacyColorMatch.Groups["r"].Value), - Int32.Parse(legacyColorMatch.Groups["g"].Value), - Int32.Parse(legacyColorMatch.Groups["b"].Value)); - foo = foo.Replace(legacyColorMatch.Groups[0].Value, ""); - } - - bool upgraded = false; - string newFoo = ReplaceDeprecatedColorCodes(foo, out upgraded); - if (!informedOwner && upgraded) - { - informedOwner = true; - TShock.Log.ConsoleInfo("We have upgraded your MotD to the new format. A backup has been created."); - } - - if (lineColor != Color.White) - motd.Append(String.Format("%{0:d3},{1:d3},{2:d3}%", lineColor.R, lineColor.G, lineColor.B)); - - motd.AppendLine(newFoo); - } - } - - if (informedOwner) - { - File.Copy(FileTools.MotdPath, String.Format("{0}_{1}.backup", FileTools.MotdPath, DateTime.Now.ToString("ddMMMyy_hhmmss"))); - File.WriteAllText(FileTools.MotdPath, motd.ToString()); - } - } - /// /// Returns a Group from the name of the group /// From cd80edb2f7a48666dd9d735db97f0de77a6851c8 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 26 Dec 2017 19:57:26 -0700 Subject: [PATCH 02/10] Remove unused, deprecated REST config option --- TShockAPI/ConfigFile.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 85e340cf..b01eb7e2 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -520,11 +520,6 @@ namespace TShockAPI [Description("How often in minutes the REST requests bucket is decreased by one. Minimum value is 1 minute.")] public int RESTRequestBucketDecreaseIntervalMinutes = 1; - /// RESTLimitOnlyFailedLoginRequests - Whether or not to limit only the max failed login requests, or all login requests. - [Obsolete("This value is no longer used and will be removed next version.")] - [Description("Whether we should limit only the max failed login requests, or all login requests.")] - public bool RESTLimitOnlyFailedLoginRequests = true; - /// ShowBackupAutosaveMessages - Whether or not to show backup auto save messages. [Description("Show backup autosave messages.")] public bool ShowBackupAutosaveMessages = true; From 4444023b2d6eb917ed4c0d6670a5769979f90666 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 26 Dec 2017 19:58:11 -0700 Subject: [PATCH 03/10] Remove deprecated distance method --- TShockAPI/TShock.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index c88fc247..1f101e90 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1724,16 +1724,6 @@ namespace TShockAPI e.Handled = true; } - /// Distance - Determines the distance between two vectors. - /// value1 - The first vector location. - /// value2 - The second vector location. - /// float - The distance between the two vectors. - [Obsolete("Use TShock.Utils.Distance(Vector2, Vector2) instead.", true)] - public static float Distance(Vector2 value1, Vector2 value2) - { - return Utils.Distance(value1, value2); - } - /// OnConfigRead - Fired when the config file has been read. /// file - The config file object. public void OnConfigRead(ConfigFile file) From 3e6cc78a2cc1c5f263a339947db0d17a10470fcd Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 26 Dec 2017 19:59:53 -0700 Subject: [PATCH 04/10] Remove obsolete GiveItemCheck. --- TShockAPI/TSPlayer.cs | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 3c747b9d..71ad2124 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1275,27 +1275,6 @@ namespace TShockAPI return true; } - /// - /// Gives an item to the player. Includes banned item spawn prevention to check if the player can spawn the item. - /// - /// The item ID. - /// The item name. - /// The width of the receiver. - /// The height of the receiver. - /// The item stack. - /// The item prefix. - /// True or false, depending if the item passed the check or not. - [Obsolete("Use the GiveItemCheck overload with fewer parameters.")] - public bool GiveItemCheck(int type, string name, int width, int height, int stack, int prefix = 0) - { - if ((TShock.Itembans.ItemIsBanned(name) && TShock.Config.PreventBannedItemSpawn) && - (TShock.Itembans.ItemIsBanned(name, this) || !TShock.Config.AllowAllowedGroupsToSpawnBannedItems)) - return false; - - GiveItem(type, name, width, height, stack, prefix); - return true; - } - /// /// Gives an item to the player. /// From 656c9afdb2f751e2a093cee667340bdf799d6c97 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 26 Dec 2017 20:03:36 -0700 Subject: [PATCH 05/10] Remove obsolete Rest event. --- TShockAPI/Rest/Rest.cs | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/TShockAPI/Rest/Rest.cs b/TShockAPI/Rest/Rest.cs index 18be5080..fad2b9b0 100644 --- a/TShockAPI/Rest/Rest.cs +++ b/TShockAPI/Rest/Rest.cs @@ -250,30 +250,6 @@ namespace Rests } } - #region Event - [Obsolete("This class will be removed in the next release")] - public class RestRequestEventArgs : HandledEventArgs - { - public RequestEventArgs Request { get; set; } - } - - [Obsolete("This method will be removed in the next release")] - public static HandlerList RestRequestEvent = new HandlerList(); - - private static bool OnRestRequestCall(RequestEventArgs request) - { - if (RestRequestEvent == null) - return false; - - var args = new RestRequestEventArgs - { - Request = request, - }; - RestRequestEvent.Invoke(null, args); - return args.Handled; - } - #endregion - /// /// Called when the receives a request /// @@ -285,9 +261,6 @@ namespace Rests if (obj == null) throw new NullReferenceException("obj"); - if (OnRestRequestCall(e)) - return; - var str = JsonConvert.SerializeObject(obj, Formatting.Indented); var jsonp = e.Request.Parameters["jsonp"]; if (!string.IsNullOrWhiteSpace(jsonp)) From 5362389e718d51004333e4cdb832ac61fab7b3ae Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 26 Dec 2017 20:04:22 -0700 Subject: [PATCH 06/10] Remove obsolete GiveItem call. --- TShockAPI/TSPlayer.cs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 71ad2124..5a2e393a 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1287,22 +1287,6 @@ namespace TShockAPI SendData(PacketTypes.ItemDrop, "", itemIndex); } - /// - /// Gives an item to the player. - /// - /// The item ID. - /// The item name. This parameter is unused. - /// The width of the receiver. - /// The height of the receiver. - /// The item stack. - /// The item prefix. - [Obsolete("Use the GiveItem overload with fewer parameters.")] - public virtual void GiveItem(int type, string name, int width, int height, int stack, int prefix = 0) - { - int itemIndex = Item.NewItem((int)X, (int)Y, width, height, type, stack, true, prefix, true); - SendData(PacketTypes.ItemDrop, "", itemIndex); - } - /// /// Sends an information message to the player. /// From 903bd5bb753934f5270dcc1af4f47ac937a1a4d8 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 26 Dec 2017 20:05:52 -0700 Subject: [PATCH 07/10] Migrate AddBan2 calls to AddBan No more deprecation warnings on this release #yolo --- TShockAPI/Commands.cs | 6 +++--- TShockAPI/DB/BanManager.cs | 19 +------------------ TShockAPI/Rest/RestManager.cs | 4 ++-- TShockAPI/TShock.cs | 2 +- TShockAPI/Utils.cs | 2 +- 5 files changed, 8 insertions(+), 25 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 542d3367..a5203995 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1371,7 +1371,7 @@ namespace TShockAPI } targetGeneralizedName = target.Name; - success = TShock.Bans.AddBan2(target.IP, target.Name, target.UUID, target.Account.Name, banReason, false, args.Player.Account.Name, + success = TShock.Bans.AddBan(target.IP, target.Name, target.UUID, target.Account.Name, banReason, false, args.Player.Account.Name, banLengthInSeconds == 0 ? "" : DateTime.UtcNow.AddSeconds(banLengthInSeconds).ToString("s")); // Since this is an online ban, we need to dc the player and tell them now. @@ -1401,7 +1401,7 @@ namespace TShockAPI Regex r = new Regex(pattern, RegexOptions.IgnoreCase); if (r.IsMatch(args.Parameters[1])) { targetGeneralizedName = "IP: " + args.Parameters[1]; - success = TShock.Bans.AddBan2(args.Parameters[1], "", "", "", banReason, + success = TShock.Bans.AddBan(args.Parameters[1], "", "", "", banReason, false, args.Player.Account.Name, banLengthInSeconds == 0 ? "" : DateTime.UtcNow.AddSeconds(banLengthInSeconds).ToString("s")); if (success && offlineUserAccount != null) { @@ -1449,7 +1449,7 @@ namespace TShockAPI string lastIP = JsonConvert.DeserializeObject>(offlineUserAccount.KnownIps).Last(); success = - TShock.Bans.AddBan2(lastIP, + TShock.Bans.AddBan(lastIP, "", offlineUserAccount.UUID, offlineUserAccount.Name, banReason, false, args.Player.Account.Name, banLengthInSeconds == 0 ? "" : DateTime.UtcNow.AddSeconds(banLengthInSeconds).ToString("s")); } diff --git a/TShockAPI/DB/BanManager.cs b/TShockAPI/DB/BanManager.cs index 7ee0fa29..53a258d2 100644 --- a/TShockAPI/DB/BanManager.cs +++ b/TShockAPI/DB/BanManager.cs @@ -205,24 +205,7 @@ namespace TShockAPI.DB /// If set to true enable throwing exceptions. /// Banner. /// Expiration date. - [Obsolete("Use AddBan2 instead of AddBan.", true)] - public bool AddBan(string ip, string name = "", string uuid = "", string reason = "", bool exceptions = false, string banner = "", string expiration = "") - { - return AddBan2(ip, name, uuid, "", reason, exceptions, banner, expiration); - } - - /// - /// Adds a ban. - /// - /// true, if ban was added, false otherwise. - /// Ip. - /// Name. - /// UUID. - /// Reason. - /// If set to true enable throwing exceptions. - /// Banner. - /// Expiration date. - public bool AddBan2(string ip, string name = "", string uuid = "", string accountName = "", string reason = "", bool exceptions = false, string banner = "", string expiration = "") + public bool AddBan(string ip, string name = "", string uuid = "", string accountName = "", string reason = "", bool exceptions = false, string banner = "", string expiration = "") { try { diff --git a/TShockAPI/Rest/RestManager.cs b/TShockAPI/Rest/RestManager.cs index 636e0407..f9f1308e 100644 --- a/TShockAPI/Rest/RestManager.cs +++ b/TShockAPI/Rest/RestManager.cs @@ -624,7 +624,7 @@ namespace TShockAPI try { - TShock.Bans.AddBan2(ip, name, "", "", args.Parameters["reason"], true, args.TokenData.Username); + TShock.Bans.AddBan(ip, name, "", "", args.Parameters["reason"], true, args.TokenData.Username); } catch (Exception e) { @@ -1001,7 +1001,7 @@ namespace TShockAPI TSPlayer player = (TSPlayer)ret; var reason = null == args.Parameters["reason"] ? "Banned via web" : args.Parameters["reason"]; - TShock.Bans.AddBan2(player.IP, player.Name, "", "", reason); + TShock.Bans.AddBan(player.IP, player.Name, "", "", reason); TShock.Utils.ForceKick(player, reason, false, true); return RestResponse("Player " + player.Name + " was banned"); } diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 1f101e90..6c4cc5fd 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -475,7 +475,7 @@ namespace TShockAPI { // A user just signed in successfully despite being banned by account name. // We should fix the ban database so that all of their ban info is up to date. - Bans.AddBan2(args.Player.IP, args.Player.Name, args.Player.UUID, args.Player.Account.Name, + Bans.AddBan(args.Player.IP, args.Player.Name, args.Player.UUID, args.Player.Account.Name, potentialBan.Reason, false, potentialBan.BanningUser, potentialBan.Expiration); // And then get rid of them. diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 6809710b..5ebe7de6 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -651,7 +651,7 @@ namespace TShockAPI string ip = player.IP; string uuid = player.UUID; string playerName = player.Name; - TShock.Bans.AddBan2(ip, playerName, uuid, "", reason, false, adminUserName); + TShock.Bans.AddBan(ip, playerName, uuid, "", reason, false, adminUserName); player.Disconnect(string.Format("Banned: {0}", reason)); string verb = force ? "force " : ""; if (string.IsNullOrWhiteSpace(adminUserName)) From 6095eccccc9e40b877f56a6d2e237ba0ab777f14 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 26 Dec 2017 20:06:29 -0700 Subject: [PATCH 08/10] Update changelog to signify removal of deprecations --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54e5d06a..c300135c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Replace `TShock.CheckTilePermission` with `TSPlayer.HasBuildPermission`, `TSPlayer.HasPaintPermission`, and `TSPlayer.HasModifiedIceSuccessfully` respectively. (@hakusaro) * Fix stack hack detection being inconsistent between two different check points. Moved `TShock.HackedInventory` to `TSPlayer.HasHackedItemStacks`. Added `GetDataHandlers.GetDataHandledEventArgs` which is where most hooks will inherit from in the future. (@hakusaro) * All `GetDataHandlers` hooks now inherit from `GetDataHandledEventArgs` which includes a `TSPlayer` and a `MemoryStream` of raw data. (@hakusaro) +* Removed _all obsolete methods in TShock marked obsolete prior to this version (all of them)_ (@nicatronTg). ## TShock 4.3.25 * Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6. From cb47240c7ed3f6696b4232ee6d8bdf62c8bc8324 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 26 Dec 2017 20:17:11 -0700 Subject: [PATCH 09/10] Fix indentation on one line in utils --- CHANGELOG.md | 2 +- TShockAPI/Utils.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c300135c..270cdf8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,7 +65,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Replace `TShock.CheckTilePermission` with `TSPlayer.HasBuildPermission`, `TSPlayer.HasPaintPermission`, and `TSPlayer.HasModifiedIceSuccessfully` respectively. (@hakusaro) * Fix stack hack detection being inconsistent between two different check points. Moved `TShock.HackedInventory` to `TSPlayer.HasHackedItemStacks`. Added `GetDataHandlers.GetDataHandledEventArgs` which is where most hooks will inherit from in the future. (@hakusaro) * All `GetDataHandlers` hooks now inherit from `GetDataHandledEventArgs` which includes a `TSPlayer` and a `MemoryStream` of raw data. (@hakusaro) -* Removed _all obsolete methods in TShock marked obsolete prior to this version (all of them)_ (@nicatronTg). +* Removed _all obsolete methods in TShock marked obsolete prior to this version (all of them)_ (@hakusaro). ## TShock 4.3.25 * Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6. diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index e94c1042..dbbd24ce 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -585,7 +585,7 @@ namespace TShockAPI TShock.Regions.Reload(); TShock.Itembans.UpdateItemBans(); TShock.ProjectileBans.UpdateBans(); - TShock.TileBans.UpdateBans(); + TShock.TileBans.UpdateBans(); Hooks.GeneralHooks.OnReloadEvent(player); } From e705e398e84557be8647b50ca67771eb6e398d23 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Wed, 27 Dec 2017 11:30:39 -0700 Subject: [PATCH 10/10] Return real nulls as opposed to string nulls --- TShockAPI/Utils.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index dbbd24ce..26493d67 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -449,7 +449,7 @@ namespace TShockAPI /// name public string GetBuffName(int id) { - return (id > 0 && id < Main.maxBuffTypes) ? Lang.GetBuffName(id) : "null"; + return (id > 0 && id < Main.maxBuffTypes) ? Lang.GetBuffName(id) : null; } /// @@ -459,7 +459,7 @@ namespace TShockAPI /// description public string GetBuffDescription(int id) { - return (id > 0 && id < Main.maxBuffTypes) ? Lang.GetBuffDescription(id) : "null"; + return (id > 0 && id < Main.maxBuffTypes) ? Lang.GetBuffDescription(id) : null; } ///