Move PlayerKillMeV2 anti-crash to Bouncer

Removed PacketTypes.PlayerKillMe since it's out of the protocol.
Removed handler method for PlayerKillMe since it's out of the
	protocol.
Updated changelog to reflect new hook changes.
This commit is contained in:
Lucas Nicodemus 2017-12-09 13:46:45 -07:00
parent 54c33a5a09
commit dd7ffe2d3a
3 changed files with 42 additions and 87 deletions

View file

@ -29,7 +29,7 @@ using static TShockAPI.GetDataHandlers;
using TerrariaApi.Server;
using Terraria.ObjectData;
using Terraria.ID;
using Terraria.DataStructures;
namespace TShockAPI
{
@ -42,6 +42,7 @@ namespace TShockAPI
{
// Setup hooks
GetDataHandlers.KillMe.Register(OnKillMe);
GetDataHandlers.NewProjectile.Register(OnNewProjectile);
GetDataHandlers.PlaceObject.Register(OnPlaceObject);
GetDataHandlers.SendTileSquare.Register(OnSendTileSquare);
@ -49,6 +50,37 @@ namespace TShockAPI
GetDataHandlers.TileEdit.Register(OnTileEdit);
}
internal void OnKillMe(object sender, GetDataHandlers.KillMeEventArgs args)
{
short dmg = args.Damage;
short id = args.PlayerId;
PlayerDeathReason playerDeathReason = args.PlayerDeathReason;
if (dmg > 20000) //Abnormal values have the potential to cause infinite loops in the server.
{
TShock.Utils.ForceKick(args.Player, "Crash Exploit Attempt", true);
TShock.Log.ConsoleError("Death Exploit Attempt: Damage {0}", dmg);
args.Handled = true;
return;
}
if (id >= Main.maxPlayers)
{
args.Handled = true;
return;
}
if (playerDeathReason != null)
{
if (playerDeathReason.GetDeathText(TShock.Players[id].Name).ToString().Length > 500)
{
TShock.Utils.Kick(TShock.Players[id], "Crash attempt", true);
args.Handled = true;
return;
}
}
}
internal void OnNewProjectile(object sender, GetDataHandlers.NewProjectileEventArgs args)
{
short ident = args.Identity;