Move most of HandleProjectileKill to Bouncer
Added GetDataHandlers.ProjectileKill hook and related arguments. Fired when a projectile kill packet is accepted by the server.
This commit is contained in:
parent
2cfa633df4
commit
c5f9a51802
3 changed files with 71 additions and 14 deletions
|
|
@ -30,6 +30,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
|
||||||
* Added `GetDataHandlers.HealOtherPlayer` hook. (@hakusaro)
|
* Added `GetDataHandlers.HealOtherPlayer` hook. (@hakusaro)
|
||||||
* Added `GetDataHandlers.PlaceObject` hook. (@hakusaro)
|
* Added `GetDataHandlers.PlaceObject` hook. (@hakusaro)
|
||||||
* `GetDataHandlers.KillMe` now sends a `TSPlayer` and a `PlayerDeathReason`. (@hakusaro)
|
* `GetDataHandlers.KillMe` now sends a `TSPlayer` and a `PlayerDeathReason`. (@hakusaro)
|
||||||
|
* Added `GetDataHandlers.ProjectileKill` hook. (@hakusaro)
|
||||||
|
|
||||||
## TShock 4.3.24
|
## TShock 4.3.24
|
||||||
* Updated OpenTerraria API to 1.3.5.3 (@DeathCradle)
|
* Updated OpenTerraria API to 1.3.5.3 (@DeathCradle)
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
// Setup hooks
|
// Setup hooks
|
||||||
|
|
||||||
|
GetDataHandlers.ProjectileKill.Register(OnProjectileKill);
|
||||||
GetDataHandlers.PlayerUpdate.Register(OnPlayerUpdate);
|
GetDataHandlers.PlayerUpdate.Register(OnPlayerUpdate);
|
||||||
GetDataHandlers.KillMe.Register(OnKillMe);
|
GetDataHandlers.KillMe.Register(OnKillMe);
|
||||||
GetDataHandlers.NewProjectile.Register(OnNewProjectile);
|
GetDataHandlers.NewProjectile.Register(OnNewProjectile);
|
||||||
|
|
@ -51,6 +52,33 @@ namespace TShockAPI
|
||||||
GetDataHandlers.TileEdit.Register(OnTileEdit);
|
GetDataHandlers.TileEdit.Register(OnTileEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Handles ProjectileKill events for throttling & out of bounds projectiles.</summary>
|
||||||
|
/// <param name="sender">The object that triggered the event.</param>
|
||||||
|
/// <param name="args">The packet arguments that the event has.</param>
|
||||||
|
internal void OnProjectileKill(object sender, GetDataHandlers.ProjectileKillEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.ProjectileIndex > Main.maxProjectiles || args.ProjectileIndex < 0)
|
||||||
|
{
|
||||||
|
// TODO: Should this be /true/ to stop the server from processing it?
|
||||||
|
args.Handled = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TShock.CheckIgnores(args.Player))
|
||||||
|
{
|
||||||
|
args.Player.RemoveProjectile(args.ProjectileIdentity, args.ProjectileOwner);
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
|
||||||
|
{
|
||||||
|
args.Player.RemoveProjectile(args.ProjectileIdentity, args.ProjectileOwner);
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Handles disabling enforcement & minor anti-exploit stuff</summary>
|
/// <summary>Handles disabling enforcement & minor anti-exploit stuff</summary>
|
||||||
/// <param name="sender">The object that triggered the event.</param>
|
/// <param name="sender">The object that triggered the event.</param>
|
||||||
/// <param name="args">The packet arguments that the event has.</param>
|
/// <param name="args">The packet arguments that the event has.</param>
|
||||||
|
|
|
||||||
|
|
@ -384,6 +384,45 @@ namespace TShockAPI
|
||||||
return args.Handled;
|
return args.Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>The arguments to the ProjectileKill packet.</summary>
|
||||||
|
public class ProjectileKillEventArgs : HandledEventArgs
|
||||||
|
{
|
||||||
|
/// <summary>The TSPlayer that fired the event.</summary>
|
||||||
|
public TSPlayer Player;
|
||||||
|
/// <summary>The projectile's identity...?</summary>
|
||||||
|
public int ProjectileIdentity;
|
||||||
|
/// <summary>The the player index of the projectile's owner (Main.players).</summary>
|
||||||
|
public byte ProjectileOwner;
|
||||||
|
/// <summary>The index of the projectile in Main.projectile.</summary>
|
||||||
|
public int ProjectileIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The event fired when a projectile kill packet is received.</summary>
|
||||||
|
public static HandlerList<ProjectileKillEventArgs> ProjectileKill;
|
||||||
|
|
||||||
|
/// <summary>Fires the ProjectileKill event.</summary>
|
||||||
|
/// <param name="player">The TSPlayer that caused the event.</param>
|
||||||
|
/// <param name="identity">The projectile identity (from the packet).</param>
|
||||||
|
/// <param name="owner">The projectile's owner (from the packet).</param>
|
||||||
|
/// <param name="index">The projectile's index (from Main.projectiles).</param>
|
||||||
|
/// <returns>bool</returns>
|
||||||
|
private static bool OnProjectileKill(TSPlayer player, int identity, byte owner, int index)
|
||||||
|
{
|
||||||
|
if (ProjectileKill == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var args = new ProjectileKillEventArgs
|
||||||
|
{
|
||||||
|
Player = player,
|
||||||
|
ProjectileIdentity = identity,
|
||||||
|
ProjectileOwner = owner,
|
||||||
|
ProjectileIndex = index,
|
||||||
|
};
|
||||||
|
|
||||||
|
ProjectileKill.Invoke(null, args);
|
||||||
|
return args.Handled;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// For use in a KillMe event
|
/// For use in a KillMe event
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -2213,19 +2252,14 @@ namespace TShockAPI
|
||||||
owner = (byte)args.Player.Index;
|
owner = (byte)args.Player.Index;
|
||||||
var index = TShock.Utils.SearchProjectile(ident, owner);
|
var index = TShock.Utils.SearchProjectile(ident, owner);
|
||||||
|
|
||||||
if (index > Main.maxProjectiles || index < 0)
|
if (OnProjectileKill(args.Player, ident, owner, index))
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var type = Main.projectile[index].type;
|
var type = Main.projectile[index].type;
|
||||||
|
|
||||||
if (TShock.CheckIgnores(args.Player))
|
// TODO: This needs to be moved somewhere else.
|
||||||
{
|
|
||||||
args.Player.RemoveProjectile(ident, owner);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TShock.CheckProjectilePermission(args.Player, index, type) && type != 102 && type != 100 && !TShock.Config.IgnoreProjKill)
|
if (TShock.CheckProjectilePermission(args.Player, index, type) && type != 102 && type != 100 && !TShock.Config.IgnoreProjKill)
|
||||||
{
|
{
|
||||||
args.Player.Disable("Does not have projectile permission to kill projectile.", DisableFlags.WriteToLogAndConsole);
|
args.Player.Disable("Does not have projectile permission to kill projectile.", DisableFlags.WriteToLogAndConsole);
|
||||||
|
|
@ -2233,12 +2267,6 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
|
|
||||||
{
|
|
||||||
args.Player.RemoveProjectile(ident, owner);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
args.Player.LastKilledProjectile = type;
|
args.Player.LastKilledProjectile = type;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue