Implementing SyncTilePickingHandler. Patching tile damage related exploits.

With this packet, players could kick all players by sending invalid world position data.
This commit is contained in:
Patrikkk 2020-06-02 19:20:27 +02:00
parent cffdadbc80
commit e738d8e794
4 changed files with 42 additions and 1 deletions

View file

@ -40,6 +40,7 @@ namespace TShockAPI
internal Handlers.NetModules.NetModulePacketHandler NetModuleHandler { get; set; }
internal Handlers.EmojiHandler EmojiHandler { get; set; }
internal Handlers.LandGolfBallInCupHandler LandGolfBallInCupHandler { get; set; }
internal Handlers.SyncTilePickingHandler SyncTilePickingHandler { get; set; }
/// <summary>Constructor call initializes Bouncer and related functionality.</summary>
/// <returns>A new Bouncer.</returns>
@ -57,6 +58,9 @@ namespace TShockAPI
LandGolfBallInCupHandler = new Handlers.LandGolfBallInCupHandler();
GetDataHandlers.LandGolfBallInCup += LandGolfBallInCupHandler.OnReceive;
SyncTilePickingHandler = new Handlers.SyncTilePickingHandler();
GetDataHandlers.SyncTilePicking += SyncTilePickingHandler.OnReceive;
// Setup hooks
GetDataHandlers.GetSection += OnGetSection;
GetDataHandlers.PlayerUpdate += OnPlayerUpdate;

View file

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using static TShockAPI.GetDataHandlers;
namespace TShockAPI.Handlers
{
class SyncTilePickingHandler : IPacketHandler<SyncTilePickingEventArgs>
{
/// <summary>
/// Invoked when player damages a tile.
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
public void OnReceive(object sender, SyncTilePickingEventArgs args)
{
if (args.PlayerIndex != args.Player.Index)
{
TShock.Log.ConsoleDebug($"SyncTilePickingHandler: SyncTilePicking packet rejected for ID spoofing. Expected {args.Player.Index}, received {args.PlayerIndex} from {args.Player.Name}.");
args.Handled = true;
return;
}
if (args.TileX > Main.maxTilesX || args.TileX < 0
|| args.TileY > Main.maxTilesY || args.TileY < 0)
{
TShock.Log.ConsoleDebug($"SyncTilePickingHandler: X and Y position is out of world bounds! - From {args.Player.Name}");
args.Handled = true;
return;
}
}
}
}

View file

@ -100,6 +100,7 @@
<Compile Include="Handlers\EmojiHandler.cs" />
<Compile Include="Handlers\LandGolfBallInCupHandler.cs" />
<Compile Include="Handlers\SendTileSquareHandler.cs" />
<Compile Include="Handlers\SyncTilePickingHandler.cs" />
<Compile Include="Hooks\AccountHooks.cs" />
<Compile Include="Hooks\GeneralHooks.cs" />
<Compile Include="Hooks\PlayerHooks.cs" />