Move emoji player index check into IllegalPerSe
This is the first commit in a pattern that I'd like to follow. The concept is that we specifically create handlers for things that are "illegal per se." That is, there are no possible situations (in the current protocol) where a packet of this type is received from a client. In this case, I moved the emoji handler out of the Handler just for emoji, since it seemed like an obvious case. The rule of thumb is simple: if something is illegal per se, there should be no possible way in the vanilla client to achieve this result. If a player sends this combination of packets they *must* be hacking. Not that there is a 99.9% chance they're hacking, but that there is a 100% unambiguous chance that they're hacking. Something is illegal per se if it can only be created by a hacked client. If there's a crashing bug that a normal player can do with a complex series of vanilla events, that is not illegal per se. The goal of this namespace and class of handlers is to handle exactly one type of protocol violation, and remove the packet accordingly. If it is ever reported that the packet can be sent from a vanilla client, the check must be removed as it is no longer a per se violation of the protocol.
This commit is contained in:
parent
e5e66264d5
commit
046d52ad2e
5 changed files with 34 additions and 10 deletions
|
|
@ -39,6 +39,7 @@ namespace TShockAPI
|
|||
internal Handlers.SendTileRectHandler STSHandler { get; set; }
|
||||
internal Handlers.NetModules.NetModulePacketHandler NetModuleHandler { get; set; }
|
||||
internal Handlers.EmojiHandler EmojiHandler { get; set; }
|
||||
internal Handlers.IllegalPerSe.EmojiPlayerMismatch EmojiPlayerMismatch { get; set; }
|
||||
internal Handlers.DisplayDollItemSyncHandler DisplayDollItemSyncHandler { get; set; }
|
||||
internal Handlers.RequestTileEntityInteractionHandler RequestTileEntityInteractionHandler { get; set; }
|
||||
internal Handlers.LandGolfBallInCupHandler LandGolfBallInCupHandler { get; set; }
|
||||
|
|
@ -54,6 +55,9 @@ namespace TShockAPI
|
|||
NetModuleHandler = new Handlers.NetModules.NetModulePacketHandler();
|
||||
GetDataHandlers.ReadNetModule += NetModuleHandler.OnReceive;
|
||||
|
||||
EmojiPlayerMismatch = new Handlers.IllegalPerSe.EmojiPlayerMismatch();
|
||||
GetDataHandlers.Emoji += EmojiPlayerMismatch.OnReceive;
|
||||
|
||||
EmojiHandler = new Handlers.EmojiHandler();
|
||||
GetDataHandlers.Emoji += EmojiHandler.OnReceive;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,24 +3,17 @@
|
|||
namespace TShockAPI.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles emoji packets and checks for validity and permissions
|
||||
/// Handles emoji packets and checks for permissions
|
||||
/// </summary>
|
||||
public class EmojiHandler : IPacketHandler<EmojiEventArgs>
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked when an emoji is sent in chat. Rejects the emoji packet if the player is spoofing IDs or does not have emoji permissions
|
||||
/// Invoked when an emoji is sent in chat. Rejects the emoji packet if the player does not have emoji permissions
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
public void OnReceive(object sender, EmojiEventArgs args)
|
||||
{
|
||||
if (args.PlayerIndex != args.Player.Index)
|
||||
{
|
||||
TShock.Log.ConsoleError($"EmojiHandler: Emoji packet rejected for ID spoofing. Expected {args.Player.Index}, received {args.PlayerIndex} from {args.Player.Name}.");
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.Player.HasPermission(Permissions.sendemoji))
|
||||
{
|
||||
args.Player.SendErrorMessage("You do not have permission to send emotes!");
|
||||
|
|
|
|||
25
TShockAPI/Handlers/IllegalPerSe/EmojiPlayerMismatch.cs
Normal file
25
TShockAPI/Handlers/IllegalPerSe/EmojiPlayerMismatch.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using static TShockAPI.GetDataHandlers;
|
||||
|
||||
namespace TShockAPI.Handlers.IllegalPerSe
|
||||
{
|
||||
/// <summary>
|
||||
/// Rejects emoji packets with mismatched identifiers
|
||||
/// </summary>
|
||||
public class EmojiPlayerMismatch : IPacketHandler<EmojiEventArgs>
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked on emoji send. Rejects packets that are impossible.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
public void OnReceive(object sender, EmojiEventArgs args)
|
||||
{
|
||||
if (args.PlayerIndex != args.Player.Index)
|
||||
{
|
||||
TShock.Log.ConsoleError($"IllegalPerSe: Emoji packet rejected for ID spoofing. Expected {args.Player.Index}, received {args.PlayerIndex} from {args.Player.Name}.");
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -106,6 +106,7 @@
|
|||
<Compile Include="Handlers\RequestTileEntityInteractionHandler.cs" />
|
||||
<Compile Include="Handlers\SendTileRectHandler.cs" />
|
||||
<Compile Include="Handlers\SyncTilePickingHandler.cs" />
|
||||
<Compile Include="Handlers\IllegalPerSe\EmojiPlayerMismatch.cs" />
|
||||
<Compile Include="Hooks\AccountHooks.cs" />
|
||||
<Compile Include="Hooks\GeneralHooks.cs" />
|
||||
<Compile Include="Hooks\PlayerHooks.cs" />
|
||||
|
|
@ -239,4 +240,4 @@
|
|||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue