Merge pull request #1969 from Pryaxis/emojipacketevent
Emojipacketevent
This commit is contained in:
commit
c70d7e2dc9
7 changed files with 89 additions and 1 deletions
|
|
@ -5,6 +5,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
|
||||||
## Upcoming Changes
|
## Upcoming Changes
|
||||||
* New permission `tshock.tp.pylon` to enable teleporting via Teleportation Pylons (@QuiCM)
|
* New permission `tshock.tp.pylon` to enable teleporting via Teleportation Pylons (@QuiCM)
|
||||||
* New permission `tshock.journey.research` to enable sharing research via item sacrifice (@QuiCM)
|
* New permission `tshock.journey.research` to enable sharing research via item sacrifice (@QuiCM)
|
||||||
|
* Add Emoji event to GetDataHandler. This packet is received when a player tries to display an emote.
|
||||||
|
* Adding EmojiHandler to handle an exploit. Adding `tshock.sendemoji` permission and checks. Added this permission to guest group by default.
|
||||||
|
|
||||||
## TShock 4.4.0 (Pre-release 10)
|
## TShock 4.4.0 (Pre-release 10)
|
||||||
* Fix all rope coils. (@Olink)
|
* Fix all rope coils. (@Olink)
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
internal Handlers.SendTileSquareHandler STSHandler { get; set; }
|
internal Handlers.SendTileSquareHandler STSHandler { get; set; }
|
||||||
internal Handlers.NetModules.NetModulePacketHandler NetModuleHandler { get; set; }
|
internal Handlers.NetModules.NetModulePacketHandler NetModuleHandler { get; set; }
|
||||||
|
internal Handlers.EmojiHandler EmojiHandler { get; set; }
|
||||||
|
|
||||||
/// <summary>Constructor call initializes Bouncer and related functionality.</summary>
|
/// <summary>Constructor call initializes Bouncer and related functionality.</summary>
|
||||||
/// <returns>A new Bouncer.</returns>
|
/// <returns>A new Bouncer.</returns>
|
||||||
|
|
@ -49,6 +50,9 @@ namespace TShockAPI
|
||||||
NetModuleHandler = new Handlers.NetModules.NetModulePacketHandler();
|
NetModuleHandler = new Handlers.NetModules.NetModulePacketHandler();
|
||||||
GetDataHandlers.ReadNetModule += NetModuleHandler.OnReceive;
|
GetDataHandlers.ReadNetModule += NetModuleHandler.OnReceive;
|
||||||
|
|
||||||
|
EmojiHandler = new Handlers.EmojiHandler();
|
||||||
|
GetDataHandlers.Emoji += EmojiHandler.OnReceiveEmoji;
|
||||||
|
|
||||||
// Setup hooks
|
// Setup hooks
|
||||||
GetDataHandlers.GetSection += OnGetSection;
|
GetDataHandlers.GetSection += OnGetSection;
|
||||||
GetDataHandlers.PlayerUpdate += OnPlayerUpdate;
|
GetDataHandlers.PlayerUpdate += OnPlayerUpdate;
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,8 @@ namespace TShockAPI.DB
|
||||||
Permissions.canpartychat,
|
Permissions.canpartychat,
|
||||||
Permissions.cantalkinthird,
|
Permissions.cantalkinthird,
|
||||||
Permissions.canchat,
|
Permissions.canchat,
|
||||||
Permissions.synclocalarea));
|
Permissions.synclocalarea,
|
||||||
|
Permissions.sendemoji));
|
||||||
|
|
||||||
AddDefaultGroup("default", "guest",
|
AddDefaultGroup("default", "guest",
|
||||||
string.Join(",",
|
string.Join(",",
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,7 @@ namespace TShockAPI
|
||||||
{ PacketTypes.CrystalInvasionStart, HandleOldOnesArmy },
|
{ PacketTypes.CrystalInvasionStart, HandleOldOnesArmy },
|
||||||
{ PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 },
|
{ PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 },
|
||||||
{ PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 },
|
{ PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 },
|
||||||
|
{ PacketTypes.Emoji, HandleEmoji },
|
||||||
{ PacketTypes.FishOutNPC, HandleFishOutNPC },
|
{ PacketTypes.FishOutNPC, HandleFishOutNPC },
|
||||||
{ PacketTypes.FoodPlatterTryPlacing, HandleFoodPlatterTryPlacing },
|
{ PacketTypes.FoodPlatterTryPlacing, HandleFoodPlatterTryPlacing },
|
||||||
{ PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker }
|
{ PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker }
|
||||||
|
|
@ -1866,6 +1867,40 @@ namespace TShockAPI
|
||||||
return args.Handled;
|
return args.Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// For use in an Emoji event.
|
||||||
|
/// </summary>
|
||||||
|
public class EmojiEventArgs : GetDataHandledEventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The player index in the packet, who sends the emoji.
|
||||||
|
/// </summary>
|
||||||
|
public byte PlayerIndex { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// The ID of the emoji, that is being received.
|
||||||
|
/// </summary>
|
||||||
|
public byte EmojiID { get; set; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Called when a player sends an emoji.
|
||||||
|
/// </summary>
|
||||||
|
public static HandlerList<EmojiEventArgs> Emoji = new HandlerList<EmojiEventArgs>();
|
||||||
|
private static bool OnEmoji(TSPlayer player, MemoryStream data, byte playerIndex, byte emojiID)
|
||||||
|
{
|
||||||
|
if (Emoji == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var args = new EmojiEventArgs
|
||||||
|
{
|
||||||
|
Player = player,
|
||||||
|
Data = data,
|
||||||
|
PlayerIndex = playerIndex,
|
||||||
|
EmojiID = emojiID
|
||||||
|
};
|
||||||
|
Emoji.Invoke(null, args);
|
||||||
|
return args.Handled;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// For use in a FishOutNPC event.
|
/// For use in a FishOutNPC event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -3556,6 +3591,17 @@ namespace TShockAPI
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool HandleEmoji(GetDataHandlerArgs args)
|
||||||
|
{
|
||||||
|
byte playerIndex = args.Data.ReadInt8();
|
||||||
|
byte emojiID = args.Data.ReadInt8();
|
||||||
|
|
||||||
|
if (OnEmoji(args.Player, args.Data, playerIndex, emojiID))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static bool HandleFishOutNPC(GetDataHandlerArgs args)
|
private static bool HandleFishOutNPC(GetDataHandlerArgs args)
|
||||||
{
|
{
|
||||||
ushort tileX = args.Data.ReadUInt16();
|
ushort tileX = args.Data.ReadUInt16();
|
||||||
|
|
|
||||||
31
TShockAPI/Handlers/EmojiHandler.cs
Normal file
31
TShockAPI/Handlers/EmojiHandler.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace TShockAPI.Handlers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Handles emoji packets and checks for validity and permissions
|
||||||
|
/// </summary>
|
||||||
|
public class EmojiHandler
|
||||||
|
{
|
||||||
|
public void OnReceiveEmoji(object sender, GetDataHandlers.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!");
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -474,6 +474,9 @@ namespace TShockAPI
|
||||||
|
|
||||||
[Description("Player can resync themselves with server state.")]
|
[Description("Player can resync themselves with server state.")]
|
||||||
public static readonly string synclocalarea = "tshock.synclocalarea";
|
public static readonly string synclocalarea = "tshock.synclocalarea";
|
||||||
|
|
||||||
|
[Description("Player can send emotes.")]
|
||||||
|
public static readonly string sendemoji = "tshock.sendemoji";
|
||||||
#endregion
|
#endregion
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lists all commands associated with a given permission
|
/// Lists all commands associated with a given permission
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@
|
||||||
<Compile Include="Handlers\NetModules\LiquidHandler.cs" />
|
<Compile Include="Handlers\NetModules\LiquidHandler.cs" />
|
||||||
<Compile Include="Handlers\NetModules\NetModulePacketHandler.cs" />
|
<Compile Include="Handlers\NetModules\NetModulePacketHandler.cs" />
|
||||||
<Compile Include="Handlers\NetModules\PylonHandler.cs" />
|
<Compile Include="Handlers\NetModules\PylonHandler.cs" />
|
||||||
|
<Compile Include="Handlers\EmojiHandler.cs" />
|
||||||
<Compile Include="Handlers\SendTileSquareHandler.cs" />
|
<Compile Include="Handlers\SendTileSquareHandler.cs" />
|
||||||
<Compile Include="Hooks\AccountHooks.cs" />
|
<Compile Include="Hooks\AccountHooks.cs" />
|
||||||
<Compile Include="Hooks\GeneralHooks.cs" />
|
<Compile Include="Hooks\GeneralHooks.cs" />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue