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.
This commit is contained in:
parent
f06d1fd238
commit
17d151b8f8
4 changed files with 16 additions and 24 deletions
|
|
@ -294,6 +294,20 @@ namespace TShockAPI.DB
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Removes a ban if it has expired.</summary>
|
||||
/// <param name="ban">The candidate ban to check.</param>
|
||||
/// <returns>If the ban has been removed.</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -479,29 +479,6 @@ namespace TShockAPI
|
|||
TShock.TileBans.UpdateBans();
|
||||
}
|
||||
|
||||
/// <summary>HasBanExpired - Returns whether or not a ban has expired or not.</summary>
|
||||
/// <param name="ban">ban - The ban object to check.</param>
|
||||
/// <param name="byName">byName - Defines whether or not the ban should be checked by name.</param>
|
||||
/// <returns>bool - True if the ban has expired.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows a file to the user.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue