From 40b07fdc7b202ef0d3e6eedb9385fa6a69158416 Mon Sep 17 00:00:00 2001 From: James Puleo Date: Thu, 6 Oct 2022 12:22:26 -0400 Subject: [PATCH 1/2] Don't allow players to sync loadout index whilst disabled --- TShockAPI/GetDataHandlers.cs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index ace40b78..111f4d5f 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -162,7 +162,8 @@ namespace TShockAPI { PacketTypes.LandGolfBallInCup, HandleLandGolfBallInCup }, { PacketTypes.FishOutNPC, HandleFishOutNPC }, { PacketTypes.FoodPlatterTryPlacing, HandleFoodPlatterTryPlacing }, - { PacketTypes.SyncCavernMonsterType, HandleSyncCavernMonsterType } + { PacketTypes.SyncCavernMonsterType, HandleSyncCavernMonsterType }, + { PacketTypes.SyncLoadout, HandleSyncLoadout } }; } @@ -4325,6 +4326,27 @@ namespace TShockAPI return true; } + private static bool HandleSyncLoadout(GetDataHandlerArgs args) + { + var playerIndex = args.Data.ReadInt8(); + var loadoutIndex = args.Data.ReadInt8(); + + // When syncing a player's own loadout index, they then sync it back to us... + // So let's only care if the index has actually changed, otherwise we might end up in a loop... + if (loadoutIndex == args.TPlayer.CurrentLoadoutIndex) + return false; + + if (args.Player.IsBeingDisabled()) + { + TShock.Log.ConsoleDebug("GetDataHandlers / HandleSyncLoadout rejected loadout index sync {0}", args.Player.Name); + NetMessage.SendData((int)PacketTypes.SyncLoadout, number: args.Player.Index, number2: args.TPlayer.CurrentLoadoutIndex); + + return true; + } + + return false; + } + public enum DoorAction { OpenDoor = 0, From cd694af73f983fe50322a3313e96c118dd204b19 Mon Sep 17 00:00:00 2001 From: James Puleo Date: Thu, 6 Oct 2022 12:24:52 -0400 Subject: [PATCH 2/2] Update `CHANGELOG.md` --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f122591..b648dd54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * SetDefaultsEventArgs now includes a nullable ItemVariant instance. (@SignatureBeef) * Use a string interpolation and escape single quotes when escaping tables (@drunderscore) * Removed obsolete resource files `TShockAPI/Resources.resx` and `TShockAPI/Resources.Designer.cs`. (@Arthri) +* Don't allow players to sync loadout index whilst disabled (@drunderscore) ## TShock 4.5.18 * Fixed `TSPlayer.GiveItem` not working if the player is in lava. (@gohjoseph)