From 09121368e402b4cd0f1f92b7f91945e5bbd259d3 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Thu, 21 Dec 2017 20:32:07 -0700 Subject: [PATCH] Move TShock.CheckRangePermission to TSPlayer TShock.CheckRangePermission is now TSPlayer.IsInRange, but the most important thing is that this method returns the opposite of what the original did, so all of the calls that would go to it are now inverted. --- CHANGELOG.md | 1 + TShockAPI/Bouncer.cs | 30 +++++++++++++++--------------- TShockAPI/GetDataHandlers.cs | 8 ++++---- TShockAPI/TSPlayer.cs | 14 ++++++++++++++ TShockAPI/TShock.cs | 20 +------------------- 5 files changed, 35 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7286ea27..88ba267a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added `TSPlayer.CheckIgnores()` and removed `TShock.CheckIgnores(TSPlayer)`. (@hakusaro) * Hooks inside TShock can now be registered with their `Register` method and can be prioritized according to the TShock HandlerList system. (@hakusaro) * Fix message requiring login not using the command specifier set in the config file. (@hakusaro) +* Move `TShock.CheckRangePermission()` to `TSPlayer.IsInRange` which **returns the opposite** of what the previous method did (see updated docs). (@hakusaro) ## TShock 4.3.25 * Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6. diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 8e81d802..d4727962 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -83,7 +83,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, args.X, args.Y)) + if (!args.Player.IsInRange(args.X, args.Y)) { NetMessage.SendData((int)PacketTypes.UpdateTileEntity, -1, -1, NetworkText.Empty, args.ItemFrame.ID, 0, 1); args.Handled = true; @@ -138,7 +138,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, args.X, args.Y)) + if (!args.Player.IsInRange(args.X, args.Y)) { args.Handled = true; return; @@ -253,7 +253,7 @@ namespace TShockAPI } if (TShock.Config.RangeChecks && - TShock.CheckRangePermission(args.Player, (int)(Main.npc[id].position.X / 16f), (int)(Main.npc[id].position.Y / 16f), 128)) + !args.Player.IsInRange((int)(Main.npc[id].position.X / 16f), (int)(Main.npc[id].position.Y / 16f), 128)) { args.Player.SendData(PacketTypes.NpcUpdate, "", id); args.Handled = true; @@ -319,7 +319,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 100)) + if (!args.Player.IsInRange(TShock.Players[id].TileX, TShock.Players[id].TileY, 100)) { args.Player.SendData(PacketTypes.PlayerHp, "", id); args.Player.SendData(PacketTypes.PlayerUpdate, "", id); @@ -373,7 +373,7 @@ namespace TShockAPI // client side (but only if it passed the range check) (i.e., return false) if (type == 0) { - if (TShock.CheckRangePermission(args.Player, (int)(Main.item[id].position.X / 16f), (int)(Main.item[id].position.Y / 16f))) + if (!args.Player.IsInRange((int)(Main.item[id].position.X / 16f), (int)(Main.item[id].position.Y / 16f))) { // Causes item duplications. Will be re added if necessary //args.Player.SendData(PacketTypes.ItemDrop, "", id); @@ -385,7 +385,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, (int)(pos.X / 16f), (int)(pos.Y / 16f))) + if (!args.Player.IsInRange((int)(pos.X / 16f), (int)(pos.Y / 16f))) { args.Player.SendData(PacketTypes.ItemDrop, "", id); args.Handled = true; @@ -465,7 +465,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 50)) + if (!args.Player.IsInRange(TShock.Players[id].TileX, TShock.Players[id].TileY, 50)) { args.Player.SendData(PacketTypes.PlayerAddBuff, "", id); args.Handled = true; @@ -516,7 +516,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, Main.chest[id].x, Main.chest[id].y)) + if (!args.Player.IsInRange(Main.chest[id].x, Main.chest[id].y)) { args.Handled = true; return; @@ -544,7 +544,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, x, y)) + if (!args.Player.IsInRange(x, y)) { args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY, Convert.ToByte(Main.npc[id].homeless)); @@ -564,7 +564,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, args.X, args.Y)) + if (!args.Player.IsInRange(args.X, args.Y)) { args.Handled = true; return; @@ -632,7 +632,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, tileX, tileY)) + if (!args.Player.IsInRange(tileX, tileY)) { args.Player.SendTileSquare(tileX, tileY, 3); args.Handled = true; @@ -765,7 +765,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, tileX, tileY, 16)) + if (!args.Player.IsInRange(tileX, tileY, 16)) { args.Player.SendTileSquare(tileX, tileY, 1); args.Handled = true; @@ -1160,7 +1160,7 @@ namespace TShockAPI || type != TileID.SilkRope || type != TileID.VineRope || type != TileID.WebRope) - && TShock.CheckRangePermission(args.Player, x, y)) + && !args.Player.IsInRange(x, y)) { args.Player.SendTileSquare(x, y, 4); args.Handled = true; @@ -1484,7 +1484,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, tileX, tileY)) + if (!args.Player.IsInRange(tileX, tileY)) { if (action == EditAction.PlaceTile && (editData == TileID.Rope || editData == TileID.SilkRope || editData == TileID.VineRope || editData == TileID.WebRope)) { @@ -1661,7 +1661,7 @@ namespace TShockAPI var tile = Main.tile[realx, realy]; var newtile = tiles[x, y]; if (TShock.CheckTilePermission(args.Player, realx, realy) || - TShock.CheckRangePermission(args.Player, realx, realy)) + !args.Player.IsInRange(realx, realy)) { continue; } diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index a8524597..310a3b64 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2578,7 +2578,7 @@ namespace TShockAPI return true; } - if (TShock.CheckRangePermission(args.Player, x, y)) + if (!args.Player.IsInRange(x, y)) { args.Player.SendData(PacketTypes.SignNew, "", id); return true; @@ -2898,7 +2898,7 @@ namespace TShockAPI if (args.Player.IsBouncerThrottled() || TShock.CheckTilePermission(args.Player, x, y, true) || - TShock.CheckRangePermission(args.Player, x, y)) + !args.Player.IsInRange(x, y)) { args.Player.SendData(PacketTypes.PaintTile, "", x, y, Main.tile[x, y].color()); return true; @@ -2942,7 +2942,7 @@ namespace TShockAPI if (args.Player.IsBouncerThrottled() || TShock.CheckTilePermission(args.Player, x, y, true) || - TShock.CheckRangePermission(args.Player, x, y)) + !args.Player.IsInRange(x, y)) { args.Player.SendData(PacketTypes.PaintWall, "", x, y, Main.tile[x, y].wallColor()); return true; @@ -3293,7 +3293,7 @@ namespace TShockAPI return true; } - if (TShock.CheckRangePermission(args.Player, (int)position.X, (int)position.Y)) + if (!args.Player.IsInRange((int)position.X, (int)position.Y)) { return true; } diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 69181389..8071ea37 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -321,6 +321,20 @@ namespace TShockAPI public bool SilentJoinInProgress; + /// Checks if a player has permission to modify a tile dependent on range checks. + /// The x coordinate of the tile. + /// The y coordinate of the tile. + /// The range to check for. + /// True if the player is in range of a tile or if range checks are off. False if not. + public bool IsInRange(int x, int y, int range = 32) + { + if (TShock.Config.RangeChecks && ((Math.Abs(TileX - x) > range) || (Math.Abs(TileY - y) > range))) + { + return false; + } + return true; + } + /// /// A list of points where ice tiles have been placed. /// diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 44c6b9f1..8e2ea548 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -585,7 +585,7 @@ namespace TShockAPI return; } - if (CheckRangePermission(tsplr, args.Chest.x, args.Chest.y)) + if (!tsplr.IsInRange(args.Chest.x, args.Chest.y)) { args.Handled = true; return; @@ -1757,24 +1757,6 @@ namespace TShockAPI e.Handled = true; } - - - - /// CheckRangePermission - Checks if a player has permission to modify a tile dependent on range checks. - /// player - The TSPlayer object. - /// x - The x coordinate of the tile. - /// y - The y coordinate of the tile. - /// range - The range to check for. - /// bool - True if the player should not be able to place the tile. False if they can, or if range checks are off. - public static bool CheckRangePermission(TSPlayer player, int x, int y, int range = 32) - { - if (Config.RangeChecks && ((Math.Abs(player.TileX - x) > range) || (Math.Abs(player.TileY - y) > range))) - { - return true; - } - return false; - } - /// CheckTilePermission - Checks to see if a player has permission to modify a tile in general. /// player - The TSPlayer object. /// tileX - The x coordinate of the tile.