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

@ -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;
}
}
}
}