Move OnPlayerBuff logic to Bouncer
This commit is contained in:
parent
c9955a74ec
commit
5cdb38675c
3 changed files with 64 additions and 39 deletions
|
|
@ -70,8 +70,9 @@ Putting this stuff down here so things don't conflict as often.
|
|||
* Fixed invasions started by TShock not reporting size correctly and probably not working at all. (@hakusaro)
|
||||
* Removed `GetDataHandlers.TileKill` and replaced it with `GetDataHandlers.PlaceChest` as the packet originally designated as tile kill is now only used for chests. (@hakusaro)
|
||||
* Added `TSPlayer` to `GetDataHandlers.NPCHome`. (@hakusaro)
|
||||
* Added a `TSPlayer` to `GetDataHandlers.ChestItemChanged`. (@hakusaro)
|
||||
* Added `TSPlayer` to `GetDataHandlers.ChestItemChanged`. (@hakusaro)
|
||||
* Fixed chest item changes not triggering any range checks, tile checks, or correct chest checks. (@hakusaro)
|
||||
* Added `TSPlayer` to `GetDataHandlers.PlayerBuff`. (@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.
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ namespace TShockAPI
|
|||
{
|
||||
// Setup hooks
|
||||
|
||||
GetDataHandlers.PlayerBuff.Register(OnPlayerBuff);
|
||||
GetDataHandlers.ChestItemChange.Register(OnChestItemChange);
|
||||
GetDataHandlers.NPCHome.Register(OnUpdateNPCHome);
|
||||
GetDataHandlers.ChestOpen.Register(OnChestOpen);
|
||||
|
|
@ -57,6 +58,63 @@ namespace TShockAPI
|
|||
GetDataHandlers.TileEdit.Register(OnTileEdit);
|
||||
}
|
||||
|
||||
/// <summary>Handles Buff events.</summary>
|
||||
/// <param name="sender">The object that triggered the event.</param>
|
||||
/// <param name="args">The packet arguments that the event has.</param>
|
||||
internal void OnPlayerBuff(object sender, GetDataHandlers.PlayerBuffEventArgs args)
|
||||
{
|
||||
byte id = args.ID;
|
||||
byte type = args.Type;
|
||||
int time = args.Time;
|
||||
|
||||
if (TShock.Players[id] == null)
|
||||
{
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TShock.CheckIgnores(args.Player))
|
||||
{
|
||||
args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (id >= Main.maxPlayers)
|
||||
{
|
||||
args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TShock.Players[id].TPlayer.hostile || !Main.pvpBuff[type])
|
||||
{
|
||||
args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 50))
|
||||
{
|
||||
args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
|
||||
{
|
||||
args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (WhitelistBuffMaxTime[type] > 0 && time <= WhitelistBuffMaxTime[type])
|
||||
{
|
||||
args.Handled = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Handles when a chest item is changed.</summary>
|
||||
/// <param name="sender">The object that triggered the event.</param>
|
||||
/// <param name="args">The packet arguments that the event has.</param>
|
||||
|
|
|
|||
|
|
@ -1057,6 +1057,7 @@ namespace TShockAPI
|
|||
/// </summary>
|
||||
public class PlayerBuffEventArgs : HandledEventArgs
|
||||
{
|
||||
public TSPlayer Player { get; set; }
|
||||
/// <summary>
|
||||
/// The Terraria playerID of the player
|
||||
/// </summary>
|
||||
|
|
@ -1075,13 +1076,14 @@ namespace TShockAPI
|
|||
/// </summary>
|
||||
public static HandlerList<PlayerBuffEventArgs> PlayerBuff;
|
||||
|
||||
private static bool OnPlayerBuff(byte id, byte type, int time)
|
||||
private static bool OnPlayerBuff(TSPlayer player, byte id, byte type, int time)
|
||||
{
|
||||
if (PlayerBuff == null)
|
||||
return false;
|
||||
|
||||
var args = new PlayerBuffEventArgs
|
||||
{
|
||||
Player = player,
|
||||
ID = id,
|
||||
Type = type,
|
||||
Time = time
|
||||
|
|
@ -2518,45 +2520,9 @@ namespace TShockAPI
|
|||
var type = args.Data.ReadInt8();
|
||||
var time = args.Data.ReadInt32();
|
||||
|
||||
if (OnPlayerBuff(id, type, time))
|
||||
if (OnPlayerBuff(args.Player, id, type, time))
|
||||
return true;
|
||||
|
||||
if (TShock.Players[id] == null)
|
||||
return false;
|
||||
|
||||
if (TShock.CheckIgnores(args.Player))
|
||||
{
|
||||
args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (id >= Main.maxPlayers)
|
||||
{
|
||||
args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!TShock.Players[id].TPlayer.hostile || !Main.pvpBuff[type])
|
||||
{
|
||||
args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
|
||||
return true;
|
||||
}
|
||||
if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 50))
|
||||
{
|
||||
args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
|
||||
return true;
|
||||
}
|
||||
if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
|
||||
{
|
||||
args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (WhitelistBuffMaxTime[type] > 0 && time <= WhitelistBuffMaxTime[type])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue