From 48370d74b7093c67cf8f45b4af4a7bee55e9f355 Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Tue, 13 Jul 2021 21:33:35 +0200 Subject: [PATCH 01/57] Missing group safeguards. - Server will no longer start up when the guest or default groups cannot be located. - Players joining with unknown groups assigned to them will be disconnected with an error --- TShockAPI/Commands.cs | 7 +++++-- TShockAPI/DB/GroupManager.cs | 15 +++++++++++++++ TShockAPI/GetDataHandlers.cs | 10 ++++++++-- TShockAPI/TShock.cs | 1 + TShockAPI/Utils.cs | 11 +++++++++++ TerrariaServerAPI | 2 +- 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index b6ba179f..80e710ad 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -823,10 +823,13 @@ namespace TShockAPI (usingUUID && account.UUID == args.Player.UUID && !TShock.Config.Settings.DisableUUIDLogin && !String.IsNullOrWhiteSpace(args.Player.UUID))) { - args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, account.ID); - var group = TShock.Groups.GetGroupByName(account.Group); + if (!TShock.Utils.AssertGroupValid(args.Player, group)) + return; + + args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, account.ID); + args.Player.Group = group; args.Player.tempGroup = null; args.Player.Account = account; diff --git a/TShockAPI/DB/GroupManager.cs b/TShockAPI/DB/GroupManager.cs index 7b3b62dd..8133edaa 100644 --- a/TShockAPI/DB/GroupManager.cs +++ b/TShockAPI/DB/GroupManager.cs @@ -202,6 +202,21 @@ namespace TShockAPI.DB Group.DefaultGroup = GetGroupByName(TShock.Config.Settings.DefaultGuestGroupName); } + internal void EnsureCoreGroupsPresent() + { + if (!GroupExists(TShock.Config.Settings.DefaultGuestGroupName)) + { + TShock.Log.ConsoleError("The guest group could not be found. This may indicate a typo in the configuration file, or that the group was renamed or deleted."); + throw new Exception("The guest group could not be found."); + } + + if(!GroupExists(TShock.Config.Settings.DefaultRegistrationGroupName)) + { + TShock.Log.ConsoleError("The default usergroup could not be found. This may indicate a typo in the configuration file, or that the group was renamed or deleted."); + throw new Exception("The default usergroup could not be found."); + } + } + private void AddDefaultGroup(string name, string parent, string permissions) { if (!GroupExists(name)) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index e92d19a9..b90f6fe1 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2450,10 +2450,13 @@ namespace TShockAPI args.Player.State = 2; NetMessage.SendData((int)PacketTypes.WorldInfo, args.Player.Index); - args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, account.ID); - var group = TShock.Groups.GetGroupByName(account.Group); + if (!TShock.Utils.AssertGroupValid(args.Player, group)) + return true; + + args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, account.ID); + args.Player.Group = group; args.Player.tempGroup = null; args.Player.Account = account; @@ -3004,6 +3007,9 @@ namespace TShockAPI var group = TShock.Groups.GetGroupByName(account.Group); + if (!TShock.Utils.AssertGroupValid(args.Player, group)) + return true; + args.Player.Group = group; args.Player.tempGroup = null; args.Player.Account = account; diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index ed74b882..bc1d26e7 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -322,6 +322,7 @@ namespace TShockAPI Regions = new RegionManager(DB); UserAccounts = new UserAccountManager(DB); Groups = new GroupManager(DB); + Groups.EnsureCoreGroupsPresent(); ProjectileBans = new ProjectileManagager(DB); TileBans = new TileManager(DB); RememberedPos = new RememberedPosManager(DB); diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 23007b19..36a6d348 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -212,6 +212,17 @@ namespace TShockAPI } while (TilePlacementValid(tileX, tileY) && TileSolid(tileX, tileY)); } + public bool AssertGroupValid(TSPlayer player, Group group) + { + if (group == null) + { + player.Disconnect("Your account's group could not be found. Please contact server administrators about this."); + return false; + } + + return true; + } + /// /// Determines if a tile is valid. /// diff --git a/TerrariaServerAPI b/TerrariaServerAPI index 8c2c0873..4b555bc3 160000 --- a/TerrariaServerAPI +++ b/TerrariaServerAPI @@ -1 +1 @@ -Subproject commit 8c2c087327bbd1f20ff6c46f4d11e5714e57064b +Subproject commit 4b555bc373dbb470bc69ebed69c79de116f28df2 From f7c550a8adc6abf0648b741fedce0726c58db499 Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Tue, 13 Jul 2021 21:39:20 +0200 Subject: [PATCH 02/57] Fix the server not reporting startup errors correctly. --- TShockAPI/TShock.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index bc1d26e7..996463e1 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -387,8 +387,8 @@ namespace TShockAPI } catch (Exception ex) { - Log.Error("Fatal Startup Exception"); - Log.Error(ex.ToString()); + Log.ConsoleError("Fatal Startup Exception"); + Log.ConsoleError(ex.ToString()); Environment.Exit(1); } } From 6154ee60c1e884c21275fc7ced7a7fb5f398f667 Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Tue, 13 Jul 2021 21:43:14 +0200 Subject: [PATCH 03/57] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85d31e64..0bf907db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Correct rejection message in LandGolfBallInCupHandler to output the proper expected player id. (@drunderscore) * Clarified the error mesage that the console is presented if a rate-limit is reached over REST to indicate that "tokens" actually refers to rate-limit tokens, and not auth tokens, and added a hint as to what config setting determines this. (@hakusaro, @patsore) * Fixed an issue where, when the console was redirected, input was disabled and commands didn't work, in TSAPI. You can now pass `-disable-commands` to disable the input thread, but by default, it will be enabled. Fixes [#1450](https://github.com/Pryaxis/TShock/issues/1450). (@DeathCradle, @QuiCM) +* Fixed missing group problems & error reporting on startup. (@bartico6) ## TShock 4.5.4 * Fixed ridiculous typo in `GetDataHandlers` which caused TShock to read the wrong field in the packet for `usingBiomeTorches`. (@hakusaro, @Arthri) From 048aaf6f0c3b503c921cdc73bc4e524eaa107274 Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Tue, 13 Jul 2021 21:47:27 +0200 Subject: [PATCH 04/57] /login kick -> error, add XML doc to Utils method. --- TShockAPI/Commands.cs | 5 ++++- TShockAPI/Utils.cs | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 80e710ad..d0c3b48a 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -825,8 +825,11 @@ namespace TShockAPI { var group = TShock.Groups.GetGroupByName(account.Group); - if (!TShock.Utils.AssertGroupValid(args.Player, group)) + if (group == null) + { + args.Player.SendErrorMessage("Login failed: The account references a group that doesn't exist."); return; + } args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, account.ID); diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 36a6d348..be3722df 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -212,6 +212,12 @@ namespace TShockAPI } while (TilePlacementValid(tileX, tileY) && TileSolid(tileX, tileY)); } + /// + /// Asserts that the group reference can be safely assigned to the player object. + /// + /// + /// + /// public bool AssertGroupValid(TSPlayer player, Group group) { if (group == null) From c759af6d49650562d8a3e4d8255ae812344a3035 Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Tue, 13 Jul 2021 21:53:54 +0200 Subject: [PATCH 05/57] Minor update. - AssertGroupValid now both sends the message and kicks the player depending on input parameter. - /login and DataHandler code is now an identical assert check. --- TShockAPI/Commands.cs | 4 ++-- TShockAPI/GetDataHandlers.cs | 4 ++-- TShockAPI/Utils.cs | 8 ++++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index d0c3b48a..c3c7090d 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -825,9 +825,9 @@ namespace TShockAPI { var group = TShock.Groups.GetGroupByName(account.Group); - if (group == null) + if (!TShock.Utils.AssertGroupValid(args.Player, group, false)) { - args.Player.SendErrorMessage("Login failed: The account references a group that doesn't exist."); + args.Player.SendErrorMessage("Login attempt failed - see the message above."); return; } diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index b90f6fe1..bc5f2175 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2452,7 +2452,7 @@ namespace TShockAPI var group = TShock.Groups.GetGroupByName(account.Group); - if (!TShock.Utils.AssertGroupValid(args.Player, group)) + if (!TShock.Utils.AssertGroupValid(args.Player, group, true)) return true; args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, account.ID); @@ -3007,7 +3007,7 @@ namespace TShockAPI var group = TShock.Groups.GetGroupByName(account.Group); - if (!TShock.Utils.AssertGroupValid(args.Player, group)) + if (!TShock.Utils.AssertGroupValid(args.Player, group, true)) return true; args.Player.Group = group; diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index be3722df..aad127dc 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -214,15 +214,19 @@ namespace TShockAPI /// /// Asserts that the group reference can be safely assigned to the player object. + /// If this assertion fails, and is true, the player is disconnected. If is false, the player will receive an error message. /// /// /// /// - public bool AssertGroupValid(TSPlayer player, Group group) + public bool AssertGroupValid(TSPlayer player, Group group, bool kick) { if (group == null) { - player.Disconnect("Your account's group could not be found. Please contact server administrators about this."); + if (kick) + player.Disconnect("Your account's group could not be loaded. Please contact server administrators about this."); + else + player.SendErrorMessage("Your account's group could not be loaded. Please contact server administrators about this."); return false; } From 51348d18064d0092ce5118af906e646f82069208 Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Sat, 31 Jul 2021 16:34:43 +0200 Subject: [PATCH 06/57] Fixes for PR 2397. - GroupManager now validates core groups in the constructor. - EnsureCoreGroupsPresent -> AssertCoreGroupsPresent. - Fix indentiation in some places. - Clarify the intent of this PR in CHANGELOG.md. --- CHANGELOG.md | 3 ++- TShockAPI/DB/GroupManager.cs | 32 ++++++++++++++++++++++++++++---- TShockAPI/TShock.cs | 1 - TShockAPI/Utils.cs | 7 ++++--- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bf907db..09d6164a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Correct rejection message in LandGolfBallInCupHandler to output the proper expected player id. (@drunderscore) * Clarified the error mesage that the console is presented if a rate-limit is reached over REST to indicate that "tokens" actually refers to rate-limit tokens, and not auth tokens, and added a hint as to what config setting determines this. (@hakusaro, @patsore) * Fixed an issue where, when the console was redirected, input was disabled and commands didn't work, in TSAPI. You can now pass `-disable-commands` to disable the input thread, but by default, it will be enabled. Fixes [#1450](https://github.com/Pryaxis/TShock/issues/1450). (@DeathCradle, @QuiCM) -* Fixed missing group problems & error reporting on startup. (@bartico6) +* Fixed errors on startup not being reported to console. (@bartico6) +* The server now correctly disconnects players with missing groups instead of throwing an exception, stalling the connection (@bartico6) ## TShock 4.5.4 * Fixed ridiculous typo in `GetDataHandlers` which caused TShock to read the wrong field in the packet for `usingBiomeTorches`. (@hakusaro, @Arthri) diff --git a/TShockAPI/DB/GroupManager.cs b/TShockAPI/DB/GroupManager.cs index 8133edaa..09b19f5a 100644 --- a/TShockAPI/DB/GroupManager.cs +++ b/TShockAPI/DB/GroupManager.cs @@ -200,9 +200,11 @@ namespace TShockAPI.DB LoadPermisions(); Group.DefaultGroup = GetGroupByName(TShock.Config.Settings.DefaultGuestGroupName); + + AssertCoreGroupsPresent(); } - internal void EnsureCoreGroupsPresent() + internal void AssertCoreGroupsPresent() { if (!GroupExists(TShock.Config.Settings.DefaultGuestGroupName)) { @@ -210,11 +212,33 @@ namespace TShockAPI.DB throw new Exception("The guest group could not be found."); } - if(!GroupExists(TShock.Config.Settings.DefaultRegistrationGroupName)) - { + if (!GroupExists(TShock.Config.Settings.DefaultRegistrationGroupName)) + { TShock.Log.ConsoleError("The default usergroup could not be found. This may indicate a typo in the configuration file, or that the group was renamed or deleted."); throw new Exception("The default usergroup could not be found."); - } + } + } + + /// + /// Asserts that the group reference can be safely assigned to the player object. + /// If this assertion fails, and is true, the player is disconnected. If is false, the player will receive an error message. + /// + /// The player in question + /// The group we want to assign them + /// Whether or not failing this check disconnects the player. + /// + public bool AssertGroupValid(TSPlayer player, Group group, bool kick) + { + if (group == null) + { + if (kick) + player.Disconnect("Your account's group could not be loaded. Please contact server administrators about this."); + else + player.SendErrorMessage("Your account's group could not be loaded. Please contact server administrators about this."); + return false; + } + + return true; } private void AddDefaultGroup(string name, string parent, string permissions) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 996463e1..2adfbf79 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -322,7 +322,6 @@ namespace TShockAPI Regions = new RegionManager(DB); UserAccounts = new UserAccountManager(DB); Groups = new GroupManager(DB); - Groups.EnsureCoreGroupsPresent(); ProjectileBans = new ProjectileManagager(DB); TileBans = new TileManager(DB); RememberedPos = new RememberedPosManager(DB); diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index aad127dc..c5bc6c46 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -216,11 +216,12 @@ namespace TShockAPI /// Asserts that the group reference can be safely assigned to the player object. /// If this assertion fails, and is true, the player is disconnected. If is false, the player will receive an error message. /// - /// - /// + /// The player in question + /// The group we want to assign them + /// Whether or not failing this check disconnects the player. /// public bool AssertGroupValid(TSPlayer player, Group group, bool kick) - { + { if (group == null) { if (kick) From 02c20337ece20c0fa6ec5c51187b82a36058e467 Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Sat, 31 Jul 2021 16:37:09 +0200 Subject: [PATCH 07/57] Further clarification in CHANGELOG. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09d6164a..03f5f754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fixed an issue where, when the console was redirected, input was disabled and commands didn't work, in TSAPI. You can now pass `-disable-commands` to disable the input thread, but by default, it will be enabled. Fixes [#1450](https://github.com/Pryaxis/TShock/issues/1450). (@DeathCradle, @QuiCM) * Fixed errors on startup not being reported to console. (@bartico6) * The server now correctly disconnects players with missing groups instead of throwing an exception, stalling the connection (@bartico6) +* The server now rejects login attempts from players who would end up with a missing group. (@bartico6) ## TShock 4.5.4 * Fixed ridiculous typo in `GetDataHandlers` which caused TShock to read the wrong field in the packet for `usingBiomeTorches`. (@hakusaro, @Arthri) From 196ce87669fe2ce43d8857347cb6427479bbb31e Mon Sep 17 00:00:00 2001 From: stacey Date: Fri, 6 Aug 2021 14:24:06 -0400 Subject: [PATCH 08/57] add colours for GetVersion testing something --- TShockAPI/Commands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 55d281c3..1e2a13b7 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5148,7 +5148,7 @@ namespace TShockAPI private static void GetVersion(CommandArgs args) { - args.Player.SendInfoMessage("TShock: {0} ({1}).", TShock.VersionNum, TShock.VersionCodename); + args.Player.SendMessage($"TShock: {TShock.VersionNum.Color(Utils.BoldHighlight)} {TShock.VersionCodename.Color(Utils.RedHighlight)}.", Color.White); } private static void ListConnectedPlayers(CommandArgs args) From d82a75836fcb714399f82fe6e9f38d637bd611f0 Mon Sep 17 00:00:00 2001 From: stacey Date: Fri, 6 Aug 2021 15:07:06 -0400 Subject: [PATCH 09/57] add colour for ListConnectedPlayers also various other minor improvements --- TShockAPI/Commands.cs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 1e2a13b7..93e021ab 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5176,16 +5176,24 @@ namespace TShockAPI } if (invalidUsage) { - args.Player.SendErrorMessage("Invalid usage, proper usage: {0}who [-i] [pagenumber]", Specifier); + args.Player.SendMessage($"List Online Players Syntax", Color.White); + args.Player.SendMessage($"{"playing".Color(Utils.BoldHighlight)} {"[-i]".Color(Utils.RedHighlight)} {"[page]".Color(Utils.GreenHighlight)}", Color.White); + args.Player.SendMessage($"Command aliases: {"playing".Color(Utils.GreenHighlight)}, {"online".Color(Utils.GreenHighlight)}, {"who".Color(Utils.GreenHighlight)}", Color.White); + args.Player.SendMessage($"Example usage: {"who".Color(Utils.BoldHighlight)} {"-i".Color(Utils.RedHighlight)}", Color.White); return; } if (displayIdsRequested && !args.Player.HasPermission(Permissions.seeids)) { - args.Player.SendErrorMessage("You do not have permission to list player ids."); + args.Player.SendErrorMessage("You do not have permission to see player IDs."); return; } - args.Player.SendSuccessMessage("Online Players ({0}/{1})", TShock.Utils.GetActivePlayerCount(), TShock.Config.Settings.MaxSlots); + if (TShock.Utils.GetActivePlayerCount() == 0) + { + args.Player.SendMessage("There are currently no players online.", Color.White); + return; + } + args.Player.SendMessage($"Online Players ({TShock.Utils.GetActivePlayerCount().Color(Utils.GreenHighlight)}/{TShock.Config.Settings.MaxSlots})", Color.White); var players = new List(); @@ -5194,13 +5202,9 @@ namespace TShockAPI if (ply != null && ply.Active) { if (displayIdsRequested) - { - players.Add(String.Format("{0} (Index: {1}{2})", ply.Name, ply.Index, ply.Account != null ? ", Account ID: " + ply.Account.ID : "")); - } + players.Add($"{ply.Name} (Index: {ply.Index}{(ply.Account != null ? ", Account ID: " + ply.Account.ID : "")})"); else - { players.Add(ply.Name); - } } } @@ -5209,7 +5213,7 @@ namespace TShockAPI new PaginationTools.Settings { IncludeHeader = false, - FooterFormat = string.Format("Type {0}who {1}{{0}} for more.", Specifier, displayIdsRequested ? "-i " : string.Empty) + FooterFormat = $"Type {Specifier}who {(displayIdsRequested ? "-i" : string.Empty)}{Specifier} for more." } ); } From 815fb9f3f8550c2e2d3ad325668248a9b4c3be65 Mon Sep 17 00:00:00 2001 From: stacey <57187883+moisterrific@users.noreply.github.com> Date: Fri, 6 Aug 2021 15:11:53 -0400 Subject: [PATCH 10/57] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9243d03..51cdb1b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added a new `DisablePrimeBombs` config option (`false` by default). Highly recommended to set this to `true` in order to prevent griefing on servers doing a `for the worthy` play-through, since the prime bombs on this seed can destroy most tiles and bypass region protection. (@moisterrific) * Added a new `/respawn` command that lets you respawn yourself or another player. Respawning yourself requires the `tshock.respawn` permission and respawning others requires the `tshock.respawn.other` permission. The full command syntax is `/respawn [player]`. (@moisterrific) * Added a notification message and silent command support for permanently changing a target player's user group. Now players who received a group change will be notified of their new group if they are currently online. (@moisterrific, @QuiCM) +* Added colours and usage examples (similiar to how the new ban system looks) for many more commands. (@moisterrific) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) From cb9740bda6fc4c5ec9411243ac45089eaeccedfe Mon Sep 17 00:00:00 2001 From: stacey Date: Fri, 6 Aug 2021 15:34:14 -0400 Subject: [PATCH 11/57] add colours to Mute also added silent support --- TShockAPI/Commands.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 93e021ab..d6f08942 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5307,14 +5307,17 @@ namespace TShockAPI { if (args.Parameters.Count < 1) { - args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}mute [reason]", Specifier); + args.Player.SendMessage("Mute Syntax", Color.White); + args.Player.SendMessage($"{"mute".Color(Utils.BoldHighlight)} <{"player".Color(Utils.RedHighlight)}> [{"reason".Color(Utils.GreenHighlight)}]", Color.White); + args.Player.SendMessage($"Example usage: {"mute".Color(Utils.BoldHighlight)} \"{args.Player.Name.Color(Utils.RedHighlight)}\" \"{"No swearing on my Christian server".Color(Utils.GreenHighlight)}\"", Color.White); + args.Player.SendMessage($"To mute a player without broadcasting to chat, use the command with {SilentSpecifier.Color(Utils.GreenHighlight)} instead of {Specifier.Color(Utils.RedHighlight)}", Color.White); return; } var players = TSPlayer.FindByNameOrID(args.Parameters[0]); if (players.Count == 0) { - args.Player.SendErrorMessage("Invalid player!"); + args.Player.SendErrorMessage($"Could not find any players named \"{args.Parameters[0]}\""); } else if (players.Count > 1) { @@ -5322,13 +5325,16 @@ namespace TShockAPI } else if (players[0].HasPermission(Permissions.mute)) { - args.Player.SendErrorMessage("You cannot mute this player."); + args.Player.SendErrorMessage($"You do not have permission to mute {players[0].Name}"); } else if (players[0].mute) { var plr = players[0]; plr.mute = false; - TSPlayer.All.SendInfoMessage("{0} has been unmuted by {1}.", plr.Name, args.Player.Name); + if (args.Silent) + args.Player.SendSuccessMessage($"You have unmuted {plr.Name}."); + else + TSPlayer.All.SendInfoMessage($"{args.Player.Name} has unmuted {plr.Name}."); } else { @@ -5337,7 +5343,10 @@ namespace TShockAPI reason = String.Join(" ", args.Parameters.ToArray(), 1, args.Parameters.Count - 1); var plr = players[0]; plr.mute = true; - TSPlayer.All.SendInfoMessage("{0} has been muted by {1} for {2}.", plr.Name, args.Player.Name, reason); + if (args.Silent) + args.Player.SendSuccessMessage($"You have muted {plr.Name} for {reason}"); + else + TSPlayer.All.SendInfoMessage($"{args.Player.Name} has muted {plr.Name} for {reason}."); } } From 45e1e4288a8953804bc45d4a1a01a47311726a32 Mon Sep 17 00:00:00 2001 From: stacey Date: Fri, 6 Aug 2021 16:09:36 -0400 Subject: [PATCH 12/57] add colours to /w, /wallow, and /r and various minor improvements --- TShockAPI/Commands.cs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index d6f08942..79fb37c1 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -582,11 +582,11 @@ namespace TShockAPI { HelpText = "Teleports you to a warp point or manages warps." }); - add(new Command(Permissions.whisper, Whisper, "whisper", "w", "tell") + add(new Command(Permissions.whisper, Whisper, "whisper", "w", "tell", "pm", "dm") { HelpText = "Sends a PM to a player." }); - add(new Command(Permissions.whisper, Wallow, "wallow") + add(new Command(Permissions.whisper, Wallow, "wallow", "wa") { AllowServer = false, HelpText = "Toggles to either ignore or recieve whispers from other players." @@ -5364,13 +5364,15 @@ namespace TShockAPI { if (args.Parameters.Count < 2) { - args.Player.SendErrorMessage("Invalid syntax! Proper usage: /whisper "); + args.Player.SendMessage("Whisper Syntax", Color.White); + args.Player.SendMessage($"{"whisper".Color(Utils.BoldHighlight)} <{"player".Color(Utils.RedHighlight)}> <{"message".Color(Utils.PinkHighlight)}>", Color.White); + args.Player.SendMessage($"Example usage: {"w".Color(Utils.BoldHighlight)} {args.Player.Name.Color(Utils.RedHighlight)} {"We're no strangers to love, you know the rules, and so do I.".Color(Utils.PinkHighlight)}", Color.White); return; } var players = TSPlayer.FindByNameOrID(args.Parameters[0]); if (players.Count == 0) { - args.Player.SendErrorMessage("Invalid player!"); + args.Player.SendErrorMessage($"Could not find any player named \"{args.Parameters[0]}\""); } else if (players.Count > 1) { @@ -5383,14 +5385,19 @@ namespace TShockAPI else { var plr = players[0]; + if (plr == args.Player) + { + args.Player.SendErrorMessage("You cannot whisper to yourself."); + return; + } if (!plr.AcceptingWhispers) { - args.Player.SendErrorMessage("This player is not accepting whispers."); + args.Player.SendErrorMessage($"{plr.Name} is not accepting whispers."); return; } var msg = string.Join(" ", args.Parameters.ToArray(), 1, args.Parameters.Count - 1); - plr.SendMessage(String.Format(" {1}", args.Player.Name, msg), Color.MediumPurple); - args.Player.SendMessage(String.Format(" {1}", plr.Name, msg), Color.MediumPurple); + plr.SendMessage($" {msg}", Color.MediumPurple); + args.Player.SendMessage($" {msg}", Color.MediumPurple); plr.LastWhisper = args.Player; args.Player.LastWhisper = plr; } @@ -5400,7 +5407,7 @@ namespace TShockAPI { args.Player.AcceptingWhispers = !args.Player.AcceptingWhispers; args.Player.SendSuccessMessage($"You {(args.Player.AcceptingWhispers ? "may now" : "will no longer")} receive whispers from other players."); - args.Player.SendSuccessMessage($"You can toggle this with the '{Specifier}wallow' command."); + args.Player.SendMessage($"You can use {Specifier.Color(Utils.GreenHighlight)}{"wa".Color(Utils.GreenHighlight)} to toggle this setting.", Color.White); } private static void Reply(CommandArgs args) @@ -5413,20 +5420,21 @@ namespace TShockAPI { if (!args.Player.LastWhisper.AcceptingWhispers) { - args.Player.SendErrorMessage("This player is not accepting whispers."); + args.Player.SendErrorMessage($"{args.Player.LastWhisper.Name} is not accepting whispers."); return; } var msg = string.Join(" ", args.Parameters); - args.Player.LastWhisper.SendMessage(String.Format(" {1}", args.Player.Name, msg), Color.MediumPurple); - args.Player.SendMessage(String.Format(" {1}", args.Player.LastWhisper.Name, msg), Color.MediumPurple); + args.Player.LastWhisper.SendMessage($" {msg}", Color.MediumPurple); + args.Player.SendMessage($" {msg}", Color.MediumPurple); } else if (args.Player.LastWhisper != null) { - args.Player.SendErrorMessage("The player you're attempting to reply to is no longer online."); + args.Player.SendErrorMessage($"{args.Player.LastWhisper.Name} is offline and cannot receive your reply."); } else { - args.Player.SendErrorMessage("You haven't previously received any whispers. Please use {0}whisper to whisper to other people.", Specifier); + args.Player.SendErrorMessage("You haven't previously received any whispers."); + args.Player.SendMessage($"You can use {Specifier.Color(Utils.GreenHighlight)}{"w".Color(Utils.GreenHighlight)} to whisper to other players.", Color.White); } } From 7e4f05eb9c29f721fc79fd07f52f468d672ff865 Mon Sep 17 00:00:00 2001 From: stacey Date: Fri, 6 Aug 2021 16:29:20 -0400 Subject: [PATCH 13/57] add colours to annoy and add silent support --- TShockAPI/Commands.cs | 13 +++++++++---- TShockAPI/TSPlayer.cs | 1 - 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 79fb37c1..a3360c95 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5442,7 +5442,10 @@ namespace TShockAPI { if (args.Parameters.Count != 2) { - args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}annoy ", Specifier); + args.Player.SendMessage("Annoy Syntax", Color.White); + args.Player.SendMessage($"{"annoy".Color(Utils.BoldHighlight)} <{"player".Color(Utils.RedHighlight)}> <{"seconds".Color(Utils.PinkHighlight)}>", Color.White); + args.Player.SendMessage($"Example usage: {"annoy".Color(Utils.BoldHighlight)} <{args.Player.Name.Color(Utils.RedHighlight)}> <{"10".Color(Utils.PinkHighlight)}>", Color.White); + args.Player.SendMessage($"You can use {SilentSpecifier.Color(Utils.GreenHighlight)} instead of {Specifier.Color(Utils.RedHighlight)} to annoy a player silently.", Color.White); return; } int annoy = 5; @@ -5450,14 +5453,16 @@ namespace TShockAPI var players = TSPlayer.FindByNameOrID(args.Parameters[0]); if (players.Count == 0) - args.Player.SendErrorMessage("Invalid player!"); + args.Player.SendErrorMessage($"Could not find any player named \"{args.Parameters[0]}\""); else if (players.Count > 1) args.Player.SendMultipleMatchError(players.Select(p => p.Name)); else { var ply = players[0]; - args.Player.SendSuccessMessage("Annoying " + ply.Name + " for " + annoy + " seconds."); - (new Thread(ply.Whoopie)).Start(annoy); + args.Player.SendSuccessMessage($"Annoying {ply.Name} for {annoy} seconds."); + if (!args.Silent) + ply.SendMessage("You are now being annoyed.", Color.LightGoldenrodYellow); + new Thread(ply.Whoopie).Start(annoy); } } diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index afde7cef..aadaf746 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1715,7 +1715,6 @@ namespace TShockAPI var time2 = (int)time; var launch = DateTime.UtcNow; var startname = Name; - SendInfoMessage("You are now being annoyed."); while ((DateTime.UtcNow - launch).TotalSeconds < time2 && startname == Name) { SendData(PacketTypes.NpcSpecial, number: Index, number2: 2f); From ca13b5011678ec7ee0f08c9612a1175e2cdb36a4 Mon Sep 17 00:00:00 2001 From: stacey Date: Fri, 6 Aug 2021 18:02:13 -0400 Subject: [PATCH 14/57] add colour and example for Rocket along with other minor improvements --- TShockAPI/Commands.cs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index a3360c95..fc0d9899 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5470,12 +5470,15 @@ namespace TShockAPI { if (args.Parameters.Count != 1) { - args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}rocket ", Specifier); + args.Player.SendMessage("Rocket Syntax", Color.White); + args.Player.SendMessage($"{"rocket".Color(Utils.BoldHighlight)} <{"player".Color(Utils.RedHighlight)}>", Color.White); + args.Player.SendMessage($"Example usage: {"rocket".Color(Utils.BoldHighlight)} {args.Player.Name.Color(Utils.RedHighlight)}", Color.White); + args.Player.SendMessage($"You can use {SilentSpecifier.Color(Utils.GreenHighlight)} instead of {Specifier.Color(Utils.RedHighlight)} to rocket a player silently.", Color.White); return; } var players = TSPlayer.FindByNameOrID(args.Parameters[0]); if (players.Count == 0) - args.Player.SendErrorMessage("Invalid player!"); + args.Player.SendErrorMessage($"Could not find any player named \"{args.Parameters[0]}\""); else if (players.Count > 1) args.Player.SendMultipleMatchError(players.Select(p => p.Name)); else @@ -5486,11 +5489,24 @@ namespace TShockAPI { ply.TPlayer.velocity.Y = -50; TSPlayer.All.SendData(PacketTypes.PlayerUpdate, "", ply.Index); - args.Player.SendSuccessMessage("Rocketed {0}.", ply.Name); + + if (!args.Silent) + { + TSPlayer.All.SendInfoMessage($"{args.Player.Name} has launched {(ply == args.Player ? (args.Player.TPlayer.Male ? "himself" : "herself") : ply.Name)} into space."); + return; + } + + if (ply == args.Player) + args.Player.SendSuccessMessage("You have launched yourself into space."); + else + args.Player.SendSuccessMessage($"You have launched {ply.Name} into space."); } else { - args.Player.SendErrorMessage("Failed to rocket player: Not logged in or not SSC mode."); + if (!Main.ServerSideCharacter) + args.Player.SendErrorMessage("SSC must be enabled to use this command."); + else + args.Player.SendErrorMessage($"Unable to rocket {ply.Name} because {(ply.TPlayer.Male ? "he" : "she")} is not logged in."); } } } From e88ae85683673a2f298503315ce67d18a9d330bd Mon Sep 17 00:00:00 2001 From: stacey Date: Fri, 6 Aug 2021 20:32:14 -0400 Subject: [PATCH 15/57] add colour msg for Rocket and example we do a lil refactoring, also added a cyan pastel coloured hex code and made various other little improvements --- TShockAPI/Commands.cs | 80 +++++++++++++++++++++++++++++++------------ TShockAPI/Utils.cs | 4 +++ 2 files changed, 62 insertions(+), 22 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index fc0d9899..2c895fd1 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5483,62 +5483,98 @@ namespace TShockAPI args.Player.SendMultipleMatchError(players.Select(p => p.Name)); else { - var ply = players[0]; + var target = players[0]; - if (ply.IsLoggedIn && Main.ServerSideCharacter) + if (target.IsLoggedIn && Main.ServerSideCharacter) { - ply.TPlayer.velocity.Y = -50; - TSPlayer.All.SendData(PacketTypes.PlayerUpdate, "", ply.Index); + target.TPlayer.velocity.Y = -50; + TSPlayer.All.SendData(PacketTypes.PlayerUpdate, "", target.Index); if (!args.Silent) { - TSPlayer.All.SendInfoMessage($"{args.Player.Name} has launched {(ply == args.Player ? (args.Player.TPlayer.Male ? "himself" : "herself") : ply.Name)} into space."); + TSPlayer.All.SendInfoMessage($"{args.Player.Name} has launched {(target == args.Player ? (args.Player.TPlayer.Male ? "himself" : "herself") : target.Name)} into space."); return; } - if (ply == args.Player) + if (target == args.Player) args.Player.SendSuccessMessage("You have launched yourself into space."); else - args.Player.SendSuccessMessage($"You have launched {ply.Name} into space."); + args.Player.SendSuccessMessage($"You have launched {target.Name} into space."); } else { if (!Main.ServerSideCharacter) args.Player.SendErrorMessage("SSC must be enabled to use this command."); else - args.Player.SendErrorMessage($"Unable to rocket {ply.Name} because {(ply.TPlayer.Male ? "he" : "she")} is not logged in."); + args.Player.SendErrorMessage($"Unable to rocket {target.Name} because {(target.TPlayer.Male ? "he" : "she")} is not logged in."); } } } private static void FireWork(CommandArgs args) { + var user = args.Player; if (args.Parameters.Count < 1) { - args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}firework [red|green|blue|yellow]", Specifier); + // firework [R|G|B|Y] + user.SendMessage("Firework Syntax", Color.White); + user.SendMessage($"{"firework".Color(Utils.CyanHighlight)} <{"player".Color(Utils.PinkHighlight)}> [{"R".Color(Utils.RedHighlight)}|{"G".Color(Utils.GreenHighlight)}|{"B".Color(Utils.BoldHighlight)}|{"Y".Color(Utils.YellowHighlight)}]", Color.White); + user.SendMessage($"Example usage: {"firework".Color(Utils.CyanHighlight)} {user.Name.Color(Utils.PinkHighlight)} {"R".Color(Utils.RedHighlight)}", Color.White); + user.SendMessage($"You can use {SilentSpecifier.Color(Utils.GreenHighlight)} instead of {Specifier.Color(Utils.RedHighlight)} to launch a firework silently.", Color.White); return; } var players = TSPlayer.FindByNameOrID(args.Parameters[0]); if (players.Count == 0) - args.Player.SendErrorMessage("Invalid player!"); + user.SendErrorMessage($"Could not find any player named \"{args.Parameters[0]}\""); else if (players.Count > 1) - args.Player.SendMultipleMatchError(players.Select(p => p.Name)); + user.SendMultipleMatchError(players.Select(p => p.Name)); else { - int type = 167; - if (args.Parameters.Count > 1) + int type = 0; + switch (args.Parameters[1].ToLower()) { - if (args.Parameters[1].ToLower() == "green") - type = 168; - else if (args.Parameters[1].ToLower() == "blue") - type = 169; - else if (args.Parameters[1].ToLower() == "yellow") - type = 170; + case "red": + case "r": + type = ProjectileID.RocketFireworkRed; + break; + case "green": + case "g": + type = ProjectileID.RocketFireworkGreen; + break; + case "blue": + case "b": + type = ProjectileID.RocketFireworkBlue; + break; + case "yellow": + case "y": + type = ProjectileID.RocketFireworkYellow; + break; + case "r2": + case "star": + type = ProjectileID.RocketFireworksBoxRed; + break; + case "g2": + case "spiral": + type = ProjectileID.RocketFireworksBoxGreen; + break; + case "b2": + case "rings": + type = ProjectileID.RocketFireworksBoxBlue; + break; + case "y2": + case "flower": + type = ProjectileID.RocketFireworksBoxYellow; + break; + default: + type = ProjectileID.RocketFireworkRed; + break; } - var ply = players[0]; - int p = Projectile.NewProjectile(Projectile.GetNoneSource(), ply.TPlayer.position.X, ply.TPlayer.position.Y - 64f, 0f, -8f, type, 0, (float)0); + var target = players[0]; + int p = Projectile.NewProjectile(Projectile.GetNoneSource(), target.TPlayer.position.X, target.TPlayer.position.Y - 64f, 0f, -8f, type, 0, 0); Main.projectile[p].Kill(); - args.Player.SendSuccessMessage("Launched Firework on {0}.", ply.Name); + args.Player.SendSuccessMessage($"You launched fireworks on {(target == user ? "yourself" : target.Name)}."); + if (!args.Silent && target != user) + target.SendSuccessMessage($"{user.Name} launched fireworks on you."); } } diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 92d45299..42f8ea96 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -62,6 +62,10 @@ namespace TShockAPI /// Hex code for a white highlight /// public const string WhiteHighlight = "FFFFFF"; + /// + /// Hex code for a cyan pastel color + /// + public const string CyanHighlight = "AAFFFF"; /// /// The lowest id for a prefix. From ded2e8544bb0c361cae2acf6435ec0e256f734cf Mon Sep 17 00:00:00 2001 From: stacey Date: Fri, 6 Aug 2021 21:11:00 -0400 Subject: [PATCH 16/57] add examples for Clear + minor refactor --- TShockAPI/Commands.cs | 51 +++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 2c895fd1..c4245fd0 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5636,18 +5636,25 @@ namespace TShockAPI private static void Clear(CommandArgs args) { + var user = args.Player; + var everyone = TSPlayer.All; + int radius = 50; + if (args.Parameters.Count != 1 && args.Parameters.Count != 2) { - args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}clear [radius]", Specifier); + user.SendMessage("Clear Syntax", Color.White); + user.SendMessage($"{"clear".Color(Utils.BoldHighlight)} <{"item".Color(Utils.GreenHighlight)}|{"npc".Color(Utils.RedHighlight)}|{"projectile".Color(Utils.YellowHighlight)}> [{"radius".Color(Utils.PinkHighlight)}]", Color.White); + user.SendMessage($"Example usage: {"clear".Color(Utils.BoldHighlight)} {"i".Color(Utils.RedHighlight)} {"10000".Color(Utils.GreenHighlight)}", Color.White); user.SendMessage($"Example usage: {"clear".Color(Utils.BoldHighlight)} {"item".Color(Utils.RedHighlight)} {"10000".Color(Utils.GreenHighlight)}", Color.White); + user.SendMessage($"If you do not specify a radius, it will use a default radius of {radius} around your character.", Color.White); + user.SendMessage($"You can use {SilentSpecifier.Color(Utils.GreenHighlight)} instead of {Specifier.Color(Utils.RedHighlight)} to execute this command silently.", Color.White); return; } - int radius = 50; if (args.Parameters.Count == 2) { if (!int.TryParse(args.Parameters[1], out radius) || radius <= 0) { - args.Player.SendErrorMessage("Invalid radius."); + user.SendErrorMessage($"\"{args.Parameters[1]}\" is not a valid radius."); return; } } @@ -5656,66 +5663,78 @@ namespace TShockAPI { case "item": case "items": + case "i": { int cleared = 0; for (int i = 0; i < Main.maxItems; i++) { - float dX = Main.item[i].position.X - args.Player.X; - float dY = Main.item[i].position.Y - args.Player.Y; + float dX = Main.item[i].position.X - user.X; + float dY = Main.item[i].position.Y - user.Y; if (Main.item[i].active && dX * dX + dY * dY <= radius * radius * 256f) { Main.item[i].active = false; - TSPlayer.All.SendData(PacketTypes.ItemDrop, "", i); + everyone.SendData(PacketTypes.ItemDrop, "", i); cleared++; } } - args.Player.SendSuccessMessage("Deleted {0} items within a radius of {1}.", cleared, radius); + if (args.Silent) + user.SendSuccessMessage($"You deleted {cleared} item{(cleared > 1 ? "s": "")} within a radius of {radius}."); + else + everyone.SendInfoMessage($"{user.Name} deleted {cleared} item{(cleared > 1 ? "s" : "")} within a radius of {radius}."); } break; case "npc": case "npcs": + case "n": { int cleared = 0; for (int i = 0; i < Main.maxNPCs; i++) { - float dX = Main.npc[i].position.X - args.Player.X; - float dY = Main.npc[i].position.Y - args.Player.Y; + float dX = Main.npc[i].position.X - user.X; + float dY = Main.npc[i].position.Y - user.Y; if (Main.npc[i].active && dX * dX + dY * dY <= radius * radius * 256f) { Main.npc[i].active = false; Main.npc[i].type = 0; - TSPlayer.All.SendData(PacketTypes.NpcUpdate, "", i); + everyone.SendData(PacketTypes.NpcUpdate, "", i); cleared++; } } - args.Player.SendSuccessMessage("Deleted {0} NPCs within a radius of {1}.", cleared, radius); + if (args.Silent) + user.SendSuccessMessage($"You deleted {cleared} NPC{(cleared > 1 ? "s" : "")} within a radius of {radius}."); + else + everyone.SendInfoMessage($"{user.Name} deleted {cleared} NPC{(cleared > 1 ? "s" : "")} within a radius of {radius}."); } break; case "proj": case "projectile": case "projectiles": + case "p": { int cleared = 0; for (int i = 0; i < Main.maxProjectiles; i++) { - float dX = Main.projectile[i].position.X - args.Player.X; - float dY = Main.projectile[i].position.Y - args.Player.Y; + float dX = Main.projectile[i].position.X - user.X; + float dY = Main.projectile[i].position.Y - user.Y; if (Main.projectile[i].active && dX * dX + dY * dY <= radius * radius * 256f) { Main.projectile[i].active = false; Main.projectile[i].type = 0; - TSPlayer.All.SendData(PacketTypes.ProjectileNew, "", i); + everyone.SendData(PacketTypes.ProjectileNew, "", i); cleared++; } } - args.Player.SendSuccessMessage("Deleted {0} projectiles within a radius of {1}.", cleared, radius); + if (args.Silent) + user.SendSuccessMessage($"You deleted {cleared} projectile{(cleared > 1 ? "s" : "")} within a radius of {radius}."); + else + everyone.SendInfoMessage($"{user.Name} deleted {cleared} projectile{(cleared > 1 ? "s" : "")} within a radius of {radius}"); } break; default: - args.Player.SendErrorMessage("Invalid clear option!"); + user.SendErrorMessage($"\"{args.Parameters[0]}\" is not a valid clear option."); break; } } From 57365a05348a38ac3df397f4e5c005b319232a36 Mon Sep 17 00:00:00 2001 From: stacey Date: Fri, 6 Aug 2021 22:22:18 -0400 Subject: [PATCH 17/57] add colours and examples for /kill also a bit of refactoring and other small improvements --- TShockAPI/Commands.cs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index c4245fd0..3eb31b0c 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5741,28 +5741,36 @@ namespace TShockAPI private static void Kill(CommandArgs args) { + // To-Do: separate kill self and kill other player into two permissions + var user = args.Player; if (args.Parameters.Count < 1) { - args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}kill ", Specifier); + user.SendMessage("Kill syntax and example", Color.White); + user.SendMessage($"{"kill".Color(Utils.BoldHighlight)} <{"player".Color(Utils.RedHighlight)}>", Color.White); + user.SendMessage($"Example usage: {"kill".Color(Utils.BoldHighlight)} {user.Name.Color(Utils.RedHighlight)}", Color.White); + user.SendMessage($"You can use {SilentSpecifier.Color(Utils.GreenHighlight)} instead of {Specifier.Color(Utils.RedHighlight)} to execute this command silently.", Color.White); return; } - string plStr = String.Join(" ", args.Parameters); - var players = TSPlayer.FindByNameOrID(plStr); + var players = TSPlayer.FindByNameOrID(String.Join(" ", args.Parameters)); + if (players.Count == 0) - { - args.Player.SendErrorMessage("Invalid player!"); - } + user.SendErrorMessage($"Could not find any player named \"{args.Parameters}\"."); else if (players.Count > 1) - { - args.Player.SendMultipleMatchError(players.Select(p => p.Name)); - } + user.SendMultipleMatchError(players.Select(p => p.Name)); else { - var plr = players[0]; - plr.KillPlayer(); - args.Player.SendSuccessMessage(string.Format("You just killed {0}!", plr.Name)); - plr.SendErrorMessage("{0} just killed you!", args.Player.Name); + var target = players[0]; + + if (target.Dead) + { + user.SendErrorMessage($"{(target == user ? "You" : target.Name)} {(target == user ? "are" : "is")} already dead!"); + return; + } + target.KillPlayer(); + user.SendSuccessMessage($"You just killed {(target == user ? "yourself" : target.Name)}!"); + if (!args.Silent && target != user) + target.SendErrorMessage($"{user.Name} just killed you!"); } } From a92e100836c3cf7a6aa57d9d40c6405b3c531620 Mon Sep 17 00:00:00 2001 From: stacey Date: Fri, 6 Aug 2021 22:34:13 -0400 Subject: [PATCH 18/57] Fix error msg error in /kill --- TShockAPI/Commands.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 3eb31b0c..ddc1b77a 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5752,10 +5752,11 @@ namespace TShockAPI return; } - var players = TSPlayer.FindByNameOrID(String.Join(" ", args.Parameters)); + string targetName = String.Join(" ", args.Parameters); + var players = TSPlayer.FindByNameOrID(targetName); if (players.Count == 0) - user.SendErrorMessage($"Could not find any player named \"{args.Parameters}\"."); + user.SendErrorMessage($"Could not find any player named \"{targetName}\"."); else if (players.Count > 1) user.SendMultipleMatchError(players.Select(p => p.Name)); else From 4c217bac65c0870183cbaa17704fe0dea55b0954 Mon Sep 17 00:00:00 2001 From: stacey Date: Fri, 6 Aug 2021 22:57:07 -0400 Subject: [PATCH 19/57] add colours + usage example for /butcher also added silent support --- TShockAPI/Commands.cs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index ddc1b77a..fc1e4e31 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5826,9 +5826,15 @@ namespace TShockAPI private static void Butcher(CommandArgs args) { + var user = args.Player; if (args.Parameters.Count > 1) { - args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}butcher [mob type]", Specifier); + user.SendMessage("Butcher Syntax and Example", Color.White); + user.SendMessage($"{"butcher".Color(Utils.BoldHighlight)} [{"NPC name".Color(Utils.RedHighlight)}|{"ID".Color(Utils.RedHighlight)}]", Color.White); + user.SendMessage($"Example usage: {"butcher".Color(Utils.BoldHighlight)} {"pigron".Color(Utils.RedHighlight)}", Color.White); + user.SendMessage("All alive NPCs (excluding town NPCs) on the server will be killed if you do not input a name or ID.", Color.White); + user.SendMessage($"To get rid of NPCs without making them drop items, use the {"clear".Color(Utils.BoldHighlight)} command instead.", Color.White); + user.SendMessage($"To execute this command silently, use {SilentSpecifier.Color(Utils.GreenHighlight)} instead of {Specifier.Color(Utils.RedHighlight)}", Color.White); return; } @@ -5839,18 +5845,16 @@ namespace TShockAPI var npcs = TShock.Utils.GetNPCByIdOrName(args.Parameters[0]); if (npcs.Count == 0) { - args.Player.SendErrorMessage("Invalid mob type!"); + user.SendErrorMessage($"\"{args.Parameters[0]}\" is not a valid NPC."); return; } - else if (npcs.Count > 1) + + if (npcs.Count > 1) { - args.Player.SendMultipleMatchError(npcs.Select(n => $"{n.FullName}({n.type})")); + user.SendMultipleMatchError(npcs.Select(n => $"{n.FullName}({n.type})")); return; } - else - { - npcId = npcs[0].netID; - } + npcId = npcs[0].netID; } int kills = 0; @@ -5862,7 +5866,11 @@ namespace TShockAPI kills++; } } - TSPlayer.All.SendInfoMessage("{0} butchered {1} NPCs.", args.Player.Name, kills); + + if (args.Silent) + user.SendSuccessMessage($"You butchered {kills} NPC{(kills > 1 ? "s": "")}."); + else + TSPlayer.All.SendInfoMessage($"{user.Name} butchered {kills} NPC{(kills > 1 ? "s" : "")}."); } private static void Item(CommandArgs args) From b32058ac51f161a9ff65c64fc31a964f43c0ea6f Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Sat, 7 Aug 2021 13:56:52 +0200 Subject: [PATCH 20/57] Remove the test method from Utils, re-route checks to GroupManager --- TShockAPI/Commands.cs | 2 +- TShockAPI/GetDataHandlers.cs | 4 ++-- TShockAPI/Utils.cs | 22 ---------------------- 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 276eee90..b2ad0264 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -825,7 +825,7 @@ namespace TShockAPI { var group = TShock.Groups.GetGroupByName(account.Group); - if (!TShock.Utils.AssertGroupValid(args.Player, group, false)) + if (!TShock.Groups.AssertGroupValid(args.Player, group, false)) { args.Player.SendErrorMessage("Login attempt failed - see the message above."); return; diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index a9445105..af75c90c 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2452,7 +2452,7 @@ namespace TShockAPI var group = TShock.Groups.GetGroupByName(account.Group); - if (!TShock.Utils.AssertGroupValid(args.Player, group, true)) + if (!TShock.Groups.AssertGroupValid(args.Player, group, true)) return true; args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, account.ID); @@ -3023,7 +3023,7 @@ namespace TShockAPI var group = TShock.Groups.GetGroupByName(account.Group); - if (!TShock.Utils.AssertGroupValid(args.Player, group, true)) + if (!TShock.Groups.AssertGroupValid(args.Player, group, true)) return true; args.Player.Group = group; diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 717f08a2..92d45299 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -212,28 +212,6 @@ namespace TShockAPI } while (TilePlacementValid(tileX, tileY) && TileSolid(tileX, tileY)); } - /// - /// Asserts that the group reference can be safely assigned to the player object. - /// If this assertion fails, and is true, the player is disconnected. If is false, the player will receive an error message. - /// - /// The player in question - /// The group we want to assign them - /// Whether or not failing this check disconnects the player. - /// - public bool AssertGroupValid(TSPlayer player, Group group, bool kick) - { - if (group == null) - { - if (kick) - player.Disconnect("Your account's group could not be loaded. Please contact server administrators about this."); - else - player.SendErrorMessage("Your account's group could not be loaded. Please contact server administrators about this."); - return false; - } - - return true; - } - /// /// Determines if a tile is valid. /// From 72dab02a615a296377929dded12dd4f26a729e69 Mon Sep 17 00:00:00 2001 From: stacey Date: Sat, 7 Aug 2021 09:50:29 -0400 Subject: [PATCH 21/57] add example for /heal and custom heal amount code is mostly based from /slap, now users will be able to heal a target player by a custom HP amount. I deliberately changed the static 600 HP amount to statLifeMax2 so it would use whatever max HP the target player has, this should make it work better w/ plugins that allow you to set your max HP beyond the base game's 600. --- TShockAPI/Commands.cs | 68 +++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index fc1e4e31..41b69a36 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -6121,45 +6121,51 @@ namespace TShockAPI private static void Heal(CommandArgs args) { - TSPlayer playerToHeal; - if (args.Parameters.Count > 0) + // heal [amount] + // To-Do: break up heal self and heal other into two separate permissions + var user = args.Player; + if (args.Parameters.Count < 1 || args.Parameters.Count > 2) { - string plStr = String.Join(" ", args.Parameters); - var players = TSPlayer.FindByNameOrID(plStr); - if (players.Count == 0) - { - args.Player.SendErrorMessage("Invalid player!"); - return; - } - else if (players.Count > 1) - { - args.Player.SendMultipleMatchError(players.Select(p => p.Name)); - return; - } - else - { - playerToHeal = players[0]; - } - } - else if (!args.Player.RealPlayer) - { - args.Player.SendErrorMessage("You can't heal yourself!"); + user.SendMessage("Heal Syntax and Example", Color.White); + user.SendMessage($"{"heal".Color(Utils.BoldHighlight)} <{"player".Color(Utils.RedHighlight)}> [{"amount".Color(Utils.GreenHighlight)}]", Color.White); + user.SendMessage($"Example usage: {"heal".Color(Utils.BoldHighlight)} {user.Name.Color(Utils.RedHighlight)} {"100".Color(Utils.GreenHighlight)}", Color.White); + user.SendMessage($"If no amount is specified, it will default to healing the target player by their max HP.", Color.White); + user.SendMessage($"To execute this command silently, use {SilentSpecifier.Color(Utils.GreenHighlight)} instead of {Specifier.Color(Utils.RedHighlight)}", Color.White); return; } - else + if (args.Parameters[0].Length == 0) { - playerToHeal = args.Player; + user.SendErrorMessage($"You didn't put a player name."); + return; } - playerToHeal.Heal(); - if (playerToHeal == args.Player) - { - args.Player.SendSuccessMessage("You just got healed!"); - } + string targetName = args.Parameters[0]; + var players = TSPlayer.FindByNameOrID(targetName); + if (players.Count == 0) + user.SendErrorMessage($"Unable to find any players named \"{targetName}\""); + else if (players.Count > 1) + user.SendMultipleMatchError(players.Select(p => p.Name)); else { - args.Player.SendSuccessMessage(string.Format("You just healed {0}", playerToHeal.Name)); - playerToHeal.SendSuccessMessage(string.Format("{0} just healed you!", args.Player.Name)); + var target = players[0]; + int amount = target.TPlayer.statLifeMax2; + + if (target.Dead) + { + user.SendErrorMessage("You can't heal a dead player!"); + return; + } + + if (args.Parameters.Count == 2) + { + int.TryParse(args.Parameters[1], out amount); + } + target.Heal(amount); + + if (args.Silent) + user.SendSuccessMessage($"You healed {(target == user ? "yourself" : target.Name)} for {amount} HP."); + else + TSPlayer.All.SendInfoMessage($"{user.Name} healed {(target == user ? (target.TPlayer.Male ? "himself" : "herself") : target.Name)} for {amount} HP."); } } From 6754cd48b4a4006045e38d9fc0ab1ec09cbec288 Mon Sep 17 00:00:00 2001 From: stacey Date: Sat, 7 Aug 2021 10:04:49 -0400 Subject: [PATCH 22/57] add examples for /buff --- TShockAPI/Commands.cs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 41b69a36..92b3abde 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -6171,42 +6171,53 @@ namespace TShockAPI private static void Buff(CommandArgs args) { + // buff [duration] + var user = args.Player; if (args.Parameters.Count < 1 || args.Parameters.Count > 2) { - args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}buff [time in seconds]", Specifier); + user.SendMessage("Buff Syntax and Example", Color.White); + user.SendMessage($"buff [duration]", Color.White); + user.SendMessage($"Example usage: buff [seconds]", Color.White); + user.SendMessage("If you don't specify the duration, it will default to 60 seconds.", Color.White); + user.SendMessage("If you put -1 as the duration, it will use the max possible time of 415 days.", Color.White); return; } + int id = 0; int time = 60; var timeLimit = (int.MaxValue / 60) - 1; + if (!int.TryParse(args.Parameters[0], out id)) { var found = TShock.Utils.GetBuffByName(args.Parameters[0]); + if (found.Count == 0) { - args.Player.SendErrorMessage("Invalid buff name!"); + user.SendErrorMessage($"Unable to find any buffs named \"{args.Parameters[0]}\""); return; } - else if (found.Count > 1) + + if (found.Count > 1) { - args.Player.SendMultipleMatchError(found.Select(f => Lang.GetBuffName(f))); + user.SendMultipleMatchError(found.Select(f => Lang.GetBuffName(f))); return; } id = found[0]; } + if (args.Parameters.Count == 2) int.TryParse(args.Parameters[1], out time); + if (id > 0 && id < Main.maxBuffTypes) { - // Max possible buff duration as of 1.4.2.2 is 35791393 seconds (415 days). + // Max possible buff duration as of Terraria 1.4.2.3 is 35791393 seconds (415 days). if (time < 0 || time > timeLimit) time = timeLimit; - args.Player.SetBuff(id, time * 60); - args.Player.SendSuccessMessage(string.Format("You have buffed yourself with {0} ({1}) for {2} seconds!", - TShock.Utils.GetBuffName(id), TShock.Utils.GetBuffDescription(id), (time))); + user.SetBuff(id, time * 60); + user.SendSuccessMessage($"You buffed yourself with {TShock.Utils.GetBuffName(id)} ({TShock.Utils.GetBuffDescription(id)}) for {time} seconds."); } else - args.Player.SendErrorMessage("Invalid buff ID!"); + user.SendErrorMessage($"\"{id}\" is not a valid buff ID!"); } private static void GBuff(CommandArgs args) From de18c5d8dac25beae6a4032a9236df2a767fec42 Mon Sep 17 00:00:00 2001 From: stacey Date: Sat, 7 Aug 2021 10:45:35 -0400 Subject: [PATCH 23/57] forgot to add colours to /buff --- TShockAPI/Commands.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 92b3abde..6f6fae34 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -6171,15 +6171,15 @@ namespace TShockAPI private static void Buff(CommandArgs args) { - // buff [duration] + // buff <"buff name|ID"> [duration] var user = args.Player; if (args.Parameters.Count < 1 || args.Parameters.Count > 2) { user.SendMessage("Buff Syntax and Example", Color.White); - user.SendMessage($"buff [duration]", Color.White); - user.SendMessage($"Example usage: buff [seconds]", Color.White); - user.SendMessage("If you don't specify the duration, it will default to 60 seconds.", Color.White); - user.SendMessage("If you put -1 as the duration, it will use the max possible time of 415 days.", Color.White); + user.SendMessage($"{"buff".Color(Utils.BoldHighlight)} <\"{"buff name".Color(Utils.RedHighlight)}|{"ID".Color(Utils.RedHighlight)}\"> [{"duration".Color(Utils.GreenHighlight)}]", Color.White); + user.SendMessage($"Example usage: {"buff".Color(Utils.BoldHighlight)} \"{"obsidian skin".Color(Utils.RedHighlight)}\" {"-1".Color(Utils.GreenHighlight)}", Color.White); + user.SendMessage($"If you don't specify the duration, it will default to {"60".Color(Utils.GreenHighlight)} seconds.", Color.White); + user.SendMessage($"If you put {"-1".Color(Utils.GreenHighlight)} as the duration, it will use the max possible time of 415 days.", Color.White); return; } From a6eff08c82510e810665e4ea158705bf749beb76 Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Sun, 8 Aug 2021 12:31:30 +0200 Subject: [PATCH 24/57] Checkout the same TSAPI as gen-dev. --- TerrariaServerAPI | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TerrariaServerAPI b/TerrariaServerAPI index 4b555bc3..8c2c0873 160000 --- a/TerrariaServerAPI +++ b/TerrariaServerAPI @@ -1 +1 @@ -Subproject commit 4b555bc373dbb470bc69ebed69c79de116f28df2 +Subproject commit 8c2c087327bbd1f20ff6c46f4d11e5714e57064b From 855bdcb57f78b971ab7923c067a206ec79be2c1f Mon Sep 17 00:00:00 2001 From: stacey Date: Sun, 8 Aug 2021 21:08:49 -0400 Subject: [PATCH 25/57] add color and examples for /gbuff --- TShockAPI/Commands.cs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 6f6fae34..7fd52b01 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -6222,9 +6222,13 @@ namespace TShockAPI private static void GBuff(CommandArgs args) { + var user = args.Player; if (args.Parameters.Count < 2 || args.Parameters.Count > 3) { - args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}gbuff [time in seconds]", Specifier); + user.SendMessage("Give Buff Syntax and Example", Color.White); + user.SendMessage($"{"gbuff".Color(Utils.BoldHighlight)} <{"player".Color(Utils.RedHighlight)}> <{"buff name".Color(Utils.PinkHighlight)}|{"ID".Color(Utils.PinkHighlight)}> [{"seconds".Color(Utils.GreenHighlight)}]", Color.White); + user.SendMessage($"Example usage: {"gbuff".Color(Utils.BoldHighlight)} {user.Name.Color(Utils.RedHighlight)} {"regen".Color(Utils.PinkHighlight)} {"-1".Color(Utils.GreenHighlight)}", Color.White); + user.SendMessage($"To buff a player without them knowing, use {SilentSpecifier.Color(Utils.RedHighlight)} instead of {Specifier.Color(Utils.GreenHighlight)}", Color.White); return; } int id = 0; @@ -6233,12 +6237,12 @@ namespace TShockAPI var foundplr = TSPlayer.FindByNameOrID(args.Parameters[0]); if (foundplr.Count == 0) { - args.Player.SendErrorMessage("Invalid player!"); + user.SendErrorMessage($"Unable to find any player named \"{args.Parameters[0]}\""); return; } else if (foundplr.Count > 1) { - args.Player.SendMultipleMatchError(foundplr.Select(p => p.Name)); + user.SendMultipleMatchError(foundplr.Select(p => p.Name)); return; } else @@ -6248,12 +6252,12 @@ namespace TShockAPI var found = TShock.Utils.GetBuffByName(args.Parameters[1]); if (found.Count == 0) { - args.Player.SendErrorMessage("Invalid buff name!"); + user.SendErrorMessage($"Unable to find any buff named \"{args.Parameters[1]}\""); return; } else if (found.Count > 1) { - args.Player.SendMultipleMatchError(found.Select(b => Lang.GetBuffName(b))); + user.SendMultipleMatchError(found.Select(b => Lang.GetBuffName(b))); return; } id = found[0]; @@ -6262,18 +6266,16 @@ namespace TShockAPI int.TryParse(args.Parameters[2], out time); if (id > 0 && id < Main.maxBuffTypes) { + var target = foundplr[0]; if (time < 0 || time > timeLimit) time = timeLimit; - foundplr[0].SetBuff(id, time * 60); - args.Player.SendSuccessMessage(string.Format("You have buffed {0} with {1} ({2}) for {3} seconds!", - foundplr[0].Name, TShock.Utils.GetBuffName(id), - TShock.Utils.GetBuffDescription(id), (time))); - foundplr[0].SendSuccessMessage(string.Format("{0} has buffed you with {1} ({2}) for {3} seconds!", - args.Player.Name, TShock.Utils.GetBuffName(id), - TShock.Utils.GetBuffDescription(id), (time))); + target.SetBuff(id, time * 60); + user.SendSuccessMessage($"You have buffed {(target == user ? "yourself" : target.Name)} with {TShock.Utils.GetBuffName(id)} ({TShock.Utils.GetBuffDescription(id)}) for {time} seconds!"); + if (!args.Silent && target != user) + target.SendSuccessMessage($"{user.Name} has buffed you with {TShock.Utils.GetBuffName(id)} ({TShock.Utils.GetBuffDescription(id)}) for {time} seconds!"); } else - args.Player.SendErrorMessage("Invalid buff ID!"); + user.SendErrorMessage("Invalid buff ID!"); } } From 988c36e3ac3071510c26d889f592dbc93c1cb781 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 17 Aug 2021 13:05:17 -0700 Subject: [PATCH 26/57] Added warning about SSC config wipe in 4.5.3 land --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e03b4fa..62554a26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * TShock defaults to saving backups every 10 minutes, and defaults to keeping backups for 4 hours. (@hakusaro) * Updated SSC bypass messaging. Now, when you connect, you're told if you're bypassing SSC. Console logging has been improved to warn when players are not being saved due to the bypass SSC permission. To turn this warning off, change `WarnPlayersAboutBypassPermission` to `false` in the `sscconfig.json` file. (@hakusaro) * Fix oversight & exploit allowing specially crafted SendTileRectangle packets to perform large-scale world griefing. In addition, `NetTile.Slope` is now the native value (byte), and accessor methods `Slope1`, `Slope2`, and `Slope3` can be used to get the old style of values out. `HalfBrick` and `Actuator` were removed from `NetTile` because these were initialized to zero and never changed or used. (@bartico6) +* Warning: a bug introduced in a prior TShock release may cause your SSC config file to be reset after applying this update. Please backup your config file prior to installing TShock 4.5.3+ if you use SSC. (@cardinal-system) ## TShock 4.5.2 * Added preliminary support for Terraria 1.4.2.2. (@hakusaro) From 5bcd37949bea47cd29622fe9262da6c522a9a156 Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Mon, 23 Aug 2021 22:58:56 +0200 Subject: [PATCH 27/57] Editing the return in HandleSpecial; Fixes #2436. --- TShockAPI/GetDataHandlers.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 3bed28b2..b4307050 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3240,6 +3240,7 @@ namespace TShockAPI { TShock.Log.ConsoleDebug($"GetDataHandlers / HandleSpecial rejected enchanted sundial permission {args.Player.Name}"); args.Player.SendErrorMessage("You do not have permission to use the Enchanted Sundial."); + return true; } else if (TShock.Config.Settings.ForceTime != "normal") { @@ -3250,8 +3251,8 @@ namespace TShockAPI } else args.Player.SendErrorMessage("You must set ForceTime to normal via config to use the Enchanted Sundial."); + return true; } - return true; } return false; From 1eae9dbecabad2466034aef73f61b651ca57805b Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Mon, 23 Aug 2021 23:00:35 +0200 Subject: [PATCH 28/57] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62554a26..6247df84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added a new `/respawn` command that lets you respawn yourself or another player. Respawning yourself requires the `tshock.respawn` permission and respawning others requires the `tshock.respawn.other` permission. The full command syntax is `/respawn [player]`. (@moisterrific) * Added a notification message and silent command support for permanently changing a target player's user group. Now players who received a group change will be notified of their new group if they are currently online. (@moisterrific, @QuiCM) * Changed the TSPlayer IP method to return the loopback IP if RealPlayer is false. (@Rozen4334) +* Changed return in ` HandleSpecial ` (GetDataHandlers) to fix Sundail problem. (@Rozen4334) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) From ea09286483b5e7b8f7bd5318141189ee2b06109b Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Mon, 23 Aug 2021 23:07:12 +0200 Subject: [PATCH 29/57] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6247df84..5c244b21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added a new `/respawn` command that lets you respawn yourself or another player. Respawning yourself requires the `tshock.respawn` permission and respawning others requires the `tshock.respawn.other` permission. The full command syntax is `/respawn [player]`. (@moisterrific) * Added a notification message and silent command support for permanently changing a target player's user group. Now players who received a group change will be notified of their new group if they are currently online. (@moisterrific, @QuiCM) * Changed the TSPlayer IP method to return the loopback IP if RealPlayer is false. (@Rozen4334) -* Changed return in ` HandleSpecial ` (GetDataHandlers) to fix Sundail problem. (@Rozen4334) +* Changed return in ` HandleSpecial ` (GetDataHandlers) to fix Sundial problem. (@Rozen4334) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) From b60d62fb74cf14c6f1f7c5d3faeba5f6f654834d Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Wed, 25 Aug 2021 12:41:28 +0200 Subject: [PATCH 30/57] Properly clarifying issue + fix; --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c55bed2a..fa5c6677 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added a new `/respawn` command that lets you respawn yourself or another player. Respawning yourself requires the `tshock.respawn` permission and respawning others requires the `tshock.respawn.other` permission. The full command syntax is `/respawn [player]`. (@moisterrific) * Added a notification message and silent command support for permanently changing a target player's user group. Now players who received a group change will be notified of their new group if they are currently online. (@moisterrific, @QuiCM) * Changed the TSPlayer IP method to return the loopback IP if RealPlayer is false. (@Rozen4334) -* Changed return in ` HandleSpecial ` (GetDataHandlers) to fix Sundial problem. (@Rozen4334) +* Changed return result in ` HandleSpecial ` to fix problem where using sundial would be ignored and return true even if succesfully passing checks. (@Rozen4334) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) From bc1a548edfbf487fddfb50e02caf861770f83d3d Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Wed, 25 Aug 2021 13:10:54 +0200 Subject: [PATCH 31/57] Following up on changelog entry suggestion; Co-authored-by: Chris <2648373+QuiCM@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa5c6677..f007a22c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added a new `/respawn` command that lets you respawn yourself or another player. Respawning yourself requires the `tshock.respawn` permission and respawning others requires the `tshock.respawn.other` permission. The full command syntax is `/respawn [player]`. (@moisterrific) * Added a notification message and silent command support for permanently changing a target player's user group. Now players who received a group change will be notified of their new group if they are currently online. (@moisterrific, @QuiCM) * Changed the TSPlayer IP method to return the loopback IP if RealPlayer is false. (@Rozen4334) -* Changed return result in ` HandleSpecial ` to fix problem where using sundial would be ignored and return true even if succesfully passing checks. (@Rozen4334) +* Fixed a bug that caused sundials to be ignored all the time, instead of only when the player has no permission or time is frozen. (@Rozen4334) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) From bc5c337b5ebcfd1ebb54bc579b94af63205595a1 Mon Sep 17 00:00:00 2001 From: Stargazing Koishi Date: Tue, 31 Aug 2021 19:54:40 -0700 Subject: [PATCH 32/57] Update `/help` for `/setup` change The auth command was renamed in 8451ef9fb77d76cf63da4c67263d8f9d5dcca99b but the `/help` command was not updated. --- TShockAPI/Commands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 195ed2e2..61a57ecd 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5109,7 +5109,7 @@ namespace TShockAPI } IEnumerable cmdNames = from cmd in ChatCommands - where cmd.CanRun(args.Player) && (cmd.Name != "auth" || TShock.SetupToken != 0) + where cmd.CanRun(args.Player) && (cmd.Name != "setup" || TShock.SetupToken != 0) select Specifier + cmd.Name; PaginationTools.SendPage(args.Player, pageNumber, PaginationTools.BuildLinesFromTerms(cmdNames), From d8aa7b0f69ec66aaa46a302f70048d00838a6a58 Mon Sep 17 00:00:00 2001 From: stacey <57187883+moisterrific@users.noreply.github.com> Date: Mon, 13 Sep 2021 10:02:03 -0400 Subject: [PATCH 33/57] Change RespawnSeconds & RespawnBossSeconds to use default a value of 0 will use the default time based on selected difficulty --- TShockAPI/Configuration/TShockConfig.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/TShockAPI/Configuration/TShockConfig.cs b/TShockAPI/Configuration/TShockConfig.cs index 14e56cb6..38ed0c46 100644 --- a/TShockAPI/Configuration/TShockConfig.cs +++ b/TShockAPI/Configuration/TShockConfig.cs @@ -251,13 +251,13 @@ namespace TShockAPI.Configuration [Description("Allows groups on the banned item allowed list to spawn banned items even if PreventBannedItemSpawn is set to true.")] public bool AllowAllowedGroupsToSpawnBannedItems = false; - /// The number of seconds a player must wait before being respawned. Cannot be longer than normal value now. Use at your own risk. - [Description("The number of seconds a player must wait before being respawned. Cannot be longer than normal value now. Use at your own risk.")] - public int RespawnSeconds = 10; + /// The number of seconds a player must wait before being respawned. Valid range: 0 (default) to 15 seconds. Use at your own risk. + [Description("The number of seconds a player must wait before being respawned. Valid range: 0 (default) to 15 seconds. Use at your own risk.")] + public int RespawnSeconds = 0; - /// The number of seconds a player must wait before being respawned if there is a boss nearby. Cannot be longer than normal value now. Use at your own risk. - [Description("The number of seconds a player must wait before being respawned if there is a boss nearby. Cannot be longer than normal value now. Use at your own risk.")] - public int RespawnBossSeconds = 10; + /// The number of seconds a player must wait before being respawned if there is a boss nearby. Valid range: 0 (default) to 30 seconds. Use at your own risk. + [Description("The number of seconds a player must wait before being respawned if there is a boss nearby. Valid range: 0 (default) to 30 seconds. Use at your own risk.")] + public int RespawnBossSeconds = 0; /// Whether or not to announce boss spawning or invasion starts. [Description("Whether or not to announce boss spawning or invasion starts.")] From 8ce61c1e0154afd35942f2e81c4f24a56eb6138e Mon Sep 17 00:00:00 2001 From: stacey <57187883+moisterrific@users.noreply.github.com> Date: Mon, 13 Sep 2021 10:04:06 -0400 Subject: [PATCH 34/57] Add RespawnSeconds change to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f007a22c..f962e669 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added a notification message and silent command support for permanently changing a target player's user group. Now players who received a group change will be notified of their new group if they are currently online. (@moisterrific, @QuiCM) * Changed the TSPlayer IP method to return the loopback IP if RealPlayer is false. (@Rozen4334) * Fixed a bug that caused sundials to be ignored all the time, instead of only when the player has no permission or time is frozen. (@Rozen4334) +* Changed `RespawnSeconds` and `RespawnBossSeconds` from `10` to `0` to respect the game's default respawn timers. (@moisterrific) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) From f7effe9c822119e93ec98b30d95a333257b298d1 Mon Sep 17 00:00:00 2001 From: Nezbednik <47603275+NezbednikSK@users.noreply.github.com> Date: Sat, 13 Nov 2021 08:37:15 +0100 Subject: [PATCH 35/57] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2dd705ce..93d08ba6 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ You need to re-run the patcher any time `OTAPI` updates. You need to rebuild `Te 1. Verify that non-zero modifications ran successfully. Then, build the Terraria Server API executable. - $ cd ./../../../ + $ cd ../../../../ $ xbuild ./TerrariaServerAPI/TerrariaServerAPI/TerrariaServerAPI.csproj \ /p:Configuration=$BUILD_MODE @@ -220,13 +220,13 @@ You need to re-run the patcher any time `OTAPI` updates. You need to rebuild `Te ##### TShock -1. Perform a NuGet restore in `TShockAPI` folder that contains `TShockAPI.sln`. +1. Perform a NuGet restore in the folder that contains `TShock.sln`. $ mono ~/bin/nuget.exe restore 1. Build TShock in the `BUILD_MODE` you set earlier. - $ xbuild ./TShockAPI.sln /p:Configuration=$BUILD_MODE + $ xbuild ./TShock.sln /p:Configuration=$BUILD_MODE You're done! From 5bf36fd799e4c73ed3c0b8cb8f79c28a3babcdfe Mon Sep 17 00:00:00 2001 From: Nezbednik <47603275+NezbednikSK@users.noreply.github.com> Date: Sat, 13 Nov 2021 08:46:14 +0100 Subject: [PATCH 36/57] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f007a22c..af12b9d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * 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 +* Updated Linux guide. (@NezbednikSK) * Fixed SendTileRectHandler not sending tile rect updates like Pylons/Mannequins to other clients. (@Stealownz) * Introduced `SoftcoreOnly` config option to allow only softcore characters to connect. (@drunderscore) * Fixed some typos that have been in the repository for over a lustrum. (@Killia0) From 42ca83e6b58ffa2fc5da2317ffcbcfad72260db4 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 19 Nov 2021 22:39:45 -0800 Subject: [PATCH 37/57] Update version codename and changelog for 1.4.3 --- CHANGELOG.md | 1 + TShockAPI/TShock.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1339f97..bf0ec5e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fixed a bug that caused sundials to be ignored all the time, instead of only when the player has no permission or time is frozen. (@Rozen4334) * Added colours and usage examples (similiar to how the new ban system looks) for many more commands. (@moisterrific) * Changed `RespawnSeconds` and `RespawnBossSeconds` from `10` to `0` to respect the game's default respawn timers. (@moisterrific) +* Updated Open Terraria API (OTAPI) and TSAPI for preliminary support of Terraria 1.4.3.0 (@Patrikkk, @DeathCradle, honorable mention: @Moneylover3246) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 958d6507..ae6b6e00 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -58,7 +58,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 = "Olympics maybe?"; + public static readonly string VersionCodename = "Herrscher of Logic"; /// 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"; From b44d72056c081942f4a765418f1094af40c8520c Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 19 Nov 2021 22:48:41 -0800 Subject: [PATCH 38/57] Update TSAPI submodule for OTAPI 2.0.0.45 (Terraria 1.4.3.0) --- CHANGELOG.md | 2 +- TerrariaServerAPI | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf0ec5e8..c35983e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fixed a bug that caused sundials to be ignored all the time, instead of only when the player has no permission or time is frozen. (@Rozen4334) * Added colours and usage examples (similiar to how the new ban system looks) for many more commands. (@moisterrific) * Changed `RespawnSeconds` and `RespawnBossSeconds` from `10` to `0` to respect the game's default respawn timers. (@moisterrific) -* Updated Open Terraria API (OTAPI) and TSAPI for preliminary support of Terraria 1.4.3.0 (@Patrikkk, @DeathCradle, honorable mention: @Moneylover3246) +* Updated Open Terraria API (OTAPI) and TSAPI for preliminary support of Terraria 1.4.3.0. This functionally changes OTAPI and points to 2.0.0.45 from 2.0.0.43 in previous versions. Developer note: SendData takes an extra arg in this version of Terraria but that's slated to be removed in a Terraria hotfix. This is vestigial and OTAPI "hacks that out." That's why it'll differ from the source code. (@Patrikkk, @DeathCradle, honorable mention: @Moneylover3246) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) diff --git a/TerrariaServerAPI b/TerrariaServerAPI index 8c2c0873..88e2ecb7 160000 --- a/TerrariaServerAPI +++ b/TerrariaServerAPI @@ -1 +1 @@ -Subproject commit 8c2c087327bbd1f20ff6c46f4d11e5714e57064b +Subproject commit 88e2ecb7d61e0c3cbc9b25dec8555458262a2796 From abb12629adab7dccba221537515e1c22de7d921a Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 20 Nov 2021 12:04:55 -0800 Subject: [PATCH 39/57] Add Deerclops to spawnboss command Fixes #2500 --- CHANGELOG.md | 1 + TShockAPI/Commands.cs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c35983e2..92e7f190 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added colours and usage examples (similiar to how the new ban system looks) for many more commands. (@moisterrific) * Changed `RespawnSeconds` and `RespawnBossSeconds` from `10` to `0` to respect the game's default respawn timers. (@moisterrific) * Updated Open Terraria API (OTAPI) and TSAPI for preliminary support of Terraria 1.4.3.0. This functionally changes OTAPI and points to 2.0.0.45 from 2.0.0.43 in previous versions. Developer note: SendData takes an extra arg in this version of Terraria but that's slated to be removed in a Terraria hotfix. This is vestigial and OTAPI "hacks that out." That's why it'll differ from the source code. (@Patrikkk, @DeathCradle, honorable mention: @Moneylover3246) +* Added Deerclops to spawnboss command. (@hakusaro, @HiddenStriker) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 08dfb7cf..0406e858 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -2674,6 +2674,11 @@ namespace TShockAPI TSPlayer.Server.SpawnNPC(npc.type, npc.FullName, amount, args.Player.TileX, args.Player.TileY); spawnName = "a Stardust Pillar"; break; + case "deerclops": + npc.SetDefaults(668); + TSPlayer.Server.SpawnNPC(npc.type, npc.FullName, amount, args.Player.TileX, args.Player.TileY); + spawnName = "a Deerclops"; + break; default: args.Player.SendErrorMessage("Invalid boss type!"); return; From 96b260532f2adb751aa1f637bd0e378f002e8566 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 20 Nov 2021 12:08:16 -0800 Subject: [PATCH 40/57] Fix GHSA-6w5v-hxr3-m2wx via changelog update --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92e7f190..bcf56c68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Changed `RespawnSeconds` and `RespawnBossSeconds` from `10` to `0` to respect the game's default respawn timers. (@moisterrific) * Updated Open Terraria API (OTAPI) and TSAPI for preliminary support of Terraria 1.4.3.0. This functionally changes OTAPI and points to 2.0.0.45 from 2.0.0.43 in previous versions. Developer note: SendData takes an extra arg in this version of Terraria but that's slated to be removed in a Terraria hotfix. This is vestigial and OTAPI "hacks that out." That's why it'll differ from the source code. (@Patrikkk, @DeathCradle, honorable mention: @Moneylover3246) * Added Deerclops to spawnboss command. (@hakusaro, @HiddenStriker) +* Fixed [GHSA-6w5v-hxr3-m2wx](https://github.com/Pryaxis/TShock/security/advisories/GHSA-6w5v-hxr3-m2wx). (@Yoraiz0r, @Arthri) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) From 16a31e6677eccb4d1a5fe9c304844780641d3db9 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 20 Nov 2021 12:10:54 -0800 Subject: [PATCH 41/57] Update changelog to fix formatting --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcf56c68..e7f2867e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fixed a bug that caused sundials to be ignored all the time, instead of only when the player has no permission or time is frozen. (@Rozen4334) * Added colours and usage examples (similiar to how the new ban system looks) for many more commands. (@moisterrific) * Changed `RespawnSeconds` and `RespawnBossSeconds` from `10` to `0` to respect the game's default respawn timers. (@moisterrific) -* Updated Open Terraria API (OTAPI) and TSAPI for preliminary support of Terraria 1.4.3.0. This functionally changes OTAPI and points to 2.0.0.45 from 2.0.0.43 in previous versions. Developer note: SendData takes an extra arg in this version of Terraria but that's slated to be removed in a Terraria hotfix. This is vestigial and OTAPI "hacks that out." That's why it'll differ from the source code. (@Patrikkk, @DeathCradle, honorable mention: @Moneylover3246) +* Updated Open Terraria API (OTAPI) and TSAPI for preliminary support of Terraria 1.4.3.0. This functionally changes OTAPI and points to 2.0.0.45 from 2.0.0.43 in previous versions. Developer note: `SendData` takes an extra arg in this version of Terraria but that's slated to be removed in a Terraria hotfix. This is vestigial and OTAPI "hacks that out" to preserve plugin compatibility. That's why it'll differ from the source code. (@Patrikkk, @DeathCradle, honorable mention: @Moneylover3246) * Added Deerclops to spawnboss command. (@hakusaro, @HiddenStriker) * Fixed [GHSA-6w5v-hxr3-m2wx](https://github.com/Pryaxis/TShock/security/advisories/GHSA-6w5v-hxr3-m2wx). (@Yoraiz0r, @Arthri) From 6bcd9753c7768891c01cb7c2cadf1f9feeae62bb Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 20 Nov 2021 12:11:28 -0800 Subject: [PATCH 42/57] Add even more formatting to changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7f2867e..7c43bf6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added colours and usage examples (similiar to how the new ban system looks) for many more commands. (@moisterrific) * Changed `RespawnSeconds` and `RespawnBossSeconds` from `10` to `0` to respect the game's default respawn timers. (@moisterrific) * Updated Open Terraria API (OTAPI) and TSAPI for preliminary support of Terraria 1.4.3.0. This functionally changes OTAPI and points to 2.0.0.45 from 2.0.0.43 in previous versions. Developer note: `SendData` takes an extra arg in this version of Terraria but that's slated to be removed in a Terraria hotfix. This is vestigial and OTAPI "hacks that out" to preserve plugin compatibility. That's why it'll differ from the source code. (@Patrikkk, @DeathCradle, honorable mention: @Moneylover3246) -* Added Deerclops to spawnboss command. (@hakusaro, @HiddenStriker) +* Added Deerclops to `/spawnboss` command. (@hakusaro, @HiddenStriker) * Fixed [GHSA-6w5v-hxr3-m2wx](https://github.com/Pryaxis/TShock/security/advisories/GHSA-6w5v-hxr3-m2wx). (@Yoraiz0r, @Arthri) ## TShock 4.5.5 From f523d38300a08cf288a9c1f2a64dc2ceceb0fcfe Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 20 Nov 2021 18:19:47 -0800 Subject: [PATCH 43/57] Check RegionProtectGemLocks before enforcing perms Fixes #2485. Bouncer now checks to ensure that RegionProtectGemLocks is enabled before attempting to reject changes from gem locks from players that don't have build permissions. --- CHANGELOG.md | 1 + TShockAPI/Bouncer.cs | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c43bf6d..95984319 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Updated Open Terraria API (OTAPI) and TSAPI for preliminary support of Terraria 1.4.3.0. This functionally changes OTAPI and points to 2.0.0.45 from 2.0.0.43 in previous versions. Developer note: `SendData` takes an extra arg in this version of Terraria but that's slated to be removed in a Terraria hotfix. This is vestigial and OTAPI "hacks that out" to preserve plugin compatibility. That's why it'll differ from the source code. (@Patrikkk, @DeathCradle, honorable mention: @Moneylover3246) * Added Deerclops to `/spawnboss` command. (@hakusaro, @HiddenStriker) * Fixed [GHSA-6w5v-hxr3-m2wx](https://github.com/Pryaxis/TShock/security/advisories/GHSA-6w5v-hxr3-m2wx). (@Yoraiz0r, @Arthri) +* Fixed an issue where player build permissions would reject gem lock changes, even if `RegionProtectGemLocks` was disabled in the config file. Now, players will be permitted to use gem locks if they don't have build permission in a region, but `RegionProtectGemLocks` is disabled. If `RegionProtectGemLocks` is enabled, players will be unable to use gem locks in a build region. (@hakusaro, @Kojirremer, @Arthri) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index a625190b..746904cd 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -1922,11 +1922,14 @@ namespace TShockAPI return; } - if (!args.Player.HasBuildPermission(args.X, args.Y)) + if (TShock.Config.Settings.RegionProtectGemLocks) { - TShock.Log.ConsoleDebug("Bouncer / OnGemLockToggle rejected permissions check from {0}", args.Player.Name); - args.Handled = true; - return; + if (!args.Player.HasBuildPermission(args.X, args.Y)) + { + TShock.Log.ConsoleDebug("Bouncer / OnGemLockToggle rejected permissions check from {0}", args.Player.Name); + args.Handled = true; + return; + } } } From 1aa9956e45c5d687644581de510f7a510cb24e86 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 20 Nov 2021 20:02:23 -0800 Subject: [PATCH 44/57] Report correct god mode status to target player The previous version of the code always told the player having their god mode toggled the state of the player that issued the command, rather than their own god mode state. This fixes that issue, and now returns the correct player's state to the correct player. --- CHANGELOG.md | 1 + TShockAPI/Commands.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95984319..af4a51b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added Deerclops to `/spawnboss` command. (@hakusaro, @HiddenStriker) * Fixed [GHSA-6w5v-hxr3-m2wx](https://github.com/Pryaxis/TShock/security/advisories/GHSA-6w5v-hxr3-m2wx). (@Yoraiz0r, @Arthri) * Fixed an issue where player build permissions would reject gem lock changes, even if `RegionProtectGemLocks` was disabled in the config file. Now, players will be permitted to use gem locks if they don't have build permission in a region, but `RegionProtectGemLocks` is disabled. If `RegionProtectGemLocks` is enabled, players will be unable to use gem locks in a build region. (@hakusaro, @Kojirremer, @Arthri) +* Fixed an issue where `/god [player]` would tell `[player]` that they were in godmode regardless of whether or not they were or not. (@hakusaro, @Kojirremer) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 0406e858..8d620e73 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -6697,7 +6697,7 @@ namespace TShockAPI if (!args.Silent || (playerToGod == args.Player)) { - playerToGod.SendSuccessMessage(string.Format("You are {0} in god mode.", args.Player.GodMode ? "now" : "no longer")); + playerToGod.SendSuccessMessage(string.Format("You are {0} in god mode.", playerToGod.GodMode ? "now" : "no longer")); } } From 70d4bb9503f467b8949cf54fc1c9e4d7cfd00515 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 20 Nov 2021 23:50:15 -0800 Subject: [PATCH 45/57] Update submodule for PacketTypes updates --- CHANGELOG.md | 1 + TerrariaServerAPI | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af4a51b0..f78915fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fixed [GHSA-6w5v-hxr3-m2wx](https://github.com/Pryaxis/TShock/security/advisories/GHSA-6w5v-hxr3-m2wx). (@Yoraiz0r, @Arthri) * Fixed an issue where player build permissions would reject gem lock changes, even if `RegionProtectGemLocks` was disabled in the config file. Now, players will be permitted to use gem locks if they don't have build permission in a region, but `RegionProtectGemLocks` is disabled. If `RegionProtectGemLocks` is enabled, players will be unable to use gem locks in a build region. (@hakusaro, @Kojirremer, @Arthri) * Fixed an issue where `/god [player]` would tell `[player]` that they were in godmode regardless of whether or not they were or not. (@hakusaro, @Kojirremer) +* In `TSAPI`: Updated `PacketTypes` to support `SetMiscEventValues` (140), `RequestLucyPopup` (141), and `SyncProjectileTrackers` (142). (@hakusaro) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) diff --git a/TerrariaServerAPI b/TerrariaServerAPI index 88e2ecb7..302d9b75 160000 --- a/TerrariaServerAPI +++ b/TerrariaServerAPI @@ -1 +1 @@ -Subproject commit 88e2ecb7d61e0c3cbc9b25dec8555458262a2796 +Subproject commit 302d9b7595f3bdc9d66190de99129c34debef260 From b17c4cfc13adb44b02924e7f434c155b07add74f Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 21 Nov 2021 14:30:59 -0800 Subject: [PATCH 46/57] Add support for disabling IP bans by default Some proxy users find it irritating when their proxy IP is banned by the ban command. This helps those users find justice in the world. --- CHANGELOG.md | 1 + TShockAPI/Commands.cs | 5 +++++ TShockAPI/Configuration/TShockConfig.cs | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f78915fe..57edca99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fixed an issue where player build permissions would reject gem lock changes, even if `RegionProtectGemLocks` was disabled in the config file. Now, players will be permitted to use gem locks if they don't have build permission in a region, but `RegionProtectGemLocks` is disabled. If `RegionProtectGemLocks` is enabled, players will be unable to use gem locks in a build region. (@hakusaro, @Kojirremer, @Arthri) * Fixed an issue where `/god [player]` would tell `[player]` that they were in godmode regardless of whether or not they were or not. (@hakusaro, @Kojirremer) * In `TSAPI`: Updated `PacketTypes` to support `SetMiscEventValues` (140), `RequestLucyPopup` (141), and `SyncProjectileTrackers` (142). (@hakusaro) +* Added `DisableDefaultIPBan` to the config file. If set to `true`, the server will not automatically IP ban players when banning them. This is useful if you run an intercepting proxy in front of TShock, and all players share the same IP. (@hakusaro, and Telegram user xmzzhh233) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 8d620e73..00a745f9 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1514,6 +1514,11 @@ namespace TShockAPI if (!exactTarget && !banAccount && !banUuid && !banName && !banIp) { banAccount = banUuid = banIp = true; + + if (TShock.Config.Settings.DisableDefaultIPBan) + { + banIp = false; + } } reason = reason ?? "Banned"; diff --git a/TShockAPI/Configuration/TShockConfig.cs b/TShockAPI/Configuration/TShockConfig.cs index 38ed0c46..18499f87 100644 --- a/TShockAPI/Configuration/TShockConfig.cs +++ b/TShockAPI/Configuration/TShockConfig.cs @@ -312,6 +312,10 @@ namespace TShockAPI.Configuration [Description("The reason given if banning a mediumcore player on death.")] public string MediumcoreBanReason = "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.")] + public bool DisableDefaultIPBan; + /// Enable or disable the whitelist based on IP addresses in the whitelist.txt file. [Description("Enable or disable the whitelist based on IP addresses in the whitelist.txt file.")] public bool EnableWhitelist; From 211b70ca3771fb42c5284d5a8565e7a2bad1ac3a Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 21 Nov 2021 14:44:53 -0800 Subject: [PATCH 47/57] Upgrade blank passwords to bcrypt hashes Previously, blank passwords were not upgraded to bcrypt hashes. This is annoying and problematic because it makes it difficult to remove the old password hashing system because those passwords might still be checked against non-bcrypt hashes. --- CHANGELOG.md | 1 + TShockAPI/DB/UserManager.cs | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57edca99..6ec260b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fixed an issue where `/god [player]` would tell `[player]` that they were in godmode regardless of whether or not they were or not. (@hakusaro, @Kojirremer) * In `TSAPI`: Updated `PacketTypes` to support `SetMiscEventValues` (140), `RequestLucyPopup` (141), and `SyncProjectileTrackers` (142). (@hakusaro) * Added `DisableDefaultIPBan` to the config file. If set to `true`, the server will not automatically IP ban players when banning them. This is useful if you run an intercepting proxy in front of TShock, and all players share the same IP. (@hakusaro, and Telegram user xmzzhh233) +* Blank passwords will be upgraded to `bcrypt` hashes automatically. Previously, blank passwords were not upgraded to bcrypt hashes. This is in preparation to remove the old password hashing system and related fallback components in the next release. Most users have been using bcrypt hashes for the past...few years. (@hakusaro) ## TShock 4.5.5 * Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro) diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index 4fedaaed..49f6b73c 100644 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -444,15 +444,11 @@ namespace TShockAPI.DB UpgradePasswordWorkFactor(password); return true; } - } + } catch (SaltParseException) { if (String.Equals(HashPassword(password), Password, StringComparison.InvariantCultureIgnoreCase)) { - // Return true to keep blank passwords working but don't convert them to bcrypt. - if (Password == "non-existant password") { - return true; - } // The password is not stored using BCrypt; upgrade it to BCrypt immediately UpgradePasswordToBCrypt(password); return true; From 35db1cc372802879b6d206a09e39a4b1515b060d Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 21 Nov 2021 16:13:32 -0800 Subject: [PATCH 48/57] Version tick: 4.5.6 --- TShockAPI/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs index 28c98cd4..47217a77 100644 --- a/TShockAPI/Properties/AssemblyInfo.cs +++ b/TShockAPI/Properties/AssemblyInfo.cs @@ -53,5 +53,5 @@ using System.Runtime.InteropServices; // 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) -[assembly: AssemblyVersion("4.5.5")] -[assembly: AssemblyFileVersion("4.5.5")] +[assembly: AssemblyVersion("4.5.6")] +[assembly: AssemblyFileVersion("4.5.6")] From 614211d7a182521c4d70b0e7dd463160771992df Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 21 Nov 2021 16:35:47 -0800 Subject: [PATCH 49/57] Fix respawning players from the server console --- CHANGELOG.md | 3 +++ TShockAPI/Commands.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ec260b2..fdacb30e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * 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 the `/respawn` command to permit respawning players from the console. (@hakusaro, @Kojirremer) + +## TShock 4.5.6 * Updated Linux guide. (@NezbednikSK) * Fixed SendTileRectHandler not sending tile rect updates like Pylons/Mannequins to other clients. (@Stealownz) * Introduced `SoftcoreOnly` config option to allow only softcore characters to connect. (@drunderscore) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 00a745f9..b03805ab 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5793,7 +5793,7 @@ namespace TShockAPI private static void Respawn(CommandArgs args) { - if (!args.Player.RealPlayer) + if (!args.Player.RealPlayer && args.Parameters.Count == 0) { args.Player.SendErrorMessage("You can't respawn the server console!"); return; From 9416e8f1e29f1321f5733f097c79ec4542f4e418 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 22 Nov 2021 10:26:57 -0800 Subject: [PATCH 50/57] Remove DIY password hashing crypto The old system for hashing passwords and permitting users to select their algorithm has been deprecated and phased out since 2015. This removes the remaining functions for hashing passwords to clear the way for .NET5/6 and for OTAPI 3. In 211b70ca3771fb42c5284d5a8565e7a2bad1ac3a, I allowed blank passwords to upgrade to bcrypt hashes. However, the minimum password length has been 4 historically for a long time. So I don't actually assume a lot of users have blank passwords, so I think there are very few, if any of the old hashes laying around. So therefore, I think this is pretty much safe to merge. --- CHANGELOG.md | 1 + TShockAPI/Configuration/TShockConfig.cs | 5 -- TShockAPI/DB/UserManager.cs | 72 +------------------------ 3 files changed, 3 insertions(+), 75 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdacb30e..9dad9c7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming changes * Fixed the `/respawn` command to permit respawning players from the console. (@hakusaro, @Kojirremer) +* Removed the old password hashing system, which predated `bcrypt` hashes and allowed specifying the hash algorithm in the config file. This also removes the config option for setting the hash algorithm (`HashAlgorithm`). This is because it helps clear the way for .NET5/6 and OTAPI 3, and because `bcrypt` has been the default since TShock 4.3 in 2015. (@hakusaro) ## TShock 4.5.6 * Updated Linux guide. (@NezbednikSK) diff --git a/TShockAPI/Configuration/TShockConfig.cs b/TShockAPI/Configuration/TShockConfig.cs index 18499f87..eeb658c1 100644 --- a/TShockAPI/Configuration/TShockConfig.cs +++ b/TShockAPI/Configuration/TShockConfig.cs @@ -368,11 +368,6 @@ namespace TShockAPI.Configuration [Description("The minimum password length for new user accounts. Can never be lower than 4.")] public int MinimumPasswordLength = 4; - /// The hash algorithm used to encrypt user passwords. - /// Valid types: "sha512", "sha256" and "md5". Append with "-xp" for the xp supported algorithms. - [Description("The hash algorithm used to encrypt user passwords. Valid types: \"sha512\", \"sha256\" and \"md5\". Append with \"-xp\" for the xp supported algorithms.")] - public string HashAlgorithm = "sha512"; - /// Determines the BCrypt work factor to use. If increased, all passwords will be upgraded to new work-factor on verify. /// The number of computational rounds is 2^n. Increase with caution. Range: 5-31. [Description("Determines the BCrypt work factor to use. If increased, all passwords will be upgraded to new work-factor on verify. The number of computational rounds is 2^n. Increase with caution. Range: 5-31.")] diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index 49f6b73c..e2af578b 100644 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -438,7 +438,7 @@ namespace TShockAPI.DB { try { - if (BCrypt.Net.BCrypt.Verify(password, Password)) + if (BCrypt.Net.BCrypt.Verify(password, Password)) { // If necessary, perform an upgrade to the highest work factor. UpgradePasswordWorkFactor(password); @@ -447,35 +447,12 @@ namespace TShockAPI.DB } catch (SaltParseException) { - if (String.Equals(HashPassword(password), Password, StringComparison.InvariantCultureIgnoreCase)) - { - // The password is not stored using BCrypt; upgrade it to BCrypt immediately - UpgradePasswordToBCrypt(password); - return true; - } + TShock.Log.ConsoleError("Error: Unable to verify the password hash for user {0} ({1})", Name, ID); return false; } return false; } - /// Upgrades a password to BCrypt, from an insecure hashing algorithm. - /// The raw user account password (unhashed) to upgrade - protected void UpgradePasswordToBCrypt(string password) - { - // Save the old password, in the event that we have to revert changes. - string oldpassword = Password; - - try - { - TShock.UserAccounts.SetUserAccountPassword(this, password); - } - catch (UserAccountManagerException e) - { - TShock.Log.ConsoleError(e.ToString()); - Password = oldpassword; // Revert changes - } - } - /// Upgrades a password to the highest work factor available in the config. /// The raw user account password (unhashed) to upgrade protected void UpgradePasswordWorkFactor(string password) @@ -536,51 +513,6 @@ namespace TShockAPI.DB Password = BCrypt.Net.BCrypt.HashPassword(password.Trim(), workFactor); } - /// - /// A dictionary of hashing algorithms and an implementation object. - /// - protected readonly Dictionary> HashTypes = new Dictionary> - { - {"sha512", () => new SHA512Managed()}, - {"sha256", () => new SHA256Managed()}, - {"md5", () => new MD5Cng()}, - {"sha512-xp", () => SHA512.Create()}, - {"sha256-xp", () => SHA256.Create()}, - {"md5-xp", () => MD5.Create()}, - }; - - /// - /// Returns a hashed string for a given string based on the config file's hash algo - /// - /// bytes to hash - /// string hash - protected string HashPassword(byte[] bytes) - { - if (bytes == null) - throw new NullReferenceException("bytes"); - Func func; - if (!HashTypes.TryGetValue(TShock.Config.Settings.HashAlgorithm.ToLower(), out func)) - throw new NotSupportedException("Hashing algorithm {0} is not supported".SFormat(TShock.Config.Settings.HashAlgorithm.ToLower())); - - using (var hash = func()) - { - var ret = hash.ComputeHash(bytes); - return ret.Aggregate("", (s, b) => s + b.ToString("X2")); - } - } - - /// - /// Returns a hashed string for a given string based on the config file's hash algo - /// - /// string to hash - /// string hash - protected string HashPassword(string password) - { - if (string.IsNullOrEmpty(password) && Password == "non-existant password") - return "non-existant password"; - return HashPassword(Encoding.UTF8.GetBytes(password)); - } - #region IEquatable /// Indicates whether the current is equal to another . From ce8623e84eca473b870b51206fb914f292cc6839 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 22 Nov 2021 18:02:40 -0800 Subject: [PATCH 51/57] Add support for 1.4.3.1 via submodule update --- CHANGELOG.md | 4 +++- TerrariaServerAPI | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dad9c7d..9bcceb76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,11 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Do not forget to sign every line you change with your name. (@hakusaro) * 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 +## TShock 4.5.7 * Fixed the `/respawn` command to permit respawning players from the console. (@hakusaro, @Kojirremer) * Removed the old password hashing system, which predated `bcrypt` hashes and allowed specifying the hash algorithm in the config file. This also removes the config option for setting the hash algorithm (`HashAlgorithm`). This is because it helps clear the way for .NET5/6 and OTAPI 3, and because `bcrypt` has been the default since TShock 4.3 in 2015. (@hakusaro) +* Updated to OTAPI 2.0.0.46, which adds support for Terraria Protocol 1.4.3.1. (@Patrikkk, @DeathCradle) +* **Change warning: a release of TShock for .NET 5 and OTAPI 3 may be imminent.** ## TShock 4.5.6 * Updated Linux guide. (@NezbednikSK) diff --git a/TerrariaServerAPI b/TerrariaServerAPI index 302d9b75..b9a0fdf6 160000 --- a/TerrariaServerAPI +++ b/TerrariaServerAPI @@ -1 +1 @@ -Subproject commit 302d9b7595f3bdc9d66190de99129c34debef260 +Subproject commit b9a0fdf6d464d17c47f70ed9327779a78a0aaee4 From 320bbad0515bedc656b74752f23528dee772fa40 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 22 Nov 2021 18:07:30 -0800 Subject: [PATCH 52/57] Version tick: 4.5.7 --- CHANGELOG.md | 3 +++ TShockAPI/Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bcceb76..54eefc42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Do not forget to sign every line you change with your name. (@hakusaro) * 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 +* With any luck, .NET 5? + ## TShock 4.5.7 * Fixed the `/respawn` command to permit respawning players from the console. (@hakusaro, @Kojirremer) * Removed the old password hashing system, which predated `bcrypt` hashes and allowed specifying the hash algorithm in the config file. This also removes the config option for setting the hash algorithm (`HashAlgorithm`). This is because it helps clear the way for .NET5/6 and OTAPI 3, and because `bcrypt` has been the default since TShock 4.3 in 2015. (@hakusaro) diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs index 47217a77..fc81908d 100644 --- a/TShockAPI/Properties/AssemblyInfo.cs +++ b/TShockAPI/Properties/AssemblyInfo.cs @@ -53,5 +53,5 @@ using System.Runtime.InteropServices; // 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) -[assembly: AssemblyVersion("4.5.6")] -[assembly: AssemblyFileVersion("4.5.6")] +[assembly: AssemblyVersion("4.5.7")] +[assembly: AssemblyFileVersion("4.5.7")] From a01b48ead5f7310ecd8283c5d9b252ba94c2ddb4 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 22 Nov 2021 19:27:40 -0800 Subject: [PATCH 53/57] Remove dead code: DBTools.cs --- CHANGELOG.md | 2 +- TShockAPI/DB/DBTools.cs | 224 ---------------------------------------- 2 files changed, 1 insertion(+), 225 deletions(-) delete mode 100644 TShockAPI/DB/DBTools.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 54eefc42..160e40b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * 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 -* With any luck, .NET 5? +* Removed `TShockAPI/DB/DBTools.cs`. This appears to have been dead code and not used by anything. (@hakusaro, @DeathCradle) ## TShock 4.5.7 * Fixed the `/respawn` command to permit respawning players from the console. (@hakusaro, @Kojirremer) diff --git a/TShockAPI/DB/DBTools.cs b/TShockAPI/DB/DBTools.cs deleted file mode 100644 index 20300aef..00000000 --- a/TShockAPI/DB/DBTools.cs +++ /dev/null @@ -1,224 +0,0 @@ -/* -TShock, a server mod for Terraria -Copyright (C) 2011-2019 Pryaxis & TShock Contributors - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -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.Data; -using System.Linq; -using System.Text; -using TShockAPI.DB; - -namespace TShockAPI.DB -{ - public class DBTools - { - public static IDbConnection database; - - public static void CreateTable(string name, bool IfNotExists, List columns) - { - //Build up Creation string :) - StringBuilder sb = new StringBuilder(); - sb.Append("CREATE TABLE "); - - if (IfNotExists) - sb.Append("IF NOT EXISTS "); - - if (TShock.Config.StorageType.ToLower() == "sqlite") - sb.Append("'" + name + "' ("); - else if (TShock.Config.StorageType.ToLower() == "mysql") - sb.Append(name + " ("); - - int count = 0; - - foreach (Column column in columns) - { - count++; - if (column.Type.ToLower() == "int") - { - if (TShock.Config.StorageType.ToLower() == "sqlite") - sb.Append(column.Name + " NUMERIC "); - else if (TShock.Config.StorageType.ToLower() == "mysql") - sb.Append(column.Name + " INT(255) "); - } - else if (column.Type.ToLower() == "string") - { - if (TShock.Config.StorageType.ToLower() == "sqlite") - sb.Append(column.Name + " TEXT "); - else if (TShock.Config.StorageType.ToLower() == "mysql") - sb.Append(column.Name + " VARCHAR(255) "); - } - if (column.Unique) - { - if (columns.Count != count) - { - sb.Append("UNIQUE, "); - } - else - sb.Append("UNIQUE) "); - } - if (columns.Count == count) - sb.Append(")"); - } - - using (var com = database.CreateCommand()) - { - com.CommandText = sb.ToString(); - com.ExecuteNonQuery(); - } - } - - public static void InsertTable(string tablename, bool Ignore, List Values, List WhereAndStatements) - { - StringBuilder sb = new StringBuilder(); - sb.Append("INSERT "); - - if (Ignore) - { - if (TShock.Config.StorageType.ToLower() == "sqlite") - sb.Append("OR IGNORE "); - else if (TShock.Config.StorageType.ToLower() == "mysql") - sb.Append("IGNORE "); - } - - if (TShock.Config.StorageType.ToLower() == "sqlite") - sb.Append("INTO '" + tablename + "' ("); - else if (TShock.Config.StorageType.ToLower() == "mysql") - sb.Append("INTO " + tablename + " "); - - using (var com = database.CreateCommand()) - { - //Values - if (TShock.Config.StorageType.ToLower() == "sqlite") - { - int count = 0; - - foreach (ColumnData columnname in Values) - { - count++; - if (Values.Count != count) - sb.Append(columnname.Name + ", "); - else - sb.Append(columnname.Name + ") "); - } - - sb.Append("VALUES ("); - count = 0; - - foreach (ColumnData columnname in Values) - { - count++; - if (Values.Count != count) - { - sb.Append("@" + columnname.Name + ", "); - com.AddParameter("@" + columnname.Name.ToLower(), columnname.Value); - } - else - { - sb.Append("@" + columnname.Name + ") "); - com.AddParameter("@" + columnname.Name.ToLower(), columnname.Value); - } - } - } - else if (TShock.Config.StorageType.ToLower() == "mysql") - { - sb.Append("SET "); - int count = 0; - - foreach (ColumnData columnname in Values) - { - count++; - if (Values.Count != count) - { - sb.Append("@" + columnname.Name + "=" + columnname.Value + ", "); - com.AddParameter("@" + columnname.Name.ToLower(), columnname.Value); - } - else - { - sb.Append("@" + columnname.Name + "=" + columnname.Value + ") "); - com.AddParameter("@" + columnname.Name.ToLower(), columnname.Value); - } - } - } - - //Where Statement (if any) - if (WhereAndStatements.Count > 0) - { - sb.Append("WHERE "); - int count = 0; - - foreach (ColumnData columnname in WhereAndStatements) - { - count++; - if (Values.Count != count) - { - sb.Append("@" + columnname.Name + "=" + columnname.Value + "-where" + " AND "); - com.AddParameter("@" + columnname.Name.ToLower() + "-where", columnname.Value); - } - else - { - sb.Append("@" + columnname.Name + "=" + columnname.Value + "-where" + ";"); - com.AddParameter("@" + columnname.Name.ToLower() + "-where", columnname.Value); - } - } - } - } - } - } - - public class Column - { - public string Name { get; set; } - public string Type { get; set; } - public bool Unique { get; set; } - public string Parameters { get; set; } - - public Column(string name, bool unique, string type, string parameters) - { - Name = name; - Type = type; - Unique = unique; - Parameters = parameters; - } - - public Column() - { - Name = string.Empty; - Type = string.Empty; - Unique = false; - Parameters = string.Empty; - } - } - - public class ColumnData - { - public string Name { get; set; } - public object Value { get; set; } - - public ColumnData(string name, object value) - { - Name = name; - Value = value; - } - - public ColumnData() - { - Name = string.Empty; - Value = string.Empty; - } - } -} From e303071dce8d49a4e5f512b4940567f8de9464ba Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 22 Nov 2021 22:14:55 -0800 Subject: [PATCH 54/57] Fix firework command failing without color After updates to the firework command, a guard was lost, allowing the switch statement that selected the color to execute on a parameter that was empty. A guard was added to prevent falling into the switch statement without enough arguments to match a color. The default type of firework was manually set to a red firework. Fixes #2507 --- CHANGELOG.md | 1 + TShockAPI/Commands.cs | 77 ++++++++++++++++++++++--------------------- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 160e40b4..46cd481e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming changes * Removed `TShockAPI/DB/DBTools.cs`. This appears to have been dead code and not used by anything. (@hakusaro, @DeathCradle) +* Fixed the `/firework` command not sending fireworks when specified without a firework color. The firework command now correctly sends red fireworks to a target if a color is not specified. (@hakusaro, @Kojirremer) ## TShock 4.5.7 * Fixed the `/respawn` command to permit respawning players from the console. (@hakusaro, @Kojirremer) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index b03805ab..dac563e4 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5546,44 +5546,47 @@ namespace TShockAPI user.SendMultipleMatchError(players.Select(p => p.Name)); else { - int type = 0; - switch (args.Parameters[1].ToLower()) + int type = ProjectileID.RocketFireworkRed; + if (args.Parameters.Count > 1) { - case "red": - case "r": - type = ProjectileID.RocketFireworkRed; - break; - case "green": - case "g": - type = ProjectileID.RocketFireworkGreen; - break; - case "blue": - case "b": - type = ProjectileID.RocketFireworkBlue; - break; - case "yellow": - case "y": - type = ProjectileID.RocketFireworkYellow; - break; - case "r2": - case "star": - type = ProjectileID.RocketFireworksBoxRed; - break; - case "g2": - case "spiral": - type = ProjectileID.RocketFireworksBoxGreen; - break; - case "b2": - case "rings": - type = ProjectileID.RocketFireworksBoxBlue; - break; - case "y2": - case "flower": - type = ProjectileID.RocketFireworksBoxYellow; - break; - default: - type = ProjectileID.RocketFireworkRed; - break; + switch (args.Parameters[1].ToLower()) + { + case "red": + case "r": + type = ProjectileID.RocketFireworkRed; + break; + case "green": + case "g": + type = ProjectileID.RocketFireworkGreen; + break; + case "blue": + case "b": + type = ProjectileID.RocketFireworkBlue; + break; + case "yellow": + case "y": + type = ProjectileID.RocketFireworkYellow; + break; + case "r2": + case "star": + type = ProjectileID.RocketFireworksBoxRed; + break; + case "g2": + case "spiral": + type = ProjectileID.RocketFireworksBoxGreen; + break; + case "b2": + case "rings": + type = ProjectileID.RocketFireworksBoxBlue; + break; + case "y2": + case "flower": + type = ProjectileID.RocketFireworksBoxYellow; + break; + default: + type = ProjectileID.RocketFireworkRed; + break; + } } var target = players[0]; int p = Projectile.NewProjectile(Projectile.GetNoneSource(), target.TPlayer.position.X, target.TPlayer.position.Y - 64f, 0f, -8f, type, 0, 0); From aa5cb132477c75415de4b4a432305a0ba3206106 Mon Sep 17 00:00:00 2001 From: Arthri <41360489+Arthri@users.noreply.github.com> Date: Tue, 23 Nov 2021 17:12:49 +0800 Subject: [PATCH 55/57] Fix bad XML(no opening /// For use in an Emoji event. /// public class EmojiEventArgs : GetDataHandledEventArgs @@ -1968,6 +1969,7 @@ namespace TShockAPI return args.Handled; } + /// /// For use in a TileEntityDisplayDollItemSync event. /// public class DisplayDollItemSyncEventArgs : GetDataHandledEventArgs @@ -2026,6 +2028,7 @@ namespace TShockAPI return args.Handled; } + /// /// For use in an OnRequestTileEntityInteraction event. /// public class RequestTileEntityInteractionEventArgs : GetDataHandledEventArgs From 350d76c31586c468a0e59eba8df78f5f6ea34756 Mon Sep 17 00:00:00 2001 From: Arthri <41360489+Arthri@users.noreply.github.com> Date: Tue, 23 Nov 2021 17:13:02 +0800 Subject: [PATCH 56/57] Fix bad XML(unescaped ampersand) --- TShockAPI/TShock.cs | 4 ++-- TShockAPI/Utils.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index ae6b6e00..1634fe77 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -79,7 +79,7 @@ namespace TShockAPI /// Players - Contains all TSPlayer objects for accessing TSPlayers currently on the server public static TSPlayer[] Players = new TSPlayer[Main.maxPlayers]; - /// Bans - Static reference to the ban manager for accessing bans & related functions. + /// Bans - Static reference to the ban manager for accessing bans & related functions. public static BanManager Bans; /// Warps - Static reference to the warp manager for accessing the warp system. public static WarpManager Warps; @@ -148,7 +148,7 @@ namespace TShockAPI /// public static event Action Initialized; - /// Version - The version required by the TerrariaAPI to be passed back for checking & loading the plugin. + /// Version - The version required by the TerrariaAPI to be passed back for checking & loading the plugin. /// value - The version number specified in the Assembly, based on the VersionNum variable set in this class. public override Version Version { diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 42f8ea96..96bbf3fb 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -894,7 +894,7 @@ namespace TShockAPI Main.recipe[i] = new Recipe(); } - /// Dumps a matrix of all permissions & all groups in Markdown table format. + /// Dumps a matrix of all permissions & all groups in Markdown table format. /// The save destination. internal void DumpPermissionMatrix(string path) { From c5eeae85909ef044af46f45119bc26d355be3f8a Mon Sep 17 00:00:00 2001 From: Arthri <41360489+Arthri@users.noreply.github.com> Date: Tue, 23 Nov 2021 17:23:44 +0800 Subject: [PATCH 57/57] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46cd481e..ee4cda84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming changes * Removed `TShockAPI/DB/DBTools.cs`. This appears to have been dead code and not used by anything. (@hakusaro, @DeathCradle) * Fixed the `/firework` command not sending fireworks when specified without a firework color. The firework command now correctly sends red fireworks to a target if a color is not specified. (@hakusaro, @Kojirremer) +* Fixed bad XML of TShock code documentation. (@Arthri) ## TShock 4.5.7 * Fixed the `/respawn` command to permit respawning players from the console. (@hakusaro, @Kojirremer)