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.
25 lines
700 B
C#
25 lines
700 B
C#
using static TShockAPI.GetDataHandlers;
|
|
|
|
namespace TShockAPI.Handlers
|
|
{
|
|
/// <summary>
|
|
/// 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 does not have emoji permissions
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="args"></param>
|
|
public void OnReceive(object sender, EmojiEventArgs args)
|
|
{
|
|
if (!args.Player.HasPermission(Permissions.sendemoji))
|
|
{
|
|
args.Player.SendErrorMessage("You do not have permission to send emotes!");
|
|
args.Handled = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|