Implement Handler.LandGolfBalInCupHandler and handle packet exploits.
Added multiple checks to prevent clients from sending the golfball packet directly, without having golf play actions.
This commit is contained in:
parent
26773f61a2
commit
4944ee3144
3 changed files with 120 additions and 0 deletions
|
|
@ -37,6 +37,7 @@ namespace TShockAPI
|
|||
internal sealed class Bouncer
|
||||
{
|
||||
internal Handlers.SendTileSquareHandler STSHandler { get; set; }
|
||||
internal Handlers.LandGolfBallInCupHandler LandGolfBallInCupHandler { get; set; }
|
||||
|
||||
/// <summary>Constructor call initializes Bouncer and related functionality.</summary>
|
||||
/// <returns>A new Bouncer.</returns>
|
||||
|
|
@ -45,6 +46,9 @@ namespace TShockAPI
|
|||
STSHandler = new Handlers.SendTileSquareHandler();
|
||||
GetDataHandlers.SendTileSquare += STSHandler.OnReceiveSendTileSquare;
|
||||
|
||||
LandGolfBallInCupHandler = new Handlers.LandGolfBallInCupHandler();
|
||||
GetDataHandlers.LandGolfBallInCup += LandGolfBallInCupHandler.OnLandGolfBallInCup;
|
||||
|
||||
// Setup hooks
|
||||
GetDataHandlers.GetSection += OnGetSection;
|
||||
GetDataHandlers.PlayerUpdate += OnPlayerUpdate;
|
||||
|
|
|
|||
115
TShockAPI/Handlers/LandGolfBallInCupHandler.cs
Normal file
115
TShockAPI/Handlers/LandGolfBallInCupHandler.cs
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Terraria;
|
||||
using Terraria.ID;
|
||||
|
||||
namespace TShockAPI.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles client side exploits of LandGolfBallInCup packet.
|
||||
/// </summary>
|
||||
public class LandGolfBallInCupHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// List of golf ball projectile IDs.
|
||||
/// </summary>
|
||||
public static readonly List<int> GolfBallProjectileIDs = new List<int>()
|
||||
{
|
||||
ProjectileID.DirtGolfBall,
|
||||
ProjectileID.GolfBallDyedBlack,
|
||||
ProjectileID.GolfBallDyedBlue,
|
||||
ProjectileID.GolfBallDyedBrown,
|
||||
ProjectileID.GolfBallDyedCyan,
|
||||
ProjectileID.GolfBallDyedGreen,
|
||||
ProjectileID.GolfBallDyedLimeGreen,
|
||||
ProjectileID.GolfBallDyedOrange,
|
||||
ProjectileID.GolfBallDyedPink,
|
||||
ProjectileID.GolfBallDyedPurple,
|
||||
ProjectileID.GolfBallDyedRed,
|
||||
ProjectileID.GolfBallDyedSkyBlue,
|
||||
ProjectileID.GolfBallDyedTeal,
|
||||
ProjectileID.GolfBallDyedViolet,
|
||||
ProjectileID.GolfBallDyedYellow
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// List of golf club item IDs
|
||||
/// </summary>
|
||||
public static readonly List<int> GolfClubItemIDs = new List<int>()
|
||||
{
|
||||
ItemID.GolfClubChlorophyteDriver,
|
||||
ItemID.GolfClubDiamondWedge,
|
||||
ItemID.GolfClubShroomitePutter,
|
||||
ItemID.Fake_BambooChest,
|
||||
ItemID.GolfClubTitaniumIron,
|
||||
ItemID.GolfClubGoldWedge,
|
||||
ItemID.GolfClubLeadPutter,
|
||||
ItemID.GolfClubMythrilIron,
|
||||
ItemID.GolfClubWoodDriver,
|
||||
ItemID.GolfClubBronzeWedge,
|
||||
ItemID.GolfClubRustyPutter,
|
||||
ItemID.GolfClubStoneIron,
|
||||
ItemID.GolfClubPearlwoodDriver,
|
||||
ItemID.GolfClubIron,
|
||||
ItemID.GolfClubDriver,
|
||||
ItemID.GolfClubWedge,
|
||||
ItemID.GolfClubPutter
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a player lands a golf ball in a cup.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
public void OnLandGolfBallInCup(object sender, GetDataHandlers.LandGolfBallInCupEventArgs args)
|
||||
{
|
||||
if (args.PlayerIndex != args.Player.Index)
|
||||
{
|
||||
TShock.Log.ConsoleError($"LandGolfBallInCupHandler: Packet is spoofing to be player ID {args.PlayerIndex}! - From [{args.Player.Index}]{args.Player.Name}");
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.TileX > Main.maxTilesX || args.TileX < 0
|
||||
|| args.TileY > Main.maxTilesY || args.TileY < 0)
|
||||
{
|
||||
TShock.Log.ConsoleError($"LandGolfBallInCupHandler: X and Y position is out of world bounds! - From {args.Player.Name}");
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Main.tile[args.TileX, args.TileY].active() && Main.tile[args.TileX, args.TileY].type != TileID.GolfHole)
|
||||
{
|
||||
TShock.Log.ConsoleError($"LandGolfBallInCupHandler: Tile at packet position X:{args.TileX} Y:{args.TileY} is not a golf hole! - From {args.Player.Name}");
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GolfBallProjectileIDs.Contains(args.ProjectileType))
|
||||
{
|
||||
TShock.Log.ConsoleError($"LandGolfBallInCupHandler: Invalid golf ball projectile ID {args.ProjectileType}! - From {args.Player.Name}");
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var usedGolfBall = args.Player.RecentlyCreatedProjectiles.Any(e => GolfBallProjectileIDs.Contains(e.Type));
|
||||
var usedGolfClub = args.Player.RecentlyCreatedProjectiles.Any(e => e.Type == ProjectileID.GolfClubHelper);
|
||||
if (!usedGolfClub && !usedGolfBall)
|
||||
{
|
||||
TShock.Log.ConsoleError($"GolfPacketHandler: Player did not have create a golf club projectile the last 5 seconds! - From {args.Player.Name}");
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GolfClubItemIDs.Contains(args.Player.SelectedItem.type))
|
||||
{
|
||||
TShock.Log.ConsoleError($"LandGolfBallInCupHandler: Item selected is not a golf club! - From {args.Player.Name}");
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -88,6 +88,7 @@
|
|||
<Compile Include="DB\ResearchDatastore.cs" />
|
||||
<Compile Include="DB\TileManager.cs" />
|
||||
<Compile Include="Extensions\ExceptionExt.cs" />
|
||||
<Compile Include="Handlers\LandGolfBallInCupHandler.cs" />
|
||||
<Compile Include="Handlers\SendTileSquareHandler.cs" />
|
||||
<Compile Include="Hooks\AccountHooks.cs" />
|
||||
<Compile Include="Hooks\GeneralHooks.cs" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue