From 00b4eb677424715976062ebdbef0a3bbdf49a729 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 12 Apr 2021 23:20:10 -0700 Subject: [PATCH 1/8] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dac4b32..826059e3 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 * Fixed server crash from `/v2/players/list` & other parameterised REST endpoints. (@QuiCM) * Added handling to the PlayerChat hook event. (@QuiCM - Thanks for the suggestion @Arthri) +* Changed the spawnboss command to support silent command specifiers. (@QuiCM, suggested by @nojomyth-dev). ## TShock 4.5.0.1 * Fixed conversion from old to new ban system for MySQL hosted ban databases. (@DeathCradle, @ATFGK) From 173d6f71f5eac97eebe653f63b588b5d1b5399a0 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 12 Apr 2021 23:21:51 -0700 Subject: [PATCH 2/8] Update changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 826059e3..743141af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,9 +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 server crash from `/v2/players/list` & other parameterised REST endpoints. (@QuiCM) +* Fixed server crash from `/v2/players/list` & other parameterised REST endpoints. (@QuiCM, reported by @ATFGK) * Added handling to the PlayerChat hook event. (@QuiCM - Thanks for the suggestion @Arthri) -* Changed the spawnboss command to support silent command specifiers. (@QuiCM, suggested by @nojomyth-dev). +* Changed the spawnboss command to support silent command specifiers. (@QuiCM, suggested by @nojomyth-dev) ## TShock 4.5.0.1 * Fixed conversion from old to new ban system for MySQL hosted ban databases. (@DeathCradle, @ATFGK) From 207b43e77217c25e520a3fe56b4f4a82f614061b Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Fri, 16 Apr 2021 06:11:26 +0200 Subject: [PATCH 3/8] Update /godmode to use JourneyMode Godmode power. - Previous Bouncer checks for GodMode (namely, Hurt) were removed. - The command now uses the GodmodePower from core Terraria - The toggle powers (which this command will now make use of) are now reset on disconnect to prevent accidentally "gifting" godmode to an unsuspecting player. --- TShockAPI/Commands.cs | 6 ++++++ TShockAPI/GetDataHandlers.cs | 10 ---------- TShockAPI/TShock.cs | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 20c21f26..d1b1f32c 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -37,6 +37,8 @@ using OTAPI.Tile; using TShockAPI.Localization; using System.Text.RegularExpressions; using Terraria.DataStructures; +using Terraria.GameContent.Creative; +using static Terraria.GameContent.Creative.CreativePowers; namespace TShockAPI { @@ -6445,6 +6447,10 @@ namespace TShockAPI playerToGod.GodMode = !playerToGod.GodMode; + var god_power = CreativePowerManager.Instance.GetPower(); + + god_power.SetEnabledState(playerToGod.Index, playerToGod.GodMode); + if (playerToGod == args.Player) { args.Player.SendSuccessMessage(string.Format("You are {0} in god mode.", args.Player.GodMode ? "now" : "no longer")); diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index deac632f..879e02ce 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2571,10 +2571,6 @@ namespace TShockAPI args.Player.PlayerData.maxHealth = max; } - if (args.Player.GodMode && (cur < max)) - { - args.Player.Heal(args.TPlayer.statLifeMax2); - } return false; } @@ -3733,12 +3729,6 @@ namespace TShockAPI if (OnPlayerDamage(args.Player, args.Data, id, direction, dmg, pvp, crit, playerDeathReason)) return true; - if (TShock.Players[id].GodMode) - { - TShock.Log.ConsoleDebug("GetDataHandlers / HandlePlayerDamageV2 rejected (god mode on) {0}", args.Player.Name); - TShock.Players[id].Heal(args.TPlayer.statLifeMax); - } - return false; } diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 52bef011..211efbc5 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -44,6 +44,7 @@ using TShockAPI.Sockets; using TShockAPI.CLI; using TShockAPI.Localization; using TShockAPI.Configuration; +using Terraria.GameContent.Creative; namespace TShockAPI { @@ -1216,6 +1217,23 @@ namespace TShockAPI Players[args.Who] = null; + //Reset toggle creative powers to default, preventing potential power transfer & desync on another user occupying this slot later. + + foreach(var kv in CreativePowerManager.Instance._powersById) + { + var power = kv.Value; + + //No need to reset sliders - those are reset manually by the game, most likely an oversight that toggles don't receive this treatment. + + if (power is CreativePowers.APerPlayerTogglePower toggle) + { + if (toggle._perPlayerIsEnabled[args.Who] == toggle._defaultToggleState) + continue; + + toggle.SetEnabledState(args.Who, toggle._defaultToggleState); + } + } + if (tsplr.ReceivedInfo) { if (!tsplr.SilentKickInProgress && tsplr.State >= 3) From 3b58b0ad1610ef57f9439d1f5de5114f3ac47263 Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Fri, 16 Apr 2021 06:30:12 +0200 Subject: [PATCH 4/8] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 743141af..31bb1005 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fixed server crash from `/v2/players/list` & other parameterised REST endpoints. (@QuiCM, reported by @ATFGK) * Added handling to the PlayerChat hook event. (@QuiCM - Thanks for the suggestion @Arthri) * Changed the spawnboss command to support silent command specifiers. (@QuiCM, suggested by @nojomyth-dev) +* Updated /godmode to use Journey Mode's Godmode power instead of healing on damage. (requested by @tlworks, backported by @bartico6, implemented preemptive bugfix for creative powers mentioned by @Stealownz) ## TShock 4.5.0.1 * Fixed conversion from old to new ban system for MySQL hosted ban databases. (@DeathCradle, @ATFGK) From 4a28d6779fa720a3782b2184e7522aa80bcf2167 Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Fri, 16 Apr 2021 07:01:11 +0200 Subject: [PATCH 5/8] Update casing & remove using static - god_power -> godPower - Remove using static on GameContent.CreativePowers, instead fully qualify the nested class. --- TShockAPI/Commands.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index d1b1f32c..c59c4962 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -38,7 +38,6 @@ using TShockAPI.Localization; using System.Text.RegularExpressions; using Terraria.DataStructures; using Terraria.GameContent.Creative; -using static Terraria.GameContent.Creative.CreativePowers; namespace TShockAPI { @@ -6447,9 +6446,9 @@ namespace TShockAPI playerToGod.GodMode = !playerToGod.GodMode; - var god_power = CreativePowerManager.Instance.GetPower(); + var godPower = CreativePowerManager.Instance.GetPower(); - god_power.SetEnabledState(playerToGod.Index, playerToGod.GodMode); + godPower.SetEnabledState(playerToGod.Index, playerToGod.GodMode); if (playerToGod == args.Player) { From 78b72df79d2333b58589093d5b1b6457526d39fb Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Fri, 16 Apr 2021 10:14:46 +0200 Subject: [PATCH 6/8] Address JourneyMode Godmode issues - Add /ungodme to allow unstucking godmode for involuntarily godmodded characters - Warn player about disabling Godmode before disconnecting - Minor change to command format to reduce code copypaste. --- TShockAPI/Commands.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index c59c4962..d10ec1c3 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -545,6 +545,11 @@ namespace TShockAPI { HelpText = "Toggles godmode on a player." }); + add(new Command("", ForceUngod, "ungodme") + { + HelpText = "Removes godmode from your character.", + AllowServer = false + }); add(new Command(Permissions.heal, Heal, "heal") { HelpText = "Heals a player in HP and MP." @@ -6450,15 +6455,20 @@ namespace TShockAPI godPower.SetEnabledState(playerToGod.Index, playerToGod.GodMode); - if (playerToGod == args.Player) - { - args.Player.SendSuccessMessage(string.Format("You are {0} in god mode.", args.Player.GodMode ? "now" : "no longer")); - } - else + if (playerToGod != args.Player) { args.Player.SendSuccessMessage(string.Format("{0} is {1} in god mode.", playerToGod.Name, playerToGod.GodMode ? "now" : "no longer")); - playerToGod.SendSuccessMessage(string.Format("You are {0} in god mode.", playerToGod.GodMode ? "now" : "no longer")); } + + playerToGod.SendSuccessMessage(string.Format("You are {0} in god mode.", args.Player.GodMode ? "now" : "no longer")); + playerToGod.SendInfoMessage("Please make sure to disable godmode using /ungodme before disconnecting, otherwise your character may remain in godmode indefinitely, including singleplayer."); + } + + private static void ForceUngod(CommandArgs args) + { + var godPower = CreativePowerManager.Instance.GetPower(); + + godPower.SetEnabledState(args.Player.Index, false); } #endregion Cheat Comamnds From 3e40ade0ca2c6a391801baad31afb4e7108b081b Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Fri, 16 Apr 2021 10:18:40 +0200 Subject: [PATCH 7/8] Added feedback to /ungodme - The command now tells the user that the operation succeeded. Previously it would be a silent command, potentially leaving the user wondering if it worked --- TShockAPI/Commands.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index d10ec1c3..3bff1f2b 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -6469,6 +6469,8 @@ namespace TShockAPI var godPower = CreativePowerManager.Instance.GetPower(); godPower.SetEnabledState(args.Player.Index, false); + + args.Player.SendSuccessMessage("Journey Godmode has been disabled on your character."); } #endregion Cheat Comamnds From 663041e8b06446dc0afe0e6dcefdf0535b0b31af Mon Sep 17 00:00:00 2001 From: quake1337 <3310937+bartico6@users.noreply.github.com> Date: Sat, 17 Apr 2021 10:07:48 +0200 Subject: [PATCH 8/8] Fix /r against offline players. - Offline players will no longer be valid /r targets. --- CHANGELOG.md | 1 + TShockAPI/Commands.cs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31bb1005..86dc96b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added handling to the PlayerChat hook event. (@QuiCM - Thanks for the suggestion @Arthri) * Changed the spawnboss command to support silent command specifiers. (@QuiCM, suggested by @nojomyth-dev) * Updated /godmode to use Journey Mode's Godmode power instead of healing on damage. (requested by @tlworks, backported by @bartico6, implemented preemptive bugfix for creative powers mentioned by @Stealownz) +* Fixed /r attempting to send messages to players that have since disconnected. (@bartico6, reported by @Arthri) ## TShock 4.5.0.1 * Fixed conversion from old to new ban system for MySQL hosted ban databases. (@DeathCradle, @ATFGK) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 3bff1f2b..7d2a42d2 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5366,12 +5366,16 @@ namespace TShockAPI { args.Player.SendErrorMessage("You are muted."); } - else if (args.Player.LastWhisper != null) + else if (args.Player.LastWhisper != null && args.Player.LastWhisper.Active) { 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); } + else if (args.Player.LastWhisper != null) + { + args.Player.SendErrorMessage("The player you're attempting to reply to is no longer online."); + } else { args.Player.SendErrorMessage("You haven't previously received any whispers. Please use {0}whisper to whisper to other people.", Specifier);