Merge pull request #1978 from Pryaxis/handlesynctilepicking
Handlesynctilepicking
This commit is contained in:
commit
5c0efce3b2
5 changed files with 92 additions and 1 deletions
|
|
@ -9,6 +9,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
|
|||
* Adding EmojiHandler to handle an exploit. Adding `tshock.sendemoji` permission and checks. Added this permission to guest group by default.
|
||||
* Handling SyncCavernMonsterType packet to prevent an exploit where players could modify the server's cavern monster types and make the server spawn any NPCs - including bosses - onto other players.
|
||||
* Added LandGolfBallInCup event which is accessible for developers to work with, as well as LandGolfBallInCup handler to handle exploits where players could send direct packets to trigger and imitate golf ball cup landing anywhere in the game world. Added two public lists in Handlers.LandGolfBallInCupHandler: GolfBallProjectileIDs and GolfClubItemIDs. (@Patrikkk)
|
||||
* Add SyncTilePicking event. This is called when a player damages a tile. Implementing SyncTilePickingHandler and patching tile damaging related exploits. (Preventing player sending invalid world position data which disconnects other players.)
|
||||
|
||||
## TShock 4.4.0 (Pre-release 10)
|
||||
* Fix all rope coils. (@Olink)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ namespace TShockAPI
|
|||
{ PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 },
|
||||
{ PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 },
|
||||
{ PacketTypes.Emoji, HandleEmoji },
|
||||
{ PacketTypes.SyncTilePicking, HandleSyncTilePicking },
|
||||
{ PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker },
|
||||
{ PacketTypes.LandGolfBallInCup, HandleLandGolfBallInCup },
|
||||
{ PacketTypes.FishOutNPC, HandleFishOutNPC },
|
||||
|
|
@ -1870,6 +1871,48 @@ namespace TShockAPI
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// For use in a SyncTilePicking event.
|
||||
/// </summary>
|
||||
public class SyncTilePickingEventArgs : GetDataHandledEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The player index in the packet, who sends the tile picking data.
|
||||
/// </summary>
|
||||
public byte PlayerIndex { get; set; }
|
||||
/// <summary>
|
||||
/// The X world position of the tile that is being picked.
|
||||
/// </summary>
|
||||
public short TileX { get; set; }
|
||||
/// <summary>
|
||||
/// The Y world position of the tile that is being picked.
|
||||
/// </summary>
|
||||
public short TileY { get; set; }
|
||||
/// <summary>
|
||||
/// The damage that is being dealt on the tile.
|
||||
/// </summary>
|
||||
public byte TileDamage { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Called when a player hits and damages a tile.
|
||||
/// </summary>
|
||||
public static HandlerList<SyncTilePickingEventArgs> SyncTilePicking = new HandlerList<SyncTilePickingEventArgs>();
|
||||
private static bool OnSyncTilePicking(TSPlayer player, MemoryStream data, byte playerIndex, short tileX, short tileY, byte tileDamage)
|
||||
{
|
||||
if (SyncTilePicking == null)
|
||||
return false;
|
||||
|
||||
var args = new SyncTilePickingEventArgs
|
||||
{
|
||||
PlayerIndex = playerIndex,
|
||||
TileX = tileX,
|
||||
TileY = tileY,
|
||||
TileDamage = tileDamage
|
||||
};
|
||||
SyncTilePicking.Invoke(null, args);
|
||||
return args.Handled;
|
||||
}
|
||||
|
||||
|
||||
/// For use in an Emoji event.
|
||||
/// </summary>
|
||||
public class EmojiEventArgs : GetDataHandledEventArgs
|
||||
|
|
@ -3653,7 +3696,20 @@ namespace TShockAPI
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static bool HandleSyncTilePicking(GetDataHandlerArgs args)
|
||||
{
|
||||
byte playerIndex = args.Data.ReadInt8();
|
||||
short tileX = args.Data.ReadInt16();
|
||||
short tileY = args.Data.ReadInt16();
|
||||
byte damage = args.Data.ReadInt8();
|
||||
|
||||
if (OnSyncTilePicking(args.Player, args.Data, playerIndex, tileX, tileY, damage))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool HandleSyncRevengeMarker(GetDataHandlerArgs args)
|
||||
{
|
||||
int uniqueID = args.Data.ReadInt32();
|
||||
|
|
|
|||
29
TShockAPI/Handlers/SyncTilePickingHandler.cs
Normal file
29
TShockAPI/Handlers/SyncTilePickingHandler.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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. Rejects the packet if its out of world bounds.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
public void OnReceive(object sender, SyncTilePickingEventArgs args)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue