Add technical infrastructure for adding account bans
This commit is contained in:
parent
a429d706fa
commit
0edfc6834f
1 changed files with 54 additions and 9 deletions
|
|
@ -43,6 +43,7 @@ namespace TShockAPI.DB
|
||||||
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("AccountName", 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),
|
||||||
|
|
@ -75,7 +76,7 @@ namespace TShockAPI.DB
|
||||||
using (var reader = database.QueryReader("SELECT * FROM Bans WHERE IP=@0", ip))
|
using (var reader = database.QueryReader("SELECT * FROM Bans WHERE IP=@0", ip))
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
return new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("UUID"), reader.Get<string>("Reason"), reader.Get<string>("BanningUser"), reader.Get<string>("Date"), reader.Get<string>("Expiration"));
|
return new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("UUID"), reader.Get<string>("AccountName"), reader.Get<string>("Reason"), reader.Get<string>("BanningUser"), reader.Get<string>("Date"), reader.Get<string>("Expiration"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -104,7 +105,7 @@ namespace TShockAPI.DB
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
banlist.Add(new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("UUID"), reader.Get<string>("Reason"), reader.Get<string>("BanningUser"), reader.Get<string>("Date"), reader.Get<string>("Expiration")));
|
banlist.Add(new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("UUID"), reader.Get<string>("AccountName"), reader.Get<string>("Reason"), reader.Get<string>("BanningUser"), reader.Get<string>("Date"), reader.Get<string>("Expiration")));
|
||||||
}
|
}
|
||||||
|
|
||||||
banlist.Sort(new BanComparer(sortMethod));
|
banlist.Sort(new BanComparer(sortMethod));
|
||||||
|
|
@ -135,7 +136,7 @@ namespace TShockAPI.DB
|
||||||
using (var reader = database.QueryReader("SELECT * FROM Bans WHERE " + namecol + "=@0", name))
|
using (var reader = database.QueryReader("SELECT * FROM Bans WHERE " + namecol + "=@0", name))
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
return new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("UUID"), reader.Get<string>("Reason"), reader.Get<string>("BanningUser"), reader.Get<string>("Date"), reader.Get<string>("Expiration"));
|
return new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("UUID"), reader.Get<string>("AccountName"), reader.Get<string>("Reason"), reader.Get<string>("BanningUser"), reader.Get<string>("Date"), reader.Get<string>("Expiration"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -157,7 +158,7 @@ namespace TShockAPI.DB
|
||||||
using (var reader = database.QueryReader("SELECT * FROM Bans WHERE UUID=@0", uuid))
|
using (var reader = database.QueryReader("SELECT * FROM Bans WHERE UUID=@0", uuid))
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
return new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("UUID"), reader.Get<string>("Reason"), reader.Get<string>("BanningUser"), reader.Get<string>("Date"), reader.Get<string>("Expiration"));
|
return new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("UUID"), reader.Get<string>("AccountName"), reader.Get<string>("Reason"), reader.Get<string>("BanningUser"), reader.Get<string>("Date"), reader.Get<string>("Expiration"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -179,6 +180,22 @@ namespace TShockAPI.DB
|
||||||
/// <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 = "")
|
||||||
|
{
|
||||||
|
return AddBan2(ip, name, uuid, "", reason, exceptions, banner, expiration);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a ban.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><c>true</c>, if ban was added, <c>false</c> otherwise.</returns>
|
||||||
|
/// <param name="ip">Ip.</param>
|
||||||
|
/// <param name="name">Name.</param>
|
||||||
|
/// <param name="uuid">UUID.</param>
|
||||||
|
/// <param name="reason">Reason.</param>
|
||||||
|
/// <param name="exceptions">If set to <c>true</c> enable throwing exceptions.</param>
|
||||||
|
/// <param name="banner">Banner.</param>
|
||||||
|
/// <param name="expiration">Expiration date.</param>
|
||||||
|
public bool AddBan2(string ip, string name = "", string uuid = "", string accountName = "", string reason = "", bool exceptions = false, string banner = "", string expiration = "")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -192,7 +209,7 @@ namespace TShockAPI.DB
|
||||||
}
|
}
|
||||||
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, AccountName, Reason, BanningUser, Date, Expiration) VALUES (@0, @1, @2, @3, @4, @5, @6, @7);", ip, name, uuid, accountName, reason, banner, DateTime.UtcNow.ToString("s"), expiration) != 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -231,6 +248,26 @@ namespace TShockAPI.DB
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a ban by account name (not character/player name).
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><c>true</c>, if ban was removed, <c>false</c> otherwise.</returns>
|
||||||
|
/// <param name="match">Match.</param>
|
||||||
|
/// <param name="casesensitive">If set to <c>true</c> casesensitive.</param>
|
||||||
|
public bool RemoveBanByAccountName(string match, bool casesensitive = true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var namecol = casesensitive ? "AccountName" : "UPPER(AccountName)";
|
||||||
|
return database.Query("DELETE FROM Bans WHERE " + namecol + "=@0", casesensitive ? match : match.ToUpper()) != 0;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
TShock.Log.Error(ex.ToString());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clears bans.
|
/// Clears bans.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -380,6 +417,12 @@ namespace TShockAPI.DB
|
||||||
/// <value>The UUID</value>
|
/// <value>The UUID</value>
|
||||||
public string UUID { get; set; }
|
public string UUID { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the account name of the ban
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The account name</value>
|
||||||
|
public String AccountName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the ban reason.
|
/// Gets or sets the ban reason.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -424,11 +467,12 @@ namespace TShockAPI.DB
|
||||||
/// <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 accountName, string reason, string banner, string date, string exp)
|
||||||
{
|
{
|
||||||
IP = ip;
|
IP = ip;
|
||||||
Name = name;
|
Name = name;
|
||||||
UUID = uuid;
|
UUID = uuid;
|
||||||
|
AccountName = accountName;
|
||||||
Reason = reason;
|
Reason = reason;
|
||||||
BanningUser = banner;
|
BanningUser = banner;
|
||||||
Date = date;
|
Date = date;
|
||||||
|
|
@ -454,10 +498,11 @@ namespace TShockAPI.DB
|
||||||
IP = string.Empty;
|
IP = string.Empty;
|
||||||
Name = string.Empty;
|
Name = string.Empty;
|
||||||
UUID = string.Empty;
|
UUID = string.Empty;
|
||||||
|
AccountName = string.Empty;
|
||||||
Reason = string.Empty;
|
Reason = string.Empty;
|
||||||
BanningUser = "";
|
BanningUser = string.Empty;
|
||||||
Date = "";
|
Date = string.Empty;
|
||||||
Expiration = "";
|
Expiration = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue