From dd50d41f2e39a8fe173cc83b4ea435dc94b1b0d0 Mon Sep 17 00:00:00 2001 From: ProfessorXZ Date: Sun, 14 Aug 2016 21:14:40 +0200 Subject: [PATCH 1/3] Fix item duplication caused by range checks & netIDs. Fixes #1162 --- TShockAPI/GetDataHandlers.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 9280dbe9..27b2d819 100755 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3322,7 +3322,8 @@ namespace TShockAPI // player is attempting to crash clients if (type < -48 || type >= Main.maxItemTypes) { - args.Player.SendData(PacketTypes.ItemDrop, "", id); + // Causes item duplications. Will be re added later if necessary + //args.Player.SendData(PacketTypes.ItemDrop, "", id); return true; } @@ -3336,7 +3337,8 @@ namespace TShockAPI { if (TShock.CheckRangePermission(args.Player, (int)(Main.item[id].position.X / 16f), (int)(Main.item[id].position.Y / 16f))) { - args.Player.SendData(PacketTypes.ItemDrop, "", id); + // Causes item duplications. Will be re added if necessary + //args.Player.SendData(PacketTypes.ItemDrop, "", id); return true; } From 1316c71a4c04343d5683d06c7bbe8e243f1711e9 Mon Sep 17 00:00:00 2001 From: ProfessorXZ Date: Sun, 14 Aug 2016 21:17:45 +0200 Subject: [PATCH 2/3] UpdateItemDrop packet now points to HandleItemDrop instead --- TShockAPI/GetDataHandlers.cs | 75 +----------------------------------- 1 file changed, 1 insertion(+), 74 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 27b2d819..cd4b7499 100755 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1233,7 +1233,7 @@ namespace TShockAPI { PacketTypes.UpdateNPCHome, UpdateNPCHome }, { PacketTypes.PlayerAddBuff, HandlePlayerAddBuff }, { PacketTypes.ItemDrop, HandleItemDrop }, - { PacketTypes.UpdateItemDrop, HandleUpdateItemDrop }, + { PacketTypes.UpdateItemDrop, HandleItemDrop }, { PacketTypes.ItemOwner, HandleItemOwner }, { PacketTypes.PlayerHp, HandlePlayerHp }, { PacketTypes.PlayerMana, HandlePlayerMana }, @@ -3381,79 +3381,6 @@ namespace TShockAPI return false; } - private static bool HandleUpdateItemDrop(GetDataHandlerArgs args) - { - var itemID = args.Data.ReadInt16(); - var position = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); - var velocity = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); - var stacks = args.Data.ReadInt16(); - var prefix = args.Data.ReadInt8(); - var noDelay = args.Data.ReadInt8() == 1; - var itemNetID = args.Data.ReadInt16(); - - if (OnItemDrop(itemID, position, velocity, stacks, prefix, noDelay, itemNetID)) - return true; - - // Invalid Net IDs can cause client crashes - if (itemNetID < -48 || itemNetID >= Main.maxItemTypes) - { - args.Player.SendData(PacketTypes.ItemDrop, "", itemID); - return true; - } - - if (prefix > Item.maxPrefixes) // Make sure the prefix is a legit value - { - args.Player.SendData(PacketTypes.ItemDrop, "", itemID); - return true; - } - - if (itemNetID == 0) //Item removed, let client do this to prevent item duplication client side (but only if it passed the range check) - { - if (TShock.CheckRangePermission(args.Player, (int)(Main.item[itemID].position.X / 16f), (int)(Main.item[itemID].position.Y / 16f))) - { - args.Player.SendData(PacketTypes.ItemDrop, "", itemID); - return true; - } - - return false; - } - - if (TShock.CheckRangePermission(args.Player, (int)(position.X / 16f), (int)(position.Y / 16f))) - { - args.Player.SendData(PacketTypes.ItemDrop, "", itemID); - return true; - } - - if (Main.item[itemID].active && Main.item[itemID].netID != itemNetID) //stop the client from changing the item type of a drop but only if the client isn't picking up the item - { - args.Player.SendData(PacketTypes.ItemDrop, "", itemID); - return true; - } - - Item item = new Item(); - item.netDefaults(itemNetID); - if ((stacks > item.maxStack || stacks <= 0) || (TShock.Itembans.ItemIsBanned(item.name, args.Player) && !args.Player.HasPermission(Permissions.allowdroppingbanneditems))) - { - args.Player.SendData(PacketTypes.ItemDrop, "", itemID); - return true; - } - if ((Main.ServerSideCharacter) && (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - args.Player.LoginMS < TShock.ServerSideCharacterConfig.LogonDiscardThreshold)) - { - //Player is probably trying to sneak items onto the server in their hands!!! - TShock.Log.ConsoleInfo("Player {0} tried to sneak {1} onto the server!", args.Player.Name, item.name); - args.Player.SendData(PacketTypes.ItemDrop, "", itemID); - return true; - - } - if (TShock.CheckIgnores(args.Player)) - { - args.Player.SendData(PacketTypes.ItemDrop, "", itemID); - return true; - } - - return false; - } - private static bool HandleItemOwner(GetDataHandlerArgs args) { var id = args.Data.ReadInt16(); From 65c061383e7550071227009748fcda5fe2fd5920 Mon Sep 17 00:00:00 2001 From: ProfessorXZ Date: Sun, 14 Aug 2016 21:31:30 +0200 Subject: [PATCH 3/3] Fixed corrupt packets caused by invalid tile IDs --- CHANGELOG.md | 1 + TShockAPI/GetDataHandlers.cs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e31dac52..83faaf91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Players can no longer quick stack items into region protected chests (@ProfessorXZ) * Rope placement is no longer blocked by range checks (@ProfessorXZ) * The Drill Containment Unit breaks blocks properly now (@ProfessorXZ) +* Fixed item duplications caused by range checks and invalid netIDs (@ProfessorXZ) * Fixed Expert mode coin duplication (@ProfessorXZ) * Players are no longer able to place liquids using LoadNetModule packet (@ProfessorXZ) * Explosives are no longer blocked by range checks (@ProfessorXZ) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index cd4b7499..0387e9e4 100755 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1907,6 +1907,12 @@ namespace TShockAPI var style = args.Data.ReadInt8(); + if (editData < 0) + { + args.Player.SendTileSquare(tileX, tileY, 4); + return true; + } + if (OnTileEdit(args.Player, tileX, tileY, action, type, editData, style)) return true; if (!TShock.Utils.TilePlacementValid(tileX, tileY))