From 8d277edf042eb676fb95282a6ab280ce5d634f56 Mon Sep 17 00:00:00 2001 From: Axeel Date: Sun, 24 May 2020 13:31:21 +0800 Subject: [PATCH 01/35] Fix npcbuff bouncer (#1881) * Fix npcbuff bouncer * Update CHANGELOG.md Co-authored-by: Lucas Nicodemus --- CHANGELOG.md | 1 + TShockAPI/Bouncer.cs | 59 ++++++++++++++++++++++---------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e019fbd0..7425d8a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming release * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) +* Fixed NPC buff bouncer. (@AxeelAnder) ## TShock 4.4.0 (Pre-release 7 (Entangled)) * Fixed bed spawn issues when trying to remove spawn point in SSC. (@Olink) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index d11cb758..6fa88feb 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -2048,36 +2048,35 @@ namespace TShockAPI // These time values are references from Projectile.cs, at npc.AddBuff() calls. private static Dictionary NPCAddBuffTimeMax = new Dictionary() { - { BuffID.Poisoned, 3600 }, - { BuffID.OnFire, 1200 }, - { BuffID.CursedInferno, 420 }, - { BuffID.Frostburn, 900 }, - { BuffID.Ichor, 1200 }, - { BuffID.Venom, 1260 }, - { BuffID.Midas, 120 }, - { BuffID.Wet, 1500 }, - { BuffID.Slimed, 1500 }, - { BuffID.Lovestruck, 1800 }, - { BuffID.Stinky, 1800 }, - { BuffID.SoulDrain, 30 }, - { BuffID.ShadowFlame, 660 }, - { BuffID.DryadsWard, 120 }, - { BuffID.BoneJavelin, 900 }, - { BuffID.StardustMinionBleed, 900 }, - { BuffID.DryadsWardDebuff, 120 }, - { BuffID.BetsysCurse, 600 }, - { BuffID.Oiled, 540 }, - { BuffID.Confused, 450 }, // Brain of Confusion Internal Item ID: 3223 - { BuffID.Daybreak, 300 }, // Solar Eruption Item ID: 3473, Daybreak Item ID: 3543 - { BuffID.BlandWhipEnemyDebuff, 240 }, - { BuffID.SwordWhipNPCDebuff, 240 }, - { BuffID.ScytheWhipEnemyDebuff, 240 }, - { BuffID.FlameWhipEnemyDebuff, 240 }, - { BuffID.ThornWhipNPCDebuff, 240 }, - { BuffID.RainbowWhipNPCDebuff, 240 }, - { BuffID.MaceWhipNPCDebuff, 240 }, - { BuffID.GelBalloonBuff, 1800 } - + { BuffID.Poisoned, 3600 }, // BuffID: 20 + { BuffID.OnFire, 1200 }, // BuffID: 24 + { BuffID.Confused, short.MaxValue }, // BuffID: 31 Brain of Confusion Internal Item ID: 3223 + { BuffID.CursedInferno, 420 }, // BuffID: 39 + { BuffID.Frostburn, 900 }, // BuffID: 44 + { BuffID.Ichor, 1200 }, // BuffID: 69 + { BuffID.Venom, 1800 }, // BuffID: 70 + { BuffID.Midas, 120 }, // BuffID: 72 + { BuffID.Wet, 1500 }, // BuffID: 103 + { BuffID.Lovestruck, 1800 }, // BuffID: 119 + { BuffID.Stinky, 1800 }, // BuffID: 120 + { BuffID.Slimed, 1500 }, // BuffID: 137 + { BuffID.SoulDrain, 30 }, // BuffID: 151 + { BuffID.ShadowFlame, 660 }, // BuffID: 153 + { BuffID.DryadsWard, 120 }, // BuffID: 165 + { BuffID.BoneJavelin, 900 }, // BuffID: 169 + { BuffID.StardustMinionBleed, 900 }, // BuffID: 183 + { BuffID.DryadsWardDebuff, 120 }, // BuffID: 186 + { BuffID.Daybreak, 300 }, // BuffID: 189 Solar Eruption Item ID: 3473, Daybreak Item ID: 3543 + { BuffID.BetsysCurse, 600 }, // BuffID: 203 + { BuffID.Oiled, 540 }, // BuffID: 204 + { BuffID.BlandWhipEnemyDebuff, 240 }, // BuffID: 307 + { BuffID.SwordWhipNPCDebuff, 240 }, // BuffID: 309 + { BuffID.ScytheWhipEnemyDebuff, 240 }, // BuffID: 310 + { BuffID.FlameWhipEnemyDebuff, 240 }, // BuffID: 313 + { BuffID.ThornWhipNPCDebuff, 240 }, // BuffID: 315 + { BuffID.RainbowWhipNPCDebuff, 240 }, // BuffID: 316 + { BuffID.MaceWhipNPCDebuff, 240 }, // BuffID: 319 + { BuffID.GelBalloonBuff, 1800 } // BuffID: 320 }; /// From 535c9a2a7e7538037c246e19542d676e1669107f Mon Sep 17 00:00:00 2001 From: Axeel Date: Sun, 24 May 2020 13:39:50 +0800 Subject: [PATCH 02/35] Fix wind command (#1879) * Fix wind command --- CHANGELOG.md | 1 + TShockAPI/Commands.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7425d8a9..23493249 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming release * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) +* Fixed /wind command. (@AxeelAnder) * Fixed NPC buff bouncer. (@AxeelAnder) ## TShock 4.4.0 (Pre-release 7 (Entangled)) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 1dc490d8..567aa3b4 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -4264,7 +4264,7 @@ namespace TShockAPI } Main.windSpeedCurrent = speed; - Main.windSpeedTarget = 0f; + Main.windSpeedTarget = speed; TSPlayer.All.SendData(PacketTypes.WorldInfo); TSPlayer.All.SendInfoMessage("{0} changed the wind speed to {1}.", args.Player.Name, speed); } From cdb1953f3647f54cf44b16107ea6949c8ab1e955 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 May 2020 23:33:16 -0700 Subject: [PATCH 03/35] Clean up world save to be less alarmist --- TShockAPI/Commands.cs | 1 - TShockAPI/SaveManager.cs | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 1dc490d8..5e3ee79f 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -4044,7 +4044,6 @@ namespace TShockAPI { tsply.SaveServerCharacter(); } - args.Player.SendSuccessMessage("Save succeeded."); } private static void Settle(CommandArgs args) diff --git a/TShockAPI/SaveManager.cs b/TShockAPI/SaveManager.cs index 54b2af98..c0af6d42 100644 --- a/TShockAPI/SaveManager.cs +++ b/TShockAPI/SaveManager.cs @@ -55,7 +55,7 @@ namespace TShockAPI // These can be caused by an unexpected error such as a bad or out of date plugin try { - TShock.Utils.Broadcast("Saving world. Momentary lag might result from this.", Color.Red); + TShock.Utils.Broadcast("Saving world...", Color.Yellow); } catch (Exception ex) { @@ -130,8 +130,11 @@ namespace TShockAPI } else WorldFile.SaveWorld(task.resetTime); + + if (TShock.Config.AnnounceSave) TShock.Utils.Broadcast("World saved.", Color.Yellow); - TShock.Log.Info(string.Format("World saved at ({0})", Main.worldPathName)); + + TShock.Log.Info(string.Format("World saved at ({0})", Main.worldPathName)); } catch (Exception e) { From 37e65b64dc5038006b4fa86e32815c5959095336 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 May 2020 23:47:50 -0700 Subject: [PATCH 04/35] Add note about what Tombstones do and don't do --- TShockAPI/Bouncer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 6fa88feb..e9281983 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -865,7 +865,6 @@ namespace TShockAPI return; } - if (stabProjectile.ContainsKey(type)) { if (stabProjectile[type] == args.Player.TPlayer.HeldItem.type) @@ -875,7 +874,6 @@ namespace TShockAPI } } - // Main.projHostile contains projectiles that can harm players // without PvP enabled and belong to enemy mobs, so they shouldn't be // possible for players to create. (Source: Ijwu, QuiCM) @@ -888,6 +886,8 @@ namespace TShockAPI } // Tombstones should never be permitted by players + // This check means like, invalid or hacked tombstones (sent from hacked clients) + // Death does not create a tombstone projectile by default if (type == ProjectileID.Tombstone) { TShock.Log.ConsoleDebug("Bouncer / OnNewProjectile rejected from tombstones from {0}", args.Player.Name); From ae87f242d76151eb9ecd4aa5885416c4b2d0c475 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 May 2020 23:56:49 -0700 Subject: [PATCH 05/35] Clarify log debug from SendTileSquare --- TShockAPI/Bouncer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index e9281983..dd55f6ef 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -711,7 +711,7 @@ namespace TShockAPI args.Player.SendTileSquare(tileX, tileY, size); } - TShock.Log.ConsoleDebug("Bouncer / SendTileSquare rejected from spaghetti from {0}", args.Player.Name); + TShock.Log.ConsoleDebug("Bouncer / SendTileSquare reimplemented from spaghetti from {0}", args.Player.Name); args.Handled = true; } From 965361c4066203e2e59c9b49a92f7d728864afaf Mon Sep 17 00:00:00 2001 From: Olink Date: Sun, 24 May 2020 03:48:08 -0400 Subject: [PATCH 06/35] Add a projectile tracker, so that we can allow fluid bombs. --- TShockAPI/Bouncer.cs | 38 +++++++++++++++++++++++++++++------- TShockAPI/GetDataHandlers.cs | 18 +++++++++++++++++ TShockAPI/TSPlayer.cs | 6 ++++++ TShockAPI/TShock.cs | 13 ++++++++++++ 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index dd55f6ef..f3a85f40 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -962,6 +962,18 @@ namespace TShockAPI // Denotes that the player has recently set a fuse - used for cheat detection. args.Player.RecentFuse = 10; } + + if (projectileCreatesLiquid.ContainsKey(type)) + { + lock (args.Player.RecentlyCreatedProjectiles) + { + args.Player.RecentlyCreatedProjectiles.Add(new ProjectileStruct() + { + Index = ident, + CreatedAt = DateTime.Now + }); + } + } } /// Handles the NPC Strike event for Bouncer. @@ -1290,6 +1302,18 @@ namespace TShockAPI args.Player.TileLiquidThreshold++; } + bool wasThereABombNearby = false; + + lock (args.Player.RecentlyCreatedProjectiles) + { + var keys = projectileCreatesLiquid.Where(k => k.Value == type).Select(k => k.Key); + var recentBombs = args.Player.RecentlyCreatedProjectiles.Where(keys.Contains(Main.projectile[p.Index].type)); + wasThereABombNearby = recentBombs.Any(r => (args.TileX > (Main.projectile[r.Index].position.X / 16.0f) - 32 + && args.TileX < (Main.projectile[r.Index].position.X / 16.0f) + 32) + && (args.TileY > (Main.projectile[r.Index].position.Y / 16.0f) - 32 + && args.TileY < (Main.projectile[r.Index].position.Y / 16.0f) + 32)); + } + // Liquid anti-cheat // Arguably the banned buckets bit should be in the item bans system if (amount != 0) @@ -1326,7 +1350,7 @@ namespace TShockAPI bucket = 6; } - if (type == LiquidType.Lava && !(bucket == 2 || bucket == 0 || bucket == 5 || bucket == 6)) + if (!wasThereABombNearby && type == LiquidType.Lava && !(bucket == 2 || bucket == 0 || bucket == 5 || bucket == 6)) { TShock.Log.ConsoleDebug("Bouncer / OnLiquidSet rejected bucket check 1 from {0}", args.Player.Name); args.Player.SendErrorMessage("You do not have permission to perform this action."); @@ -1336,7 +1360,7 @@ namespace TShockAPI return; } - if (type == LiquidType.Lava && TShock.Itembans.ItemIsBanned("Lava Bucket", args.Player)) + if (!wasThereABombNearby && type == LiquidType.Lava && TShock.Itembans.ItemIsBanned("Lava Bucket", args.Player)) { TShock.Log.ConsoleDebug("Bouncer / OnLiquidSet rejected lava bucket from {0}", args.Player.Name); args.Player.SendErrorMessage("You do not have permission to perform this action."); @@ -1346,7 +1370,7 @@ namespace TShockAPI return; } - if (type == LiquidType.Water && !(bucket == 1 || bucket == 0 || bucket == 4)) + if (!wasThereABombNearby && type == LiquidType.Water && !(bucket == 1 || bucket == 0 || bucket == 4)) { TShock.Log.ConsoleDebug("Bouncer / OnLiquidSet rejected bucket check 2 from {0}", args.Player.Name); args.Player.SendErrorMessage("You do not have permission to perform this action."); @@ -1356,7 +1380,7 @@ namespace TShockAPI return; } - if (type == LiquidType.Water && TShock.Itembans.ItemIsBanned("Water Bucket", args.Player)) + if (!wasThereABombNearby && type == LiquidType.Water && TShock.Itembans.ItemIsBanned("Water Bucket", args.Player)) { TShock.Log.ConsoleDebug("Bouncer / OnLiquidSet rejected bucket check 3 from {0}", args.Player.Name); args.Player.SendErrorMessage("You do not have permission to perform this action."); @@ -1366,7 +1390,7 @@ namespace TShockAPI return; } - if (type == LiquidType.Honey && !(bucket == 3 || bucket == 0)) + if (!wasThereABombNearby && type == LiquidType.Honey && !(bucket == 3 || bucket == 0)) { TShock.Log.ConsoleDebug("Bouncer / OnLiquidSet rejected bucket check 4 from {0}", args.Player.Name); args.Player.SendErrorMessage("You do not have permission to perform this action."); @@ -1376,7 +1400,7 @@ namespace TShockAPI return; } - if (type == LiquidType.Honey && TShock.Itembans.ItemIsBanned("Honey Bucket", args.Player)) + if (!wasThereABombNearby && type == LiquidType.Honey && TShock.Itembans.ItemIsBanned("Honey Bucket", args.Player)) { TShock.Log.ConsoleDebug("Bouncer / OnLiquidSet rejected bucket check 5 from {0}", args.Player.Name); args.Player.SendErrorMessage("You do not have permission to perform this action."); @@ -1395,7 +1419,7 @@ namespace TShockAPI return; } - if (!args.Player.IsInRange(tileX, tileY, 16)) + if (!wasThereABombNearby && !args.Player.IsInRange(tileX, tileY, 16)) { TShock.Log.ConsoleDebug("Bouncer / OnLiquidSet rejected range checks from {0}", args.Player.Name); args.Player.SendTileSquare(tileX, tileY, 1); diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 19c6f4b0..57c8985f 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2386,6 +2386,10 @@ namespace TShockAPI } args.Player.LastKilledProjectile = type; + lock (args.Player.RecentlyCreatedProjectiles) + { + args.Player.RecentlyCreatedProjectiles.ForEach(s => { if (s.Index == index) { s.Killed = true; } }); + } return false; } @@ -3446,6 +3450,13 @@ namespace TShockAPI { ProjectileID.MysticSnakeCoil, TileID.MysticSnakeRope } }; + internal static Dictionary projectileCreatesLiquid = new Dictionary + { + {ProjectileID.LavaBomb, LiquidType.Lava}, + {ProjectileID.WetBomb, LiquidType.Water}, + {ProjectileID.HoneyBomb, LiquidType.Honey} + }; + internal static Dictionary ropeCoilPlacements = new Dictionary { {ItemID.RopeCoil, TileID.Rope}, @@ -3461,5 +3472,12 @@ namespace TShockAPI { {TileID.MinecartTrack, 3} }; + + internal struct ProjectileStruct + { + public int Index { get; set; } + public DateTime CreatedAt { get; set; } + public bool Killed { get; internal set; } + } } } diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 86642e69..277e9b00 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -764,6 +764,12 @@ namespace TShockAPI /// public int LastKilledProjectile = 0; + /// + /// Keeps track of recently created projectiles by this player. TShock.cs OnSecondUpdate() removes from this in an async task. + /// Projectiles older than 5 seconds are purged from this collection as they are no longer "recent". + /// + internal List RecentlyCreatedProjectiles = new List(); + /// /// The current region this player is in, or null if none. /// diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index d0b174b4..656a1314 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -44,6 +44,7 @@ using Microsoft.Xna.Framework; using TShockAPI.Sockets; using TShockAPI.CLI; using TShockAPI.Localization; +using System.Threading.Tasks; namespace TShockAPI { @@ -1064,6 +1065,18 @@ namespace TShockAPI } } } + + Task.Run(() => + { + if (player != null && player.TPlayer.whoAmI >= 0) + { + var threshold = DateTime.Now.AddSeconds(-5); + lock (player.RecentlyCreatedProjectiles) + { + player.RecentlyCreatedProjectiles = player.RecentlyCreatedProjectiles.Where(s => s.CreatedAt > threshold).ToList(); + } + } + }); } Utils.SetConsoleTitle(false); } From fecdb755ff94c8812c091e1153cd1a79e8401921 Mon Sep 17 00:00:00 2001 From: Olink Date: Sun, 24 May 2020 03:50:01 -0400 Subject: [PATCH 07/35] Add entry to changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23493249..c0074b8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) * Fixed /wind command. (@AxeelAnder) * Fixed NPC buff bouncer. (@AxeelAnder) +* Fix fluid bombs. (@Olink) ## TShock 4.4.0 (Pre-release 7 (Entangled)) * Fixed bed spawn issues when trying to remove spawn point in SSC. (@Olink) From 3b0c5f777551caf54be2ba6b3b19dae06489d1fd Mon Sep 17 00:00:00 2001 From: Olink Date: Sun, 24 May 2020 03:54:27 -0400 Subject: [PATCH 08/35] Make bouncer compile. Reduce range checks. --- TShockAPI/Bouncer.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index f3a85f40..afa5d6a3 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -1307,11 +1307,11 @@ namespace TShockAPI lock (args.Player.RecentlyCreatedProjectiles) { var keys = projectileCreatesLiquid.Where(k => k.Value == type).Select(k => k.Key); - var recentBombs = args.Player.RecentlyCreatedProjectiles.Where(keys.Contains(Main.projectile[p.Index].type)); - wasThereABombNearby = recentBombs.Any(r => (args.TileX > (Main.projectile[r.Index].position.X / 16.0f) - 32 - && args.TileX < (Main.projectile[r.Index].position.X / 16.0f) + 32) - && (args.TileY > (Main.projectile[r.Index].position.Y / 16.0f) - 32 - && args.TileY < (Main.projectile[r.Index].position.Y / 16.0f) + 32)); + var recentBombs = args.Player.RecentlyCreatedProjectiles.Where(p => keys.Contains(Main.projectile[p.Index].type)); + wasThereABombNearby = recentBombs.Any(r => (args.TileX > (Main.projectile[r.Index].position.X / 16.0f) - 16 + && args.TileX < (Main.projectile[r.Index].position.X / 16.0f) + 16) + && (args.TileY > (Main.projectile[r.Index].position.Y / 16.0f) - 16 + && args.TileY < (Main.projectile[r.Index].position.Y / 16.0f) + 16)); } // Liquid anti-cheat From 9209ac0b73c90d8d64aaf8d4e6e7fcfe2eb9243c Mon Sep 17 00:00:00 2001 From: Zack Date: Sun, 24 May 2020 04:19:00 -0400 Subject: [PATCH 09/35] Apply suggestions from code review Co-authored-by: Lucas Nicodemus --- CHANGELOG.md | 2 +- TShockAPI/Bouncer.cs | 2 +- TShockAPI/TSPlayer.cs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0074b8c..1505337c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) * Fixed /wind command. (@AxeelAnder) * Fixed NPC buff bouncer. (@AxeelAnder) -* Fix fluid bombs. (@Olink) +* Fixed lava, wet, and honey bombs. (@Olink) ## TShock 4.4.0 (Pre-release 7 (Entangled)) * Fixed bed spawn issues when trying to remove spawn point in SSC. (@Olink) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index afa5d6a3..a506d079 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -1303,7 +1303,7 @@ namespace TShockAPI } bool wasThereABombNearby = false; - +// The +/- 16 is compensation for maximum detonation distance, but it might be possible to drop to 5 and be conservative lock (args.Player.RecentlyCreatedProjectiles) { var keys = projectileCreatesLiquid.Where(k => k.Value == type).Select(k => k.Key); diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 277e9b00..3d7deaae 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -765,8 +765,8 @@ namespace TShockAPI public int LastKilledProjectile = 0; /// - /// Keeps track of recently created projectiles by this player. TShock.cs OnSecondUpdate() removes from this in an async task. - /// Projectiles older than 5 seconds are purged from this collection as they are no longer "recent". + /// Keeps track of recently created projectiles by this player. TShock.cs OnSecondUpdate() removes from this in an async task. + /// Projectiles older than 5 seconds are purged from this collection as they are no longer "recent." /// internal List RecentlyCreatedProjectiles = new List(); From b73088306d7aad990d2c9c088f8da4c71376f7d9 Mon Sep 17 00:00:00 2001 From: Olink Date: Sun, 24 May 2020 04:27:12 -0400 Subject: [PATCH 10/35] Move the projectile refresh to Bouncer. Bouncer now has an OnSecondUpdate(). Move projectile created tracking to GetDataHandler from Bouncer. --- TShockAPI/Bouncer.cs | 33 +++++++++++++++++++-------------- TShockAPI/GetDataHandlers.cs | 12 ++++++++++++ TShockAPI/TShock.cs | 15 ++------------- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index a506d079..a5e14115 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -19,18 +19,17 @@ using System; using System.Collections.Generic; using System.Linq; using Terraria.ID; -using TShockAPI.DB; using TShockAPI.Net; using Terraria; using Microsoft.Xna.Framework; using OTAPI.Tile; using TShockAPI.Localization; using static TShockAPI.GetDataHandlers; -using TerrariaApi.Server; using Terraria.ObjectData; using Terraria.DataStructures; using Terraria.Localization; using TShockAPI.Models.PlayerUpdate; +using System.Threading.Tasks; namespace TShockAPI { @@ -962,18 +961,6 @@ namespace TShockAPI // Denotes that the player has recently set a fuse - used for cheat detection. args.Player.RecentFuse = 10; } - - if (projectileCreatesLiquid.ContainsKey(type)) - { - lock (args.Player.RecentlyCreatedProjectiles) - { - args.Player.RecentlyCreatedProjectiles.Add(new ProjectileStruct() - { - Index = ident, - CreatedAt = DateTime.Now - }); - } - } } /// Handles the NPC Strike event for Bouncer. @@ -2069,6 +2056,24 @@ namespace TShockAPI } } + internal void OnSecondUpdate() + { + Task.Run(() => + { + foreach (var player in TShock.Players) + { + if (player != null && player.TPlayer.whoAmI >= 0) + { + var threshold = DateTime.Now.AddSeconds(-5); + lock (player.RecentlyCreatedProjectiles) + { + player.RecentlyCreatedProjectiles = player.RecentlyCreatedProjectiles.Where(s => s.CreatedAt > threshold).ToList(); + } + } + } + }); + } + // These time values are references from Projectile.cs, at npc.AddBuff() calls. private static Dictionary NPCAddBuffTimeMax = new Dictionary() { diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 57c8985f..606f56a6 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2322,6 +2322,18 @@ namespace TShockAPI if (OnNewProjectile(args.Data, ident, pos, vel, knockback, dmg, owner, type, index, args.Player)) return true; + if (projectileCreatesLiquid.ContainsKey(type)) + { + lock (args.Player.RecentlyCreatedProjectiles) + { + args.Player.RecentlyCreatedProjectiles.Add(new ProjectileStruct() + { + Index = ident, + CreatedAt = DateTime.Now + }); + } + } + return false; } diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 656a1314..6f685654 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -44,7 +44,6 @@ using Microsoft.Xna.Framework; using TShockAPI.Sockets; using TShockAPI.CLI; using TShockAPI.Localization; -using System.Threading.Tasks; namespace TShockAPI { @@ -1065,19 +1064,9 @@ namespace TShockAPI } } } - - Task.Run(() => - { - if (player != null && player.TPlayer.whoAmI >= 0) - { - var threshold = DateTime.Now.AddSeconds(-5); - lock (player.RecentlyCreatedProjectiles) - { - player.RecentlyCreatedProjectiles = player.RecentlyCreatedProjectiles.Where(s => s.CreatedAt > threshold).ToList(); - } - } - }); } + + Bouncer.OnSecondUpdate(); Utils.SetConsoleTitle(false); } From 8edca72919d0c705e2965a9d0379c4a6932da1ba Mon Sep 17 00:00:00 2001 From: Olink Date: Sun, 24 May 2020 04:33:03 -0400 Subject: [PATCH 11/35] Add config option for the bomb radius. --- TShockAPI/Bouncer.cs | 8 ++++---- TShockAPI/ConfigFile.cs | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index a5e14115..7dde6776 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -1295,10 +1295,10 @@ namespace TShockAPI { var keys = projectileCreatesLiquid.Where(k => k.Value == type).Select(k => k.Key); var recentBombs = args.Player.RecentlyCreatedProjectiles.Where(p => keys.Contains(Main.projectile[p.Index].type)); - wasThereABombNearby = recentBombs.Any(r => (args.TileX > (Main.projectile[r.Index].position.X / 16.0f) - 16 - && args.TileX < (Main.projectile[r.Index].position.X / 16.0f) + 16) - && (args.TileY > (Main.projectile[r.Index].position.Y / 16.0f) - 16 - && args.TileY < (Main.projectile[r.Index].position.Y / 16.0f) + 16)); + wasThereABombNearby = recentBombs.Any(r => (args.TileX > (Main.projectile[r.Index].position.X / 16.0f) - TShock.Config.BombExplosionRadius + && args.TileX < (Main.projectile[r.Index].position.X / 16.0f) + TShock.Config.BombExplosionRadius) + && (args.TileY > (Main.projectile[r.Index].position.Y / 16.0f) - TShock.Config.BombExplosionRadius + && args.TileY < (Main.projectile[r.Index].position.Y / 16.0f) + TShock.Config.BombExplosionRadius)); } // Liquid anti-cheat diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index fb920732..6fd5794c 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -527,6 +527,9 @@ namespace TShockAPI [Description("Whether or not the server should output debug level messages related to system operation.")] public bool DebugLogs = false; + [Description("Determines the range in tiles that a bomb can affect tiles.")] + public int BombExplosionRadius = 5; + /// /// Reads a configuration file from a given path /// From 3105a977a406d890411724a9c1c79694d4a4f449 Mon Sep 17 00:00:00 2001 From: Olink Date: Sun, 24 May 2020 04:37:15 -0400 Subject: [PATCH 12/35] Add fluid rockets. --- TShockAPI/GetDataHandlers.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 606f56a6..7d76a0d4 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3465,8 +3465,11 @@ namespace TShockAPI internal static Dictionary projectileCreatesLiquid = new Dictionary { {ProjectileID.LavaBomb, LiquidType.Lava}, + {ProjectileID.LavaRocket, LiquidType.Lava }, {ProjectileID.WetBomb, LiquidType.Water}, - {ProjectileID.HoneyBomb, LiquidType.Honey} + {ProjectileID.WetRocket, LiquidType.Water }, + {ProjectileID.HoneyBomb, LiquidType.Honey}, + {ProjectileID.HoneyRocket, LiquidType.Honey } }; internal static Dictionary ropeCoilPlacements = new Dictionary From a0fd1d04a9f076c69869ef6fc0a3cf20a837c251 Mon Sep 17 00:00:00 2001 From: Zack Date: Sun, 24 May 2020 04:38:53 -0400 Subject: [PATCH 13/35] Update CHANGELOG.md Co-authored-by: Lucas Nicodemus --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1505337c..05ce14d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) * Fixed /wind command. (@AxeelAnder) * Fixed NPC buff bouncer. (@AxeelAnder) -* Fixed lava, wet, and honey bombs. (@Olink) +* Fixed lava, wet, honey bombs; and lava, wet, and honey rockets. (@Olink) ## TShock 4.4.0 (Pre-release 7 (Entangled)) * Fixed bed spawn issues when trying to remove spawn point in SSC. (@Olink) From e39af6f9176b3626133f9fae264ba7613b8832fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B1=BC=E9=B1=BC?= Date: Sun, 24 May 2020 16:47:54 +0800 Subject: [PATCH 14/35] fix npc home removal. rename something related. --- CHANGELOG.md | 1 + TShockAPI/Bouncer.cs | 4 ++-- TShockAPI/GetDataHandlers.cs | 23 +++++++++++++++-------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23493249..a59a5159 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) * Fixed /wind command. (@AxeelAnder) * Fixed NPC buff bouncer. (@AxeelAnder) +* Fixed players are unable to remove an NPC. Change `byte NPCHomeChangeEventArgs.Homeless` to `HouseholdStatus NPCHomeChangeEventArgs.HouseholdStatus`. (@AxeelAnder) ## TShock 4.4.0 (Pre-release 7 (Entangled)) * Fixed bed spawn issues when trying to remove spawn point in SSC. (@Olink) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index dd55f6ef..e5600d90 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -1547,7 +1547,6 @@ namespace TShockAPI int id = args.ID; short x = args.X; short y = args.Y; - byte homeless = args.Homeless; if (!args.Player.HasBuildPermission(x, y)) { @@ -1558,7 +1557,8 @@ namespace TShockAPI return; } - if (!args.Player.IsInRange(x, y)) + // When kicking out an npc, x and y in args are 0, we shouldn't check range at this case + if (args.HouseholdStatus != HouseholdStatus.Homeless && !args.Player.IsInRange(x, y)) { args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY, Convert.ToByte(Main.npc[id].homeless)); diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 19c6f4b0..8c5a314b 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -125,7 +125,7 @@ namespace TShockAPI { PacketTypes.NpcSpecial, HandleSpecial }, { PacketTypes.NpcAddBuff, HandleNPCAddBuff }, { PacketTypes.PlayerAddBuff, HandlePlayerAddBuff }, - { PacketTypes.UpdateNPCHome, UpdateNPCHome }, + { PacketTypes.UpdateNPCHome, HandleUpdateNPCHome }, { PacketTypes.SpawnBossorInvasion, HandleSpawnBoss }, { PacketTypes.PaintTile, HandlePaintTile }, { PacketTypes.PaintWall, HandlePaintWall }, @@ -1307,6 +1307,13 @@ namespace TShockAPI return args.Handled; } + public enum HouseholdStatus : byte + { + None = 0, + Homeless = 1, + HasRoom = 2, + } + /// /// For use in a NPCHome event /// @@ -1325,15 +1332,15 @@ namespace TShockAPI /// public short Y { get; set; } /// - /// ByteBool homeless + /// HouseholdStatus of the NPC /// - public byte Homeless { get; set; } + public HouseholdStatus HouseholdStatus { get; set; } } /// /// NPCHome - Called when an NPC's home is changed /// public static HandlerList NPCHome = new HandlerList(); - private static bool OnUpdateNPCHome(TSPlayer player, MemoryStream data, short id, short x, short y, byte homeless) + private static bool OnUpdateNPCHome(TSPlayer player, MemoryStream data, short id, short x, short y, byte houseHoldStatus) { if (NPCHome == null) return false; @@ -1345,7 +1352,7 @@ namespace TShockAPI ID = id, X = x, Y = y, - Homeless = homeless, + HouseholdStatus = (HouseholdStatus) houseHoldStatus, }; NPCHome.Invoke(null, args); return args.Handled; @@ -2763,14 +2770,14 @@ namespace TShockAPI return true; } - private static bool UpdateNPCHome(GetDataHandlerArgs args) + private static bool HandleUpdateNPCHome(GetDataHandlerArgs args) { var id = args.Data.ReadInt16(); var x = args.Data.ReadInt16(); var y = args.Data.ReadInt16(); - var homeless = args.Data.ReadInt8(); + var householdStatus = args.Data.ReadInt8(); - if (OnUpdateNPCHome(args.Player, args.Data, id, x, y, homeless)) + if (OnUpdateNPCHome(args.Player, args.Data, id, x, y, householdStatus)) return true; if (!args.Player.HasPermission(Permissions.movenpc)) From f1b35e47cc440d2131fd23b09b8044e68e6a4033 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 24 May 2020 13:23:18 -0700 Subject: [PATCH 15/35] Update config description for bomb range --- TShockAPI/ConfigFile.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 6fd5794c..4806cfc5 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -527,7 +527,7 @@ namespace TShockAPI [Description("Whether or not the server should output debug level messages related to system operation.")] public bool DebugLogs = false; - [Description("Determines the range in tiles that a bomb can affect tiles.")] + [Description("Determines the range in tiles that a bomb can affect tiles from detonation point.")] public int BombExplosionRadius = 5; /// From 39028484f0747731b0e23d894f5977bfb263f93f Mon Sep 17 00:00:00 2001 From: Olink Date: Sun, 24 May 2020 16:36:13 -0400 Subject: [PATCH 16/35] Fixes #1890. Added support for two new invasions. --- CHANGELOG.md | 8 +++++--- TShockAPI/GetDataHandlers.cs | 28 +++++++++++++++++----------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57305fd8..7a888f9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,12 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fixed /wind command. (@AxeelAnder) * Fixed NPC buff bouncer. (@AxeelAnder) * Fixed players are unable to remove an NPC. Change `byte NPCHomeChangeEventArgs.Homeless` to `HouseholdStatus NPCHomeChangeEventArgs.HouseholdStatus`. (@AxeelAnder) -* Fixed lava, wet, honey, and dry bombs; - and lava, wet, honey, and dry grenades; - and lava, wet, honey, and dry rockets; +* Fixed lava, wet, honey, and dry bombs; + and lava, wet, honey, and dry grenades; + and lava, wet, honey, and dry rockets; and lava, wet, honey, and dry mines. (@Olink) +* Fix Bloody Tear displaying the wrong text when used. (@Olink) + ## TShock 4.4.0 (Pre-release 7 (Entangled)) * Fixed bed spawn issues when trying to remove spawn point in SSC. (@Olink) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 0e426783..8076d30b 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2850,38 +2850,44 @@ namespace TShockAPI string thing; switch (thingType) { + case -11: + thing = "applied advanced combat techniques"; + break; + case -10: + thing = "summoned a Blood Moon"; + break; case -8: - thing = "a Moon Lord"; + thing = "summoned a Moon Lord"; break; case -7: - thing = "a Martian invasion"; + thing = "summoned a Martian invasion"; break; case -6: - thing = "an eclipse"; + thing = "summoned an eclipse"; break; case -5: - thing = "a frost moon"; + thing = "summoned a frost moon"; break; case -4: - thing = "a pumpkin moon"; + thing = "summoned a pumpkin moon"; break; case -3: - thing = "the Pirates"; + thing = "summoned the Pirates"; break; case -2: - thing = "the Snow Legion"; + thing = "summoned the Snow Legion"; break; case -1: - thing = "a Goblin Invasion"; + thing = "summoned a Goblin Invasion"; break; default: - thing = String.Format("the {0}", npc.FullName); + thing = String.Format("summoned the {0}", npc.FullName); break; } if (TShock.Config.AnonymousBossInvasions) - TShock.Utils.SendLogs(string.Format("{0} summoned {1}!", args.Player.Name, thing), Color.PaleVioletRed, args.Player); + TShock.Utils.SendLogs(string.Format("{0} {1}!", args.Player.Name, thing), Color.PaleVioletRed, args.Player); else - TShock.Utils.Broadcast(String.Format("{0} summoned {1}!", args.Player.Name, thing), 175, 75, 255); + TShock.Utils.Broadcast(String.Format("{0} {1}!", args.Player.Name, thing), 175, 75, 255); return false; } From cb570ec2e080348312235419b2eb1bfd02fcb1d1 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Sun, 24 May 2020 22:59:02 +0200 Subject: [PATCH 17/35] Wrap permissions in #regions. --- TShockAPI/Permissions.cs | 41 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index b08c122d..60a5ee54 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -31,8 +31,7 @@ namespace TShockAPI /// Contains the permission nodes used in TShock. public static class Permissions { - // tshock.account nodes - + #region tshock.account nodes [Description("User can register account in game.")] public static readonly string canregister = "tshock.account.register"; @@ -44,9 +43,9 @@ namespace TShockAPI [Description("User can change password in game.")] public static readonly string canchangepassword = "tshock.account.changepassword"; + #endregion - // tshock.admin nodes - + #region tshock.admin nodes [Description("User can set build protection status.")] public static readonly string antibuild = "tshock.admin.antibuild"; @@ -106,17 +105,17 @@ namespace TShockAPI [Description("User can get other users' info.")] public static readonly string userinfo = "tshock.admin.userinfo"; + #endregion - // tshock.buff nodes - + #region tshock.buff nodes [Description("User can buff self.")] public static readonly string buff = "tshock.buff.self"; [Description("User can buff other players.")] public static readonly string buffplayer = "tshock.buff.others"; + #endregion - // tshock.cfg nodes - + #region tshock.cfg nodes [Description("User is notified when an update is available, user can turn off / restart the server.")] public static readonly string maintenance = "tshock.cfg.maintenance"; @@ -131,9 +130,9 @@ namespace TShockAPI [Description("User can create reference files of Terraria IDs and the permission matrix in the server folder.")] public static readonly string createdumps = "tshock.cfg.createdumps"; + #endregion - // tshock.ignore nodes - + #region tshock.ignore nodes [Description("Prevents you from being reverted by kill tile abuse detection.")] public static readonly string ignorekilltiledetection = "tshock.ignore.removetile"; @@ -169,9 +168,9 @@ namespace TShockAPI [Description("Prevents you from being disabled by abnormal MP.")] public static readonly string ignoremp = "tshock.ignore.mp"; + #endregion - // tshock.item nodes - + #region tshock.item nodes [Description("User can give items.")] public static readonly string give = "tshock.item.give"; @@ -180,9 +179,9 @@ namespace TShockAPI [Description("Allows you to use banned items.")] public static readonly string usebanneditem = "tshock.item.usebanned"; + #endregion - // tshock.npc nodes - + #region tshock.npc nodes [Description("User can edit the max spawns.")] public static readonly string maxspawns = "tshock.npc.maxspawns"; @@ -227,9 +226,9 @@ namespace TShockAPI [Description("Allows a user to elevate to superadmin for 10 minutes.")] public static readonly string su = "tshock.su"; + #endregion - // tshock.tp nodes - + #region tshock.tp nodes [Description("User can teleport *everyone* to them.")] public static readonly string tpallothers = "tshock.tp.allothers"; @@ -268,9 +267,9 @@ namespace TShockAPI [Description("User can use wormhole potions.")] public static readonly string wormhole = "tshock.tp.wormhole"; + #endregion - // tshock.world nodes - + #region tshock.world nodes [Description("User can use the 'worldevent' command")] public static readonly string manageevents = "tshock.world.events"; @@ -372,9 +371,9 @@ namespace TShockAPI [Description("Player can toggle party event.")] public static readonly string toggleparty = "tshock.world.toggleparty"; + #endregion - // Non-grouped - + #region Non-grouped [Description("User can clear items or projectiles.")] public static readonly string clear = "tshock.clear"; @@ -428,7 +427,7 @@ namespace TShockAPI [Description("Player can see advanced information about any user account.")] public static readonly string advaccountinfo = "tshock.accountinfo.details"; - + #endregion /// /// Lists all commands associated with a given permission /// From 35c103e0114cd3c0c4d473a7134913cd697c59ce Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 24 May 2020 14:04:11 -0700 Subject: [PATCH 18/35] Fix bouncer debug message being incorrect --- TShockAPI/Bouncer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index e5600d90..28406095 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -528,7 +528,7 @@ namespace TShockAPI if (args.Player.HasPermission(Permissions.allowclientsideworldedit)) { - TShock.Log.ConsoleDebug("Bouncer / SendTileSquare rejected clientside world edit from {0}", args.Player.Name); + TShock.Log.ConsoleDebug("Bouncer / SendTileSquare accepted clientside world edit from {0}", args.Player.Name); args.Handled = false; return; } From 472b81e9f436a55a3c5a7b8e8989e0d3ae6c8bd9 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 24 May 2020 14:04:35 -0700 Subject: [PATCH 19/35] Increase default thresholds in config file Based on user testing of the new explosives from Olink, these really need to be higher to support the new lava/wet/dry/honey bombs/explosives. --- TShockAPI/ConfigFile.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index fb920732..bda097c3 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -275,11 +275,11 @@ namespace TShockAPI /// Disables a player and reverts their actions if this number of tile places is exceeded within 1 second. [Description("Disables a player and reverts their actions if this number of tile places is exceeded within 1 second.")] - public int TilePlaceThreshold = 20; + public int TilePlaceThreshold = 32; /// Disables a player if this number of liquid sets is exceeded within 1 second. [Description("Disables a player if this number of liquid sets is exceeded within 1 second.")] - public int TileLiquidThreshold = 15; + public int TileLiquidThreshold = 50; /// Disable a player if this number of projectiles is created within 1 second. [Description("Disable a player if this number of projectiles is created within 1 second.")] From d04f57d8649ffec277fcd10a88afd454e9da2a59 Mon Sep 17 00:00:00 2001 From: Olink Date: Sun, 24 May 2020 17:09:25 -0400 Subject: [PATCH 20/35] Fixes #1867 --- CHANGELOG.md | 1 + TShockAPI/GetDataHandlers.cs | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a888f9e..46e2ce49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin and lava, wet, honey, and dry rockets; and lava, wet, honey, and dry mines. (@Olink) * Fix Bloody Tear displaying the wrong text when used. (@Olink) +* Fix the visibility toggle for the last two accessory slots. (@Olink) ## TShock 4.4.0 (Pre-release 7 (Entangled)) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 8076d30b..46e3502d 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1923,11 +1923,14 @@ namespace TShockAPI args.Player.TPlayer.shirtColor = shirtColor; args.Player.TPlayer.underShirtColor = underShirtColor; args.Player.TPlayer.shoeColor = shoeColor; + //@Olink: If you need to change bool[10], please make sure you also update the for loops below to account for it. + //There are two arrays from terraria that we only have a single array for. You will need to make sure that you are looking + //at the correct terraria array (hideVisual or hideVisual2). args.Player.TPlayer.hideVisibleAccessory = new bool[10]; for (int i = 0; i < 8; i++) args.Player.TPlayer.hideVisibleAccessory[i] = hideVisual[i]; - for (int i = 8; i < 10; i++) - args.Player.TPlayer.hideVisibleAccessory[i] = hideVisual2[i]; + for (int i = 0; i < 2; i++) + args.Player.TPlayer.hideVisibleAccessory[i+8] = hideVisual2[i]; args.Player.TPlayer.hideMisc = hideMisc; args.Player.TPlayer.extraAccessory = extraSlot; NetMessage.SendData((int)PacketTypes.PlayerInfo, -1, args.Player.Index, NetworkText.FromLiteral(args.Player.Name), args.Player.Index); From d253903de03fcbd0b015006e0943a533dad18082 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Mon, 25 May 2020 01:17:11 +0200 Subject: [PATCH 21/35] Add journey permissions to Permissions.cs --- TShockAPI/Permissions.cs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index 60a5ee54..f7e68fc8 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -373,6 +373,44 @@ namespace TShockAPI public static readonly string toggleparty = "tshock.world.toggleparty"; #endregion + #region tshock.journey nodes + [Description("User can use Creative UI freeze time.")] + public static readonly string journey_timefreeze = "tshock.journey.time.freeze"; + + [Description("User can use Creative UI to set world time.")] + public static readonly string journey_timeset = "tshock.journey.time.set"; + + [Description("User can use Creative UI to set world time speed.")] + public static readonly string journey_timespeed = "tshock.journey.time.setspeed"; + + [Description("User can use Creative UI to to toggle character godmode.")] + public static readonly string journey_godmode = "tshock.journey.godmode"; + + [Description("User can use Creative UI to set world wind strength/seed.")] + public static readonly string journey_windstrength = "tshock.journey.wind.strength"; + + [Description("User can use Creative UI to stop the world wind strength from changing.")] + public static readonly string journey_windfreeze = "tshock.journey.wind.freeze"; + + [Description("User can use Creative UI to set world rain strength/seed.")] + public static readonly string journey_rainstrength = "tshock.journey.rain.strength"; + + [Description("User can use Creative UI to stop the world rain strength from changing.")] + public static readonly string journey_rainfreeze = "tshock.journey.rain.freeze"; + + [Description("User can use Creative UI to toggle increased placement range.")] + public static readonly string journey_placementrange = "tshock.journey.placementrange"; + + [Description("User can use Creative UI to set world difficulty/mode.")] + public static readonly string journey_setdifficulty = "tshock.journey.setdifficulty"; + + [Description("User can use Creative UI to stop the biome spread of the world.")] + public static readonly string journey_biomespreadfreeze = "tshock.journey.biomespreadfreeze"; + + [Description("User can use Creative UI to set the NPC spawn rate of the world.")] + public static readonly string journey_setdawn = "tshock.journey.setspawnrate"; + #endregion + #region Non-grouped [Description("User can clear items or projectiles.")] public static readonly string clear = "tshock.clear"; @@ -475,5 +513,7 @@ namespace TShockAPI File.WriteAllText("PermissionsDescriptions.txt", sb.ToString()); } + + public static void FromJourneyModePermission(string tshockPermission) } } From 6fa288e5db0218fbaa811f25f2917467369f812a Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Mon, 25 May 2020 01:36:26 +0200 Subject: [PATCH 22/35] Read PowerModule netmodule data and check for permissions Removed leftover from previous commit. Fixed a typeo. --- TShockAPI/GetDataHandlers.cs | 124 +++++++++++++++++++++++++++++++++++ TShockAPI/Permissions.cs | 4 +- 2 files changed, 125 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 0e426783..5175312a 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3107,6 +3107,130 @@ namespace TShockAPI private static bool HandleLoadNetModule(GetDataHandlerArgs args) { + short moduleId = args.Data.ReadInt16(); + if (moduleId == 6) // Power module. + { + short powerId = args.Data.ReadInt16(); + switch (powerId) + { + case 0: + { + if (!args.Player.HasPermission(Permissions.journey_timefreeze)) + { + args.Player.SendErrorMessage("You have no permission to freeze the time of the server!"); + return true; + } + break; + } + case 1: + case 2: + case 3: + case 4: + { + if (!args.Player.HasPermission(Permissions.journey_timeset)) + { + args.Player.SendErrorMessage("You have no permission to modify the time of the server!"); + return true; + } + break; + } + case 5: + { + if (!args.Player.HasPermission(Permissions.journey_godmode)) + { + args.Player.SendErrorMessage("You have no permission to toggle godmode!"); + return true; + } + break; + } + case 6: + { + if (!args.Player.HasPermission(Permissions.journey_windstrength)) + { + args.Player.SendErrorMessage("You have no permission to modify the wind strength of the server!"); + return true; + } + break; + } + case 7: + { + if (!args.Player.HasPermission(Permissions.journey_rainstrength)) + { + args.Player.SendErrorMessage("You have no permission to modify the rain strength of the server!"); + return true; + } + break; + } + case 8: + { + if (!args.Player.HasPermission(Permissions.journey_timespeed)) + { + args.Player.SendErrorMessage("You have no permission to modify the time speed of the server!"); + return true; + } + break; + } + case 9: + { + if (!args.Player.HasPermission(Permissions.journey_rainfreeze)) + { + args.Player.SendErrorMessage("You have no permission to freeze the rain strength of the server!"); + return true; + } + break; + } + case 10: + { + if (!args.Player.HasPermission(Permissions.journey_windfreeze)) + { + args.Player.SendErrorMessage("You have no permission to freeze the wind strength of the server!"); + return true; + } + break; + } + case 11: + { + if (!args.Player.HasPermission(Permissions.journey_placementrange)) + { + args.Player.SendErrorMessage("You have no permission to modify the tile placement range of your character!"); + return true; + } + break; + } + case 12: + { + if (!args.Player.HasPermission(Permissions.journey_setdifficulty)) + { + args.Player.SendErrorMessage("You have no permission to modify the world dificulty of the server!"); + return true; + } + break; + } + case 13: + { + if (!args.Player.HasPermission(Permissions.journey_biomespreadfreeze)) + { + args.Player.SendErrorMessage("You have no permission to freeze the biome spread of server!"); + return true; + } + break; + } + case 14: + { + if (!args.Player.HasPermission(Permissions.journey_setspawnrate)) + { + args.Player.SendErrorMessage("You have no permission to modify the NPC spawn rate of server!"); + return true; + } + break; + } + default: + { + return true; + } + } + } + // As of 1.4.x.x, this is now used for more things: // NetCreativePowersModule // NetCreativePowerPermissionsModule diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index f7e68fc8..322b1199 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -408,7 +408,7 @@ namespace TShockAPI public static readonly string journey_biomespreadfreeze = "tshock.journey.biomespreadfreeze"; [Description("User can use Creative UI to set the NPC spawn rate of the world.")] - public static readonly string journey_setdawn = "tshock.journey.setspawnrate"; + public static readonly string journey_setspawnrate = "tshock.journey.setspawnrate"; #endregion #region Non-grouped @@ -513,7 +513,5 @@ namespace TShockAPI File.WriteAllText("PermissionsDescriptions.txt", sb.ToString()); } - - public static void FromJourneyModePermission(string tshockPermission) } } From 63f63347a4347f3ef7a9dc056459f6abef931735 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Mon, 25 May 2020 01:38:13 +0200 Subject: [PATCH 23/35] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57305fd8..a343c23e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin and lava, wet, honey, and dry grenades; and lava, wet, honey, and dry rockets; and lava, wet, honey, and dry mines. (@Olink) +* Adding Journey mode user account permissions. (@Patrikkk) ## TShock 4.4.0 (Pre-release 7 (Entangled)) * Fixed bed spawn issues when trying to remove spawn point in SSC. (@Olink) From a1621329a3d03b1bab95bd754d0b1a533f9f8712 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Mon, 25 May 2020 02:12:59 +0200 Subject: [PATCH 24/35] Add enums for magic numbers. --- TShockAPI/GetDataHandlers.cs | 68 +++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 5175312a..d4a4e96b 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3108,12 +3108,12 @@ namespace TShockAPI private static bool HandleLoadNetModule(GetDataHandlerArgs args) { short moduleId = args.Data.ReadInt16(); - if (moduleId == 6) // Power module. + if (moduleId == (int)NetModulesTypes.CreativePowers) { - short powerId = args.Data.ReadInt16(); + CreativePowerTypes powerId = (CreativePowerTypes)args.Data.ReadInt16(); switch (powerId) { - case 0: + case CreativePowerTypes.FreezeTime: { if (!args.Player.HasPermission(Permissions.journey_timefreeze)) { @@ -3122,10 +3122,10 @@ namespace TShockAPI } break; } - case 1: - case 2: - case 3: - case 4: + case CreativePowerTypes.SetDawn: + case CreativePowerTypes.SetNoon: + case CreativePowerTypes.SetDusk: + case CreativePowerTypes.SetMidnight: { if (!args.Player.HasPermission(Permissions.journey_timeset)) { @@ -3134,7 +3134,7 @@ namespace TShockAPI } break; } - case 5: + case CreativePowerTypes.Godmode: { if (!args.Player.HasPermission(Permissions.journey_godmode)) { @@ -3143,7 +3143,7 @@ namespace TShockAPI } break; } - case 6: + case CreativePowerTypes.WindStrength: { if (!args.Player.HasPermission(Permissions.journey_windstrength)) { @@ -3152,7 +3152,7 @@ namespace TShockAPI } break; } - case 7: + case CreativePowerTypes.RainStrength: { if (!args.Player.HasPermission(Permissions.journey_rainstrength)) { @@ -3161,7 +3161,7 @@ namespace TShockAPI } break; } - case 8: + case CreativePowerTypes.TimeSpeed: { if (!args.Player.HasPermission(Permissions.journey_timespeed)) { @@ -3170,7 +3170,7 @@ namespace TShockAPI } break; } - case 9: + case CreativePowerTypes.RainFreeze: { if (!args.Player.HasPermission(Permissions.journey_rainfreeze)) { @@ -3179,7 +3179,7 @@ namespace TShockAPI } break; } - case 10: + case CreativePowerTypes.WindFreeze: { if (!args.Player.HasPermission(Permissions.journey_windfreeze)) { @@ -3188,7 +3188,7 @@ namespace TShockAPI } break; } - case 11: + case CreativePowerTypes.IncreasePlacementRange: { if (!args.Player.HasPermission(Permissions.journey_placementrange)) { @@ -3197,7 +3197,7 @@ namespace TShockAPI } break; } - case 12: + case CreativePowerTypes.WorldDifficulty: { if (!args.Player.HasPermission(Permissions.journey_setdifficulty)) { @@ -3206,7 +3206,7 @@ namespace TShockAPI } break; } - case 13: + case CreativePowerTypes.BiomeSpreadFreeze: { if (!args.Player.HasPermission(Permissions.journey_biomespreadfreeze)) { @@ -3215,7 +3215,7 @@ namespace TShockAPI } break; } - case 14: + case CreativePowerTypes.SetSpawnRate: { if (!args.Player.HasPermission(Permissions.journey_setspawnrate)) { @@ -3639,5 +3639,39 @@ namespace TShockAPI public DateTime CreatedAt { get; set; } public bool Killed { get; internal set; } } + + public enum NetModulesTypes + { + Liquid, + Text, + Ping, + Ambience, + Bestiary, + CreativeUnlocks, + CreativePowers, + CreativeUnlocksPlayerReport, + TeleportPylon, + Particles, + CreativePowerPermissions + } + + public enum CreativePowerTypes + { + FreezeTime, + SetDawn, + SetNoon, + SetDusk, + SetMidnight, + Godmode, + WindStrength, + RainStrength, + TimeSpeed, + RainFreeze, + WindFreeze, + IncreasePlacementRange, + WorldDifficulty, + BiomeSpreadFreeze, + SetSpawnRate + } } } From 1eeb77d61f79e4d55b28aaea2c7489bc5a8e24f0 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 24 May 2020 17:32:12 -0700 Subject: [PATCH 25/35] Update codename --- TShockAPI/TShock.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 6e0ed31c..c1032d43 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -57,7 +57,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 = "Go to sleep Patrikkk, Icy, Chris, Death, Axeel, Zaicon, hakusaro, and Yoraiz0r <3"; + public static readonly string VersionCodename = "Go to sleep Patrikkk, Icy, Chris, Death, Axeel, Zaicon, hakusaro, Zack, and Yoraiz0r <3"; /// 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 a3e507c8f1526c3996954631781d19e16681335c Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 24 May 2020 20:46:54 -0700 Subject: [PATCH 26/35] Update defect report template --- .github/ISSUE_TEMPLATE/defect-report.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/defect-report.md b/.github/ISSUE_TEMPLATE/defect-report.md index 930f1aee..918d5ab7 100644 --- a/.github/ISSUE_TEMPLATE/defect-report.md +++ b/.github/ISSUE_TEMPLATE/defect-report.md @@ -9,6 +9,8 @@ assignees: '' + + * TShock version: * TShock build number (if known): @@ -31,8 +33,12 @@ PUT SUPER LONG ERROR MESSAGES IN THE TICK MARKS -#### Any log messages from files that end in `.log` or `.txt`? +#### Any log messages from files that end in `.log` or `.txt`? What are the last 100 log messages from the server console? + + #### What plugins and what versions of those plugins are you running? + +If I didn't provide any logs this issue, please close my issue immediately. I'm sorry for the inconvenience. From a2cbd65f59852797c5b7d2f309cf7c0866ba95ea Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 24 May 2020 20:54:54 -0700 Subject: [PATCH 27/35] Add more info about journey perms to changelog --- CHANGELOG.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 557b5e84..aefdd081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,19 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin and lava, wet, honey, and dry mines. (@Olink) * Fix Bloody Tear displaying the wrong text when used. (@Olink) * Fix the visibility toggle for the last two accessory slots. (@Olink) -* Adding Journey mode user account permissions. (@Patrikkk) - +* Adding Journey mode user account permissions. Journey mode must be enabled for these to have any effect. (@Patrikkk) + * `tshock.journey.time.freeze` + * `tshock.journey.time.set` + * `tshock.journey.time.setspeed` + * `tshock.journey.godmode` + * `tshock.journey.wind.strength` + * `tshock.journey.wind.freeze` + * `tshock.journey.rain.strength` + * `tshock.journey.rain.freeze` + * `tshock.journey.placementrange` + * `tshock.journey.setdifficulty` + * `tshock.journey.biomespreadfreeze` + * `tshock.journey.setspawnrate` ## TShock 4.4.0 (Pre-release 7 (Entangled)) * Fixed bed spawn issues when trying to remove spawn point in SSC. (@Olink) From 2cd4e2f858c53df1c039c29909f5c85f73aafa9c Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 24 May 2020 20:56:23 -0700 Subject: [PATCH 28/35] Update changelog again for vtick --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aefdd081..bd797700 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,10 @@ This is the rolling changelog for TShock for Terraria. Use past tense when adding new entries; sign your name off when you add or change something. This should primarily be things like user changes, not necessarily codebase changes unless it's really relevant or large. -## Upcoming release +## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) * Fixed /wind command. (@AxeelAnder) -* Fixed NPC buff bouncer. (@AxeelAnder) +* Fixed NPC debuff issue when attempting to fight bosses resulting in kicks. (@AxeelAnder) * Fixed players are unable to remove an NPC. Change `byte NPCHomeChangeEventArgs.Homeless` to `HouseholdStatus NPCHomeChangeEventArgs.HouseholdStatus`. (@AxeelAnder) * Fixed lava, wet, honey, and dry bombs; and lava, wet, honey, and dry grenades; From cb31997acc21914aa303f914da046910435f8baf Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 24 May 2020 20:59:25 -0700 Subject: [PATCH 29/35] One more changelog change --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd797700..e4d6864e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * `tshock.journey.setdifficulty` * `tshock.journey.biomespreadfreeze` * `tshock.journey.setspawnrate` +* Changed default thresholds for some changes in the config file to accommodate new items & changes to Terraria. (@hakusaro) ## TShock 4.4.0 (Pre-release 7 (Entangled)) * Fixed bed spawn issues when trying to remove spawn point in SSC. (@Olink) From 6eb80389910ec642106372ff5f45f19ae759047b Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 24 May 2020 22:19:10 -0700 Subject: [PATCH 30/35] Refactor grammar of permission error --- TShockAPI/GetDataHandlers.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index d5e3b2c7..6c9cec8c 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3126,7 +3126,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_timefreeze)) { - args.Player.SendErrorMessage("You have no permission to freeze the time of the server!"); + args.Player.SendErrorMessage("You don't have permission to freeze the time of the server!"); return true; } break; @@ -3138,7 +3138,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_timeset)) { - args.Player.SendErrorMessage("You have no permission to modify the time of the server!"); + args.Player.SendErrorMessage("You don't have permission to modify the time of the server!"); return true; } break; @@ -3147,7 +3147,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_godmode)) { - args.Player.SendErrorMessage("You have no permission to toggle godmode!"); + args.Player.SendErrorMessage("You don't have permission to toggle godmode!"); return true; } break; @@ -3156,7 +3156,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_windstrength)) { - args.Player.SendErrorMessage("You have no permission to modify the wind strength of the server!"); + args.Player.SendErrorMessage("You don't have permission to modify the wind strength of the server!"); return true; } break; @@ -3165,7 +3165,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_rainstrength)) { - args.Player.SendErrorMessage("You have no permission to modify the rain strength of the server!"); + args.Player.SendErrorMessage("You don't have permission to modify the rain strength of the server!"); return true; } break; @@ -3174,7 +3174,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_timespeed)) { - args.Player.SendErrorMessage("You have no permission to modify the time speed of the server!"); + args.Player.SendErrorMessage("You don't have permission to modify the time speed of the server!"); return true; } break; @@ -3183,7 +3183,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_rainfreeze)) { - args.Player.SendErrorMessage("You have no permission to freeze the rain strength of the server!"); + args.Player.SendErrorMessage("You don't have permission to freeze the rain strength of the server!"); return true; } break; @@ -3192,7 +3192,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_windfreeze)) { - args.Player.SendErrorMessage("You have no permission to freeze the wind strength of the server!"); + args.Player.SendErrorMessage("You don't have permission to freeze the wind strength of the server!"); return true; } break; @@ -3201,7 +3201,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_placementrange)) { - args.Player.SendErrorMessage("You have no permission to modify the tile placement range of your character!"); + args.Player.SendErrorMessage("You don't have permission to modify the tile placement range of your character!"); return true; } break; @@ -3210,7 +3210,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_setdifficulty)) { - args.Player.SendErrorMessage("You have no permission to modify the world dificulty of the server!"); + args.Player.SendErrorMessage("You don't have permission to modify the world dificulty of the server!"); return true; } break; @@ -3219,7 +3219,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_biomespreadfreeze)) { - args.Player.SendErrorMessage("You have no permission to freeze the biome spread of server!"); + args.Player.SendErrorMessage("You don't have permission to freeze the biome spread of server!"); return true; } break; @@ -3228,7 +3228,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_setspawnrate)) { - args.Player.SendErrorMessage("You have no permission to modify the NPC spawn rate of server!"); + args.Player.SendErrorMessage("You don't have permission to modify the NPC spawn rate of server!"); return true; } break; From 56b695b80bbe06a914066138c394e4541404209d Mon Sep 17 00:00:00 2001 From: Olink Date: Mon, 25 May 2020 02:24:03 -0400 Subject: [PATCH 31/35] Add initial support for Journey mode in SSC. --- TShockAPI/DB/ResearchDatastore.cs | 123 ++++++++++++++++++++++++++++++ TShockAPI/GetDataHandlers.cs | 16 ++++ TShockAPI/PlayerData.cs | 17 +++++ TShockAPI/TShock.cs | 3 + TShockAPI/TShockAPI.csproj | 3 +- 5 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 TShockAPI/DB/ResearchDatastore.cs diff --git a/TShockAPI/DB/ResearchDatastore.cs b/TShockAPI/DB/ResearchDatastore.cs new file mode 100644 index 00000000..d4fa2197 --- /dev/null +++ b/TShockAPI/DB/ResearchDatastore.cs @@ -0,0 +1,123 @@ +using MySql.Data.MySqlClient; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Terraria; +using Terraria.ID; + +namespace TShockAPI.DB +{ + /// + /// This class is used as the data interface for Journey mode research. + /// This information is maintained such that SSC characters will be properly set up with + /// the world's current research. + /// + public class ResearchDatastore + { + private IDbConnection database; + + /// + /// In-memory cache of what items have been sacrificed. + /// The first call to GetSacrificedItems will load this with data from the database. + /// + private Dictionary _itemsSacrificed; + + /// + /// Initializes a new instance of the class. + /// + /// A valid connection to the TShock database + public ResearchDatastore(IDbConnection db) + { + database = db; + + var table = new SqlTable("Research", + new SqlColumn("WorldId", MySqlDbType.Int32), + new SqlColumn("PlayerId", MySqlDbType.Int32), + new SqlColumn("ItemId", MySqlDbType.Int32), + new SqlColumn("AmountSacrificed", MySqlDbType.Int32), + new SqlColumn("TimeSacrificed", MySqlDbType.DateTime) + ); + var creator = new SqlTableCreator(db, + db.GetSqlType() == SqlType.Sqlite + ? (IQueryBuilder)new SqliteQueryCreator() + : new MysqlQueryCreator()); + try + { + creator.EnsureTableStructure(table); + } + catch (DllNotFoundException) + { + System.Console.WriteLine("Possible problem with your database - is Sqlite3.dll present?"); + throw new Exception("Could not find a database library (probably Sqlite3.dll)"); + } + } + + /// + /// This call will return the memory-cached list of items sacrificed. + /// If the cache is not initialized, it will be initialized from the database. + /// + /// + public Dictionary GetSacrificedItems() + { + if (_itemsSacrificed == null) + { + _itemsSacrificed = ReadFromDatabase(); + } + + return _itemsSacrificed; + } + + /// + /// This function will return a Dictionary<ItemId, AmountSacrificed> representing + /// what the progress of research on items is for this world. + /// + /// A dictionary of ItemID keys and Amount Sacrificed values. + private Dictionary ReadFromDatabase() + { + Dictionary sacrificedItems = new Dictionary(); + + var sql = @"select itemId, sum(AmountSacrificed) totalSacrificed + from Research + where WorldId = @0 + group by itemId"; + + using (var reader = database.QueryReader(sql, Main.worldID)) + { + while (reader.Read()) + { + var itemId = reader.Get("itemId"); + var amount = reader.Get("totalSacrificed"); + sacrificedItems[itemId] = amount; + } + } + + return sacrificedItems; + } + + /// + /// This method will sacrifice an amount of an item for research. + /// + /// The net ItemId that is being researched. + /// The amount of items being sacrificed. + /// The player who sacrificed the item for research. + /// The cumulative total sacrifices for this item. + public int SacrificeItem(int itemId, int amount, TSPlayer player) + { + var itemsSacrificed = GetSacrificedItems(); + if (!(itemsSacrificed.ContainsKey(itemId))) + itemsSacrificed[itemId] = 0; + + var sql = @"insert into Research (WorldId, PlayerId, ItemId, AmountSacrificed, TimeSacrificed) values (@0, @1, @2, @3, @4)"; + var result = database.Query(sql, Main.worldID, player.Account.ID, itemId, amount, DateTime.Now); + if (result == 1) + { + itemsSacrificed[itemId] += amount; + } + + return itemsSacrificed[itemId]; + } + } +} diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index d5e3b2c7..4ea4d729 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -39,6 +39,8 @@ using TShockAPI.Localization; using TShockAPI.Models; using TShockAPI.Models.PlayerUpdate; using TShockAPI.Models.Projectiles; +using Terraria.Net; +using Terraria.GameContent.NetModules; namespace TShockAPI { @@ -3238,6 +3240,20 @@ namespace TShockAPI return true; } } + } else if (moduleId == (int)NetModulesTypes.CreativeUnlocksPlayerReport) + { + var unknownField = args.Data.ReadByte(); + + if (unknownField == 0) //this is required or something??? + { + var itemId = args.Data.ReadUInt16(); + var amount = args.Data.ReadUInt16(); + + var totalSacrificed = TShock.ResearchDatastore.SacrificeItem(itemId, amount, args.Player); + + var response = NetCreativeUnlocksModule.SerializeItemSacrifice(itemId, totalSacrificed); + NetManager.Instance.Broadcast(response); + } } // As of 1.4.x.x, this is now used for more things: diff --git a/TShockAPI/PlayerData.cs b/TShockAPI/PlayerData.cs index 64a33676..6e649768 100644 --- a/TShockAPI/PlayerData.cs +++ b/TShockAPI/PlayerData.cs @@ -20,6 +20,9 @@ using Microsoft.Xna.Framework; using Terraria; using TShockAPI; using Terraria.Localization; +using Terraria.GameContent.NetModules; +using Terraria.Net; +using Terraria.ID; namespace TShockAPI { @@ -480,6 +483,20 @@ namespace TShockAPI NetMessage.SendData(76, -1, -1, NetworkText.Empty, player.Index); NetMessage.SendData(39, player.Index, -1, NetworkText.Empty, 400); + + + var sacrificedItems = TShock.ResearchDatastore.GetSacrificedItems(); + for(int i = 0; i < ItemID.Count; i++) + { + var amount = 0; + if (sacrificedItems.ContainsKey(i)) + { + amount = sacrificedItems[i]; + } + + var response = NetCreativeUnlocksModule.SerializeItemSacrifice(i, amount); + NetManager.Instance.SendToClient(response, player.TPlayer.whoAmI); + } } } } diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index c1032d43..aa1791d5 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -100,6 +100,8 @@ namespace TShockAPI public static RememberedPosManager RememberedPos; /// CharacterDB - Static reference to the SSC character manager. public static CharacterManager CharacterDB; + /// Contains the information about what research has been performed in Journey mode. + public static ResearchDatastore ResearchDatastore; /// Config - Static reference to the config system, for accessing values set in users' config files. public static ConfigFile Config { get; set; } /// ServerSideCharacterConfig - Static reference to the server side character config, for accessing values set by users to modify SSC. @@ -324,6 +326,7 @@ namespace TShockAPI TileBans = new TileManager(DB); RememberedPos = new RememberedPosManager(DB); CharacterDB = new CharacterManager(DB); + ResearchDatastore = new ResearchDatastore(DB); RestApi = new SecureRest(Netplay.ServerIP, Config.RestApiPort); RestManager = new RestManager(RestApi); RestManager.RegisterRestfulCommands(); diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index 02b9e43e..c941ea0a 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -85,6 +85,7 @@ + @@ -220,4 +221,4 @@ --> - \ No newline at end of file + From 96ad7a5dd89c8d82ebb2ddbd8bbe4b72d620ca6e Mon Sep 17 00:00:00 2001 From: Olink Date: Mon, 25 May 2020 02:26:58 -0400 Subject: [PATCH 32/35] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4d6864e..783a1b99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ This is the rolling changelog for TShock for Terraria. Use past tense when adding new entries; sign your name off when you add or change something. This should primarily be things like user changes, not necessarily codebase changes unless it's really relevant or large. +## Upcoming Release +* Initial support for Journey mode in SSC worlds. (@Olink) + ## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) * Fixed /wind command. (@AxeelAnder) From 91998deaf3fb89b43d341927641c378359d81755 Mon Sep 17 00:00:00 2001 From: Olink Date: Mon, 25 May 2020 03:03:29 -0400 Subject: [PATCH 33/35] Add spawn boss packet handlers for pets. --- CHANGELOG.md | 3 +++ TShockAPI/GetDataHandlers.cs | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4d6864e..7313922c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ This is the rolling changelog for TShock for Terraria. Use past tense when adding new entries; sign your name off when you add or change something. This should primarily be things like user changes, not necessarily codebase changes unless it's really relevant or large. +## Upcoming Release +* Fix pet licenses. (@Olink) + ## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) * Fixed /wind command. (@AxeelAnder) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index d5e3b2c7..93da1ccb 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2853,6 +2853,15 @@ namespace TShockAPI string thing; switch (thingType) { + case -14: + thing = "has sent a request to the bunny delivery service"; + break; + case -13: + thing = "has sent a request to the dog delivery service"; + break; + case -12: + thing = "has sent a request to the cat delivery service"; + break; case -11: thing = "applied advanced combat techniques"; break; From df22a331323773d2db0eaec448037909a6837f23 Mon Sep 17 00:00:00 2001 From: Olink Date: Mon, 25 May 2020 03:07:54 -0400 Subject: [PATCH 34/35] Add some try/catch blocks around the sql commands. --- TShockAPI/DB/ResearchDatastore.cs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/TShockAPI/DB/ResearchDatastore.cs b/TShockAPI/DB/ResearchDatastore.cs index d4fa2197..b861aedd 100644 --- a/TShockAPI/DB/ResearchDatastore.cs +++ b/TShockAPI/DB/ResearchDatastore.cs @@ -84,16 +84,21 @@ namespace TShockAPI.DB where WorldId = @0 group by itemId"; - using (var reader = database.QueryReader(sql, Main.worldID)) - { - while (reader.Read()) + try { + using (var reader = database.QueryReader(sql, Main.worldID)) { - var itemId = reader.Get("itemId"); - var amount = reader.Get("totalSacrificed"); - sacrificedItems[itemId] = amount; + while (reader.Read()) + { + var itemId = reader.Get("itemId"); + var amount = reader.Get("totalSacrificed"); + sacrificedItems[itemId] = amount; + } } } - + catch (Exception ex) + { + TShock.Log.Error(ex.ToString()); + } return sacrificedItems; } @@ -111,7 +116,17 @@ namespace TShockAPI.DB itemsSacrificed[itemId] = 0; var sql = @"insert into Research (WorldId, PlayerId, ItemId, AmountSacrificed, TimeSacrificed) values (@0, @1, @2, @3, @4)"; - var result = database.Query(sql, Main.worldID, player.Account.ID, itemId, amount, DateTime.Now); + + var result = 0; + try + { + result = database.Query(sql, Main.worldID, player.Account.ID, itemId, amount, DateTime.Now); + } + catch (Exception ex) + { + TShock.Log.Error(ex.ToString()); + } + if (result == 1) { itemsSacrificed[itemId] += amount; From 2b4faf4d9b0d87b8a5927d7cc15b39d304c79ee0 Mon Sep 17 00:00:00 2001 From: Zack Date: Mon, 25 May 2020 03:11:41 -0400 Subject: [PATCH 35/35] Update TShockAPI/DB/ResearchDatastore.cs @hakusaro raised a solid point in Discord. Co-authored-by: Lucas Nicodemus --- TShockAPI/DB/ResearchDatastore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/DB/ResearchDatastore.cs b/TShockAPI/DB/ResearchDatastore.cs index b861aedd..cb7d933c 100644 --- a/TShockAPI/DB/ResearchDatastore.cs +++ b/TShockAPI/DB/ResearchDatastore.cs @@ -50,7 +50,7 @@ namespace TShockAPI.DB } catch (DllNotFoundException) { - System.Console.WriteLine("Possible problem with your database - is Sqlite3.dll present?"); + Console.WriteLine("Possible problem with your database - is Sqlite3.dll present?"); throw new Exception("Could not find a database library (probably Sqlite3.dll)"); } }