From a418ada6f57b3105ff5fd4e6d0c82ac1860a334b Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 11 Dec 2011 10:58:55 -0700 Subject: [PATCH] Added some config options for the unsafe fixes. --- TShockAPI/ConfigFile.cs | 6 ++++++ TShockAPI/GetDataHandlers.cs | 17 +++++++++++++---- TShockAPI/TShock.cs | 6 +++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index fc579a72..22d5f9ef 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -204,6 +204,12 @@ namespace TShockAPI [Description("Displays a player's IP on join to everyone who has the log permission")] public bool DisplayIPToAdmins = false; + + [Description("Some tiles are 'fixed' by not letting TShock handle them. Disabling this may break certain asthetic tiles.")] + public bool EnableInsecureTileFixes = true; + + [Description("Some weapons override the range checks, however malicious users can take advantage of this and send lots of packets of certain types. Disabling this will turn off weapons that affect this.")] + public bool EnableRangeCheckOverrides = true; public static ConfigFile Read(string path) { diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index d820d631..f15c5345 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -257,9 +257,11 @@ namespace TShockAPI var newtile = tiles[x, y]; if ((tile.type == 128 && newtile.Type == 128) || (tile.type == 105 && newtile.Type == 105)) { - Console.WriteLine("SendTileSquareCalled on a 128 or 105."); - changed = true; - return false; + //Console.WriteLine("SendTileSquareCalled on a 128 or 105."); + if (TShock.Config.EnableInsecureTileFixes) + { + return false; + } } if (tile.type == 0x17 && newtile.Type == 0x2) @@ -346,7 +348,14 @@ namespace TShockAPI } if (TShock.Config.RangeChecks && ((Math.Abs(plyX - tileX) > 32) || (Math.Abs(plyY - tileY) > 32))) { - if (!(type == 1 && ((tiletype == 0 && args.Player.TPlayer.selectedItem == 114) || (tiletype == 127 && args.Player.TPlayer.selectedItem == 496)|| (tiletype == 53 && args.Player.TPlayer.selectedItem == 266)))) + if ((type == 1 && ((tiletype == 0 && args.Player.TPlayer.selectedItem == 114) || (tiletype == 127 && args.Player.TPlayer.selectedItem == 496)|| (tiletype == 53 && args.Player.TPlayer.selectedItem == 266)))) + { + if (!TShock.Config.EnableRangeCheckOverrides) + { + args.Player.SendMessage("This item has been disabled by the server owner."); + return true; + } + } else { Log.Debug(string.Format("TilePlaced(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5}, Type:{6})", plyX, plyY, tileX, tileY, Math.Abs(plyX - tileX), Math.Abs(plyY - tileY), tiletype)); diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 45c97126..0b985c57 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -32,6 +32,7 @@ using System.Diagnostics; using System.IO; using System.Net; using System.Reflection; +using System.Runtime.InteropServices; using System.Threading; using Community.CsharpSqlite.SQLiteClient; using Hooks; @@ -47,7 +48,7 @@ namespace TShockAPI [APIVersion(1, 9)] public class TShock : TerrariaPlugin { - public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version; + public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version; public static readonly string VersionCodename = "1.1 broke our API"; public static string SavePath = "tshock"; @@ -103,6 +104,8 @@ namespace TShockAPI Order = 0; } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] public override void Initialize() { @@ -216,6 +219,7 @@ namespace TShockAPI Log.Error(ex.ToString()); Environment.Exit(1); } + } private void callHome()