Move Utils.Ban -> TSPlayer.Ban.
Arguably, this is one of the more controversial methods that's being kept. Because it kicks and bans a target player, it's more useful than removing it and requiring people to interface with the TShock Ban Manager directly (not a good move for the future). Whether or not this method sucks is up for debate, but right now I think it's totally fine to keep it around in a different location.
This commit is contained in:
parent
a5a3aae599
commit
152c67f27c
4 changed files with 30 additions and 31 deletions
|
|
@ -71,7 +71,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
|
|||
* Removed `Utils.ActivePlayers()` -- use `TShock.Players.Length` instead. (@hakusaro)
|
||||
* Moved `Utils.Kick()` to `TSPlayer` since its first argument was a `TSPlayer` object. (@hakusaro)
|
||||
* Removed `Utils.ForceKick()`. (@hakusaro)
|
||||
* removed `Utils.GetPlayerIP()`. (@hakusaro)
|
||||
* Removed `Utils.GetPlayerIP()`. (@hakusaro)
|
||||
* Moved `Utils.Ban()` to `TSPlayer.Ban()`. (@hakusaro)
|
||||
|
||||
## TShock 4.3.25
|
||||
* Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6.
|
||||
|
|
|
|||
|
|
@ -2384,7 +2384,7 @@ namespace TShockAPI
|
|||
{
|
||||
if (TShock.Config.BanOnHardcoreDeath)
|
||||
{
|
||||
if (!TShock.Utils.Ban(args.Player, TShock.Config.HardcoreBanReason, false, "hardcore-death"))
|
||||
if (!args.Player.Ban(TShock.Config.HardcoreBanReason, false, "hardcore-death"))
|
||||
args.Player.Kick("You died! Normally, you'd be banned.", true, true);
|
||||
}
|
||||
else
|
||||
|
|
@ -2448,7 +2448,7 @@ namespace TShockAPI
|
|||
{
|
||||
if (TShock.Config.BanOnMediumcoreDeath)
|
||||
{
|
||||
if (!TShock.Utils.Ban(args.Player, TShock.Config.MediumcoreBanReason, false, "mediumcore-death"))
|
||||
if (!args.Player.Ban(TShock.Config.MediumcoreBanReason, false, "mediumcore-death"))
|
||||
args.Player.Kick("You died! Normally, you'd be banned.", true, true);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1574,6 +1574,32 @@ namespace TShockAPI
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bans and disconnects the player from the server.
|
||||
/// </summary>
|
||||
/// <param name="reason">The reason to be displayed to the server.</param>
|
||||
/// <param name="force">If the ban should bypass immunity to ban checks.</param>
|
||||
/// <param name="adminUserName">The player who initiated the ban.</param>
|
||||
public bool Ban(string reason, bool force = false, string adminUserName = null)
|
||||
{
|
||||
if (!ConnectionAlive)
|
||||
return true;
|
||||
if (force || !HasPermission(Permissions.immunetoban))
|
||||
{
|
||||
string ip = IP;
|
||||
string uuid = UUID;
|
||||
TShock.Bans.AddBan(ip, Name, uuid, "", reason, false, adminUserName);
|
||||
Disconnect(string.Format("Banned: {0}", reason));
|
||||
string verb = force ? "force " : "";
|
||||
if (string.IsNullOrWhiteSpace(adminUserName))
|
||||
TSPlayer.All.SendInfoMessage("{0} was {1}banned for '{2}'.", Name, verb, reason);
|
||||
else
|
||||
TSPlayer.All.SendInfoMessage("{0} {1}banned {2} for '{3}'.", adminUserName, verb, Name, reason);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void LogStackFrame()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -507,34 +507,6 @@ namespace TShockAPI
|
|||
Hooks.GeneralHooks.OnReloadEvent(player);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bans and kicks a player from the server.
|
||||
/// </summary>
|
||||
/// <param name="player">TSPlayer player</param>
|
||||
/// <param name="reason">string reason</param>
|
||||
/// <param name="force">bool force (default: false)</param>
|
||||
/// <param name="adminUserName">string adminUserName (default: null)</param>
|
||||
public bool Ban(TSPlayer player, string reason, bool force = false, string adminUserName = null)
|
||||
{
|
||||
if (!player.ConnectionAlive)
|
||||
return true;
|
||||
if (force || !player.HasPermission(Permissions.immunetoban))
|
||||
{
|
||||
string ip = player.IP;
|
||||
string uuid = player.UUID;
|
||||
string playerName = player.Name;
|
||||
TShock.Bans.AddBan(ip, playerName, uuid, "", reason, false, adminUserName);
|
||||
player.Disconnect(string.Format("Banned: {0}", reason));
|
||||
string verb = force ? "force " : "";
|
||||
if (string.IsNullOrWhiteSpace(adminUserName))
|
||||
TSPlayer.All.SendInfoMessage("{0} was {1}banned for '{2}'.", playerName, verb, reason);
|
||||
else
|
||||
TSPlayer.All.SendInfoMessage("{0} {1}banned {2} for '{3}'.", adminUserName, verb, playerName, reason);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue