From 4f66e660d48d99f7251a85648645b62b6acf5ed8 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Tue, 9 Jun 2020 00:01:57 +0200 Subject: [PATCH 1/5] Bouncer OnTileEdit - Add tile replace action to tileban check. Tiny change, but a pressing matter. My smallest PR ever? hahah. --- CHANGELOG.md | 1 + TShockAPI/Bouncer.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9883b79..c73fa5b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming changes * Installed new sprinklers! +* Fix issue where players could replace tiles with banned tiles without permission. (@Patrikkk) ## TShock 4.4.0 (Pre-release 11) * New permission `tshock.tp.pylon` to enable teleporting via Teleportation Pylons (@QuiCM) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 117c8aac..3a0fa623 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -259,7 +259,7 @@ namespace TShockAPI int lastKilledProj = args.Player.LastKilledProjectile; ITile tile = Main.tile[tileX, tileY]; - if (action == EditAction.PlaceTile) + if (action == EditAction.PlaceTile || action == EditAction.ReplaceTile) { if (TShock.TileBans.TileIsBanned(editData, args.Player)) { From 0d0641c8c0ddbb556ef6c810aea73250070ea93a Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Tue, 9 Jun 2020 00:23:23 +0200 Subject: [PATCH 2/5] Bouncer OnTileEdit - Adding more checks on ReplaceTile action. --- TShockAPI/Bouncer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 3a0fa623..934793e9 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -358,7 +358,7 @@ namespace TShockAPI } } - if (editData >= (action == EditAction.PlaceTile ? Main.maxTileSets : Main.maxWallTypes)) + if (editData >= ((action == EditAction.PlaceTile || action == EditAction.ReplaceTile) ? Main.maxTileSets : Main.maxWallTypes)) { TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (ms3) {0} {1} {2}", args.Player.Name, action, editData); args.Player.SendTileSquare(tileX, tileY, 4); @@ -536,7 +536,7 @@ namespace TShockAPI return; } - if ((action == EditAction.PlaceTile || action == EditAction.PlaceWall) && !args.Player.HasPermission(Permissions.ignoreplacetiledetection)) + if ((action == EditAction.PlaceTile || action == EditAction.ReplaceTile || action == EditAction.PlaceWall) && !args.Player.HasPermission(Permissions.ignoreplacetiledetection)) { args.Player.TilePlaceThreshold++; var coords = new Vector2(tileX, tileY); From 6c22cfd57c1d3aac6348f84f5d63017b244b335d Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Tue, 9 Jun 2020 00:39:04 +0200 Subject: [PATCH 3/5] Bouncer OnTileData - Add more checks on ReplaceTile/ReplaceWall --- CHANGELOG.md | 6 +++++- TShockAPI/Bouncer.cs | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c73fa5b3..947c640c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,11 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming changes * Installed new sprinklers! -* Fix issue where players could replace tiles with banned tiles without permission. (@Patrikkk) +* Fix multiple holes in Bouncer OnTileData. (@Patrikkk, @hakusaro) + * Issue where players could replace tiles with banned tiles without permission. + * Including replace action in TilePlace threshold incrementation, so players cannot bypass the threshold while replacing tiles/walls. + * Including check for maxTileSets when player is replacing tiles, so players cannot send invalid tile data through the replace tile action. + * Including a check for ReplaceWall when the tile is a Breakable/CutTile. ## TShock 4.4.0 (Pre-release 11) * New permission `tshock.tp.pylon` to enable teleporting via Teleportation Pylons (@QuiCM) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 934793e9..2de3b614 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -330,7 +330,7 @@ namespace TShockAPI return; } } - else if (action == EditAction.PlaceTile || action == EditAction.PlaceWall) + else if (action == EditAction.PlaceTile || action == EditAction.ReplaceTile || action == EditAction.PlaceWall || action == EditAction.ReplaceWall) { if ((action == EditAction.PlaceTile && TShock.Config.PreventInvalidPlaceStyle) && (MaxPlaceStyles.ContainsKey(editData) && style > MaxPlaceStyles[editData]) && @@ -437,7 +437,7 @@ namespace TShockAPI } if (TShock.Config.AllowCutTilesAndBreakables && Main.tileCut[tile.type]) { - if (action == EditAction.KillWall) + if (action == EditAction.KillWall || action == EditAction.ReplaceWall) { TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from sts allow cut from {0} {1} {2}", args.Player.Name, action, editData); args.Player.SendTileSquare(tileX, tileY, 1); @@ -536,7 +536,7 @@ namespace TShockAPI return; } - if ((action == EditAction.PlaceTile || action == EditAction.ReplaceTile || action == EditAction.PlaceWall) && !args.Player.HasPermission(Permissions.ignoreplacetiledetection)) + if ((action == EditAction.PlaceTile || action == EditAction.ReplaceTile || action == EditAction.PlaceWall || action == EditAction.ReplaceWall) && !args.Player.HasPermission(Permissions.ignoreplacetiledetection)) { args.Player.TilePlaceThreshold++; var coords = new Vector2(tileX, tileY); @@ -545,7 +545,7 @@ namespace TShockAPI args.Player.TilesCreated.Add(coords, Main.tile[tileX, tileY]); } - if ((action == EditAction.KillTile || action == EditAction.KillTileNoItem || action == EditAction.KillWall) && Main.tileSolid[Main.tile[tileX, tileY].type] && + if ((action == EditAction.KillTile || action == EditAction.KillTileNoItem || action == EditAction.ReplaceTile || action == EditAction.KillWall || action == EditAction.ReplaceWall) && Main.tileSolid[Main.tile[tileX, tileY].type] && !args.Player.HasPermission(Permissions.ignorekilltiledetection)) { args.Player.TileKillThreshold++; From 5decc50bd929a8f30c72cc55048072d947ca5c7a Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Tue, 9 Jun 2020 14:04:27 +0200 Subject: [PATCH 4/5] Bouncer OnNewProjectile - Add checks on directional projectiles. **This commit does not have any effect on actual gameplay as of current project state, but it does let valid projectile creation pass through instead of getting caught up in Bouncer. That catch is currently disabled for the time being, until all valid projectile creation check is added.** Things would have get caught up in our bouncer eversince 1.4. We commented out the catch (the disable and handling) for now, but none of these new projectiles were added to let them pass. Renaming stabProjectile to directionalProjectile. Adding staffs to directionalProjectiles Adding check for GolfClubHelper projectile. Left in a debug check for golfball projectile. I would want to see if the reject gets triggered in a proper server enviroment. I didn't want to handle the projectile just yet. Adding GolfBallItemIDs list in Handlers.LandGolfBallInCupHandler.cs --- CHANGELOG.md | 5 ++ TShockAPI/Bouncer.cs | 49 +++++++++++++++++-- .../Handlers/LandGolfBallInCupHandler.cs | 20 ++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9883b79..4be999f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming changes * Installed new sprinklers! +* Adding checks in Bouncer OnNewProjectile (@Patrikkk): + * For valid golf club and golf ball creation. + * Renamed stabProjectile to directionalProjectile for a more accurate naming. + * Adding staff projectiles to the directionalProjectiles Dictionary to include staffs in the valid projectile creation check. + * Adding GolfBallItemIDs list in Handlers.LandGolfBallInCupHandler.cs ## TShock 4.4.0 (Pre-release 11) * New permission `tshock.tp.pylon` to enable teleporting via Teleportation Pylons (@QuiCM) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 117c8aac..83fa5ac6 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -717,15 +717,32 @@ namespace TShockAPI return; } - if (stabProjectile.ContainsKey(type)) + /// If the projectile is a directional projectile, check if the player is holding their respected item to validate the projectile creation. + if (directionalProjectiles.ContainsKey(type)) { - if (stabProjectile[type] == args.Player.TPlayer.HeldItem.type) + if (directionalProjectiles[type] == args.Player.TPlayer.HeldItem.type) { args.Handled = false; return; } } + /// If the created projectile is a golf club, check if the player is holding one of the golf club items to validate the projectile creation. + if (type == ProjectileID.GolfClubHelper && Handlers.LandGolfBallInCupHandler.GolfClubItemIDs.Contains(args.Player.TPlayer.HeldItem.type)) + { + args.Handled = false; + return; + } + + /// If the created projectile is a golf ball and the player is not holding a golf club item and neither a golf ball item and neither they have had a golf club projectile created recently. + if (Handlers.LandGolfBallInCupHandler.GolfBallProjectileIDs.Contains(type) && + !Handlers.LandGolfBallInCupHandler.GolfClubItemIDs.Contains(args.Player.TPlayer.HeldItem.type) && + !Handlers.LandGolfBallInCupHandler.GolfBallItemIDs.Contains(args.Player.TPlayer.HeldItem.type) && + !args.Player.RecentlyCreatedProjectiles.Any(p => p.Type == ProjectileID.GolfClubHelper)) + { + TShock.Log.ConsoleDebug("Bouncer / OnNewProjectile please report to tshock about this! normally this is a reject from {0} {1} (golf)", args.Player.Name, type); + } + // Main.projHostile contains projectiles that can harm players // without PvP enabled and belong to enemy mobs, so they shouldn't be // possible for players to create. (Source: Ijwu, QuiCM) @@ -2118,9 +2135,33 @@ namespace TShockAPI TileID.Campfire }; - private static Dictionary stabProjectile = new Dictionary() + /// + /// These projectiles have been added or modified with Terraria 1.4. + /// They come from normal items, but to have the directional functionality, they must be projectiles. + /// + private static Dictionary directionalProjectiles = new Dictionary() { - { ProjectileID.GladiusStab, ItemID.Gladius }, + ///Spears + { ProjectileID.DarkLance, ItemID.DarkLance}, + { ProjectileID.Trident, ItemID.Trident}, + { ProjectileID.Spear, ItemID.Spear}, + { ProjectileID.MythrilHalberd, ItemID.MythrilHalberd}, + { ProjectileID.AdamantiteGlaive, ItemID.AdamantiteGlaive}, + { ProjectileID.CobaltNaginata, ItemID.CobaltNaginata}, + { ProjectileID.Gungnir, ItemID.Gungnir}, + { ProjectileID.MushroomSpear, ItemID.MushroomSpear}, + { ProjectileID.TheRottedFork, ItemID.TheRottedFork}, + { ProjectileID.PalladiumPike, ItemID.PalladiumPike}, + { ProjectileID.OrichalcumHalberd, ItemID.OrichalcumHalberd}, + { ProjectileID.TitaniumTrident, ItemID.TitaniumTrident}, + { ProjectileID.ChlorophytePartisan, ItemID.ChlorophytePartisan}, + { ProjectileID.NorthPoleWeapon, ItemID.NorthPole}, + { ProjectileID.ObsidianSwordfish, ItemID.ObsidianSwordfish}, + { ProjectileID.Swordfish, ItemID.Swordfish}, + { ProjectileID.MonkStaffT2, ItemID.MonkStaffT2}, + { ProjectileID.ThunderSpear, ItemID.ThunderSpear}, + { ProjectileID.GladiusStab, ItemID.Gladius}, + /// ShortSwords { ProjectileID.RulerStab, ItemID.Ruler }, { ProjectileID.CopperShortswordStab, ItemID.CopperShortsword }, { ProjectileID.TinShortswordStab, ItemID.TinShortsword }, diff --git a/TShockAPI/Handlers/LandGolfBallInCupHandler.cs b/TShockAPI/Handlers/LandGolfBallInCupHandler.cs index 43e95a35..1038d27e 100644 --- a/TShockAPI/Handlers/LandGolfBallInCupHandler.cs +++ b/TShockAPI/Handlers/LandGolfBallInCupHandler.cs @@ -59,6 +59,26 @@ namespace TShockAPI.Handlers ItemID.GolfClubWedge, ItemID.GolfClubPutter }; + /// + /// List of golf ball item IDs. + /// + public static readonly List GolfBallItemIDs = new List() + { + ItemID.GolfBall, + ItemID.GolfBallDyedBlack, + ItemID.GolfBallDyedBlue, + ItemID.GolfBallDyedBrown, + ItemID.GolfBallDyedCyan, + ItemID.GolfBallDyedGreen, + ItemID.GolfBallDyedLimeGreen, + ItemID.GolfBallDyedOrange, + ItemID.GolfBallDyedPink, + ItemID.GolfBallDyedPurple, + ItemID.GolfBallDyedRed, + ItemID.GolfBallDyedSkyBlue, + ItemID.GolfBallDyedTeal, + ItemID.GolfBallDyedViolet + }; /// /// Invoked when a player lands a golf ball in a cup. From b633f60567e2093ac26651e995d5ff4cfe9307ec Mon Sep 17 00:00:00 2001 From: Chris <2648373+QuiCM@users.noreply.github.com> Date: Wed, 10 Jun 2020 13:27:33 +0930 Subject: [PATCH 5/5] Resolve STS issue #1999 --- CHANGELOG.md | 1 + TShockAPI/Handlers/SendTileSquareHandler.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86157f72..e699b5b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Renamed stabProjectile to directionalProjectile for a more accurate naming. * Adding staff projectiles to the directionalProjectiles Dictionary to include staffs in the valid projectile creation check. * Adding GolfBallItemIDs list in Handlers.LandGolfBallInCupHandler.cs +* Fixed an issue in the SendTileSquare handler that was rejecting valid tile objects (@QuiCM) ## TShock 4.4.0 (Pre-release 11) * New permission `tshock.tp.pylon` to enable teleporting via Teleportation Pylons (@QuiCM) diff --git a/TShockAPI/Handlers/SendTileSquareHandler.cs b/TShockAPI/Handlers/SendTileSquareHandler.cs index 2bf0c729..c7449087 100644 --- a/TShockAPI/Handlers/SendTileSquareHandler.cs +++ b/TShockAPI/Handlers/SendTileSquareHandler.cs @@ -470,7 +470,7 @@ namespace TShockAPI.Handlers return false; } - if (x + width >= size || y + height + offsetY >= size) + if (x + width > size || y + height + offsetY > size) { // This is ugly, but we want to mark all these tiles as processed so that we're not hitting this check multiple times for one dodgy tile object for (int i = x; i < size; i++)