diff --git a/CHANGELOG.md b/CHANGELOG.md index 4963ff3b..b0e08b08 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)_ (@hakusaro). * Removed broken noclip detection and attempted prevention. TShock wasn't doing a good job at stopping noclip. It's always worse to claim that you do something that you can't/don't do, so removing this is better than keeping broken detection in. (@hakusaro) * Replaced `Utils.FindPlayer` with `TSPlayer.FindByNameOrID` to more appropriately be object orientated. (@hakusaro) * Removed `Utils.ActivePlayers()` -- use `TShock.Players.Length` instead. (@hakusaro) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index a8c44869..2c593d8f 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/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 41a8a5b5..fdca0eeb 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -516,11 +516,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; 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/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)) diff --git a/TShockAPI/Rest/RestManager.cs b/TShockAPI/Rest/RestManager.cs index cad79834..de34395e 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,8 +1001,9 @@ 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); player.Kick(reason, true, false, null, true); + TShock.Utils.ForceKick(player, reason, false, true); return RestResponse("Player " + player.Name + " was banned"); } diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index bb94688a..bf7d776c 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1312,27 +1312,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. /// @@ -1345,22 +1324,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. /// diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 18b618e7..a4ac0c5e 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. @@ -886,8 +886,6 @@ namespace TShockAPI Utils.ComputeMaxStyles(); Utils.FixChestStacks(); - Utils.UpgradeMotD(); - if (Config.UseServerName) { Main.worldName = Config.ServerName; @@ -1726,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) diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 58b83786..f6af228d 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() {} @@ -409,7 +403,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; } /// @@ -419,7 +413,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; } /// @@ -528,7 +522,7 @@ namespace TShockAPI TShock.Regions.Reload(); TShock.Itembans.UpdateItemBans(); TShock.ProjectileBans.UpdateBans(); - TShock.TileBans.UpdateBans(); + TShock.TileBans.UpdateBans(); Hooks.GeneralHooks.OnReloadEvent(player); } @@ -548,7 +542,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)) @@ -606,98 +600,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 ///