Merge branch 'general-devel' into handlegolfpacket

This commit is contained in:
Patrikkk 2020-06-02 11:52:32 +02:00 committed by GitHub
commit d919c11add
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 115 additions and 3 deletions

View file

@ -5,6 +5,9 @@ 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.
* 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) * 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)
## TShock 4.4.0 (Pre-release 10) ## TShock 4.4.0 (Pre-release 10)

View file

@ -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; }
internal Handlers.LandGolfBallInCupHandler LandGolfBallInCupHandler { get; set; } internal Handlers.LandGolfBallInCupHandler LandGolfBallInCupHandler { get; set; }
/// <summary>Constructor call initializes Bouncer and related functionality.</summary> /// <summary>Constructor call initializes Bouncer and related functionality.</summary>
@ -50,6 +51,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;
LandGolfBallInCupHandler = new Handlers.LandGolfBallInCupHandler(); LandGolfBallInCupHandler = new Handlers.LandGolfBallInCupHandler();
GetDataHandlers.LandGolfBallInCup += LandGolfBallInCupHandler.OnLandGolfBallInCup; GetDataHandlers.LandGolfBallInCup += LandGolfBallInCupHandler.OnLandGolfBallInCup;

View file

@ -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(",",

View file

@ -151,10 +151,12 @@ namespace TShockAPI
{ PacketTypes.CrystalInvasionStart, HandleOldOnesArmy }, { PacketTypes.CrystalInvasionStart, HandleOldOnesArmy },
{ PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 }, { PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 },
{ PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 }, { PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 },
{ PacketTypes.Emoji, HandleEmoji },
{ PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker }, { PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker },
{ PacketTypes.LandGolfBallInCup, HandleLandGolfBallInCup }, { PacketTypes.LandGolfBallInCup, HandleLandGolfBallInCup },
{ PacketTypes.FishOutNPC, HandleFishOutNPC }, { PacketTypes.FishOutNPC, HandleFishOutNPC },
{ PacketTypes.FoodPlatterTryPlacing, HandleFoodPlatterTryPlacing } { PacketTypes.FoodPlatterTryPlacing, HandleFoodPlatterTryPlacing },
{ PacketTypes.SyncCavernMonsterType, HandleSyncCavernMonsterType }
}; };
} }
@ -1868,7 +1870,41 @@ namespace TShockAPI
} }
/// <summary> /// <summary>
/// For use in a LandGolfBallInCup event. /// 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>
/// For use in a LandBallInCup event.
/// </summary> /// </summary>
public class LandGolfBallInCupEventArgs : GetDataHandledEventArgs public class LandGolfBallInCupEventArgs : GetDataHandledEventArgs
{ {
@ -3607,6 +3643,32 @@ 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 HandleSyncRevengeMarker(GetDataHandlerArgs args)
{
int uniqueID = args.Data.ReadInt32();
Vector2 location = args.Data.ReadVector2();
int netId = args.Data.ReadInt32();
float npcHpPercent = args.Data.ReadSingle();
int npcTypeAgainstDiscouragement = args.Data.ReadInt32(); //tfw the argument is Type Against Discouragement
int npcAiStyleAgainstDiscouragement = args.Data.ReadInt32(); //see ^
int coinsValue = args.Data.ReadInt32();
float baseValue = args.Data.ReadSingle();
bool spawnedFromStatus = args.Data.ReadBoolean();
return false;
}
private static bool HandleSyncRevengeMarker(GetDataHandlerArgs args) private static bool HandleSyncRevengeMarker(GetDataHandlerArgs args)
{ {
int uniqueID = args.Data.ReadInt32(); int uniqueID = args.Data.ReadInt32();
@ -3662,6 +3724,13 @@ namespace TShockAPI
return false; return false;
} }
private static bool HandleSyncCavernMonsterType(GetDataHandlerArgs args)
{
args.Player.Kick("Exploit attempt detected!");
TShock.Log.ConsoleDebug($"HandleSyncCavernMonsterType: Player is trying to modify NPC cavernMonsterType; this is a crafted packet! - From {args.Player.Name}");
return true;
}
public enum EditAction public enum EditAction
{ {
KillTile = 0, KillTile = 0,

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

View file

@ -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

View file

@ -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\LandGolfBallInCupHandler.cs" /> <Compile Include="Handlers\LandGolfBallInCupHandler.cs" />
<Compile Include="Handlers\SendTileSquareHandler.cs" /> <Compile Include="Handlers\SendTileSquareHandler.cs" />
<Compile Include="Hooks\AccountHooks.cs" /> <Compile Include="Hooks\AccountHooks.cs" />