diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 0a1abb40..71c22b66 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -143,6 +143,7 @@ namespace TShockAPI add(Permissions.tp, TP, "tp"); add(Permissions.tphere, TPHere, "tphere"); add(Permissions.tphere, SendWarp, "sendwarp", "sw"); + add(Permissions.tpallow, TPAllow, "tpallow"); add(Permissions.warp, UseWarp, "warp"); add(Permissions.managewarp, SetWarp, "setwarp"); add(Permissions.managewarp, DeleteWarp, "delwarp"); @@ -1270,11 +1271,20 @@ namespace TShockAPI args.Player.SendMessage("Invalid player!", Color.Red); else if (players.Count > 1) args.Player.SendMessage("More than one player matched!", Color.Red); + else if (!args.Player.TPAllow && !args.Player.Group.HasPermission(Permissions.tpall)) + { + var plr = players[0]; + args.Player.SendMessage(plr.Name + " Has Selected For Users Not To Teleport To Them"); + plr.SendMessage(args.Player.Name + " Attempted To Teleport To You"); + } else { var plr = players[0]; if (args.Player.Teleport(plr.TileX, plr.TileY + 3)) + { args.Player.SendMessage(string.Format("Teleported to {0}", plr.Name)); + plr.SendMessage(args.Player.Name + " Teleported To You"); + } } } @@ -1325,10 +1335,18 @@ namespace TShockAPI plr.SendMessage(string.Format("You were teleported to {0}.", args.Player.Name)); args.Player.SendMessage(string.Format("You brought {0} here.", plr.Name)); } - } } + private static void TPAllow(CommandArgs args) + { + if (!args.Player.TPAllow) + args.Player.SendMessage("Other Players Can Now Teleport To You"); + if (args.Player.TPAllow) + args.Player.SendMessage("Other Players Can No Longer Teleport To You"); + args.Player.TPAllow = !args.Player.TPAllow; + } + private static void SendWarp(CommandArgs args) { if (args.Parameters.Count < 2) @@ -1678,7 +1696,8 @@ namespace TShockAPI { FileTools.SetupConfig(); TShock.Groups.LoadPermisions(); - args.Player.SendMessage("Configuration & Permissions reload complete. Some changes may require server restart."); + TShock.Regions.ReloadAllRegions(); + args.Player.SendMessage("Configuration, Permissions, and Regions reload complete. Some changes may require server restart."); } private static void ServerPassword(CommandArgs args) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index fc579a72..c4ad5de8 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -204,6 +204,15 @@ 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; + + [Description("Disabling this prevents players from being banned or kicked based on item stacks.")] + public bool EnableItemStackChecks = true; public static ConfigFile Read(string path) { diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 17a3b1b5..4ab2cc31 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -116,6 +116,8 @@ namespace TShockAPI {PacketTypes.SignNew, HandleSign}, {PacketTypes.PlayerSlot, HandlePlayerSlot}, {PacketTypes.TileGetSection, HandleGetSection}, + {PacketTypes.UpdateNPCHome, UpdateNPCHome }, + {PacketTypes.PlayerAddBuff, HandlePlayerBuff}, }; } @@ -158,7 +160,10 @@ namespace TShockAPI if (stack>it.maxStack) { string reason = string.Format("Item Stack Hack Detected: player has {0} {1}(s) in one stack", stack,itemname); - TShock.Utils.HandleCheater(args.Player, reason); + if (TShock.Config.EnableItemStackChecks) + { + TShock.Utils.HandleCheater(args.Player, reason); + } } return false; @@ -253,11 +258,13 @@ namespace TShockAPI var tile = Main.tile[realx, realy]; var newtile = tiles[x, y]; - Debug.WriteLine(string.Format("SendTileSquare : {0}, {1}", tile.type, newtile.Type)); - if ((tile.type == 128 && newtile.Type == 128) || (tile.type == 105 || newtile.Type == 105)) + if ((tile.type == 128 && newtile.Type == 128) || (tile.type == 105 && newtile.Type == 105)) { - Console.WriteLine("SendTileSquareCalled on a 128 or 105."); - changed = true; + //Console.WriteLine("SendTileSquareCalled on a 128 or 105."); + if (TShock.Config.EnableInsecureTileFixes) + { + return false; + } } if (tile.type == 0x17 && newtile.Type == 0x2) @@ -409,7 +416,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 == 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)); @@ -430,6 +444,13 @@ namespace TShockAPI args.Player.SendTileSquare(x, y); return true; } + if (tiletype == 141 && !args.Player.Group.HasPermission(Permissions.canexplosive)) + { + args.Player.SendMessage("You do not have permission to place explosives.", Color.Red); + TShock.Utils.SendLogs(string.Format("{0} tried to place explosives", args.Player.Name), Color.Red); + args.Player.SendTileSquare(x, y); + return true; + } } if (!args.Player.Group.HasPermission(Permissions.editspawn) && !TShock.Regions.CanBuild(x, y, args.Player) && TShock.Regions.InArea(x, y)) { @@ -588,6 +609,18 @@ namespace TShockAPI else return TShock.Utils.HandleExplosivesUser(args.Player, TShock.Config.ExplosiveAbuseReason); } + if (args.Player.Index != owner)//ignores projectiles whose senders aren't the same as their owners + { + TShock.Players[args.Player.Index].SendData(PacketTypes.ProjectileNew, "", ident);//update projectile on senders end so he knows it didnt get created + return true; + } + Projectile proj = new Projectile(); + proj.SetDefaults(type); + if (proj.hostile)//ignores all hostile projectiles from the client they shouldn't be sending them anyways + { + TShock.Players[args.Player.Index].SendData(PacketTypes.ProjectileNew, "", ident); + return true; + } return false; } @@ -823,5 +856,20 @@ namespace TShockAPI args.Player.RequestedSection = true; return false; } + + private static bool UpdateNPCHome( GetDataHandlerArgs args ) + { + if (!args.Player.Group.HasPermission(Permissions.movenpc)) + { + args.Player.SendMessage("You do not have permission to relocate NPCs.", Color.Red); + return true; + } + return false; + } + + private static bool HandlePlayerBuff(GetDataHandlerArgs args) + { + return !args.Player.Group.HasPermission(Permissions.ignoregriefdetection); + } } } diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index af7e5bcc..aa2be51a 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -141,6 +141,18 @@ namespace TShockAPI [Description("User can change hardmode state.")] public static readonly string hardmode; + [Description("User can change the homes of NPCs.")] + public static readonly string movenpc; + + [Description("Required to be able to place Explosives")] + public static readonly string canexplosive; + + [Description("Users can stop people from TPing to them")] + public static readonly string tpallow; + + [Description("Users can tp to anyone")] + public static readonly string tpall; + static Permissions() { foreach (var field in typeof(Permissions).GetFields()) diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs index b7182e30..612a9ae1 100644 --- a/TShockAPI/Properties/AssemblyInfo.cs +++ b/TShockAPI/Properties/AssemblyInfo.cs @@ -36,5 +36,5 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.3.4.1205")] -[assembly: AssemblyFileVersion("3.3.4.1205")] +[assembly: AssemblyVersion("3.3.4.1211")] +[assembly: AssemblyFileVersion("3.3.4.1211")] diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 768e6665..89221924 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -56,6 +56,7 @@ namespace TShockAPI public bool IsLoggedIn; public int UserID = -1; public bool HasBeenNaggedAboutLoggingIn; + public bool TPAllow = true; public bool TpLock = false; Player FakePlayer; public bool RequestedSection = false; 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() diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index d9cb993b..9a60f687 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -184,7 +184,7 @@ - +