Move Utils.Kick to TSPlayer.Kick
This commit is contained in:
parent
b613fdcda6
commit
f79c6a2962
6 changed files with 40 additions and 41 deletions
|
|
@ -67,6 +67,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
|
|||
* All `GetDataHandlers` hooks now inherit from `GetDataHandledEventArgs` which includes a `TSPlayer` and a `MemoryStream` of raw data. (@hakusaro)
|
||||
* Replaced `Utils.FindPlayer` with `TSPlayer.FindByNameOrID` to more appropriately be object orientated. (@hakusaro)
|
||||
* Removed `Utils.ActivePlayers()` -- use `TShock.Players.Length` instead. (@hakusaro)
|
||||
* Moved `Utils.Kick()` to `TSPlayer` since its first argument was a `TSPlayer` object. (@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.
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ namespace TShockAPI
|
|||
{
|
||||
if (TShock.Config.KickOnDamageThresholdBroken)
|
||||
{
|
||||
TShock.Utils.Kick(args.Player, string.Format("NPC damage exceeded {0}.", TShock.Config.MaxDamage));
|
||||
args.Player.Kick(string.Format("NPC damage exceeded {0}.", TShock.Config.MaxDamage));
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
|
@ -313,7 +313,7 @@ namespace TShockAPI
|
|||
{
|
||||
if (TShock.Config.KickOnDamageThresholdBroken)
|
||||
{
|
||||
TShock.Utils.Kick(args.Player, string.Format("Player damage exceeded {0}.", TShock.Config.MaxDamage));
|
||||
args.Player.Kick(string.Format("Player damage exceeded {0}.", TShock.Config.MaxDamage));
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
|
@ -958,7 +958,7 @@ namespace TShockAPI
|
|||
{
|
||||
if (playerDeathReason.GetDeathText(TShock.Players[id].Name).ToString().Length > 500)
|
||||
{
|
||||
TShock.Utils.Kick(TShock.Players[id], "Death reason outside of normal bounds.", true);
|
||||
TShock.Players[id].Kick("Death reason outside of normal bounds.", true);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -783,7 +783,7 @@ namespace TShockAPI
|
|||
{
|
||||
TShock.Log.Warn(String.Format("{0} ({1}) had {2} or more invalid login attempts and was kicked automatically.",
|
||||
args.Player.IP, args.Player.Name, TShock.Config.MaximumLoginAttempts));
|
||||
TShock.Utils.Kick(args.Player, "Too many invalid login attempts.");
|
||||
args.Player.Kick("Too many invalid login attempts.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1279,7 +1279,7 @@ namespace TShockAPI
|
|||
string reason = args.Parameters.Count > 1
|
||||
? String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1))
|
||||
: "Misbehaviour.";
|
||||
if (!TShock.Utils.Kick(players[0], reason, !args.Player.RealPlayer, false, args.Player.Name))
|
||||
if (!players[0].Kick(reason, !args.Player.RealPlayer, false, args.Player.Name))
|
||||
{
|
||||
args.Player.SendErrorMessage("You can't kick another admin!");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1579,6 +1579,38 @@ namespace TShockAPI
|
|||
LogStackFrame();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects this player from the server with a reason.
|
||||
/// </summary>
|
||||
/// <param name="reason">The reason to display to the user and to the server on kick.</param>
|
||||
/// <param name="force">If the kick should happen regardless of immunity to kick permissions.</param>
|
||||
/// <param name="silent">If no message should be broadcasted to the server.</param>
|
||||
/// <param name="adminUserName">The originator of the kick, for display purposes.</param>
|
||||
/// <param name="saveSSI">If the player's server side character should be saved on kick.</param>
|
||||
public bool Kick(string reason, bool force = false, bool silent = false, string adminUserName = null, bool saveSSI = false)
|
||||
{
|
||||
if (!ConnectionAlive)
|
||||
return true;
|
||||
if (force || !HasPermission(Permissions.immunetokick))
|
||||
{
|
||||
SilentKickInProgress = silent;
|
||||
if (IsLoggedIn && saveSSI)
|
||||
SaveServerCharacter();
|
||||
Disconnect(string.Format("Kicked: {0}", reason));
|
||||
TShock.Log.ConsoleInfo(string.Format("Kicked {0} for : '{1}'", Name, reason));
|
||||
string verb = force ? "force " : "";
|
||||
if (!silent)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(adminUserName))
|
||||
TShock.Utils.Broadcast(string.Format("{0} was {1}kicked for '{2}'", Name, verb, reason.ToLower()), Color.Green);
|
||||
else
|
||||
TShock.Utils.Broadcast(string.Format("{0} {1}kicked {2} for '{3}'", adminUserName, verb, Name, reason.ToLower()), Color.Green);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void LogStackFrame()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1426,7 +1426,7 @@ namespace TShockAPI
|
|||
|
||||
if (args.Text.Length > 500)
|
||||
{
|
||||
Utils.Kick(tsplr, "Crash attempt via long chat packet.", true);
|
||||
tsplr.Kick("Crash attempt via long chat packet.", true);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -558,41 +558,7 @@ namespace TShockAPI
|
|||
/// <param name="saveSSI">bool saveSSI (default: false)</param>
|
||||
public void ForceKick(TSPlayer player, string reason, bool silent = false, bool saveSSI = false)
|
||||
{
|
||||
Kick(player, reason, true, silent, null, saveSSI);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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="silent">bool silent (default: false)</param>
|
||||
/// <param name="adminUserName">string adminUserName (default: null)</param>
|
||||
/// <param name="saveSSI">bool saveSSI (default: false)</param>
|
||||
public bool Kick(TSPlayer player, string reason, bool force = false, bool silent = false, string adminUserName = null, bool saveSSI = false)
|
||||
{
|
||||
if (!player.ConnectionAlive)
|
||||
return true;
|
||||
if (force || !player.HasPermission(Permissions.immunetokick))
|
||||
{
|
||||
string playerName = player.Name;
|
||||
player.SilentKickInProgress = silent;
|
||||
if (player.IsLoggedIn && saveSSI)
|
||||
player.SaveServerCharacter();
|
||||
player.Disconnect(string.Format("Kicked: {0}", reason));
|
||||
TShock.Log.ConsoleInfo(string.Format("Kicked {0} for : '{1}'", playerName, reason));
|
||||
string verb = force ? "force " : "";
|
||||
if (!silent)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(adminUserName))
|
||||
Broadcast(string.Format("{0} was {1}kicked for '{2}'", playerName, verb, reason.ToLower()), Color.Green);
|
||||
else
|
||||
Broadcast(string.Format("{0} {1}kicked {2} for '{3}'", adminUserName, verb, playerName, reason.ToLower()), Color.Green);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
player.Kick(reason, true, silent, null, saveSSI);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue