TShock/TShockAPI/Handlers/IllegalPerSe/EmojiPlayerMismatch.cs
Lucas Nicodemus 046d52ad2e 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.
2021-05-27 23:59:43 -07:00

25 lines
745 B
C#

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