BanManager.cs now consistently uses tabs

This commit is contained in:
White 2017-02-21 21:17:31 +10:30
parent ebc188a826
commit c3cffd1559

View file

@ -24,34 +24,34 @@ using MySql.Data.MySqlClient;
namespace TShockAPI.DB namespace TShockAPI.DB
{ {
/// <summary> /// <summary>
/// Class that manages bans. /// Class that manages bans.
/// </summary> /// </summary>
public class BanManager public class BanManager
{ {
private IDbConnection database; private IDbConnection database;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="TShockAPI.DB.BanManager"/> class. /// Initializes a new instance of the <see cref="TShockAPI.DB.BanManager"/> class.
/// </summary> /// </summary>
/// <param name="db">A valid connection to the TShock database</param> /// <param name="db">A valid connection to the TShock database</param>
public BanManager(IDbConnection db) public BanManager(IDbConnection db)
{ {
database = db; database = db;
var table = new SqlTable("Bans", var table = new SqlTable("Bans",
new SqlColumn("IP", MySqlDbType.String, 16) {Primary = true}, new SqlColumn("IP", MySqlDbType.String, 16) { Primary = true },
new SqlColumn("Name", MySqlDbType.Text), new SqlColumn("Name", MySqlDbType.Text),
new SqlColumn("UUID", MySqlDbType.Text), new SqlColumn("UUID", MySqlDbType.Text),
new SqlColumn("Reason", MySqlDbType.Text), new SqlColumn("Reason", MySqlDbType.Text),
new SqlColumn("BanningUser", MySqlDbType.Text), new SqlColumn("BanningUser", MySqlDbType.Text),
new SqlColumn("Date", MySqlDbType.Text), new SqlColumn("Date", MySqlDbType.Text),
new SqlColumn("Expiration", MySqlDbType.Text) new SqlColumn("Expiration", MySqlDbType.Text)
); );
var creator = new SqlTableCreator(db, var creator = new SqlTableCreator(db,
db.GetSqlType() == SqlType.Sqlite db.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder) new SqliteQueryCreator() ? (IQueryBuilder)new SqliteQueryCreator()
: new MysqlQueryCreator()); : new MysqlQueryCreator());
try try
{ {
creator.EnsureTableStructure(table); creator.EnsureTableStructure(table);
@ -185,33 +185,33 @@ namespace TShockAPI.DB
return null; return null;
} }
/// <summary> /// <summary>
/// Adds a ban. /// Adds a ban.
/// </summary> /// </summary>
/// <returns><c>true</c>, if ban was added, <c>false</c> otherwise.</returns> /// <returns><c>true</c>, if ban was added, <c>false</c> otherwise.</returns>
/// <param name="ip">Ip.</param> /// <param name="ip">Ip.</param>
/// <param name="name">Name.</param> /// <param name="name">Name.</param>
/// <param name="uuid">UUID.</param> /// <param name="uuid">UUID.</param>
/// <param name="reason">Reason.</param> /// <param name="reason">Reason.</param>
/// <param name="exceptions">If set to <c>true</c> enable throwing exceptions.</param> /// <param name="exceptions">If set to <c>true</c> enable throwing exceptions.</param>
/// <param name="banner">Banner.</param> /// <param name="banner">Banner.</param>
/// <param name="expiration">Expiration date.</param> /// <param name="expiration">Expiration date.</param>
public bool AddBan(string ip, string name = "", string uuid = "", string reason = "", bool exceptions = false, string banner = "", string expiration = "") public bool AddBan(string ip, string name = "", string uuid = "", string reason = "", bool exceptions = false, string banner = "", string expiration = "")
{ {
try try
{ {
/* /*
* If the ban already exists, update its entry with the new date * If the ban already exists, update its entry with the new date
* and expiration details. * and expiration details.
*/ */
if (GetBanByIp(ip) != null) if (GetBanByIp(ip) != null)
{ {
return database.Query("UPDATE Bans SET Date = @0, Expiration = @1 WHERE IP = @2", DateTime.UtcNow.ToString("s"), expiration, ip) == 1; return database.Query("UPDATE Bans SET Date = @0, Expiration = @1 WHERE IP = @2", DateTime.UtcNow.ToString("s"), expiration, ip) == 1;
} }
else else
{ {
return database.Query("INSERT INTO Bans (IP, Name, UUID, Reason, BanningUser, Date, Expiration) VALUES (@0, @1, @2, @3, @4, @5, @6);", ip, name, uuid, reason, banner, DateTime.UtcNow.ToString("s"), expiration) != 0; return database.Query("INSERT INTO Bans (IP, Name, UUID, Reason, BanningUser, Date, Expiration) VALUES (@0, @1, @2, @3, @4, @5, @6);", ip, name, uuid, reason, banner, DateTime.UtcNow.ToString("s"), expiration) != 0;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -222,14 +222,14 @@ namespace TShockAPI.DB
return false; return false;
} }
/// <summary> /// <summary>
/// Removes a ban. /// Removes a ban.
/// </summary> /// </summary>
/// <returns><c>true</c>, if ban was removed, <c>false</c> otherwise.</returns> /// <returns><c>true</c>, if ban was removed, <c>false</c> otherwise.</returns>
/// <param name="match">Match.</param> /// <param name="match">Match.</param>
/// <param name="byName">If set to <c>true</c> by name.</param> /// <param name="byName">If set to <c>true</c> by name.</param>
/// <param name="casesensitive">If set to <c>true</c> casesensitive.</param> /// <param name="casesensitive">If set to <c>true</c> casesensitive.</param>
/// <param name="exceptions">If set to <c>true</c> exceptions.</param> /// <param name="exceptions">If set to <c>true</c> exceptions.</param>
public bool RemoveBan(string match, bool byName = false, bool casesensitive = true, bool exceptions = false) public bool RemoveBan(string match, bool byName = false, bool casesensitive = true, bool exceptions = false)
{ {
try try
@ -249,10 +249,10 @@ namespace TShockAPI.DB
return false; return false;
} }
/// <summary> /// <summary>
/// Clears bans. /// Clears bans.
/// </summary> /// </summary>
/// <returns><c>true</c>, if bans were cleared, <c>false</c> otherwise.</returns> /// <returns><c>true</c>, if bans were cleared, <c>false</c> otherwise.</returns>
public bool ClearBans() public bool ClearBans()
{ {
try try
@ -290,96 +290,96 @@ namespace TShockAPI.DB
AddedOldestToNewest AddedOldestToNewest
} }
/// <summary> /// <summary>
/// Model class that represents a ban entry in the TShock database. /// Model class that represents a ban entry in the TShock database.
/// </summary> /// </summary>
public class Ban public class Ban
{ {
/// <summary> /// <summary>
/// Gets or sets the IP address of the ban entry. /// Gets or sets the IP address of the ban entry.
/// </summary> /// </summary>
/// <value>The IP Address</value> /// <value>The IP Address</value>
public string IP { get; set; } public string IP { get; set; }
/// <summary> /// <summary>
/// Gets or sets the name. /// Gets or sets the name.
/// </summary> /// </summary>
/// <value>The name.</value> /// <value>The name.</value>
public string Name { get; set; } public string Name { get; set; }
/// <summary> /// <summary>
/// Gets or sets the Client UUID of the ban /// Gets or sets the Client UUID of the ban
/// </summary> /// </summary>
/// <value>The UUID</value> /// <value>The UUID</value>
public string UUID { get; set; } public string UUID { get; set; }
/// <summary> /// <summary>
/// Gets or sets the ban reason. /// Gets or sets the ban reason.
/// </summary> /// </summary>
/// <value>The ban reason.</value> /// <value>The ban reason.</value>
public string Reason { get; set; } public string Reason { get; set; }
/// <summary> /// <summary>
/// Gets or sets the name of the user who added this ban entry. /// Gets or sets the name of the user who added this ban entry.
/// </summary> /// </summary>
/// <value>The banning user.</value> /// <value>The banning user.</value>
public string BanningUser { get; set; } public string BanningUser { get; set; }
/// <summary> /// <summary>
/// Gets or sets the UTC date of when the ban is to take effect /// Gets or sets the UTC date of when the ban is to take effect
/// </summary> /// </summary>
/// <value>The date, which must be in UTC</value> /// <value>The date, which must be in UTC</value>
public string Date { get; set; } public string Date { get; set; }
/// <summary> /// <summary>
/// Gets the <see cref="System.DateTime"/> object representation of the <see cref="Date"/> string. /// Gets the <see cref="System.DateTime"/> object representation of the <see cref="Date"/> string.
/// </summary> /// </summary>
public DateTime DateTime { get; } public DateTime DateTime { get; }
/// <summary> /// <summary>
/// Gets or sets the expiration date, in which the ban shall be lifted /// Gets or sets the expiration date, in which the ban shall be lifted
/// </summary> /// </summary>
/// <value>The expiration.</value> /// <value>The expiration.</value>
public string Expiration { get; set; } public string Expiration { get; set; }
/// <summary> /// <summary>
/// Gets the <see cref="System.DateTime"/> object representation of the <see cref="Expiration"/> string. /// Gets the <see cref="System.DateTime"/> object representation of the <see cref="Expiration"/> string.
/// </summary> /// </summary>
public DateTime ExpirationDateTime { get; } public DateTime ExpirationDateTime { get; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="TShockAPI.DB.Ban"/> class. /// Initializes a new instance of the <see cref="TShockAPI.DB.Ban"/> class.
/// </summary> /// </summary>
/// <param name="ip">Ip.</param> /// <param name="ip">Ip.</param>
/// <param name="name">Name.</param> /// <param name="name">Name.</param>
/// <param name="uuid">UUID.</param> /// <param name="uuid">UUID.</param>
/// <param name="reason">Reason.</param> /// <param name="reason">Reason.</param>
/// <param name="banner">Banner.</param> /// <param name="banner">Banner.</param>
/// <param name="date">UTC ban date.</param> /// <param name="date">UTC ban date.</param>
/// <param name="exp">Expiration time</param> /// <param name="exp">Expiration time</param>
public Ban(string ip, string name, string uuid, string reason, string banner, string date, string exp) public Ban(string ip, string name, string uuid, string reason, string banner, string date, string exp)
{ {
IP = ip; IP = ip;
Name = name; Name = name;
UUID = uuid; UUID = uuid;
Reason = reason; Reason = reason;
BanningUser = banner; BanningUser = banner;
Date = date; Date = date;
Expiration = exp; Expiration = exp;
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="TShockAPI.DB.Ban"/> class. /// Initializes a new instance of the <see cref="TShockAPI.DB.Ban"/> class.
/// </summary> /// </summary>
public Ban() public Ban()
{ {
IP = string.Empty; IP = string.Empty;
Name = string.Empty; Name = string.Empty;
UUID = string.Empty; UUID = string.Empty;
Reason = string.Empty; Reason = string.Empty;
BanningUser = ""; BanningUser = "";
Date = ""; Date = "";
Expiration = ""; Expiration = "";
} }
} }
} }