From 59f9440d174504b69ec81f3368c1b501f0148fb4 Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Mon, 12 Dec 2022 17:15:34 -0800 Subject: [PATCH 01/94] Use same TSPlayer.Active check --- TShockAPI/Bouncer.cs | 6 +++--- TShockAPI/Commands.cs | 8 ++++---- TShockAPI/Rest/RestManager.cs | 6 +++--- TShockAPI/Utils.cs | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index affa1609..e86501b1 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -1878,7 +1878,7 @@ namespace TShockAPI return; } - if (TShock.Players[id] == null) + if (TShock.Players[id] == null || !TShock.Players[id].Active) { TShock.Log.ConsoleDebug(GetString( "Bouncer / OnPlayerBuff rejected {0} ({1}) applying buff {2} to {3} for {4} ticks: target is null", args.Player.Name, @@ -2081,7 +2081,7 @@ namespace TShockAPI short amount = args.Amount; byte plr = args.TargetPlayerIndex; - if (amount <= 0 || Main.player[plr] == null || !Main.player[plr].active) + if (amount <= 0 || TShock.Players[plr] == null || !TShock.Players[plr].Active) { TShock.Log.ConsoleDebug(GetString("Bouncer / OnHealOtherPlayer rejected null checks")); args.Handled = true; @@ -2589,7 +2589,7 @@ namespace TShockAPI byte direction = args.Direction; PlayerDeathReason reason = args.PlayerDeathReason; - if (id >= Main.maxPlayers || TShock.Players[id] == null) + if (id >= Main.maxPlayers || TShock.Players[id] == null || !TShock.Players[id].Active) { TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerDamage rejected null check")); args.Handled = true; diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 2214f252..74fa4f42 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -3070,12 +3070,12 @@ namespace TShockAPI args.Player.SendErrorMessage(GetString("You do not have permission to teleport all other players.")); return; } - for (int i = 0; i < Main.maxPlayers; i++) + foreach (var player in TShock.Players) { - if (Main.player[i].active && (Main.player[i] != args.TPlayer)) + if (player != null && player.Active && player.Index != args.Player.Index) { - if (TShock.Players[i].Teleport(args.TPlayer.position.X, args.TPlayer.position.Y)) - TShock.Players[i].SendSuccessMessage(GetString("You were teleported to {0}.", args.Player.Name)); + if (player.Teleport(args.TPlayer.position.X, args.TPlayer.position.Y)) + player.SendSuccessMessage(GetString("You were teleported to {0}.", args.Player.Name)); } } args.Player.SendSuccessMessage(GetString("Teleported everyone to yourself.")); diff --git a/TShockAPI/Rest/RestManager.cs b/TShockAPI/Rest/RestManager.cs index c41e7767..b6efd6c5 100644 --- a/TShockAPI/Rest/RestManager.cs +++ b/TShockAPI/Rest/RestManager.cs @@ -402,7 +402,7 @@ namespace TShockAPI {"serverversion", Main.versionNumber}, {"tshockversion", TShock.VersionNum}, {"port", TShock.Config.Settings.ServerPort}, - {"playercount", Main.player.Where(p => null != p && p.active).Count()}, + {"playercount", TShock.Utils.GetActivePlayerCount()}, {"maxplayers", TShock.Config.Settings.MaxSlots}, {"world", (TShock.Config.Settings.UseServerName ? TShock.Config.Settings.ServerName : Main.worldName)}, {"uptime", (DateTime.Now - System.Diagnostics.Process.GetCurrentProcess().StartTime).ToString(@"d'.'hh':'mm':'ss")}, @@ -944,8 +944,8 @@ namespace TShockAPI [Token] private object PlayerList(RestRequestArgs args) { - var activeplayers = Main.player.Where(p => null != p && p.active).ToList(); - return new RestObject() { { "players", string.Join(", ", activeplayers.Select(p => p.name)) } }; + var activeplayers = TShock.Players.Where(p => null != p && p.Active).Select(p => p.Name); + return new RestObject() { { "players", string.Join(", ", activeplayers) } }; } [Description("Fetches detailed user information on all connected users, and can be filtered by specifying a key value pair filter users where the key is a field and the value is a users field value.")] diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index efe17130..a7291e73 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -172,7 +172,7 @@ namespace TShockAPI foreach (TSPlayer player in TShock.Players) { if (player != null && player != excludedPlayer && player.Active && player.HasPermission(Permissions.logs) && - player.DisplayLogs && TShock.Config.Settings.DisableSpewLogs == false) + player.DisplayLogs && !TShock.Config.Settings.DisableSpewLogs) player.SendMessage(log, color); } } @@ -183,7 +183,7 @@ namespace TShockAPI /// The number of active players on the server. public int GetActivePlayerCount() { - return Main.player.Where(p => null != p && p.active).Count(); + return TShock.Players.Count(p => null != p && p.Active); } //Random should not be generated in a method From 8b57f321250a03a71853e09589c1e0ce8977c02e Mon Sep 17 00:00:00 2001 From: James Puleo Date: Tue, 20 Dec 2022 21:36:31 -0500 Subject: [PATCH 02/94] Detect invalid TShock installations There are two common mistakes made by those installing/updating TShock: - Extracting TShock into the Terraria client directory - Extracting TShock 5 or newer into a legacy (TShock 4 or older) install By checking for the existence of a file named `TerrariaServer.exe`, we can potentially detect these invalid installations, and prompt the user with a more useful diagnostic, rather than (likely) crashing moments later. --- TShockLauncher/Program.cs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/TShockLauncher/Program.cs b/TShockLauncher/Program.cs index 4a139370..0163cc2d 100644 --- a/TShockLauncher/Program.cs +++ b/TShockLauncher/Program.cs @@ -29,12 +29,30 @@ along with this program. If not, see . using System.Reflection; using TShockPluginManager; +// On occasion, users have been seen extracting TShock into their client installation directory -- this is of course incorrect, and is known +// to cause issues. Let's attempt to catch this before anything happens (specifically, before Terraria assemblies are resolved) and prevent +// TShock from launching. +if (File.Exists("TerrariaServer.exe")) +{ + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine("A \"TerrariaServer.exe\" file has been found in the current working directory."); + Console.Error.WriteLine( + "This indicates either installation into a Terraria client directory, or installation into a legacy (TShock 4 or older) TShock directory."); + Console.Error.WriteLine( + "TShock is never to be installed inside a Terraria client directory. You should instead extract your TShock installation into it's own directory."); + Console.Error.WriteLine( + "If you are updating a legacy TShock installation, please follow the following documentation to update: https://ikebukuro.tshock.co/#/?id=upgrading-from-tshock-4"); + Console.Error.WriteLine("The launcher will now exit."); + Console.ResetColor(); + return 1; +} + if (args.Length > 0 && args[0].ToLower() == "plugins") { var items = args.ToList(); items.RemoveAt(0); await NugetCLI.Main(items); - return; + return 0; } @@ -42,7 +60,7 @@ Dictionary _cache = new Dictionary(); System.Runtime.Loader.AssemblyLoadContext.Default.Resolving += Default_Resolving; -Start(); +return Start(); /// /// Resolves a module from the ./bin folder, either with a .dll by preference or .exe @@ -70,7 +88,8 @@ Assembly? Default_Resolving(System.Runtime.Loader.AssemblyLoadContext arg1, Asse /// Initiates the TSAPI server. /// /// This method exists so that the resolver can attach before TSAPI needs its dependencies. -void Start() +int Start() { TerrariaApi.Server.Program.Main(args); + return 0; } From 3776baaf129eb03f16d61a3f16072a0e348e4ef7 Mon Sep 17 00:00:00 2001 From: James Puleo Date: Tue, 20 Dec 2022 21:42:50 -0500 Subject: [PATCH 03/94] Update `docs/changelog.md` --- docs/changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index f43f9651..9295ece7 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -105,6 +105,8 @@ Use past tense when adding new entries; sign your name off when you add or chang * Initialized achievements and the `AchievementManager` on the server. This ensures that players cannot cause exceptions to be thrown, chat messages are always logged, and allows achievement names to be localized in the console. Also added a test case for this. (@drunderscore) * Allowed multiple test cases to be in TShock's test suite. (@drunderscore) * Fixed unable to use Purification/Evil Powder in jungle. (@sgkoishi) +* Detected invalid installations, by checking for a file named `TerrariaServer.exe`. (@drunderscore) + * This made the two most common installation mistakes (extracting into the Terraria client directory, and extracting TShock 5 or newer into a TShock 4 or older install) prompt the user with a more useful diagnostic, rather than (likely) crashing moments later. ## TShock 5.1.3 * Added support for Terraria 1.4.4.9 via OTAPI 3.1.20. (@SignatureBeef) From 10aca8573dc2c3dd8ca7d3866bf6e5f0e676ff9a Mon Sep 17 00:00:00 2001 From: Stargazing Koishi Date: Tue, 7 Mar 2023 18:39:38 -0800 Subject: [PATCH 04/94] Remove Connection: Close for REST api fix #2923 --- TShockAPI/Rest/Rest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/TShockAPI/Rest/Rest.cs b/TShockAPI/Rest/Rest.cs index 58cc23d8..a6e681e2 100644 --- a/TShockAPI/Rest/Rest.cs +++ b/TShockAPI/Rest/Rest.cs @@ -351,7 +351,6 @@ namespace Rests { str = string.Format("{0}({1});", jsonp, str); } - e.Response.Connection.Type = ConnectionType.Close; e.Response.ContentType = new ContentTypeHeader("application/json; charset=utf-8"); e.Response.Add(serverHeader); var bytes = Encoding.UTF8.GetBytes(str); From 1948ad3d2cf960619bd9954bec87072d6aa207b1 Mon Sep 17 00:00:00 2001 From: Stargazing Koishi Date: Thu, 9 Mar 2023 21:01:09 -0800 Subject: [PATCH 05/94] Update changelog.md --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index be96f88c..8af0bada 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -106,6 +106,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Allowed multiple test cases to be in TShock's test suite. (@drunderscore) * Fixed unable to use Purification/Evil Powder in jungle. (@sgkoishi) * Set the `GetDataHandledEventArgs.Player` property for the `SyncTilePicking` data handler. (@drunderscore) +* Fixed unable to transfer long response body for REST API. (@sgkoishi, #2925) ## TShock 5.1.3 * Added support for Terraria 1.4.4.9 via OTAPI 3.1.20. (@SignatureBeef) From 823d942b4728b34dcb380572600452f8ddfde888 Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Fri, 28 Apr 2023 15:55:14 -0700 Subject: [PATCH 06/94] Update changelog --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index c4a95d14..88a8c518 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -110,6 +110,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Allowed Flower Boots to place Ash Flowers on Ash Grass blocks. (@punchready) * Removed unnecessary range check that artifically shortened quick stack reach. (@boddyn, #2885, @bcat) * Improved the exploit protection in tile rect handling. (@punchready) +* Changed the use of `Player.active` to `TSPlayer.Active` for consistency. (@sgkoishi, #2939) ## TShock 5.1.3 * Added support for Terraria 1.4.4.9 via OTAPI 3.1.20. (@SignatureBeef) From 3d11d84d7339ffe7f165cf2f15316a1d6660dd48 Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Sat, 13 May 2023 03:56:07 -0700 Subject: [PATCH 07/94] Fix dump-reference-data mutate command name --- TShockAPI/Permissions.cs | 15 +++------------ docs/changelog.md | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index d7ec7166..debc8ea5 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -529,18 +529,9 @@ namespace TShockAPI field.GetCustomAttributes(false).FirstOrDefault(o => o is DescriptionAttribute) as DescriptionAttribute; var desc = descattr != null && !string.IsNullOrWhiteSpace(descattr.Description) ? descattr.Description : GetString("No description available."); - var commands = GetCommands(name); - foreach (var c in commands) - { - for (var i = 0; i < c.Names.Count; i++) - { - c.Names[i] = "/" + c.Names[i]; - } - } - var strs = - commands.Select( - c => - c.Name + (c.Names.Count > 1 ? " ({0})".SFormat(string.Join(" ", c.Names.ToArray(), 1, c.Names.Count - 1)) : "")); + var strs = GetCommands(name).Select(c => c.Names.Count > 1 + ? $"{c.Name} ({string.Join(" ", c.Names.Skip(1).Select(n => $"/{n}"))})" + : c.Name); sb.AppendLine($"## {name}"); sb.AppendLine($"{desc}"); diff --git a/docs/changelog.md b/docs/changelog.md index 3f64f355..d7b1d19f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,7 +78,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. --> ## Upcoming changes -Your changes could be here! +* Fixed `/dump-reference-data` mutate the command names. (#2943, @sgkoishi) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From 51ecef73a16dd1df10bf093ef529be57c5bd1b64 Mon Sep 17 00:00:00 2001 From: Stargazing Koishi Date: Sat, 13 May 2023 04:09:15 -0700 Subject: [PATCH 08/94] Optimize Linq Co-authored-by: Arthri <41360489+Arthri@users.noreply.github.com> --- TShockAPI/Permissions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index debc8ea5..99ac5d7d 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -530,8 +530,8 @@ namespace TShockAPI var desc = descattr != null && !string.IsNullOrWhiteSpace(descattr.Description) ? descattr.Description : GetString("No description available."); var strs = GetCommands(name).Select(c => c.Names.Count > 1 - ? $"{c.Name} ({string.Join(" ", c.Names.Skip(1).Select(n => $"/{n}"))})" - : c.Name); + ? $"/{c.Name} (/{string.Join(" /", c.Names.Skip(1))})" + : $"/{c.Name}"); sb.AppendLine($"## {name}"); sb.AppendLine($"{desc}"); From c3f5994451b02a0b93230b41519f34fa97ac9a9a Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 10:08:02 +0700 Subject: [PATCH 09/94] Added optional arguments `stack` and `prefixId` to the `NetItem` constructor --- TShockAPI/NetItem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/NetItem.cs b/TShockAPI/NetItem.cs index 278fda1c..03596a1f 100644 --- a/TShockAPI/NetItem.cs +++ b/TShockAPI/NetItem.cs @@ -155,7 +155,7 @@ namespace TShockAPI /// The net ID. /// The stack. /// The prefix ID. - public NetItem(int netId, int stack, byte prefixId) + public NetItem(int netId, int stack = 1, byte prefixId = 0) { _netId = netId; _stack = stack; From 62b8e5067ce3d97055ff7ed8063d9994909816c4 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 10:13:25 +0700 Subject: [PATCH 10/94] Added the `NetItem.Build' method. The method will create a Terraria.Item instance based on the data from the structure. --- TShockAPI/NetItem.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/TShockAPI/NetItem.cs b/TShockAPI/NetItem.cs index 03596a1f..095d3f1c 100644 --- a/TShockAPI/NetItem.cs +++ b/TShockAPI/NetItem.cs @@ -162,6 +162,24 @@ namespace TShockAPI _prefixId = prefixId; } + /// + /// Creates based on data from this structure. + /// + /// A copy of the item. + /// If the item ID is 0. + public Item Build() + { + if (_netId == 0) + throw new Exception("It is impossible to create an item whose ID is 0."); + Item item = new Item(); + + item.netDefaults(_netId); + item.stack = _stack; + item.prefix = _prefixId; + + return item; + } + /// /// Converts the to a string. /// From 86be1738ccc2f6d8930d4fe3dea411acc310dd49 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 10:13:59 +0700 Subject: [PATCH 11/94] Added a constructor with arguments taking `Terraria.Item`. --- TShockAPI/NetItem.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/TShockAPI/NetItem.cs b/TShockAPI/NetItem.cs index 095d3f1c..86fe82a7 100644 --- a/TShockAPI/NetItem.cs +++ b/TShockAPI/NetItem.cs @@ -162,6 +162,17 @@ namespace TShockAPI _prefixId = prefixId; } + /// + /// Creates a new . + /// + /// Item in the game. + public NetItem(Item item) + { + _netId = item.netID; + _stack = item.stack; + _prefixId = item.prefix; + } + /// /// Creates based on data from this structure. /// From 7ab05707869366b884cce0680efee356cfc6ea7e Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 10:22:39 +0700 Subject: [PATCH 12/94] Update changelog.md --- docs/changelog.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 3f64f355..54e6ff66 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,7 +78,10 @@ Use past tense when adding new entries; sign your name off when you add or chang * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. --> ## Upcoming changes -Your changes could be here! +* Updated `TShockAPI.NetItem` (@AgaSpace): + * Added constructor overload with parameter `Terraria.Item`. + * Added the `Build` method to get a copy of `Terraria.Item`. + * In the constructor I added optional parameters `stack` and `prefix`. ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From 2e8823434c298e3052674add48d54b83fb658cae Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 10:30:52 +0700 Subject: [PATCH 13/94] Updated the PlayerData constructors. Added a new constructor with a parameter that is responsible for installing TShock items into inventory. The `TSPlayer` parameter was not used, so I labeled the constructor obsolete. --- TShockAPI/PlayerData.cs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/TShockAPI/PlayerData.cs b/TShockAPI/PlayerData.cs index 2a8dd41f..aae27672 100644 --- a/TShockAPI/PlayerData.cs +++ b/TShockAPI/PlayerData.cs @@ -23,6 +23,7 @@ using Terraria.Localization; using Terraria.GameContent.NetModules; using Terraria.Net; using Terraria.ID; +using System; namespace TShockAPI { @@ -63,18 +64,27 @@ namespace TShockAPI public int unlockedSuperCart; public int enabledSuperCart; - public PlayerData(TSPlayer player) + /// + /// Sets the default values for the inventory. + /// + [Obsolete("The player argument is not used.")] + public PlayerData(TSPlayer player) : this(true) { } + + /// + /// Sets the default values for the inventory. + /// + /// Is it necessary to load items from TShock's config + public PlayerData(bool includingStarterInventory = true) { for (int i = 0; i < NetItem.MaxInventory; i++) - { this.inventory[i] = new NetItem(); - } - for (int i = 0; i < TShock.ServerSideCharacterConfig.Settings.StartingInventory.Count; i++) - { - var item = TShock.ServerSideCharacterConfig.Settings.StartingInventory[i]; - StoreSlot(i, item.NetId, item.PrefixId, item.Stack); - } + if (includingStarterInventory) + for (int i = 0; i < TShock.ServerSideCharacterConfig.Settings.StartingInventory.Count; i++) + { + var item = TShock.ServerSideCharacterConfig.Settings.StartingInventory[i]; + StoreSlot(i, item.NetId, item.PrefixId, item.Stack); + } } /// From 763519150a5a4ab4fdca7435cdf0dfa8c3d3e246 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 10:33:54 +0700 Subject: [PATCH 14/94] Updated the `PlayerData.StoreSlot` method Removed the ability to call a method when a slot less than 0 is specified. Added an overload that takes `NetItem` in parameters. --- TShockAPI/PlayerData.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/TShockAPI/PlayerData.cs b/TShockAPI/PlayerData.cs index aae27672..b2866eb1 100644 --- a/TShockAPI/PlayerData.cs +++ b/TShockAPI/PlayerData.cs @@ -96,12 +96,22 @@ namespace TShockAPI /// public void StoreSlot(int slot, int netID, byte prefix, int stack) { - if (slot > (this.inventory.Length - 1)) //if the slot is out of range then dont save + StoreSlot(slot, new NetItem(netID, stack, prefix)); + } + + /// + /// Stores an item at the specific storage slot + /// + /// + /// + public void StoreSlot(int slot, NetItem item) + { + if (slot > (this.inventory.Length - 1) || slot < 0) //if the slot is out of range then dont save { return; } - this.inventory[slot] = new NetItem(netID, stack, prefix); + this.inventory[slot] = item; } /// From b184133a7f8594e84bf8dca16d0c1525715477fd Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 10:43:01 +0700 Subject: [PATCH 15/94] Updated the call to the obsolete constructor `PlayerData` --- TShockAPI/DB/CharacterManager.cs | 2 +- TShockAPI/GetDataHandlers.cs | 4 ++-- TShockAPI/TSPlayer.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/TShockAPI/DB/CharacterManager.cs b/TShockAPI/DB/CharacterManager.cs index 5a5e13a6..357dc746 100644 --- a/TShockAPI/DB/CharacterManager.cs +++ b/TShockAPI/DB/CharacterManager.cs @@ -79,7 +79,7 @@ namespace TShockAPI.DB public PlayerData GetPlayerData(TSPlayer player, int acctid) { - PlayerData playerData = new PlayerData(player); + PlayerData playerData = new PlayerData(false); try { diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 1ef2f4f8..f82b7a8e 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2619,9 +2619,9 @@ namespace TShockAPI private static bool HandleConnecting(GetDataHandlerArgs args) { var account = TShock.UserAccounts.GetUserAccountByName(args.Player.Name);// - args.Player.DataWhenJoined = new PlayerData(args.Player); + args.Player.DataWhenJoined = new PlayerData(false); args.Player.DataWhenJoined.CopyCharacter(args.Player); - args.Player.PlayerData = new PlayerData(args.Player); + args.Player.PlayerData = new PlayerData(false); args.Player.PlayerData.CopyCharacter(args.Player); if (account != null && !TShock.Config.Settings.DisableUUIDLogin) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index ef5c3c22..afbd3176 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1267,7 +1267,7 @@ namespace TShockAPI } } - PlayerData = new PlayerData(this); + PlayerData = new PlayerData(); Group = TShock.Groups.GetGroupByName(TShock.Config.Settings.DefaultGuestGroupName); tempGroup = null; if (tempGroupTimer != null) From 8ccb3c6210077c8ddaf90dcc799ac096a0362b39 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 10:43:12 +0700 Subject: [PATCH 16/94] Update changelog.md --- docs/changelog.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 3f64f355..93485b3f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,7 +78,9 @@ Use past tense when adding new entries; sign your name off when you add or chang * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. --> ## Upcoming changes -Your changes could be here! +* Added a constructor for `TShockAPI.PlayerData` that accepts the `includingStarterInventory` parameter, which is responsible for loading the TShock inventory. +* Declared the constructor `TShockAPI.PlayerData` accepting the argument `TShockAPI.TSPlayer` obsolete. +* Updated the `PlayerData.StoreSlot` method: Added an overload that takes `TShockAPI.NetItem`. ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From 22d8575e01bad823c7e6fac60e24413d77bde990 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 12:04:17 +0700 Subject: [PATCH 17/94] Corrected the `UserAccountNotExistException` documentation. --- TShockAPI/DB/UserManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index 0354989e..7b8fe4a2 100644 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -619,7 +619,7 @@ namespace TShockAPI.DB public class UserAccountNotExistException : UserAccountManagerException { /// Creates a new UserAccountNotExistException object, with the user account name in the message. - /// The user account name to be pasesd in the message. + /// The user account name to be passed in the message. /// A new UserAccountNotExistException object with a message containing the user account name that does not exist. public UserAccountNotExistException(string name) : base(GetString($"User account {name} does not exist")) From 8a0920b6eabadb40bc43cb65a4eb565366ff0f75 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 12:08:11 +0700 Subject: [PATCH 18/94] Added a hook `AccountHooks.AccountGroupUpdate`. --- TShockAPI/Hooks/AccountHooks.cs | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/TShockAPI/Hooks/AccountHooks.cs b/TShockAPI/Hooks/AccountHooks.cs index 9c08b26d..e224b467 100644 --- a/TShockAPI/Hooks/AccountHooks.cs +++ b/TShockAPI/Hooks/AccountHooks.cs @@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +using System.ComponentModel; using TShockAPI.DB; namespace TShockAPI.Hooks { @@ -39,6 +40,37 @@ namespace TShockAPI.Hooks } } + public abstract class AccountGroupUpdateEventArgs : HandledEventArgs + { + public string AccountName { get; private set; } + public Group Group { get; set; } + + public AccountGroupUpdateEventArgs(string accountName, Group group) + { + this.AccountName = accountName; + this.Group = group; + } + } + + public class AccountGroupUpdateByPluginEventArgs : AccountGroupUpdateEventArgs + { + public AccountGroupUpdateByPluginEventArgs(string accountName, Group group) : base(accountName, group) + { + } + } + public class AccountGroupUpdateByPlayerEventArgs : AccountGroupUpdateEventArgs + { + /// + /// The player who updated the user's group + /// + public TSPlayer Player { get; private set; } + + public AccountGroupUpdateByPlayerEventArgs(TSPlayer player, string accountName, Group group) : base(accountName, group) + { + this.Player = player; + } + } + public class AccountHooks { public delegate void AccountCreateD(AccountCreateEventArgs e); @@ -62,5 +94,25 @@ namespace TShockAPI.Hooks AccountDelete(new AccountDeleteEventArgs(u)); } + + public delegate void AccountGroupUpdateD(AccountGroupUpdateEventArgs e); + public static event AccountGroupUpdateD AccountGroupUpdate; + + public static bool OnAccountGroupUpdate(UserAccount account, TSPlayer author, ref Group group) + { + AccountGroupUpdateEventArgs args = new AccountGroupUpdateByPlayerEventArgs(author, account.Name, group); + AccountGroupUpdate?.Invoke(args); + group = args.Group; + + return args.Handled; + } + public static bool OnAccountGroupUpdate(UserAccount account, ref Group group) + { + AccountGroupUpdateEventArgs args = new AccountGroupUpdateByPluginEventArgs(account.Name, group); + AccountGroupUpdate?.Invoke(args); + group = args.Group; + + return args.Handled; + } } } From 1e037748c1d511fdc3449ff6261a55a049b4e96d Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 12:13:56 +0700 Subject: [PATCH 19/94] Updated the `UserManager.SetUserGroup`. Added an exception `UserGroupUpdateLockedException`, which appears when a hook locks a group change. Added an overload for `UserManager.SetUserGroup`, with the `TSPlayer` parameter (author) --- TShockAPI/DB/UserManager.cs | 51 ++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index 7b8fe4a2..6411b289 100644 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -25,6 +25,7 @@ using MySql.Data.MySqlClient; using System.Text.RegularExpressions; using BCrypt.Net; using System.Security.Cryptography; +using TShockAPI.Hooks; namespace TShockAPI.DB { @@ -166,7 +167,41 @@ namespace TShockAPI.DB if (null == grp) throw new GroupNotExistsException(group); - if (_database.Query("UPDATE Users SET UserGroup = @0 WHERE Username = @1;", group, account.Name) == 0) + if (AccountHooks.OnAccountGroupUpdate(account, ref grp)) + throw new UserGroupUpdateLockedException(account.Name); + + if (_database.Query("UPDATE Users SET UserGroup = @0 WHERE Username = @1;", grp.Name, account.Name) == 0) + throw new UserAccountNotExistException(account.Name); + + try + { + // Update player group reference for any logged in player + foreach (var player in TShock.Players.Where(p => p != null && p.Account != null && p.Account.Name == account.Name)) + { + player.Group = grp; + } + } + catch (Exception ex) + { + throw new UserAccountManagerException(GetString("SetUserGroup SQL returned an error"), ex); + } + } + /// + /// Sets the group for a given username + /// + /// Who changes the group + /// The user account + /// The user account group to be set + public void SetUserGroup(TSPlayer author, UserAccount account, string group) + { + Group grp = TShock.Groups.GetGroupByName(group); + if (null == grp) + throw new GroupNotExistsException(group); + + if (AccountHooks.OnAccountGroupUpdate(account, author, ref grp)) + throw new UserGroupUpdateLockedException(account.Name); + + if (_database.Query("UPDATE Users SET UserGroup = @0 WHERE Username = @1;", grp.Name, account.Name) == 0) throw new UserAccountNotExistException(account.Name); try @@ -627,6 +662,20 @@ namespace TShockAPI.DB } } + /// The UserGroupUpdateLockedException used when the user group update failed and the request failed as a result.. + [Serializable] + public class UserGroupUpdateLockedException : UserAccountManagerException + { + /// Creates a new UserGroupUpdateLockedException object. + /// The name of the user who failed to change the group. + /// New UserGroupUpdateLockedException object with a message containing the name of the user account that failed to change the group. + public UserGroupUpdateLockedException(string name) : + base(GetString($"The user {name} group could not be updated")) + { + } + } + + /// A GroupNotExistsException, used when a group does not exist. [Serializable] public class GroupNotExistsException : UserAccountManagerException From 230d9b094591b196b40aff2905e90d8bf88ec9f8 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 12:17:47 +0700 Subject: [PATCH 20/94] Updated the `SetUserGroup` in the commands. --- TShockAPI/Commands.cs | 6 +++++- TShockAPI/Rest/RestManager.cs | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 2214f252..164bda89 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1176,7 +1176,7 @@ namespace TShockAPI try { - TShock.UserAccounts.SetUserGroup(account, args.Parameters[2]); + TShock.UserAccounts.SetUserGroup(args.Player, account, args.Parameters[2]); TShock.Log.ConsoleInfo(GetString("{0} changed account {1} to group {2}.", args.Player.Name, account.Name, args.Parameters[2])); args.Player.SendSuccessMessage(GetString("Account {0} has been changed to group {1}.", account.Name, args.Parameters[2])); @@ -1193,6 +1193,10 @@ namespace TShockAPI { args.Player.SendErrorMessage(GetString($"User {account.Name} does not exist.")); } + catch (UserGroupUpdateLockedException) + { + args.Player.SendErrorMessage(GetString("Hook blocked the attempt to change the user group.")); + } catch (UserAccountManagerException e) { args.Player.SendErrorMessage(GetString($"User {account.Name} could not be added. Check console for details.")); diff --git a/TShockAPI/Rest/RestManager.cs b/TShockAPI/Rest/RestManager.cs index c41e7767..0a96b004 100644 --- a/TShockAPI/Rest/RestManager.cs +++ b/TShockAPI/Rest/RestManager.cs @@ -555,7 +555,8 @@ namespace TShockAPI { try { - TShock.UserAccounts.SetUserGroup(account, group); + TShock.UserAccounts.SetUserGroup(new TSRestPlayer(args.TokenData.Username, TShock.Groups.GetGroupByName(args.TokenData.UserGroupName)), + account, group); response.Add("group-response", "Group updated successfully"); } catch (Exception e) From 4e85c5ddac099fad4ecfb4ae472854d526729d2a Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 12:19:05 +0700 Subject: [PATCH 21/94] Update changelog.md --- docs/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 3f64f355..ebfcd895 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,7 +78,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. --> ## Upcoming changes -Your changes could be here! +* Added a hook `AccountHooks.AccountGroupUpdate`, which is called when you change the user group. (@AgaSpace) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From cc753cf1dac747db6dc613d9c0b7faed9045fdda Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Tue, 6 Jun 2023 16:00:18 +0700 Subject: [PATCH 22/94] Removed unnecessary abstraction. --- TShockAPI/Hooks/AccountHooks.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/TShockAPI/Hooks/AccountHooks.cs b/TShockAPI/Hooks/AccountHooks.cs index e224b467..ae9fff24 100644 --- a/TShockAPI/Hooks/AccountHooks.cs +++ b/TShockAPI/Hooks/AccountHooks.cs @@ -40,7 +40,7 @@ namespace TShockAPI.Hooks } } - public abstract class AccountGroupUpdateEventArgs : HandledEventArgs + public class AccountGroupUpdateEventArgs : HandledEventArgs { public string AccountName { get; private set; } public Group Group { get; set; } @@ -52,12 +52,6 @@ namespace TShockAPI.Hooks } } - public class AccountGroupUpdateByPluginEventArgs : AccountGroupUpdateEventArgs - { - public AccountGroupUpdateByPluginEventArgs(string accountName, Group group) : base(accountName, group) - { - } - } public class AccountGroupUpdateByPlayerEventArgs : AccountGroupUpdateEventArgs { /// @@ -108,7 +102,7 @@ namespace TShockAPI.Hooks } public static bool OnAccountGroupUpdate(UserAccount account, ref Group group) { - AccountGroupUpdateEventArgs args = new AccountGroupUpdateByPluginEventArgs(account.Name, group); + AccountGroupUpdateEventArgs args = new AccountGroupUpdateEventArgs(account.Name, group); AccountGroupUpdate?.Invoke(args); group = args.Group; From f18243242fcf04a15ede101db6ed827544b0e165 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Tue, 6 Jun 2023 16:12:05 +0700 Subject: [PATCH 23/94] Update Group.cs --- TShockAPI/Group.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/TShockAPI/Group.cs b/TShockAPI/Group.cs index ff2ba2e9..0858dfd4 100644 --- a/TShockAPI/Group.cs +++ b/TShockAPI/Group.cs @@ -52,17 +52,17 @@ namespace TShockAPI /// /// The group that this group inherits permissions from. /// - public Group Parent { get; set; } + public virtual Group Parent { get; set; } /// /// The chat prefix for this group. /// - public string Prefix { get; set; } + public virtual string Prefix { get; set; } /// /// The chat suffix for this group. /// - public string Suffix { get; set; } + public virtual string Suffix { get; set; } /// /// The name of the parent, not particularly sure why this is here. @@ -154,15 +154,15 @@ namespace TShockAPI /// /// The group's chat color red byte. /// - public byte R = 255; + public virtual byte R { get; set; } = 255; /// /// The group's chat color green byte. /// - public byte G = 255; + public virtual byte G { get; set; } = 255; /// /// The group's chat color blue byte. /// - public byte B = 255; + public virtual byte B { get; set; } = 255; /// /// The default group attributed to unregistered users. @@ -242,7 +242,7 @@ namespace TShockAPI /// Adds a permission to the list of negated permissions. /// /// The permission to negate. - public void NegatePermission(string permission) + public virtual void NegatePermission(string permission) { // Avoid duplicates if (!negatedpermissions.Contains(permission)) @@ -256,7 +256,7 @@ namespace TShockAPI /// Adds a permission to the list of permissions. /// /// The permission to add. - public void AddPermission(string permission) + public virtual void AddPermission(string permission) { if (permission.StartsWith("!")) { @@ -276,7 +276,7 @@ namespace TShockAPI /// will parse "!permission" and add it to the negated permissions. /// /// The new list of permissions to associate with the group. - public void SetPermission(List permission) + public virtual void SetPermission(List permission) { permissions.Clear(); negatedpermissions.Clear(); @@ -288,7 +288,7 @@ namespace TShockAPI /// where "!permission" will remove a negated permission. /// /// - public void RemovePermission(string permission) + public virtual void RemovePermission(string permission) { if (permission.StartsWith("!")) { @@ -302,7 +302,7 @@ namespace TShockAPI /// Assigns all fields of this instance to another. /// /// The other instance. - public void AssignTo(Group otherGroup) + public virtual void AssignTo(Group otherGroup) { otherGroup.Name = Name; otherGroup.Parent = Parent; From 121afa963cbff2910f4418851371700dba124651 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Tue, 6 Jun 2023 16:18:48 +0700 Subject: [PATCH 24/94] Added a `Group.Color` --- TShockAPI/Group.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/TShockAPI/Group.cs b/TShockAPI/Group.cs index 0858dfd4..f0d64b2d 100644 --- a/TShockAPI/Group.cs +++ b/TShockAPI/Group.cs @@ -20,6 +20,8 @@ using System; using System.Linq; using System.Collections.Generic; +using Microsoft.Xna.Framework; + namespace TShockAPI { /// @@ -164,6 +166,17 @@ namespace TShockAPI /// public virtual byte B { get; set; } = 255; + public virtual Color Color + { + get => new Color(R, G, B); + set + { + R = value.R; + G = value.G; + B = value.B; + } + } + /// /// The default group attributed to unregistered users. /// From 73e2440043f172355d537a1ef1fe5a8159caa939 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Tue, 6 Jun 2023 16:21:52 +0700 Subject: [PATCH 25/94] Added XML documentation. --- TShockAPI/Group.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TShockAPI/Group.cs b/TShockAPI/Group.cs index f0d64b2d..0867a8a0 100644 --- a/TShockAPI/Group.cs +++ b/TShockAPI/Group.cs @@ -166,6 +166,9 @@ namespace TShockAPI /// public virtual byte B { get; set; } = 255; + /// + /// Simplifies work with the , , properties. + /// public virtual Color Color { get => new Color(R, G, B); From 914d7432646080ab7eae8d0ccebd4c375f7c7439 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Tue, 6 Jun 2023 19:15:58 +0700 Subject: [PATCH 26/94] Changed the method from `NetItem.Build` to `NetItem.ToItem`. --- TShockAPI/NetItem.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/NetItem.cs b/TShockAPI/NetItem.cs index 86fe82a7..0a3e0c99 100644 --- a/TShockAPI/NetItem.cs +++ b/TShockAPI/NetItem.cs @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -178,7 +178,7 @@ namespace TShockAPI /// /// A copy of the item. /// If the item ID is 0. - public Item Build() + public Item ToItem() { if (_netId == 0) throw new Exception("It is impossible to create an item whose ID is 0."); From a917beaca0ae3f63774fbb212bce51cd5d0f41e5 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Wed, 7 Jun 2023 23:44:04 +0700 Subject: [PATCH 27/94] Update changelog.md --- docs/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 3f64f355..ec7f000f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,7 +78,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. --> ## Upcoming changes -Your changes could be here! +* Added more modification options to `Group`. (@AgaSpace) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From dc817911346ac7c82180553d53a45d3325c5b5ab Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 8 Jun 2023 12:41:11 +0700 Subject: [PATCH 28/94] Removed RGB properties --- TShockAPI/Group.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TShockAPI/Group.cs b/TShockAPI/Group.cs index 0867a8a0..45086eef 100644 --- a/TShockAPI/Group.cs +++ b/TShockAPI/Group.cs @@ -156,15 +156,15 @@ namespace TShockAPI /// /// The group's chat color red byte. /// - public virtual byte R { get; set; } = 255; + public byte R = 255; /// /// The group's chat color green byte. /// - public virtual byte G { get; set; } = 255; + public byte G = 255; /// /// The group's chat color blue byte. /// - public virtual byte B { get; set; } = 255; + public byte B = 255; /// /// Simplifies work with the , , properties. From 3a90029d5199e724baeaf04a1aea010b9be3e103 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 8 Jun 2023 16:33:32 +0700 Subject: [PATCH 29/94] Allowed to receive an item if it is 0. --- TShockAPI/NetItem.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/TShockAPI/NetItem.cs b/TShockAPI/NetItem.cs index 0a3e0c99..13f3f49d 100644 --- a/TShockAPI/NetItem.cs +++ b/TShockAPI/NetItem.cs @@ -180,8 +180,6 @@ namespace TShockAPI /// If the item ID is 0. public Item ToItem() { - if (_netId == 0) - throw new Exception("It is impossible to create an item whose ID is 0."); Item item = new Item(); item.netDefaults(_netId); From b3f314985070afc450da441524698c1640d6dccc Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 8 Jun 2023 16:34:06 +0700 Subject: [PATCH 30/94] Update changelog.md --- docs/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 54e6ff66..e02dcbdc 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -80,7 +80,7 @@ Use past tense when adding new entries; sign your name off when you add or chang ## Upcoming changes * Updated `TShockAPI.NetItem` (@AgaSpace): * Added constructor overload with parameter `Terraria.Item`. - * Added the `Build` method to get a copy of `Terraria.Item`. + * Added the `ToItem` method to get a copy of `Terraria.Item`. * In the constructor I added optional parameters `stack` and `prefix`. ## TShock 5.2 From 4eb2aa49de40e5c64b4dc09acacdf554634737c6 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 8 Jun 2023 18:11:26 +0700 Subject: [PATCH 31/94] Removed unnecessary documentation --- TShockAPI/NetItem.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/TShockAPI/NetItem.cs b/TShockAPI/NetItem.cs index 13f3f49d..0f0dc6e3 100644 --- a/TShockAPI/NetItem.cs +++ b/TShockAPI/NetItem.cs @@ -177,7 +177,6 @@ namespace TShockAPI /// Creates based on data from this structure. /// /// A copy of the item. - /// If the item ID is 0. public Item ToItem() { Item item = new Item(); From 5498f84942c5487b651214db20a331c7f7b87dc6 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 8 Jun 2023 18:12:25 +0700 Subject: [PATCH 32/94] Update changelog.md --- docs/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index e02dcbdc..d1f486b2 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -81,7 +81,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Updated `TShockAPI.NetItem` (@AgaSpace): * Added constructor overload with parameter `Terraria.Item`. * Added the `ToItem` method to get a copy of `Terraria.Item`. - * In the constructor I added optional parameters `stack` and `prefix`. + * In the constructor `stack` and `prefix` are now optional parameters. ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From b5b72e9f6c4a6d439ddc158fb6d01fb8391a0257 Mon Sep 17 00:00:00 2001 From: James Puleo Date: Fri, 9 Jun 2023 03:00:45 -0400 Subject: [PATCH 33/94] Ensure `TSPlayer.PlayerData` is non-null whilst syncing loadouts During connection, we receive a `SyncLoadout` packet before the `ContinueConnecting2` packet, meaning we have not yet created a `PlayerData` for this player. --- TShockAPI/GetDataHandlers.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 1ef2f4f8..b736a512 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -4445,6 +4445,11 @@ namespace TShockAPI return true; } + // Don't modify the player data if it isn't there. + // This is the case whilst the player is connecting, as we receive the SyncLoadout packet before the ContinueConnecting2 packet. + if (args.Player.PlayerData == null) + return false; + // The client does not sync slot changes when changing loadouts, it only tells the server the loadout index changed, // and the server will replicate the changes the client did. This means that PlayerData.StoreSlot is never called, so we need to // swap around the PlayerData items ourself. From fbc1d9dc8d792f3b9511736276ca40e8d7b35184 Mon Sep 17 00:00:00 2001 From: James Puleo Date: Fri, 9 Jun 2023 03:05:43 -0400 Subject: [PATCH 34/94] Update `docs/changelog.md` --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index f02867f8..d329a6df 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -88,6 +88,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Added a method `TSPlayer.UpdateSection` with arguments `rectangle` and `isLoaded`, which will load some area from the server to the player. (@AgaSpace) * Added a method `TSPlayer.GiveItem`, which has `TShockAPI.NetItem` structure in its arguments. (@AgaSpace) * Added a property `TSPlayer.Hostile`, which gets pvp player mode. +* Ensured `TSPlayer.PlayerData` is non-null whilst syncing loadouts. (@drunderscore) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From a6666ff21abf1d40133a98eb5dfe2e5e0c6b8c58 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sat, 10 Jun 2023 13:59:38 +0700 Subject: [PATCH 35/94] Updated the message --- TShockAPI/DB/UserManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index 6411b289..6fc50d98 100644 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -670,7 +670,7 @@ namespace TShockAPI.DB /// The name of the user who failed to change the group. /// New UserGroupUpdateLockedException object with a message containing the name of the user account that failed to change the group. public UserGroupUpdateLockedException(string name) : - base(GetString($"The user {name} group could not be updated")) + base(GetString($"Unable to update group of user {name}.")) { } } From ffed36c6fd9f1003f7d9f7094867d89420212e4d Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 15 Jun 2023 12:00:13 +0700 Subject: [PATCH 36/94] Added hooks --- TShockAPI/Hooks/PlayerHooks.cs | 101 +++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/TShockAPI/Hooks/PlayerHooks.cs b/TShockAPI/Hooks/PlayerHooks.cs index 7a3e2067..e6b68581 100644 --- a/TShockAPI/Hooks/PlayerHooks.cs +++ b/TShockAPI/Hooks/PlayerHooks.cs @@ -119,6 +119,53 @@ namespace TShockAPI.Hooks public string CommandPrefix { get; set; } } + /// + /// EventArgs used for the event. + /// + public class PrePlayerCommandEventArgs : HandledEventArgs + { + /// + /// The command entered by the player. + /// + public Command Command { get; } + /// + /// Command arguments. + /// + public CommandArgs Arguments { get; set; } + + public PrePlayerCommandEventArgs(Command command, CommandArgs args) + { + Command = command; + Arguments = args; + } + } + + /// + /// EventArgs used for the event. + /// + public class PostPlayerCommandEventArgs + { + /// + /// The command entered by the player. + /// + public Command Command { get; } + /// + /// Command arguments. + /// + public CommandArgs Arguments { get; } + /// + /// Is the command executed. + /// + public bool Handled { get; } + + public PostPlayerCommandEventArgs(Command command, CommandArgs arguments, bool handled) + { + Command = command; + Arguments = arguments; + Handled = handled; + } + } + /// /// EventArgs used for the event. /// @@ -343,6 +390,26 @@ namespace TShockAPI.Hooks /// public static event PlayerCommandD PlayerCommand; + /// + /// The delegate of the event. + /// + /// The EventArgs for this event. + public delegate void PrePlayerCommandD(PrePlayerCommandEventArgs e); + /// + /// Fired before the command is run. + /// + public static event PrePlayerCommandD PrePlayerCommand; + + /// + /// The delegate of the event. + /// + /// The EventArgs for this event. + public delegate void PostPlayerCommandD(PostPlayerCommandEventArgs e); + /// + /// Fired after the command is run. + /// + public static event PostPlayerCommandD PostPlayerCommand; + /// /// The delegate of the event. /// @@ -449,6 +516,40 @@ namespace TShockAPI.Hooks return playerCommandEventArgs.Handled; } + /// + /// Fires the event. + /// + /// Command to be executed + /// Command arguments + /// True if the event has been handled. + public static bool OnPrePlayerCommand(Command cmd, ref CommandArgs arguments) + { + if (PrePlayerCommand == null) + return false; + + PrePlayerCommandEventArgs args = new PrePlayerCommandEventArgs(cmd, arguments); + + PrePlayerCommand(args); + + arguments = args.Arguments; + return args.Handled; + } + + /// + /// Fires the event. + /// + /// Executed command. + /// Command arguments. + /// Is the command executed. + public static void OnPostPlayerCommand(Command cmd, CommandArgs arguments, bool handled) + { + if (PostPlayerCommand == null) + return; + + PostPlayerCommandEventArgs args = new PostPlayerCommandEventArgs(cmd, arguments, handled); + PostPlayerCommand(args); + } + /// /// Fires the event. /// From 380f823e6186667e5379f867ec09b66b66b0fa60 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 15 Jun 2023 12:00:49 +0700 Subject: [PATCH 37/94] Added a `Run` overload to `Command`. The overload executes the CommandArgs you want. --- TShockAPI/Commands.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 2214f252..f10be370 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -148,24 +148,29 @@ namespace TShockAPI Permissions = new List(); } - public bool Run(string msg, bool silent, TSPlayer ply, List parms) + public bool Run(CommandArgs args) { - if (!CanRun(ply)) + if (!CanRun(args.Player)) return false; try { - CommandDelegate(new CommandArgs(msg, silent, ply, parms)); + CommandDelegate(args); } catch (Exception e) { - ply.SendErrorMessage(GetString("Command failed, check logs for more details.")); + args.Player.SendErrorMessage(GetString("Command failed, check logs for more details.")); TShock.Log.Error(e.ToString()); } return true; } + public bool Run(string msg, bool silent, TSPlayer ply, List parms) + { + return Run(new CommandArgs(msg, silent, ply, parms)); + } + public bool Run(string msg, TSPlayer ply, List parms) { return Run(msg, false, ply, parms); @@ -704,7 +709,12 @@ namespace TShockAPI TShock.Utils.SendLogs(GetString("{0} executed: {1}{2}.", player.Name, silent ? SilentSpecifier : Specifier, cmdText), Color.PaleVioletRed, player); else TShock.Utils.SendLogs(GetString("{0} executed (args omitted): {1}{2}.", player.Name, silent ? SilentSpecifier : Specifier, cmdName), Color.PaleVioletRed, player); - cmd.Run(cmdText, silent, player, args); + + CommandArgs arguments = new CommandArgs(cmdText, silent, player, args); + bool handled = PlayerHooks.OnPrePlayerCommand(cmd, ref arguments); + if (!handled) + cmd.Run(arguments); + PlayerHooks.OnPostPlayerCommand(cmd, arguments, handled); } } return true; From 7a3b2e051f6d7fe7dd012d0457f83050238360d0 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 15 Jun 2023 12:11:44 +0700 Subject: [PATCH 38/94] Update changelog.md --- docs/changelog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 3f64f355..f5a0003c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,7 +78,8 @@ Use past tense when adding new entries; sign your name off when you add or chang * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. --> ## Upcoming changes -Your changes could be here! +* Added `PlayerHooks.PrePlayerCommand` hook, which fired before command execution. +* Added `PlayerHooks.PostPlayerCommand` hook, which fired after command execution. ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From a656a1cc198014e06514c62b4f11456b29db0773 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 15 Jun 2023 12:17:11 +0700 Subject: [PATCH 39/94] Added authorship --- docs/changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index f5a0003c..52868390 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,8 +78,8 @@ Use past tense when adding new entries; sign your name off when you add or chang * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. --> ## Upcoming changes -* Added `PlayerHooks.PrePlayerCommand` hook, which fired before command execution. -* Added `PlayerHooks.PostPlayerCommand` hook, which fired after command execution. +* Added `PlayerHooks.PrePlayerCommand` hook, which fired before command execution. (@AgaSpace) +* Added `PlayerHooks.PostPlayerCommand` hook, which fired after command execution. (@AgaSpace) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From 1ef96f9537131aa5df55900ecbc39b69bc210935 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 15 Jun 2023 13:01:52 +0700 Subject: [PATCH 40/94] Marked the `PlayerCommand` hook as obsolete. --- TShockAPI/Hooks/PlayerHooks.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TShockAPI/Hooks/PlayerHooks.cs b/TShockAPI/Hooks/PlayerHooks.cs index e6b68581..15cac88d 100644 --- a/TShockAPI/Hooks/PlayerHooks.cs +++ b/TShockAPI/Hooks/PlayerHooks.cs @@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +using System; using System.Collections.Generic; using System.ComponentModel; using TShockAPI.DB; @@ -388,6 +389,7 @@ namespace TShockAPI.Hooks /// /// Fired by players when using a command. /// + [Obsolete("There is an alternative to PlayerHooks.PrePlayerCommand")] public static event PlayerCommandD PlayerCommand; /// From 21422f25fd3b4c3a0476ea1e83ee0de8d8895cf4 Mon Sep 17 00:00:00 2001 From: Zoom L1 <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 15 Jun 2023 15:51:01 +0700 Subject: [PATCH 41/94] Update TShockAPI/Hooks/PlayerHooks.cs Co-authored-by: Arthri <41360489+Arthri@users.noreply.github.com> --- TShockAPI/Hooks/PlayerHooks.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Hooks/PlayerHooks.cs b/TShockAPI/Hooks/PlayerHooks.cs index 15cac88d..8135a3f9 100644 --- a/TShockAPI/Hooks/PlayerHooks.cs +++ b/TShockAPI/Hooks/PlayerHooks.cs @@ -408,7 +408,7 @@ namespace TShockAPI.Hooks /// The EventArgs for this event. public delegate void PostPlayerCommandD(PostPlayerCommandEventArgs e); /// - /// Fired after the command is run. + /// Fired after a command is run. /// public static event PostPlayerCommandD PostPlayerCommand; From b40f0e632e1dfb8966dca14a9ee707318a1ed12f Mon Sep 17 00:00:00 2001 From: Zoom L1 <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 15 Jun 2023 16:01:43 +0700 Subject: [PATCH 42/94] Update TShockAPI/Hooks/PlayerHooks.cs Co-authored-by: Arthri <41360489+Arthri@users.noreply.github.com> --- TShockAPI/Hooks/PlayerHooks.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Hooks/PlayerHooks.cs b/TShockAPI/Hooks/PlayerHooks.cs index 8135a3f9..dd35d662 100644 --- a/TShockAPI/Hooks/PlayerHooks.cs +++ b/TShockAPI/Hooks/PlayerHooks.cs @@ -398,7 +398,7 @@ namespace TShockAPI.Hooks /// The EventArgs for this event. public delegate void PrePlayerCommandD(PrePlayerCommandEventArgs e); /// - /// Fired before the command is run. + /// Fired before a command is run. /// public static event PrePlayerCommandD PrePlayerCommand; From db40d5034833e0a0833d50de3e87d2da99b08af7 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 15 Jun 2023 16:03:43 +0700 Subject: [PATCH 43/94] Updated the message --- TShockAPI/Hooks/PlayerHooks.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Hooks/PlayerHooks.cs b/TShockAPI/Hooks/PlayerHooks.cs index dd35d662..183205fe 100644 --- a/TShockAPI/Hooks/PlayerHooks.cs +++ b/TShockAPI/Hooks/PlayerHooks.cs @@ -389,7 +389,7 @@ namespace TShockAPI.Hooks /// /// Fired by players when using a command. /// - [Obsolete("There is an alternative to PlayerHooks.PrePlayerCommand")] + [Obsolete("Use PlayerHooks.PrePlayerCommand.")] public static event PlayerCommandD PlayerCommand; /// From 723719350b07daf84ec14aa12d57e1d6691697b4 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 15 Jun 2023 17:37:22 +0700 Subject: [PATCH 44/94] Made `PostPlayerCommandEventArgs` inherited from `HandledEventArgs`. --- TShockAPI/Hooks/PlayerHooks.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/TShockAPI/Hooks/PlayerHooks.cs b/TShockAPI/Hooks/PlayerHooks.cs index 183205fe..b5048274 100644 --- a/TShockAPI/Hooks/PlayerHooks.cs +++ b/TShockAPI/Hooks/PlayerHooks.cs @@ -144,7 +144,7 @@ namespace TShockAPI.Hooks /// /// EventArgs used for the event. /// - public class PostPlayerCommandEventArgs + public class PostPlayerCommandEventArgs : HandledEventArgs { /// /// The command entered by the player. @@ -154,10 +154,6 @@ namespace TShockAPI.Hooks /// Command arguments. /// public CommandArgs Arguments { get; } - /// - /// Is the command executed. - /// - public bool Handled { get; } public PostPlayerCommandEventArgs(Command command, CommandArgs arguments, bool handled) { From 87fabd3d260b8bc77a47e939fdc7c756dc967b59 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Thu, 15 Jun 2023 18:44:30 +0700 Subject: [PATCH 45/94] Removed the "obsolete" tag --- TShockAPI/Hooks/PlayerHooks.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/TShockAPI/Hooks/PlayerHooks.cs b/TShockAPI/Hooks/PlayerHooks.cs index b5048274..43756464 100644 --- a/TShockAPI/Hooks/PlayerHooks.cs +++ b/TShockAPI/Hooks/PlayerHooks.cs @@ -385,7 +385,6 @@ namespace TShockAPI.Hooks /// /// Fired by players when using a command. /// - [Obsolete("Use PlayerHooks.PrePlayerCommand.")] public static event PlayerCommandD PlayerCommand; /// From b6041a738e61f9c995e2b3bbcd3c101f658f3ff5 Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Thu, 21 Dec 2023 20:39:43 -0800 Subject: [PATCH 46/94] Whitelist the Striking Moment (`ParryDamageBuff`) buff --- TShockAPI/Bouncer.cs | 6 ++++++ docs/changelog.md | 1 + 2 files changed, 7 insertions(+) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 6ff7fd1a..4a41a42c 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -434,6 +434,12 @@ namespace TShockAPI CanBeAddedWithoutHostile = true, CanOnlyBeAppliedToSender = true }; + PlayerAddBuffWhitelist[BuffID.WindPushed] = new BuffLimit + { + MaxTicks = 2, + CanBeAddedWithoutHostile = true, + CanOnlyBeAppliedToSender = true + }; #endregion Whitelist } diff --git a/docs/changelog.md b/docs/changelog.md index 035df8ad..235b5ec9 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -90,6 +90,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Added a property `TSPlayer.Hostile`, which gets pvp player mode. (@AgaSpace) * Fixed typo in `/gbuff`. (@sgkoishi, #2955) * Rewrote the `.dockerignore` file into a denylist. (@timschumi) +* Added `ParryDamageBuff` (Striking Moment with Brand of the Inferno and shield) to the `PlayerAddBuffWhitelist` (@sgkoishi, #3005) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From 3c2a3f3e53e2eb25ba3d6eeb2ebf066136dcdaa8 Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Thu, 21 Dec 2023 20:43:41 -0800 Subject: [PATCH 47/94] Add unstaged changes --- TShockAPI/Bouncer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 4a41a42c..594d76ff 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -434,9 +434,9 @@ namespace TShockAPI CanBeAddedWithoutHostile = true, CanOnlyBeAppliedToSender = true }; - PlayerAddBuffWhitelist[BuffID.WindPushed] = new BuffLimit + PlayerAddBuffWhitelist[BuffID.ParryDamageBuff] = new BuffLimit { - MaxTicks = 2, + MaxTicks = 300, CanBeAddedWithoutHostile = true, CanOnlyBeAppliedToSender = true }; From cf726368c51647f6189729bead08ef658644951d Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Fri, 22 Dec 2023 13:19:58 -0800 Subject: [PATCH 48/94] Use seconds as the time unit --- TShockAPI/Bouncer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 594d76ff..22d6461a 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -424,7 +424,7 @@ namespace TShockAPI }; PlayerAddBuffWhitelist[BuffID.BrainOfConfusionBuff] = new BuffLimit { - MaxTicks = 240, + MaxTicks = 60 * 4, CanBeAddedWithoutHostile = true, CanOnlyBeAppliedToSender = true }; @@ -436,7 +436,7 @@ namespace TShockAPI }; PlayerAddBuffWhitelist[BuffID.ParryDamageBuff] = new BuffLimit { - MaxTicks = 300, + MaxTicks = 60 * 5, CanBeAddedWithoutHostile = true, CanOnlyBeAppliedToSender = true }; From dbca317639625fe3e317d05f521fb04b6cb37d96 Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Wed, 27 Dec 2023 13:01:55 -0800 Subject: [PATCH 49/94] Update CursedInferno time limit --- TShockAPI/Bouncer.cs | 2 +- docs/changelog.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 22d6461a..aed7ac04 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -2860,7 +2860,7 @@ namespace TShockAPI { BuffID.Poisoned, 3600 }, // BuffID: 20 { BuffID.OnFire, 1200 }, // BuffID: 24 { BuffID.Confused, short.MaxValue }, // BuffID: 31 Brain of Confusion Internal Item ID: 3223 - { BuffID.CursedInferno, 420 }, // BuffID: 39 + { BuffID.CursedInferno, 600 }, // BuffID: 39 { BuffID.Frostburn, 900 }, // BuffID: 44 { BuffID.Ichor, 1200 }, // BuffID: 69 { BuffID.Venom, 1800 }, // BuffID: 70 diff --git a/docs/changelog.md b/docs/changelog.md index 235b5ec9..2a4fbfcd 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -90,7 +90,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Added a property `TSPlayer.Hostile`, which gets pvp player mode. (@AgaSpace) * Fixed typo in `/gbuff`. (@sgkoishi, #2955) * Rewrote the `.dockerignore` file into a denylist. (@timschumi) -* Added `ParryDamageBuff` (Striking Moment with Brand of the Inferno and shield) to the `PlayerAddBuffWhitelist` (@sgkoishi, #3005) +* Added `ParryDamageBuff` (Striking Moment with Brand of the Inferno and shield) for player, updated `CursedInferno` buff for NPC (@sgkoishi, #3005) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From aa526223a6a941933cf7a46fb2177ef58d5eb5cc Mon Sep 17 00:00:00 2001 From: Johannes Grimm Date: Tue, 30 Jan 2024 17:55:39 +0100 Subject: [PATCH 50/94] fix: off no save command Added seting SaveOnSeverExit befor shutting down the server Fixes #2938 --- TShockAPI/Commands.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index d39b84e0..496669bb 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -2044,6 +2044,7 @@ namespace TShockAPI private static void OffNoSave(CommandArgs args) { string reason = ((args.Parameters.Count > 0) ? GetString("Server shutting down: ") + String.Join(" ", args.Parameters) : GetString("Server shutting down.")); + Netplay.SaveOnServerExit = false; TShock.Utils.StopServer(false, reason); } From 5c4db00f1e997bce7122f9da3937560d77ddfc08 Mon Sep 17 00:00:00 2001 From: Arthri <41360489+a@users.noreply.github.com> Date: Wed, 24 Apr 2024 05:31:49 +0000 Subject: [PATCH 51/94] Fix Cursed Flare --- TShockAPI/Bouncer.cs | 2 +- docs/changelog.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 6ff7fd1a..58c14b1c 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -2854,7 +2854,7 @@ namespace TShockAPI { BuffID.Poisoned, 3600 }, // BuffID: 20 { BuffID.OnFire, 1200 }, // BuffID: 24 { BuffID.Confused, short.MaxValue }, // BuffID: 31 Brain of Confusion Internal Item ID: 3223 - { BuffID.CursedInferno, 420 }, // BuffID: 39 + { BuffID.CursedInferno, 600 }, // BuffID: 39 { BuffID.Frostburn, 900 }, // BuffID: 44 { BuffID.Ichor, 1200 }, // BuffID: 69 { BuffID.Venom, 1800 }, // BuffID: 70 diff --git a/docs/changelog.md b/docs/changelog.md index 27e037d6..b1974546 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -92,6 +92,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Fixed typo in `/gbuff`. (@sgkoishi, #2955) * Rewrote the `.dockerignore` file into a denylist. (@timschumi) * Added CI for Docker images. (@timschumi) +* Fixed Cursed Flares kicking players for invalid buff. (@Arthri) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From 8df09cb4a8a8707524390265744e61e3dbe690c6 Mon Sep 17 00:00:00 2001 From: Cai <13110818005@qq.com> Date: Wed, 31 Jul 2024 19:11:50 +0800 Subject: [PATCH 52/94] fix: /help, /me, and /p commands can't work in non-English languages --- TShockAPI/Localization/EnglishLanguage.cs | 26 +++++++++++++++++++++++ TShockAPI/TShock.cs | 4 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Localization/EnglishLanguage.cs b/TShockAPI/Localization/EnglishLanguage.cs index 1ec4ecea..97507141 100644 --- a/TShockAPI/Localization/EnglishLanguage.cs +++ b/TShockAPI/Localization/EnglishLanguage.cs @@ -20,7 +20,9 @@ using System; using System.Collections.Generic; using System.Linq; using Terraria; +using Terraria.Initializers; using Terraria.Localization; +using Terraria.UI.Chat; namespace TShockAPI.Localization { @@ -37,6 +39,8 @@ namespace TShockAPI.Localization private static readonly Dictionary Buffs = new Dictionary(); + private static readonly Dictionary VanillaCommands = new Dictionary(); + internal static void Initialize() { var culture = Language.ActiveCulture; @@ -71,6 +75,15 @@ namespace TShockAPI.Localization var i = (int)field.GetValue(null); Prefixs.Add(i, Lang.prefix[i].Value); } + + ChatInitializer.Load(); + foreach (var command in ChatManager.Commands._localizedCommands) + { + if (VanillaCommands.ContainsKey(command.Value._name)) + continue; + VanillaCommands.Add(command.Value._name,command.Key.Value); + } + ChatManager.Commands._localizedCommands.Clear(); } finally { @@ -136,5 +149,18 @@ namespace TShockAPI.Localization return null; } + + /// + /// Get vanilla command text in English + /// + /// vanilla command name + /// vanilla command text English + public static string GetCommandTextByName(string name) + { + string commandText; + if (VanillaCommands.TryGetValue(name, out commandText)) + return commandText; + return null; + } } } diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 054e31df..48fab88d 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1497,11 +1497,11 @@ namespace TShockAPI { if (!String.IsNullOrEmpty(text)) { - text = item.Key.Value + ' ' + text; + text = EnglishLanguage.GetCommandTextByName(item.Value._name) + ' ' + text; } else { - text = item.Key.Value; + text = EnglishLanguage.GetCommandTextByName(item.Value._name); } break; } From b90182f1e5a8cc47057fbb809bd2ee3311c13714 Mon Sep 17 00:00:00 2001 From: Cai <13110818005@qq.com> Date: Wed, 31 Jul 2024 19:16:23 +0800 Subject: [PATCH 53/94] update changelog --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index b1974546..d2e1444e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -93,6 +93,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Rewrote the `.dockerignore` file into a denylist. (@timschumi) * Added CI for Docker images. (@timschumi) * Fixed Cursed Flares kicking players for invalid buff. (@Arthri) +* Fixed /help, /me, and /p commands can't work in non-English languages (@ACaiCat) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From a8624a816344dd39a63a701e98fe57c086613a34 Mon Sep 17 00:00:00 2001 From: Cai <13110818005@qq.com> Date: Wed, 31 Jul 2024 19:16:23 +0800 Subject: [PATCH 54/94] update changelog --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index b1974546..d2e1444e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -93,6 +93,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Rewrote the `.dockerignore` file into a denylist. (@timschumi) * Added CI for Docker images. (@timschumi) * Fixed Cursed Flares kicking players for invalid buff. (@Arthri) +* Fixed /help, /me, and /p commands can't work in non-English languages (@ACaiCat) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From 7419205548fb9779f83bc924222c1df9741ddff5 Mon Sep 17 00:00:00 2001 From: Cai <13110818005@qq.com> Date: Wed, 31 Jul 2024 19:24:53 +0800 Subject: [PATCH 55/94] rename --- TShockAPI/Localization/EnglishLanguage.cs | 14 +++++++------- TShockAPI/TShock.cs | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/TShockAPI/Localization/EnglishLanguage.cs b/TShockAPI/Localization/EnglishLanguage.cs index 97507141..334c4780 100644 --- a/TShockAPI/Localization/EnglishLanguage.cs +++ b/TShockAPI/Localization/EnglishLanguage.cs @@ -39,7 +39,7 @@ namespace TShockAPI.Localization private static readonly Dictionary Buffs = new Dictionary(); - private static readonly Dictionary VanillaCommands = new Dictionary(); + private static readonly Dictionary VanillaCommandsPrefixs = new Dictionary(); internal static void Initialize() { @@ -79,9 +79,9 @@ namespace TShockAPI.Localization ChatInitializer.Load(); foreach (var command in ChatManager.Commands._localizedCommands) { - if (VanillaCommands.ContainsKey(command.Value._name)) + if (VanillaCommandsPrefixs.ContainsKey(command.Value._name)) continue; - VanillaCommands.Add(command.Value._name,command.Key.Value); + VanillaCommandsPrefixs.Add(command.Value._name,command.Key.Value); } ChatManager.Commands._localizedCommands.Clear(); } @@ -151,14 +151,14 @@ namespace TShockAPI.Localization } /// - /// Get vanilla command text in English + /// Get vanilla command prefix in English /// /// vanilla command name - /// vanilla command text English - public static string GetCommandTextByName(string name) + /// vanilla command prefix in English + public static string GetCommandPrefixByName(string name) { string commandText; - if (VanillaCommands.TryGetValue(name, out commandText)) + if (VanillaCommandsPrefixs.TryGetValue(name, out commandText)) return commandText; return null; } diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 48fab88d..9c1015bc 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1497,11 +1497,11 @@ namespace TShockAPI { if (!String.IsNullOrEmpty(text)) { - text = EnglishLanguage.GetCommandTextByName(item.Value._name) + ' ' + text; + text = EnglishLanguage.GetCommandPrefixByName(item.Value._name) + ' ' + text; } else { - text = EnglishLanguage.GetCommandTextByName(item.Value._name); + text = EnglishLanguage.GetCommandPrefixByName(item.Value._name); } break; } From 5075997264b48e27960e3446a948ecb0ea0f5a03 Mon Sep 17 00:00:00 2001 From: quicm <2648373+quicm@users.noreply.github.com> Date: Tue, 17 Dec 2024 01:13:01 +1030 Subject: [PATCH 56/94] Add bandaid fix to RemoteClient.Reset for SecAd GHSA-hvm9-wc8j-mgrc --- TShockAPI/TShock.cs | 8 ++++++++ TShockAPI/TShockAPI.csproj | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 054e31df..bcd72aa3 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -428,6 +428,8 @@ namespace TShockAPI Hooks.AccountHooks.AccountDelete += OnAccountDelete; Hooks.AccountHooks.AccountCreate += OnAccountCreate; + On.Terraria.RemoteClient.Reset += RemoteClient_Reset; + GetDataHandlers.InitGetDataHandler(); Commands.InitCommands(); @@ -496,6 +498,12 @@ namespace TShockAPI } } + private static void RemoteClient_Reset(On.Terraria.RemoteClient.orig_Reset orig, RemoteClient client) + { + client.ClientUUID = null; + orig(client); + } + private static void OnAchievementInitializerLoad(ILContext il) { // Modify AchievementInitializer.Load to remove the Main.netMode == 2 check (occupies the first 4 IL instructions) diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index a3731709..9da8cd08 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -18,7 +18,7 @@ Also, be sure to release on github with the exact assembly version tag as below so that the update manager works correctly (via the Github releases api and mimic) --> - 5.2.0 + 5.2.1 TShock for Terraria Pryaxis & TShock Contributors TShockAPI From 3da4bf4b45ad77f96afb261aaf92c82056c7bf4c Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 3 Jan 2025 00:05:25 +0900 Subject: [PATCH 57/94] Remove inactive people from sponsors --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 8275735a..75b69d48 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,2 @@ # These are supported funding model platforms -github: [SignatureBeef, hakusaro, Stealownz, QuiCM] +github: [SignatureBeef, QuiCM] From 99701f9a8415382c8a48ecc324d988a8a579d3f0 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 4 Jan 2025 05:31:04 +0900 Subject: [PATCH 58/94] Update logo url in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b5559b37..0369df53 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

- TShock for Terraria
+ TShock for Terraria
AppVeyor Build Status From 1b31665a888769be8747637c5be51e81ff8cbf26 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 4 Jan 2025 05:31:27 +0900 Subject: [PATCH 59/94] Update logo in readme --- README_cn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_cn.md b/README_cn.md index e038817e..65c5eba6 100644 --- a/README_cn.md +++ b/README_cn.md @@ -1,5 +1,5 @@

- TShock for Terraria
+ TShock for Terraria
AppVeyor Build Status From af969898b1e54f684e48cd30bc019393725c4a00 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 3 Jan 2025 21:17:29 +0000 Subject: [PATCH 60/94] Update dependency NuGet.Packaging to 6.3.4 [SECURITY] --- TShockPluginManager/TShockPluginManager.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockPluginManager/TShockPluginManager.csproj b/TShockPluginManager/TShockPluginManager.csproj index 33c503fd..774f9819 100644 --- a/TShockPluginManager/TShockPluginManager.csproj +++ b/TShockPluginManager/TShockPluginManager.csproj @@ -7,7 +7,7 @@ - + From 68bb381ece3fca103ddb6f5c2197046de70be498 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 4 Jan 2025 13:24:14 +0100 Subject: [PATCH 61/94] docker: Bump docker/build-push-action to v6 --- .github/workflows/ci-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index deb811a2..41454ae4 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -15,7 +15,7 @@ jobs: - name: Set up buildx uses: docker/setup-buildx-action@v3 - name: Build image - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . platforms: linux/amd64,linux/arm64,linux/arm/v7,windows/amd64 From a82881b7d3a01f002c2cc15151f6c50ed5cdbc92 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 4 Jan 2025 13:33:23 +0100 Subject: [PATCH 62/94] docker: Tag and push images to GHCR automatically Co-authored-by: BrailleBennett Co-authored-by: TheSuperGamer20578 --- .github/workflows/ci-docker.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index 41454ae4..691c8e81 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -5,6 +5,8 @@ on: [push, pull_request] jobs: build: runs-on: ubuntu-latest + permissions: + packages: write steps: - name: Checkout uses: actions/checkout@v4 @@ -14,12 +16,25 @@ jobs: uses: docker/setup-qemu-action@v3 - name: Set up buildx uses: docker/setup-buildx-action@v3 + - name: Login to ghcr.io + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Generate version information + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} - name: Build image uses: docker/build-push-action@v6 with: context: . platforms: linux/amd64,linux/arm64,linux/arm/v7,windows/amd64 - push: false + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} pull: true cache-from: type=gha, scope=${{ github.workflow }} cache-to: type=gha, scope=${{ github.workflow }} From cc3d2af15f100d6b3a23a4cb252a40b67fe6e006 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 4 Jan 2025 13:45:19 +0100 Subject: [PATCH 63/94] docker: Generate build provenance attestations Co-authored-by: BrailleBennett Co-authored-by: TheSuperGamer20578 --- .github/workflows/ci-docker.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index 691c8e81..82e152a9 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -6,6 +6,8 @@ jobs: build: runs-on: ubuntu-latest permissions: + attestations: write + id-token: write packages: write steps: - name: Checkout @@ -28,6 +30,7 @@ jobs: with: images: ghcr.io/${{ github.repository }} - name: Build image + id: build uses: docker/build-push-action@v6 with: context: . @@ -38,3 +41,9 @@ jobs: pull: true cache-from: type=gha, scope=${{ github.workflow }} cache-to: type=gha, scope=${{ github.workflow }} + - name: Generate build provenance attestation + uses: actions/attest-build-provenance@v2 + with: + subject-name: ghcr.io/${{ github.repository }} + subject-digest: ${{ steps.build.outputs.digest }} + push-to-registry: true From ca3dfcdf17947b09b525fe593e2ac8bf17602a4c Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 4 Jan 2025 14:04:57 +0100 Subject: [PATCH 64/94] docker: Push semver tags if a version tag is pushed --- .github/workflows/ci-docker.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index 82e152a9..cb09fc93 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -29,6 +29,14 @@ jobs: uses: docker/metadata-action@v5 with: images: ghcr.io/${{ github.repository }} + tags: | + type=schedule + type=ref,event=branch + type=ref,event=tag,enable=${{ !startsWith(github.ref, 'refs/tags/v') }} + type=ref,event=pr + type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} + type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} + type=semver,pattern={{major}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} - name: Build image id: build uses: docker/build-push-action@v6 From 660ec5bc601f075860f77d4330cf2c37fa2180c2 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 4 Jan 2025 14:14:38 +0100 Subject: [PATCH 65/94] docker: Restrict tagging 'latest' to version tags --- .github/workflows/ci-docker.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index cb09fc93..6965c773 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -37,6 +37,8 @@ jobs: type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} type=semver,pattern={{major}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} + flavor: | + latest=${{ startsWith(github.ref, 'refs/tags/v') }} - name: Build image id: build uses: docker/build-push-action@v6 From cbdae5b15eedd5237199f0539ffc6d6b7d92e185 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 4 Jan 2025 14:29:40 +0100 Subject: [PATCH 66/94] Add a changelog entry for publishing to GHCR --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index b1974546..b5303c5f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -93,6 +93,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Rewrote the `.dockerignore` file into a denylist. (@timschumi) * Added CI for Docker images. (@timschumi) * Fixed Cursed Flares kicking players for invalid buff. (@Arthri) +* Added automatic publishing of Docker images to GHCR. (@timschumi) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From d54711651b9f2732f8200db238c710561e126e2d Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 4 Jan 2025 14:36:58 +0100 Subject: [PATCH 67/94] docker: Update documentation for officially provided Docker images --- docs/docker.md | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/docs/docker.md b/docs/docker.md index ca018510..afc4bdfc 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -14,32 +14,27 @@ Open ports can also be passed through using `-p :`. For Example: ```bash -# Building the image using buildx and loading it into docker -docker buildx build -t tshock:latest --load . - -# Running the image docker run -p 7777:7777 -p 7878:7878 \ -v /home/cider/tshock/:/tshock \ -v /home/cider/.local/share/Terraria/Worlds:/worlds \ -v /home/cider/tshock/plugins:/plugins \ - --rm -it tshock:latest \ + --rm -it ghcr.io/pryaxis/tshock:latest \ -world /worlds/backflip.wld -motd "OMFG DOCKER" ``` -## Building for Other Platforms +## Building custom images -Using `docker buildx`, you could build [multi-platform images](https://docs.docker.com/build/building/multi-platform/) for TShock. +Occasionally, it may be necessary to adjust TShock with customizations that are not included in the upstream project. +Therefore, these changes are also not available in the officially provided Docker images. + +To build and load a Docker image from your local checkout, use the following `buildx` command: -For Example: ```bash -# Building the image using buildx and loading it into docker -docker buildx build -t tshock:linux-arm64 --platform linux/arm64 --load . - -# Running the image -docker run -p 7777:7777 -p 7878:7878 \ - -v /home/cider/tshock/:/tshock \ - -v /home/cider/.local/share/Terraria/Worlds:/worlds \ - -v /home/cider/tshock/plugins:/plugins \ - --rm -it tshock:linux-arm64 \ - -world /worlds/backflip.wld -motd "ARM64 ftw" +docker buildx build -t tshock:latest --load . +``` + +It is also possible to build [multi-platform images](https://docs.docker.com/build/building/multi-platform/) for TShock (e.g. an image targeting `arm64`, on a host that is not `arm64`): + +```bash +docker buildx build -t tshock:linux-arm64 --platform linux/arm64 --load . ``` From 02ce8fdf0deac5c52a98070d9970fbd1b5654490 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sun, 5 Jan 2025 01:30:28 +0100 Subject: [PATCH 68/94] docker: Don't push to the registry for Pull Requests This requires more thought on how to handle secrets, and whether to just omit it permanently. --- .github/workflows/ci-docker.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index 6965c773..3d47d3c6 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -45,13 +45,14 @@ jobs: with: context: . platforms: linux/amd64,linux/arm64,linux/arm/v7,windows/amd64 - push: true + push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} pull: true cache-from: type=gha, scope=${{ github.workflow }} cache-to: type=gha, scope=${{ github.workflow }} - name: Generate build provenance attestation + if: ${{ github.event_name != 'pull_request' }} uses: actions/attest-build-provenance@v2 with: subject-name: ghcr.io/${{ github.repository }} From d53517104ced20ce5f7b17b8351b200d20769463 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 5 Jan 2025 10:45:58 +0000 Subject: [PATCH 69/94] Update dependency NuGet.Protocol to 6.3.3 [SECURITY] --- TShockPluginManager/TShockPluginManager.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockPluginManager/TShockPluginManager.csproj b/TShockPluginManager/TShockPluginManager.csproj index 774f9819..1d53f320 100644 --- a/TShockPluginManager/TShockPluginManager.csproj +++ b/TShockPluginManager/TShockPluginManager.csproj @@ -8,7 +8,7 @@ - + From e21322b86beb0850d4302aa9c622d5c825ea3dec Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 5 Jan 2025 10:58:00 +0000 Subject: [PATCH 70/94] Update dependency SharpZipLib to 1.4.2 --- TShockInstaller/TShockInstaller.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockInstaller/TShockInstaller.csproj b/TShockInstaller/TShockInstaller.csproj index 9b73d66a..ac3bfff4 100644 --- a/TShockInstaller/TShockInstaller.csproj +++ b/TShockInstaller/TShockInstaller.csproj @@ -12,6 +12,6 @@ - + From 78dd32a8374c9d8a0bc5b5a80b37c38708fb21f1 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 25 Jan 2025 21:28:24 +0900 Subject: [PATCH 71/94] Fix changelog versioning --- docs/changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index b1974546..54b23a8a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,6 +78,9 @@ Use past tense when adding new entries; sign your name off when you add or chang * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. --> ## Upcoming changes +* You know the drill + +## TShock 5.2.1 * Updated `TSPlayer.GodMode`. (@AgaSpace) * Previously the field was used as some kind of dataset changed by /godmode command, but now it is a property that receives/changes data in journey mode. * Added the `TSPlayer.Client` property. It allows the developer to get the `RemoteClient` player, without an additional call to `Terraria.Netplay.Clients`. (@AgaSpace) From b4968adb7d964f851633f840d407654e6e90b9aa Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 25 Jan 2025 22:27:48 +0900 Subject: [PATCH 72/94] Fix typo in config file Closes https://github.com/Pryaxis/TShock/pull/3052 --- TShockAPI/Configuration/TShockConfig.cs | 4 ++-- docs/changelog.md | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Configuration/TShockConfig.cs b/TShockAPI/Configuration/TShockConfig.cs index 79c374b2..c91466fe 100644 --- a/TShockAPI/Configuration/TShockConfig.cs +++ b/TShockAPI/Configuration/TShockConfig.cs @@ -320,8 +320,8 @@ namespace TShockAPI.Configuration [Description("The reason given if banning a mediumcore player on death.")] public string MediumcoreBanReason = GetString("Death results in a ban"); - ///

Disbales IP bans by default, if no arguments are passed to the ban command. - [Description("Disbales IP bans by default, if no arguments are passed to the ban command.")] + /// Disables IP bans by default, if no arguments are passed to the ban command. + [Description("Disables IP bans by default, if no arguments are passed to the ban command.")] public bool DisableDefaultIPBan; /// Enable or disable the whitelist based on IP addresses in the whitelist.txt file. diff --git a/docs/changelog.md b/docs/changelog.md index 683cddcb..00aec595 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -79,6 +79,8 @@ Use past tense when adding new entries; sign your name off when you add or chang ## Upcoming changes * Fixed `/dump-reference-data` mutate the command names. (#2943, @sgkoishi) +* You know the drill +* Fix typo in config for IP bans. (@redchess64) ## TShock 5.2.1 * Updated `TSPlayer.GodMode`. (@AgaSpace) From 9aba57dab6d6886f61f76a4a0597116f5efe1cb7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 25 Jan 2025 13:31:02 +0000 Subject: [PATCH 73/94] Update dependency MySql.Data to 8.4.0 --- TShockAPI/TShockAPI.csproj | 2 +- TShockLauncher/TShockLauncher.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index 9da8cd08..34df3c74 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -34,7 +34,7 @@ - + diff --git a/TShockLauncher/TShockLauncher.csproj b/TShockLauncher/TShockLauncher.csproj index e3c4ac32..fbe428bb 100644 --- a/TShockLauncher/TShockLauncher.csproj +++ b/TShockLauncher/TShockLauncher.csproj @@ -30,7 +30,7 @@ - + From 8246b95739b0a3e8e0e20491be7b1c7a6ae13275 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 25 Jan 2025 22:50:15 +0900 Subject: [PATCH 74/94] Disable stupid semantic commits --- renovate.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/renovate.json b/renovate.json index 159ec1e2..4292e678 100644 --- a/renovate.json +++ b/renovate.json @@ -1,7 +1,8 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ - "config:base" + "config:base", + ":semanticCommitsDisabled" ], "git-submodules": { "enabled": true From 7e9b97be29849720f815eecc6daa1fa523d872a6 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 25 Jan 2025 22:51:42 +0900 Subject: [PATCH 75/94] Disable renovate This is really irritating --- renovate.json | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 renovate.json diff --git a/renovate.json b/renovate.json deleted file mode 100644 index 4292e678..00000000 --- a/renovate.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:base", - ":semanticCommitsDisabled" - ], - "git-submodules": { - "enabled": true - }, - "packageRules": [ - { - "matchPackageNames": ["OTAPI.Upcoming", "ModFramework", "TerrariaServerAPI"], - "ignoreUnstable": "false", - "bumpVersion": "prerelease", - "groupName": "OTAPI things" - } - ] -} From 61a81bb4ff8d0a07f9870cc776045fe3a741448b Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Sun, 26 Jan 2025 01:00:17 +0900 Subject: [PATCH 76/94] Fix merge conflict --- docs/changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 75e8d251..841bba3b 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -130,6 +130,10 @@ Use past tense when adding new entries; sign your name off when you add or chang * Allowed multiple test cases to be in TShock's test suite. (@drunderscore) * Fixed unable to use Purification/Evil Powder in jungle. (@sgkoishi) * Set the `GetDataHandledEventArgs.Player` property for the `SyncTilePicking` data handler. (@drunderscore) +* Relaxed custom death message restrictions to allow Inferno potions in PvP. (@drunderscore) +* Allowed Flower Boots to place Ash Flowers on Ash Grass blocks. (@punchready) +* Removed unnecessary range check that artifically shortened quick stack reach. (@boddyn, #2885, @bcat) +* Re-wrote tile rect handling from scratch, fixing a certain exploitable flaw in the old code and significantly reducing the potential exploit surface, potentially even down to zero. (@punchready) ## TShock 5.1.3 * Added support for Terraria 1.4.4.9 via OTAPI 3.1.20. (@SignatureBeef) From b984ff8b65433e54478459421dba9247df2c62bb Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 26 Jan 2025 08:45:11 +0900 Subject: [PATCH 77/94] Apply patch from https://github.com/Pryaxis/TShock/pull/3018 This applies https://github.com/Pryaxis/TShock/pull/3018 as a patch per @punchready because they deleted the head repository so that we can't merge it and none of the git objects have valid refs anymore on the command line and we can't merge it on the gui. --- TShockAPI/Commands.cs | 11 ++++++----- docs/changelog.md | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index e7491632..1006b50f 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -4622,21 +4622,22 @@ namespace TShockAPI { if (args.Parameters.Count != 1) { - args.Player.SendErrorMessage(GetString("Invalid syntax. Proper syntax: {0}wind .", Specifier)); + args.Player.SendErrorMessage(GetString("Invalid syntax. Proper syntax: {0}wind .", Specifier)); return; } - int speed; - if (!int.TryParse(args.Parameters[0], out speed) || speed * 100 < 0) + float mph; + if (!float.TryParse(args.Parameters[0], out mph) || mph is < -40f or > 40f) { - args.Player.SendErrorMessage(GetString("Invalid wind speed.")); + args.Player.SendErrorMessage(GetString("Invalid wind speed (must be between -40 and 40).")); return; } + float speed = mph / 50f; // -40 to 40 mph -> -0.8 to 0.8 Main.windSpeedCurrent = speed; Main.windSpeedTarget = speed; TSPlayer.All.SendData(PacketTypes.WorldInfo); - TSPlayer.All.SendInfoMessage(GetString("{0} changed the wind speed to {1}.", args.Player.Name, speed)); + TSPlayer.All.SendInfoMessage(GetString("{0} changed the wind speed to {1}mph.", args.Player.Name, mph)); } #endregion Time/PvpFun Commands diff --git a/docs/changelog.md b/docs/changelog.md index 4866e01c..41fa2853 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -83,6 +83,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Changed the use of `Player.active` to `TSPlayer.Active` for consistency. (@sgkoishi, #2939) * Fix typo in config for IP bans. (@redchess64) * Fixed unable to transfer long response body for REST API. (@sgkoishi, #2925) +* Fixed the `/wind` command not being very helpful. (@punchready) ## TShock 5.2.1 * Updated `TSPlayer.GodMode`. (@AgaSpace) From fdee582dc74266b9e5231414c78ee34a13baf7e8 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 26 Jan 2025 09:00:41 +0900 Subject: [PATCH 78/94] Redirect ikebukuro to wiki This redirects the hosted docs on github pages to the wiki, which is easier for normal people to edit. --- docs/index.html | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/docs/index.html b/docs/index.html index 2ae1df82..0cfccf11 100644 --- a/docs/index.html +++ b/docs/index.html @@ -11,12 +11,7 @@
From 52ed275be2393a496edf26430b1f7d05a8fe72b5 Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Sun, 26 Jan 2025 13:00:06 +0900 Subject: [PATCH 79/94] Fix #2895 --- TShockPluginManager/Nuget.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/TShockPluginManager/Nuget.cs b/TShockPluginManager/Nuget.cs index 9fdefb6b..1d00fe1c 100644 --- a/TShockPluginManager/Nuget.cs +++ b/TShockPluginManager/Nuget.cs @@ -30,7 +30,6 @@ using NuGet.Versioning; namespace TShockPluginManager { - public class Nugetter { // this object can figure out the right framework folders to use from a set of packages @@ -82,15 +81,13 @@ namespace TShockPluginManager // make sure the source repository can actually tell us about dependencies var dependencyInfoResource = await sourceRepository.GetResourceAsync(); // get the try and dependencies - // (the above function returns a nullable value, but doesn't properly indicate it as such) - #pragma warning disable CS8602 - var dependencyInfo = await dependencyInfoResource?.ResolvePackage( + if (dependencyInfoResource is null) continue; + var dependencyInfo = await dependencyInfoResource.ResolvePackage( package, framework, cacheContext, logger, CancellationToken.None); - #pragma warning restore CS8602 // oop, we don't have the ability to get dependency info from this repository, or // it wasn't found. let's try the next source repository! - if (dependencyInfo == null) continue; + if (dependencyInfo is null) continue; availablePackages.Add(dependencyInfo); foreach (var dependency in dependencyInfo.Dependencies) @@ -302,8 +299,11 @@ namespace TShockPluginManager var relativeFolder = Path.GetDirectoryName(packageRelativeFilePath); var targetFolder = Path.Join(isPlugin ? "./ServerPlugins" : "./bin", relativeFolder); - Directory.CreateDirectory(targetFolder); - File.Copy(filePath, Path.Join(targetFolder, Path.GetFileName(filePath)), true); + if (File.Exists(filePath)) + { + Directory.CreateDirectory(targetFolder); + File.Copy(filePath, Path.Join(targetFolder, Path.GetFileName(filePath)), true); + } } } } From 74a07150f82eefb4a3359bb7f3b0911f91d8f5ae Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 26 Jan 2025 13:37:38 +0900 Subject: [PATCH 80/94] Update submodule --- TerrariaServerAPI | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TerrariaServerAPI b/TerrariaServerAPI index 8a3fffd7..d4bb7e3a 160000 --- a/TerrariaServerAPI +++ b/TerrariaServerAPI @@ -1 +1 @@ -Subproject commit 8a3fffd71db401736ea80619122c70c449c10ff3 +Subproject commit d4bb7e3a21e875cfeb23bcf5cf847c85d9470ccf From c4a141308e58d4c7cc9ac07fac8143434597b13d Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Sun, 26 Jan 2025 15:11:15 +0900 Subject: [PATCH 81/94] Automatic language detection --- TShockAPI/I18n.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/TShockAPI/I18n.cs b/TShockAPI/I18n.cs index e8f5eedb..ac2985d0 100644 --- a/TShockAPI/I18n.cs +++ b/TShockAPI/I18n.cs @@ -60,6 +60,12 @@ namespace TShockAPI } } + if (LanguageManager.Instance.ActiveCulture == GameCulture.DefaultCulture) + { + var bf = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static; + // LanguageManager.SetLanguage will change this so we need to reset it back to null + typeof(CultureInfo).GetField("s_currentThreadUICulture", bf)?.SetValue(null, null); + } return CultureInfo.CurrentUICulture; } } From 605be8f813dcc01cd24e3c422d545dea720f5b0c Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Mon, 27 Jan 2025 08:11:36 +0900 Subject: [PATCH 82/94] Detect xterm compatibility to avoid console spam --- TShockAPI/Utils.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 23b1e224..3b9c0286 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -1149,11 +1149,15 @@ namespace TShockAPI /// If the server is empty; determines if we should use Utils.GetActivePlayerCount() for player count or 0. internal void SetConsoleTitle(bool empty) { + if (ShouldSkipTitle) + return; Console.Title = GetString("{0}{1}/{2} on {3} @ {4}:{5} (TShock for Terraria v{6})", !string.IsNullOrWhiteSpace(TShock.Config.Settings.ServerName) ? TShock.Config.Settings.ServerName + " - " : "", empty ? 0 : GetActivePlayerCount(), TShock.Config.Settings.MaxSlots, Main.worldName, Netplay.ServerIP.ToString(), Netplay.ListenPort, TShock.VersionNum); } + // Some terminals doesn't supports XTerm escape sequences for setting the title + private static bool ShouldSkipTitle = !System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows) && !(Environment.GetEnvironmentVariable("TERM")?.Contains("xterm") ?? false); /// Determines the distance between two vectors. /// The first vector location. From 49b1003eca32fa8028d39402f48bb1932f0f5a66 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 27 Jan 2025 21:07:36 +0900 Subject: [PATCH 83/94] Update github actions upload artifact to v4 This is part of #3050, but thinking about this logically, the deprecation of v3 happens in just 3 days, so unless we want to have .NET 9 testing done in the next 3 days (unlikely?), it's not a great idea to let this break. --- .github/workflows/ci-otapi3.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-otapi3.yml b/.github/workflows/ci-otapi3.yml index f5599ffc..e72d8c22 100644 --- a/.github/workflows/ci-otapi3.yml +++ b/.github/workflows/ci-otapi3.yml @@ -63,14 +63,14 @@ jobs: tar -cvf ../../../../../../TShock-Beta-${{ matrix.arch }}-Release.tar * - name: Upload artifact (non-Windows) - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: ${{ matrix.arch != 'win-x64' }} with: name: TShock-Beta-${{ matrix.arch }}-Release path: TShock-Beta-${{ matrix.arch }}-Release.tar - name: Upload artifact (Windows) - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: ${{ matrix.arch == 'win-x64' }} with: name: TShock-Beta-${{ matrix.arch }}-Release From d35934b3a2c0e89af2f19f75e622049e5ac9f23b Mon Sep 17 00:00:00 2001 From: ohayo Date: Thu, 30 Jan 2025 22:46:13 +1000 Subject: [PATCH 84/94] Check for bans on connection as well as join, etc Should prevent people from being able to bypass this. --- TShockAPI/TShock.cs | 2 ++ docs/changelog.md | 1 + 2 files changed, 3 insertions(+) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 365c531d..6955efdd 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1376,6 +1376,8 @@ namespace TShockAPI } } } + + Bans.CheckBan(player); Players[args.Who] = player; } diff --git a/docs/changelog.md b/docs/changelog.md index 490a6b0a..910696ce 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,6 +78,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. --> ## Upcoming changes +* Fixed a security issue with how bans are handled on join. (@ohayo) * Fixed `/dump-reference-data` mutate the command names. (#2943, @sgkoishi) * Added `ParryDamageBuff` (Striking Moment with Brand of the Inferno and shield) for player, updated `CursedInferno` buff for NPC (@sgkoishi, #3005) * Changed the use of `Player.active` to `TSPlayer.Active` for consistency. (@sgkoishi, #2939) From 53789b40e4bd1211fa564d05f135226af95912b9 Mon Sep 17 00:00:00 2001 From: ohayo Date: Fri, 31 Jan 2025 09:17:26 +1000 Subject: [PATCH 85/94] Prevent further things from clients who dont handshake - The player will only finish the handshake once they spawn their player, a normal client would always do this eventually. - They cannot chat, even if they request world data but just not spawn their player. - Other clients will not be notified of their join/leave in both cases (dont request WD or do but dont spawn) - And most importantly, they do not show on the in game player list but still show on the server console /playing cmd. --- TShockAPI/Commands.cs | 2 +- TShockAPI/GetDataHandlers.cs | 3 +++ TShockAPI/TSPlayer.cs | 3 +++ TShockAPI/TShock.cs | 18 ++++++++++++++---- TShockAPI/Utils.cs | 2 +- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index f7d3247a..d82f10e2 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5363,7 +5363,7 @@ namespace TShockAPI foreach (TSPlayer ply in TShock.Players) { - if (ply != null && ply.Active) + if (ply != null && ply.Active && ply.FinishedHandshake) { if (displayIdsRequested) if (ply.Account != null) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index b736a512..8f70fd2c 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2726,6 +2726,8 @@ namespace TShockAPI short numberOfDeathsPVP = args.Data.ReadInt16(); PlayerSpawnContext context = (PlayerSpawnContext)args.Data.ReadByte(); + args.Player.FinishedHandshake = true; + if (OnPlayerSpawn(args.Player, args.Data, player, spawnx, spawny, respawnTimer, numberOfDeathsPVE, numberOfDeathsPVP, context)) return true; @@ -2762,6 +2764,7 @@ namespace TShockAPI args.Player.Dead = true; else args.Player.Dead = false; + return false; } diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index c9194c36..cb66649a 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -351,6 +351,9 @@ namespace TShockAPI /// Determines if the player is disabled for not clearing their trash. A re-login is the only way to reset this. public bool IsDisabledPendingTrashRemoval; + /// Determines if the player has finished the handshake (Sent all necessary packets for connection, such as Request World Data, Spawn Player, etc). A normal client would do all of this no problem. + public bool FinishedHandshake = false; + /// Checks to see if active throttling is happening on events by Bouncer. Rejects repeated events by malicious clients in a short window. /// If the player is currently being throttled by Bouncer, or not. public bool IsBouncerThrottled() diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 6955efdd..ae9738cc 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1399,7 +1399,8 @@ namespace TShockAPI return; } - Bans.CheckBan(player); + if (Bans.CheckBan(player)) + return; } /// OnLeave - Called when a player leaves the server. @@ -1439,7 +1440,7 @@ namespace TShockAPI if (tsplr.ReceivedInfo) { - if (!tsplr.SilentKickInProgress && tsplr.State >= 3) + if (!tsplr.SilentKickInProgress && tsplr.State >= 3 && tsplr.FinishedHandshake) //The player has left, do not broadcast any clients exploiting the behaviour of not spawning their player. Utils.Broadcast(GetString("{0} has left.", tsplr.Name), Color.Yellow); Log.Info(GetString("{0} disconnected.", tsplr.Name)); @@ -1460,6 +1461,9 @@ namespace TShockAPI } } + + tsplr.FinishedHandshake = false; + // Fire the OnPlayerLogout hook too, if the player was logged in and they have a TSPlayer object. if (tsplr.IsLoggedIn) { @@ -1489,6 +1493,12 @@ namespace TShockAPI return; } + if (!tsplr.FinishedHandshake) + { + args.Handled = true; + return; + } + if (args.Text.Length > 500) { tsplr.Kick(GetString("Crash attempt via long chat packet."), true); @@ -1705,14 +1715,14 @@ namespace TShockAPI Log.Info(GetString("{0} ({1}) from '{2}' group from '{3}' joined. ({4}/{5})", player.Name, player.IP, player.Group.Name, player.Country, TShock.Utils.GetActivePlayerCount(), TShock.Config.Settings.MaxSlots)); - if (!player.SilentJoinInProgress) + if (!player.SilentJoinInProgress && player.FinishedHandshake) Utils.Broadcast(GetString("{0} ({1}) has joined.", player.Name, player.Country), Color.Yellow); } else { Log.Info(GetString("{0} ({1}) from '{2}' group joined. ({3}/{4})", player.Name, player.IP, player.Group.Name, TShock.Utils.GetActivePlayerCount(), TShock.Config.Settings.MaxSlots)); - if (!player.SilentJoinInProgress) + if (!player.SilentJoinInProgress && player.FinishedHandshake) Utils.Broadcast(GetString("{0} has joined.", player.Name), Color.Yellow); } diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 3b9c0286..613e7a8a 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -183,7 +183,7 @@ namespace TShockAPI /// The number of active players on the server. public int GetActivePlayerCount() { - return TShock.Players.Count(p => null != p && p.Active); + return TShock.Players.Count(p => null != p && p.Active && p.FinishedHandshake); } //Random should not be generated in a method From ed398430bc51b835a97fa7dec3b9f86375ae6587 Mon Sep 17 00:00:00 2001 From: ohayo Date: Fri, 31 Jan 2025 10:04:50 +1000 Subject: [PATCH 86/94] Update changelog.md --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index 910696ce..afcfc727 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,6 +78,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. --> ## Upcoming changes +* Added a variable for handshake (True upon spawn player), clients no longer notify others of their presence and cant chat if this is never set to true. (@ohayo) * Fixed a security issue with how bans are handled on join. (@ohayo) * Fixed `/dump-reference-data` mutate the command names. (#2943, @sgkoishi) * Added `ParryDamageBuff` (Striking Moment with Brand of the Inferno and shield) for player, updated `CursedInferno` buff for NPC (@sgkoishi, #3005) From e4e28cb1b561dbf9a30eafd925c8fe93052e0aad Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 1 Feb 2025 22:32:36 +0900 Subject: [PATCH 87/94] Version tick: 5.2.2 --- TShockAPI/TShock.cs | 2 +- TShockAPI/TShockAPI.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index ae9738cc..e984da2f 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -63,7 +63,7 @@ namespace TShockAPI /// VersionNum - The version number the TerrariaAPI will return back to the API. We just use the Assembly info. public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version; /// VersionCodename - The version codename is displayed when the server starts. Inspired by software codenames conventions. - public static readonly string VersionCodename = "Intensity"; + public static readonly string VersionCodename = "East"; /// SavePath - This is the path TShock saves its data in. This path is relative to the TerrariaServer.exe (not in ServerPlugins). public static string SavePath = "tshock"; diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index 34df3c74..88f61606 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -18,7 +18,7 @@ Also, be sure to release on github with the exact assembly version tag as below so that the update manager works correctly (via the Github releases api and mimic) --> - 5.2.1 + 5.2.2 TShock for Terraria Pryaxis & TShock Contributors TShockAPI From 20532135580568478ba7dbc98150604751454e99 Mon Sep 17 00:00:00 2001 From: Arthri <41360489+a@users.noreply.github.com> Date: Sat, 8 Feb 2025 07:13:03 +0000 Subject: [PATCH 88/94] Bounce infinite or NaN velocity / position --- TShockAPI/Bouncer.cs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 0f5f6e3c..bfcd1836 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -504,6 +504,14 @@ namespace TShockAPI return; } + if (!float.IsFinite(pos.X) || !float.IsFinite(pos.Y)) + { + TShock.Log.ConsoleInfo(GetString("Bouncer / OnPlayerUpdate force kicked (attempted to set position to infinity or NaN) from {0}", args.Player.Name)); + args.Player.Kick(GetString("Detected DOOM set to ON position."), true, true); + args.Handled = true; + return; + } + if (pos.X < 0 || pos.Y < 0 || pos.X >= Main.maxTilesX * 16 - 16 || pos.Y >= Main.maxTilesY * 16 - 16) { TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlayerUpdate rejected from (position check) {0}", args.Player.Name)); @@ -1072,6 +1080,22 @@ namespace TShockAPI bool noDelay = args.NoDelay; short type = args.Type; + if (!float.IsFinite(pos.X) || !float.IsFinite(pos.Y)) + { + TShock.Log.ConsoleInfo(GetString("Bouncer / OnItemDrop force kicked (attempted to set position to infinity or NaN) from {0}", args.Player.Name)); + args.Player.Kick(GetString("Detected DOOM set to ON position."), true, true); + args.Handled = true; + return; + } + + if (!float.IsFinite(vel.X) || !float.IsFinite(vel.Y)) + { + TShock.Log.ConsoleInfo(GetString("Bouncer / OnItemDrop force kicked (attempted to set velocity to infinity or NaN) from {0}", args.Player.Name)); + args.Player.Kick(GetString("Detected DOOM set to ON position."), true, true); + args.Handled = true; + return; + } + // player is attempting to crash clients if (type < -48 || type >= Terraria.ID.ItemID.Count) { @@ -1175,6 +1199,22 @@ namespace TShockAPI int index = args.Index; float[] ai = args.Ai; + if (!float.IsFinite(pos.X) || !float.IsFinite(pos.Y)) + { + TShock.Log.ConsoleInfo(GetString("Bouncer / OnNewProjectile force kicked (attempted to set position to infinity or NaN) from {0}", args.Player.Name)); + args.Player.Kick(GetString("Detected DOOM set to ON position."), true, true); + args.Handled = true; + return; + } + + if (!float.IsFinite(vel.X) || !float.IsFinite(vel.Y)) + { + TShock.Log.ConsoleInfo(GetString("Bouncer / OnNewProjectile force kicked (attempted to set velocity to infinity or NaN) from {0}", args.Player.Name)); + args.Player.Kick(GetString("Detected DOOM set to ON position."), true, true); + args.Handled = true; + return; + } + if (index > Main.maxProjectiles) { TShock.Log.ConsoleDebug(GetString("Bouncer / OnNewProjectile rejected from above projectile limit from {0}", args.Player.Name)); From 64d819bebb086f92e55bcd6d1ae26d64d6eb7af0 Mon Sep 17 00:00:00 2001 From: Arthri <41360489+a@users.noreply.github.com> Date: Sat, 8 Feb 2025 07:18:06 +0000 Subject: [PATCH 89/94] Changelog entry --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index afcfc727..505419e2 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -95,6 +95,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * * Ensured `TSPlayer.PlayerData` is non-null whilst syncing loadouts. (@drunderscore) * * Detected invalid installations, by checking for a file named `TerrariaServer.exe`. (@drunderscore) * This made the two most common installation mistakes (extracting into the Terraria client directory, and extracting TShock 5 or newer into a TShock 4 or older install) prompt the user with a more useful diagnostic, rather than (likely) crashing moments later. +* Changed Bouncer to block updates which set the following fields to infinity or NaN: player position, projectile position, projectile velocity, item position, and item velocity. (@Arthri) ## TShock 5.2.1 * Updated `TSPlayer.GodMode`. (@AgaSpace) From 836cc33c8dd338fe558b8e6c5f1b410d0573d7ad Mon Sep 17 00:00:00 2001 From: Joseph Goh Date: Mon, 27 Jan 2025 09:58:40 +0800 Subject: [PATCH 90/94] rewrite: bed spawning for SSC --- TShockAPI/GetDataHandlers.cs | 81 ++++++++++++++++++++++-------------- TShockAPI/PlayerData.cs | 14 +------ TShockAPI/TSPlayer.cs | 37 +++++++++++----- TShockAPI/TShock.cs | 16 +++---- docs/changelog.md | 3 ++ 5 files changed, 90 insertions(+), 61 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 8f70fd2c..07010c94 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2248,7 +2248,7 @@ namespace TShockAPI var args = new SyncTilePickingEventArgs { - Player = player, + Player = player, PlayerIndex = playerIndex, TileX = tileX, TileY = tileY, @@ -2719,8 +2719,8 @@ namespace TShockAPI } byte player = args.Data.ReadInt8(); - short spawnx = args.Data.ReadInt16(); - short spawny = args.Data.ReadInt16(); + short spawnX = args.Data.ReadInt16(); + short spawnY = args.Data.ReadInt16(); int respawnTimer = args.Data.ReadInt32(); short numberOfDeathsPVE = args.Data.ReadInt16(); short numberOfDeathsPVP = args.Data.ReadInt16(); @@ -2728,43 +2728,62 @@ namespace TShockAPI args.Player.FinishedHandshake = true; - if (OnPlayerSpawn(args.Player, args.Data, player, spawnx, spawny, respawnTimer, numberOfDeathsPVE, numberOfDeathsPVP, context)) + if (OnPlayerSpawn(args.Player, args.Data, player, spawnX, spawnY, respawnTimer, numberOfDeathsPVE, numberOfDeathsPVP, context)) return true; + + args.Player.Dead = respawnTimer > 0; - if ((Main.ServerSideCharacter) && (spawnx == -1 && spawny == -1)) //this means they want to spawn to vanilla spawn + if (Main.ServerSideCharacter) { - args.Player.sX = Main.spawnTileX; - args.Player.sY = Main.spawnTileY; - args.Player.Teleport(args.Player.sX * 16, (args.Player.sY * 16) - 48); - TShock.Log.ConsoleDebug(GetString("GetDataHandlers / HandleSpawn force teleport 'vanilla spawn' {0}", args.Player.Name)); - } + // As long as the player has not changed his spawnpoint since initial connection, + // we should not use the client's spawnpoint value. This is because the spawnpoint + // value is not saved on the client when SSC is enabled. Hence, we have to assert + // the server-saved spawnpoint value until we can detect that the player has changed + // his spawn. Once we detect the spawnpoint changed, the client's spawnpoint value + // becomes the correct one to use. + // + // Note that spawnpoint changes (right-clicking beds) are not broadcasted to the + // server. Hence, the only way to detect spawnpoint changes is from the + // PlayerSpawn packet. - else if ((Main.ServerSideCharacter) && (args.Player.sX > 0) && (args.Player.sY > 0) && (args.TPlayer.SpawnX > 0) && ((args.TPlayer.SpawnX != args.Player.sX) && (args.TPlayer.SpawnY != args.Player.sY))) - { - args.Player.sX = args.TPlayer.SpawnX; - args.Player.sY = args.TPlayer.SpawnY; - - if (((Main.tile[args.Player.sX, args.Player.sY - 1].active() && Main.tile[args.Player.sX, args.Player.sY - 1].type == TileID.Beds)) && (WorldGen.StartRoomCheck(args.Player.sX, args.Player.sY - 1))) + // handle initial connection + if (args.Player.State == 3) { - args.Player.Teleport(args.Player.sX * 16, (args.Player.sY * 16) - 48); - TShock.Log.ConsoleDebug(GetString("GetDataHandlers / HandleSpawn force teleport phase 1 {0}", args.Player.Name)); - } - } + // server saved spawnpoint value + args.Player.initialSpawn = true; + args.Player.initialServerSpawnX = args.TPlayer.SpawnX; + args.Player.initialServerSpawnY = args.TPlayer.SpawnY; - else if ((Main.ServerSideCharacter) && (args.Player.sX > 0) && (args.Player.sY > 0)) - { - if (((Main.tile[args.Player.sX, args.Player.sY - 1].active() && Main.tile[args.Player.sX, args.Player.sY - 1].type == TileID.Beds)) && (WorldGen.StartRoomCheck(args.Player.sX, args.Player.sY - 1))) + // initial client spawn point, do not use this to spawn the player + // we only use it to detect if the spawnpoint has changed during this session + args.Player.initialClientSpawnX = spawnX; + args.Player.initialClientSpawnY = spawnY; + + // we first let the game handle completing the connection (state 3 => 10), + // then we will spawn the player at the saved spawnpoint in the next second, + // by reasserting the correct spawnpoint value + return false; + } + + // once we detect the client has changed his spawnpoint in the current session, + // the client spawnpoint value will be correct for the rest of the session + if (args.Player.spawnSynced || args.Player.initialClientSpawnX != spawnX || args.Player.initialClientSpawnY != spawnY) { - args.Player.Teleport(args.Player.sX * 16, (args.Player.sY * 16) - 48); - TShock.Log.ConsoleDebug(GetString("GetDataHandlers / HandleSpawn force teleport phase 2 {0}", args.Player.Name)); + // Player has changed his spawnpoint, client and server TPlayer.Spawn{X,Y} is now synced + args.Player.spawnSynced = true; + return false; } + + // the player has not changed his spawnpoint yet, so we assert the server-saved spawnpoint + // by teleporting the player instead of letting the game use the client's incorrect spawnpoint. + TShock.Log.ConsoleDebug(GetString("GetDataHandlers / HandleSpawn force ssc teleport for {0} at ({1},{2})", args.Player.Name, args.TPlayer.SpawnX, args.TPlayer.SpawnY)); + args.Player.TeleportSpawnpoint(); + + args.TPlayer.respawnTimer = respawnTimer; + args.TPlayer.numberOfDeathsPVE = numberOfDeathsPVE; + args.TPlayer.numberOfDeathsPVP = numberOfDeathsPVP; + return true; } - - if (respawnTimer > 0) - args.Player.Dead = true; - else - args.Player.Dead = false; - return false; } diff --git a/TShockAPI/PlayerData.cs b/TShockAPI/PlayerData.cs index 2a8dd41f..bab9f7a6 100644 --- a/TShockAPI/PlayerData.cs +++ b/TShockAPI/PlayerData.cs @@ -104,16 +104,8 @@ namespace TShockAPI this.maxHealth = player.TPlayer.statLifeMax; this.mana = player.TPlayer.statMana; this.maxMana = player.TPlayer.statManaMax; - if (player.sX > 0 && player.sY > 0) - { - this.spawnX = player.sX; - this.spawnY = player.sY; - } - else - { - this.spawnX = player.TPlayer.SpawnX; - this.spawnY = player.TPlayer.SpawnY; - } + this.spawnX = player.TPlayer.SpawnX; + this.spawnY = player.TPlayer.SpawnY; extraSlot = player.TPlayer.extraAccessory ? 1 : 0; this.skinVariant = player.TPlayer.skinVariant; this.hair = player.TPlayer.hair; @@ -266,8 +258,6 @@ namespace TShockAPI player.TPlayer.statManaMax = this.maxMana; player.TPlayer.SpawnX = this.spawnX; player.TPlayer.SpawnY = this.spawnY; - player.sX = this.spawnX; - player.sY = this.spawnY; player.TPlayer.hairDye = this.hairDye; player.TPlayer.anglerQuestsFinished = this.questsCompleted; player.TPlayer.UsingBiomeTorches = this.usingBiomeTorches == 1; diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index cb66649a..4fd65275 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -177,8 +177,13 @@ namespace TShockAPI ///
public int RPPending = 0; - public int sX = -1; - public int sY = -1; + + public bool initialSpawn = false; + public int initialServerSpawnX = -2; + public int initialServerSpawnY = -2; + public bool spawnSynced = false; + public int initialClientSpawnX = -2; + public int initialClientSpawnY = -2; /// /// A queue of tiles destroyed by the player for reverting. @@ -1383,6 +1388,25 @@ namespace TShockAPI return true; } + /// + /// Teleports the player to their spawnpoint. + /// Teleports to main spawnpoint if their bed is not active. + /// Supports SSC. + /// + public bool TeleportSpawnpoint() + { + // NOTE: it is vanilla behaviour to not permanently override the spawnpoint if the bed spawn is broken/invalid + int x = TPlayer.SpawnX; + int y = TPlayer.SpawnY; + if ((x == -1 && y == -1) || + !Main.tile[x, y - 1].active() || Main.tile[x, y - 1].type != TileID.Beds || !WorldGen.StartRoomCheck(x, y - 1)) + { + x = Main.spawnTileX; + y = Main.spawnTileY; + } + return Teleport(x * 16, y * 16 - 48); + } + /// /// Heals the player. /// @@ -1397,14 +1421,7 @@ namespace TShockAPI /// public void Spawn(PlayerSpawnContext context, int? respawnTimer = null) { - if (this.sX > 0 && this.sY > 0) - { - Spawn(this.sX, this.sY, context, respawnTimer); - } - else - { - Spawn(TPlayer.SpawnX, TPlayer.SpawnY, context, respawnTimer); - } + Spawn(TPlayer.SpawnX, TPlayer.SpawnY, context, respawnTimer); } /// diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index e984da2f..c5f2b968 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1182,16 +1182,16 @@ namespace TShockAPI if (player.RecentFuse > 0) player.RecentFuse--; - if ((Main.ServerSideCharacter) && (player.TPlayer.SpawnX > 0) && (player.sX != player.TPlayer.SpawnX)) + if (Main.ServerSideCharacter && player.initialSpawn) { - player.sX = player.TPlayer.SpawnX; - player.sY = player.TPlayer.SpawnY; - } + player.initialSpawn = false; - if ((Main.ServerSideCharacter) && (player.sX > 0) && (player.sY > 0) && (player.TPlayer.SpawnX < 0)) - { - player.TPlayer.SpawnX = player.sX; - player.TPlayer.SpawnY = player.sY; + // reassert the correct spawnpoint value after the game's Spawn handler changed it + player.TPlayer.SpawnX = player.initialServerSpawnX; + player.TPlayer.SpawnY = player.initialServerSpawnY; + + player.TeleportSpawnpoint(); + TShock.Log.ConsoleDebug(GetString("OnSecondUpdate / initial ssc spawn for {0} at ({1}, {2})", player.Name, player.TPlayer.SpawnX, player.TPlayer.SpawnY)); } if (player.RPPending > 0) diff --git a/docs/changelog.md b/docs/changelog.md index afcfc727..3c9051c0 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -95,6 +95,9 @@ Use past tense when adding new entries; sign your name off when you add or chang * * Ensured `TSPlayer.PlayerData` is non-null whilst syncing loadouts. (@drunderscore) * * Detected invalid installations, by checking for a file named `TerrariaServer.exe`. (@drunderscore) * This made the two most common installation mistakes (extracting into the Terraria client directory, and extracting TShock 5 or newer into a TShock 4 or older install) prompt the user with a more useful diagnostic, rather than (likely) crashing moments later. +* Rewrote bed spawning for SSC. (@PotatoCider) + * Removed `TSPlayer.s{X,Y}` in favour of using desyncing client and server spawnpoint values (`Terraria.Player.Spawn{X,Y}`) until the player has changed their spawnpoint per session. + * Partially fixed the bed spawning bug when SSC is enabled. Players would need to spawn at their beds at least once to tell TShock that the player's spawnpoint has changed. ## TShock 5.2.1 * Updated `TSPlayer.GodMode`. (@AgaSpace) From 1e23785a04dfcedb139f00ed86d0666640844361 Mon Sep 17 00:00:00 2001 From: LaoSparrow Date: Fri, 28 Feb 2025 23:01:40 +0800 Subject: [PATCH 91/94] fix(Bouncer/SendTileRectHandler): MatchRemoval incorrect check range --- TShockAPI/Handlers/SendTileRectHandler.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TShockAPI/Handlers/SendTileRectHandler.cs b/TShockAPI/Handlers/SendTileRectHandler.cs index d85185b8..e5e3f360 100644 --- a/TShockAPI/Handlers/SendTileRectHandler.cs +++ b/TShockAPI/Handlers/SendTileRectHandler.cs @@ -327,7 +327,7 @@ namespace TShockAPI.Handlers private bool MatchRemoval(TSPlayer player, TileRect rect) { - for (int x = rect.X; x < rect.Y + rect.Width; x++) + for (int x = rect.X; x < rect.X + rect.Width; x++) { for (int y = rect.Y; y < rect.Y + rect.Height; y++) { @@ -910,7 +910,7 @@ namespace TShockAPI.Handlers } } - /* + /* * This is a copy of the `WorldGen.Convert` method with the following precise changes: * - Added a `MockTile tile` parameter * - Changed the `i` and `j` parameters to `k` and `l` @@ -921,7 +921,7 @@ namespace TShockAPI.Handlers * - Removed the ifs checking the bounds of the tile and wall types * - Removed branches that would call `WorldGen.KillTile` * - Changed branches depending on randomness to instead set the property to both values after one another - * + * * This overall leads to a method that can be called on a MockTile and real-world coordinates and will spit out the proper conversion changes into the MockTile. */ From 28aa3aea482badcd54344d910c7f8811a8e1a99e Mon Sep 17 00:00:00 2001 From: LaoSparrow Date: Sat, 1 Mar 2025 01:42:18 +0800 Subject: [PATCH 92/94] fix(Bouncer/SendTileRectHandler): tile rect changes not synced between clients && unable to place HatRack --- TShockAPI/Handlers/SendTileRectHandler.cs | 67 +++++++++++++---------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/TShockAPI/Handlers/SendTileRectHandler.cs b/TShockAPI/Handlers/SendTileRectHandler.cs index e5e3f360..d66c3ef6 100644 --- a/TShockAPI/Handlers/SendTileRectHandler.cs +++ b/TShockAPI/Handlers/SendTileRectHandler.cs @@ -78,6 +78,13 @@ namespace TShockAPI.Handlers Removal, } + public enum MatchResult + { + NotMatched, + RejectChanges, + BroadcastChanges, + } + private readonly int Width; private readonly int Height; @@ -179,11 +186,11 @@ namespace TShockAPI.Handlers /// The player the operation originates from. /// The tile rectangle of the operation. /// , if the rect matches this operation and the changes have been applied, otherwise . - public bool Matches(TSPlayer player, TileRect rect) + public MatchResult Matches(TSPlayer player, TileRect rect) { if (rect.Width != Width || rect.Height != Height) { - return false; + return MatchResult.NotMatched; } for (int x = 0; x < rect.Width; x++) @@ -195,7 +202,7 @@ namespace TShockAPI.Handlers { if (tile.Type != TileType) { - return false; + return MatchResult.NotMatched; } } if (Type is MatchType.Placement or MatchType.StateChange) @@ -204,7 +211,7 @@ namespace TShockAPI.Handlers { if (tile.FrameX < 0 || tile.FrameX > MaxFrameX || tile.FrameX % FrameXStep != 0) { - return false; + return MatchResult.NotMatched; } } if (MaxFrameY != IGNORE_FRAME) @@ -214,7 +221,7 @@ namespace TShockAPI.Handlers // this is the only tile type sent in a tile rect where the frame have a different pattern (56, 74, 92 instead of 54, 72, 90) if (!(TileType == TileID.LunarMonolith && tile.FrameY % FrameYStep == 2)) { - return false; + return MatchResult.NotMatched; } } } @@ -223,7 +230,7 @@ namespace TShockAPI.Handlers { if (tile.Active) { - return false; + return MatchResult.NotMatched; } } } @@ -236,7 +243,7 @@ namespace TShockAPI.Handlers if (!player.HasBuildPermission(x, y)) { // for simplicity, let's pretend that the edit was valid, but do not execute it - return true; + return MatchResult.RejectChanges; } } } @@ -257,10 +264,10 @@ namespace TShockAPI.Handlers } } - return false; + return MatchResult.NotMatched; } - private bool MatchPlacement(TSPlayer player, TileRect rect) + private MatchResult MatchPlacement(TSPlayer player, TileRect rect) { for (int x = rect.X; x < rect.Y + rect.Width; x++) { @@ -268,7 +275,7 @@ namespace TShockAPI.Handlers { if (Main.tile[x, y].active()) // the client will kill tiles that auto break before placing the object { - return false; + return MatchResult.NotMatched; } } } @@ -277,7 +284,7 @@ namespace TShockAPI.Handlers if (TShock.TileBans.TileIsBanned((short)TileType, player)) { // for simplicity, let's pretend that the edit was valid, but do not execute it - return true; + return MatchResult.RejectChanges; } for (int x = 0; x < rect.Width; x++) @@ -291,10 +298,10 @@ namespace TShockAPI.Handlers } } - return true; + return MatchResult.BroadcastChanges; } - private bool MatchStateChange(TSPlayer player, TileRect rect) + private MatchResult MatchStateChange(TSPlayer player, TileRect rect) { for (int x = rect.X; x < rect.Y + rect.Width; x++) { @@ -302,7 +309,7 @@ namespace TShockAPI.Handlers { if (!Main.tile[x, y].active() || Main.tile[x, y].type != TileType) { - return false; + return MatchResult.NotMatched; } } } @@ -322,10 +329,10 @@ namespace TShockAPI.Handlers } } - return true; + return MatchResult.BroadcastChanges; } - private bool MatchRemoval(TSPlayer player, TileRect rect) + private MatchResult MatchRemoval(TSPlayer player, TileRect rect) { for (int x = rect.X; x < rect.X + rect.Width; x++) { @@ -333,7 +340,7 @@ namespace TShockAPI.Handlers { if (!Main.tile[x, y].active() || Main.tile[x, y].type != TileType) { - return false; + return MatchResult.NotMatched; } } } @@ -348,7 +355,7 @@ namespace TShockAPI.Handlers } } - return true; + return MatchResult.BroadcastChanges; } } @@ -364,7 +371,7 @@ namespace TShockAPI.Handlers TileRectMatch.Placement(2, 3, TileID.TargetDummy, 54, 36, 18, 18), TileRectMatch.Placement(3, 4, TileID.TeleportationPylon, 468, 54, 18, 18), TileRectMatch.Placement(2, 3, TileID.DisplayDoll, 126, 36, 18, 18), - TileRectMatch.Placement(2, 3, TileID.HatRack, 90, 54, 18, 18), + TileRectMatch.Placement(3, 4, TileID.HatRack, 90, 54, 18, 18), TileRectMatch.Placement(2, 2, TileID.ItemFrame, 162, 18, 18, 18), TileRectMatch.Placement(3, 3, TileID.WeaponsRack2, 90, 36, 18, 18), TileRectMatch.Placement(1, 1, TileID.FoodPlatter, 18, 0, 18, 18), @@ -436,7 +443,7 @@ namespace TShockAPI.Handlers TShock.Log.ConsoleDebug(GetString($"Bouncer / SendTileRect rejected from throttle from {args.Player.Name}")); // send correcting data - args.Player.SendTileRect(args.TileX, args.TileY, args.Length, args.Width); + args.Player.SendTileRect(args.TileX, args.TileY, args.Width, args.Length); return; } @@ -446,7 +453,7 @@ namespace TShockAPI.Handlers TShock.Log.ConsoleDebug(GetString($"Bouncer / SendTileRect rejected from being disabled from {args.Player.Name}")); // send correcting data - args.Player.SendTileRect(args.TileX, args.TileY, args.Length, args.Width); + args.Player.SendTileRect(args.TileX, args.TileY, args.Width, args.Length); return; } @@ -468,7 +475,7 @@ namespace TShockAPI.Handlers TShock.Log.ConsoleDebug(GetString($"Bouncer / SendTileRect reimplemented from {args.Player.Name}")); // send correcting data - args.Player.SendTileRect(args.TileX, args.TileY, args.Length, args.Width); + args.Player.SendTileRect(args.TileX, args.TileY, args.Width, args.Length); return; } @@ -478,7 +485,7 @@ namespace TShockAPI.Handlers TShock.Log.ConsoleDebug(GetString($"Bouncer / SendTileRect rejected from out of range from {args.Player.Name}")); // send correcting data - args.Player.SendTileRect(args.TileX, args.TileY, args.Length, args.Width); + args.Player.SendTileRect(args.TileX, args.TileY, args.Width, args.Length); return; } @@ -488,19 +495,23 @@ namespace TShockAPI.Handlers TShock.Log.ConsoleDebug(GetString($"Bouncer / SendTileRect reimplemented from {args.Player.Name}")); // send correcting data - args.Player.SendTileRect(args.TileX, args.TileY, args.Length, args.Width); + args.Player.SendTileRect(args.TileX, args.TileY, args.Width, args.Length); return; } // check if the rect matches any valid operation foreach (TileRectMatch match in Matches) { - if (match.Matches(args.Player, rect)) + var result = match.Matches(args.Player, rect); + if (result != TileRectMatch.MatchResult.NotMatched) { TShock.Log.ConsoleDebug(GetString($"Bouncer / SendTileRect reimplemented from {args.Player.Name}")); // send correcting data - args.Player.SendTileRect(args.TileX, args.TileY, args.Length, args.Width); + if (result == TileRectMatch.MatchResult.RejectChanges) + args.Player.SendTileRect(args.TileX, args.TileY, args.Width, args.Length); + if (result == TileRectMatch.MatchResult.BroadcastChanges) + TSPlayer.All.SendTileRect(args.TileX, args.TileY, args.Width, args.Length); return; } } @@ -511,14 +522,14 @@ namespace TShockAPI.Handlers TShock.Log.ConsoleDebug(GetString($"Bouncer / SendTileRect reimplemented from {args.Player.Name}")); // send correcting data - args.Player.SendTileRect(args.TileX, args.TileY, args.Length, args.Width); + args.Player.SendTileRect(args.TileX, args.TileY, args.Width, args.Length); return; } TShock.Log.ConsoleDebug(GetString($"Bouncer / SendTileRect rejected from matches from {args.Player.Name}")); // send correcting data - args.Player.SendTileRect(args.TileX, args.TileY, args.Length, args.Width); + args.Player.SendTileRect(args.TileX, args.TileY, args.Width, args.Length); return; } From 61e574ce7230544ce42dc3f730fda99d4843ad75 Mon Sep 17 00:00:00 2001 From: LaoSparrow Date: Sat, 1 Mar 2025 02:02:24 +0800 Subject: [PATCH 93/94] docs(changelog): update entries --- docs/changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index afcfc727..147d5559 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -95,6 +95,10 @@ Use past tense when adding new entries; sign your name off when you add or chang * * Ensured `TSPlayer.PlayerData` is non-null whilst syncing loadouts. (@drunderscore) * * Detected invalid installations, by checking for a file named `TerrariaServer.exe`. (@drunderscore) * This made the two most common installation mistakes (extracting into the Terraria client directory, and extracting TShock 5 or newer into a TShock 4 or older install) prompt the user with a more useful diagnostic, rather than (likely) crashing moments later. +* Updated `TShockAPI.Handlers.SendTileRectHandler` (@LaoSparrow): + * Fixed incorrect validating range in `TileRectMatch.MatchRemoval`. + * Fixed tile rect changes (e.g. turning on and off campfires) are not synced between clients. + * Fixed unable to place Hat Rack without permission `tshock.ignore.sendtilesquare`. ## TShock 5.2.1 * Updated `TSPlayer.GodMode`. (@AgaSpace) From 740c5c9250c262e2602292ac9e5b2d396ec0f842 Mon Sep 17 00:00:00 2001 From: LaoSparrow Date: Sat, 1 Mar 2025 03:41:30 +0800 Subject: [PATCH 94/94] fix(GetDataHandlers): handle and ignore `NpcItemStrike(msgid 24)` --- TShockAPI/GetDataHandlers.cs | 8 ++++++++ docs/changelog.md | 1 + 2 files changed, 9 insertions(+) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 8f70fd2c..22cfadb3 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -95,6 +95,7 @@ namespace TShockAPI { PacketTypes.TileSendSquare, HandleSendTileRect }, { PacketTypes.ItemDrop, HandleItemDrop }, { PacketTypes.ItemOwner, HandleItemOwner }, + { PacketTypes.NpcItemStrike, HandleNpcItemStrike }, { PacketTypes.ProjectileNew, HandleProjectileNew }, { PacketTypes.NpcStrike, HandleNpcStrike }, { PacketTypes.ProjectileDestroy, HandleProjectileKill }, @@ -2945,6 +2946,13 @@ namespace TShockAPI return false; } + private static bool HandleNpcItemStrike(GetDataHandlerArgs args) + { + // Never sent by vanilla client, ignore this + TShock.Log.ConsoleDebug(GetString("GetDataHandlers / HandleNpcItemStrike surprise packet! Someone tell the TShock team! {0}", args.Player.Name)); + return true; + } + private static bool HandleProjectileNew(GetDataHandlerArgs args) { short ident = args.Data.ReadInt16(); diff --git a/docs/changelog.md b/docs/changelog.md index 147d5559..cf4e43f2 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -99,6 +99,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Fixed incorrect validating range in `TileRectMatch.MatchRemoval`. * Fixed tile rect changes (e.g. turning on and off campfires) are not synced between clients. * Fixed unable to place Hat Rack without permission `tshock.ignore.sendtilesquare`. +* Updated `GetDataHandlers` to ignore `NpcItemStrike(msgid 24)`, which should never be sent by a vanilla client. (@LaoSparrow) ## TShock 5.2.1 * Updated `TSPlayer.GodMode`. (@AgaSpace)