Ban rewrite
This commit is contained in:
parent
5af1f8f76a
commit
56de9f6684
9 changed files with 679 additions and 860 deletions
|
|
@ -478,26 +478,13 @@ namespace TShockAPI
|
|||
args.Player.Account.KnownIps = JsonConvert.SerializeObject(KnownIps, Formatting.Indented);
|
||||
UserAccounts.UpdateLogin(args.Player.Account);
|
||||
|
||||
Ban potentialBan = Bans.GetBanByAccountName(args.Player.Account.Name);
|
||||
//Check if this user has any recorded bans
|
||||
var validBan = Bans.GetBansByIdentifiers($"acc:{args.Player.Account.Name}", $"uuid:{args.Player.UUID}").FirstOrDefault(b => Bans.IsValidBan(b));
|
||||
|
||||
if (potentialBan != null)
|
||||
//If they do and any are still valid, kick them
|
||||
if (validBan != null)
|
||||
{
|
||||
// A user just signed in successfully despite being banned by account name.
|
||||
// We should fix the ban database so that all of their ban info is up to date.
|
||||
Bans.AddBan(args.Player.IP, args.Player.Name, args.Player.UUID, args.Player.Account.Name,
|
||||
potentialBan.Reason, false, potentialBan.BanningUser, potentialBan.Expiration);
|
||||
|
||||
// And then get rid of them.
|
||||
if (potentialBan.Expiration == "")
|
||||
{
|
||||
args.Player.Kick(String.Format("Permanently banned by {0} for {1}", potentialBan.BanningUser
|
||||
,potentialBan.Reason), true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Player.Kick(String.Format("Still banned by {0} for {1}", potentialBan.BanningUser,
|
||||
potentialBan.Reason), true, true);
|
||||
}
|
||||
args.Player.Kick($"You are banned: {validBan.Reason}", true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -816,7 +803,7 @@ namespace TShockAPI
|
|||
Console.WriteLine("Startup parameter overrode REST port.");
|
||||
}
|
||||
})
|
||||
.AddFlags(playerSet, (p)=>
|
||||
.AddFlags(playerSet, (p) =>
|
||||
{
|
||||
int slots;
|
||||
if (int.TryParse(p, out slots))
|
||||
|
|
@ -1100,7 +1087,7 @@ namespace TShockAPI
|
|||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if(!OnCreep(args.Grass))
|
||||
if (!OnCreep(args.Grass))
|
||||
{
|
||||
args.Handled = true;
|
||||
}
|
||||
|
|
@ -1209,65 +1196,45 @@ namespace TShockAPI
|
|||
return;
|
||||
}
|
||||
|
||||
Ban ban = null;
|
||||
if (Config.EnableBanOnUsernames)
|
||||
{
|
||||
var newban = Bans.GetBanByName(player.Name);
|
||||
if (null != newban)
|
||||
ban = newban;
|
||||
}
|
||||
|
||||
if (Config.EnableIPBans && null == ban)
|
||||
{
|
||||
ban = Bans.GetBanByIp(player.IP);
|
||||
}
|
||||
|
||||
if (Config.EnableUUIDBans && null == ban && !String.IsNullOrWhiteSpace(player.UUID))
|
||||
{
|
||||
ban = Bans.GetBanByUUID(player.UUID);
|
||||
}
|
||||
Ban ban = Bans.GetBansByIdentifiers($"name:{player.Name}", $"uuid:{player.UUID}", $"ip:{player.IP}").FirstOrDefault(b => Bans.IsValidBan(b));
|
||||
|
||||
if (ban != null)
|
||||
{
|
||||
if (!Bans.RemoveBanIfExpired(ban))
|
||||
if (ban.ExpirationDateTime == DateTime.MaxValue)
|
||||
{
|
||||
DateTime exp;
|
||||
if (!DateTime.TryParse(ban.Expiration, out exp))
|
||||
player.Disconnect("You are banned: " + ban.Reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
TimeSpan ts = ban.ExpirationDateTime - DateTime.UtcNow;
|
||||
int months = ts.Days / 30;
|
||||
if (months > 0)
|
||||
{
|
||||
player.Disconnect("Permanently banned for: " + ban.Reason);
|
||||
player.Disconnect(String.Format("You are banned for {0} month{1} and {2} day{3}: {4}",
|
||||
months, months == 1 ? "" : "s", ts.Days, ts.Days == 1 ? "" : "s", ban.Reason));
|
||||
}
|
||||
else if (ts.Days > 0)
|
||||
{
|
||||
player.Disconnect(String.Format("You are banned for {0} day{1} and {2} hour{3}: {4}",
|
||||
ts.Days, ts.Days == 1 ? "" : "s", ts.Hours, ts.Hours == 1 ? "" : "s", ban.Reason));
|
||||
}
|
||||
else if (ts.Hours > 0)
|
||||
{
|
||||
player.Disconnect(String.Format("You are banned for {0} hour{1} and {2} minute{3}: {4}",
|
||||
ts.Hours, ts.Hours == 1 ? "" : "s", ts.Minutes, ts.Minutes == 1 ? "" : "s", ban.Reason));
|
||||
}
|
||||
else if (ts.Minutes > 0)
|
||||
{
|
||||
player.Disconnect(String.Format("You are banned for {0} minute{1} and {2} second{3}: {4}",
|
||||
ts.Minutes, ts.Minutes == 1 ? "" : "s", ts.Seconds, ts.Seconds == 1 ? "" : "s", ban.Reason));
|
||||
}
|
||||
else
|
||||
{
|
||||
TimeSpan ts = exp - DateTime.UtcNow;
|
||||
int months = ts.Days / 30;
|
||||
if (months > 0)
|
||||
{
|
||||
player.Disconnect(String.Format("You are banned for {0} month{1} and {2} day{3}: {4}",
|
||||
months, months == 1 ? "" : "s", ts.Days, ts.Days == 1 ? "" : "s", ban.Reason));
|
||||
}
|
||||
else if (ts.Days > 0)
|
||||
{
|
||||
player.Disconnect(String.Format("You are banned for {0} day{1} and {2} hour{3}: {4}",
|
||||
ts.Days, ts.Days == 1 ? "" : "s", ts.Hours, ts.Hours == 1 ? "" : "s", ban.Reason));
|
||||
}
|
||||
else if (ts.Hours > 0)
|
||||
{
|
||||
player.Disconnect(String.Format("You are banned for {0} hour{1} and {2} minute{3}: {4}",
|
||||
ts.Hours, ts.Hours == 1 ? "" : "s", ts.Minutes, ts.Minutes == 1 ? "" : "s", ban.Reason));
|
||||
}
|
||||
else if (ts.Minutes > 0)
|
||||
{
|
||||
player.Disconnect(String.Format("You are banned for {0} minute{1} and {2} second{3}: {4}",
|
||||
ts.Minutes, ts.Minutes == 1 ? "" : "s", ts.Seconds, ts.Seconds == 1 ? "" : "s", ban.Reason));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Disconnect(String.Format("You are banned for {0} second{1}: {2}",
|
||||
ts.Seconds, ts.Seconds == 1 ? "" : "s", ban.Reason));
|
||||
}
|
||||
player.Disconnect(String.Format("You are banned for {0} second{1}: {2}",
|
||||
ts.Seconds, ts.Seconds == 1 ? "" : "s", ban.Reason));
|
||||
}
|
||||
args.Handled = true;
|
||||
}
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1647,7 +1614,8 @@ namespace TShockAPI
|
|||
player.RecentlyCreatedProjectiles.RemoveAll(p => p.Index == e.number && p.Killed);
|
||||
}
|
||||
|
||||
if (!player.RecentlyCreatedProjectiles.Any(p => p.Index == e.number)) {
|
||||
if (!player.RecentlyCreatedProjectiles.Any(p => p.Index == e.number))
|
||||
{
|
||||
player.RecentlyCreatedProjectiles.Add(new GetDataHandlers.ProjectileStruct()
|
||||
{
|
||||
Index = e.number,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue