Added basic framework for allowing for ban durations and banning admin.
Added BanningUser, Date(of ban), and Expiration to the db On join, Expiration is checked, if ban is expired we remove it and the user is allowed on. When running the ban command, your UAN is used as the banning user, and the date is that moment, with no expiration. #531
This commit is contained in:
parent
222042cc4d
commit
856def83b3
6 changed files with 75 additions and 22 deletions
|
|
@ -34,7 +34,10 @@ namespace TShockAPI.DB
|
|||
var table = new SqlTable("Bans",
|
||||
new SqlColumn("IP", MySqlDbType.String, 16) {Primary = true},
|
||||
new SqlColumn("Name", MySqlDbType.Text),
|
||||
new SqlColumn("Reason", MySqlDbType.Text)
|
||||
new SqlColumn("Reason", MySqlDbType.Text),
|
||||
new SqlColumn("BanningUser", MySqlDbType.Text),
|
||||
new SqlColumn("Date", MySqlDbType.Text),
|
||||
new SqlColumn("Expiration", MySqlDbType.Text)
|
||||
);
|
||||
var creator = new SqlTableCreator(db,
|
||||
db.GetSqlType() == SqlType.Sqlite
|
||||
|
|
@ -58,7 +61,7 @@ namespace TShockAPI.DB
|
|||
using (var reader = database.QueryReader("SELECT * FROM Bans WHERE IP=@0", ip))
|
||||
{
|
||||
if (reader.Read())
|
||||
return new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("Reason"));
|
||||
return new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("Reason"), reader.Get<string>("BanningUser"), reader.Get<string>("Date"), reader.Get<string>("Expiration"));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -77,7 +80,7 @@ namespace TShockAPI.DB
|
|||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
banlist.Add(new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("Reason")));
|
||||
banlist.Add(new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("Reason"), reader.Get<string>("BanningUser"), reader.Get<string>("Date"), reader.Get<string>("Expiration")));
|
||||
}
|
||||
return banlist;
|
||||
}
|
||||
|
|
@ -100,7 +103,7 @@ namespace TShockAPI.DB
|
|||
using (var reader = database.QueryReader("SELECT * FROM Bans WHERE " + namecol + "=@0", name))
|
||||
{
|
||||
if (reader.Read())
|
||||
return new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("Reason"));
|
||||
return new Ban(reader.Get<string>("IP"), reader.Get<string>("Name"), reader.Get<string>("Reason"), reader.Get<string>("BanningUser"), reader.Get<string>("Date"), reader.Get<string>("Expiration"));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -114,14 +117,14 @@ namespace TShockAPI.DB
|
|||
[Obsolete("This method is for signature compatibility for external code only")]
|
||||
public bool AddBan(string ip, string name, string reason)
|
||||
{
|
||||
return AddBan(ip, name, reason, false);
|
||||
return AddBan(ip, name, reason, false, "", "");
|
||||
}
|
||||
#endif
|
||||
public bool AddBan(string ip, string name = "", string reason = "", bool exceptions = false)
|
||||
public bool AddBan(string ip, string name = "", string reason = "", bool exceptions = false, string banner = "", string expiration = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
return database.Query("INSERT INTO Bans (IP, Name, Reason) VALUES (@0, @1, @2);", ip, name, reason) != 0;
|
||||
return database.Query("INSERT INTO Bans (IP, Name, Reason, BanningUser, Date, Expiration) VALUES (@0, @1, @2, @3, @4, @5);", ip, name, reason, banner, DateTime.Now.ToString("G"), expiration) != 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -180,11 +183,20 @@ namespace TShockAPI.DB
|
|||
|
||||
public string Reason { get; set; }
|
||||
|
||||
public Ban(string ip, string name, string reason)
|
||||
public string BanningUser { get; set; }
|
||||
|
||||
public string Date { get; set; }
|
||||
|
||||
public string Expiration { get; set; }
|
||||
|
||||
public Ban(string ip, string name, string reason, string banner, string date, string exp)
|
||||
{
|
||||
IP = ip;
|
||||
Name = name;
|
||||
Reason = reason;
|
||||
BanningUser = banner;
|
||||
Date = date;
|
||||
Expiration = exp;
|
||||
}
|
||||
|
||||
public Ban()
|
||||
|
|
@ -192,6 +204,9 @@ namespace TShockAPI.DB
|
|||
IP = string.Empty;
|
||||
Name = string.Empty;
|
||||
Reason = string.Empty;
|
||||
BanningUser = "";
|
||||
Date = "";
|
||||
Expiration = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue