From 17d151b8f82f0ec7fceefb5084796f482b97d4a3 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 29 Dec 2017 08:32:45 -0700 Subject: [PATCH] Move HasBanExpired to Bans.RemoveBanIfExpired(). The ban system needs a full rewrite anyway, but this move removes something from Utils, puts it closer to its operating point, simplifies the method, and clarifies what it actually does. --- CHANGELOG.md | 1 + TShockAPI/DB/BanManager.cs | 14 ++++++++++++++ TShockAPI/TShock.cs | 2 +- TShockAPI/Utils.cs | 23 ----------------------- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04b5b844..b51cfcdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Moved `Utils.Ban()` to `TSPlayer.Ban()`. (@hakusaro) * Moved `Utils.SendMultipleMatchError()` to `TSPlayer.SendMultipleMatchError`. (@hakusaro) * Removed `Utils.GetPlayers()`. Iterate over the TSPlayers on the server and make your own list. +* Removed `Utils.HasBanExpired()` and replaced with `Bans.RemoveBanIfExpired()`. (@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/DB/BanManager.cs b/TShockAPI/DB/BanManager.cs index 53a258d2..c83ff7e0 100644 --- a/TShockAPI/DB/BanManager.cs +++ b/TShockAPI/DB/BanManager.cs @@ -294,6 +294,20 @@ namespace TShockAPI.DB } return false; } + + /// Removes a ban if it has expired. + /// The candidate ban to check. + /// If the ban has been removed. + public bool RemoveBanIfExpired(Ban ban) + { + if (!string.IsNullOrWhiteSpace(ban.Expiration) && (ban.ExpirationDateTime != null) && (DateTime.UtcNow >= ban.ExpirationDateTime)) + { + RemoveBan(ban.IP, false, false, false); + return true; + } + + return false; + } } /// diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index a4ac0c5e..9549b6fb 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1310,7 +1310,7 @@ namespace TShockAPI if (ban != null) { - if (!Utils.HasBanExpired(ban)) + if (!Bans.RemoveBanIfExpired(ban)) { DateTime exp; if (!DateTime.TryParse(ban.Expiration, out exp)) diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index c6cfc7c4..778d211c 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -479,29 +479,6 @@ namespace TShockAPI TShock.TileBans.UpdateBans(); } - /// HasBanExpired - Returns whether or not a ban has expired or not. - /// ban - The ban object to check. - /// byName - Defines whether or not the ban should be checked by name. - /// bool - True if the ban has expired. - public bool HasBanExpired(Ban ban, bool byName = false) - { - if (!string.IsNullOrWhiteSpace(ban.Expiration) && (ban.ExpirationDateTime != null) && (DateTime.UtcNow >= ban.ExpirationDateTime)) - { - if (byName) - { - TShock.Bans.RemoveBan(ban.Name, true, true, false); - } - else - { - TShock.Bans.RemoveBan(ban.IP, false, false, false); - } - - return true; - } - - return false; - } - /// /// Shows a file to the user. ///