From e1da5aa7bcd1e7c167f43a0e7415cec8558a3221 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Wed, 20 May 2020 20:25:41 +0200 Subject: [PATCH 01/64] Missing backtick from RegionManager Group table. Group is a reserved keyword in MySQL 8. Requires backtick. Missed this from previous commit. Version 8 would error on table creation. --- TShockAPI/DB/RegionManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/DB/RegionManager.cs b/TShockAPI/DB/RegionManager.cs index eaf8f1ba..ee62b8d3 100644 --- a/TShockAPI/DB/RegionManager.cs +++ b/TShockAPI/DB/RegionManager.cs @@ -51,7 +51,7 @@ namespace TShockAPI.DB new SqlColumn("WorldID", MySqlDbType.VarChar, 50) { Unique = true }, new SqlColumn("UserIds", MySqlDbType.Text), new SqlColumn("Protected", MySqlDbType.Int32), - new SqlColumn("Groups", MySqlDbType.Text), + new SqlColumn("`Groups`", MySqlDbType.Text), new SqlColumn("Owner", MySqlDbType.VarChar, 50), new SqlColumn("Z", MySqlDbType.Int32){ DefaultValue = "0" } ); From a8366c6fbaf5cdf96230b9d8bc5a582be0869484 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Wed, 20 May 2020 20:28:56 +0200 Subject: [PATCH 02/64] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0563d49..8d890326 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming changes * Update player spawn related things to 1.4. `Terraria.Player.Spawn` method now has a required argument, `PlayerSpawnContext context`. (@AxeelAnder) * Make sqlite db path configurable. (@AxeelAnder) +* Make TShock database MySQL 8 compatible by backticking `Group` column name in Region table. ## TShock 4.4.0 (Pre-release 4) * Debug logging now provides ConsoleDebug and ILog has been updated to support the concept of debug logs. Debug logs are now controlled by `config.json` instead of by preprocessor debug flag. (@hakusaro) From 5706eaf1385a3b0d7c8ce10b3b196c37c9159feb Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Sun, 24 May 2020 02:02:50 +0200 Subject: [PATCH 03/64] Fix SQL incompatibility. This is the real fix for MySql8 compatibility, without breaking SQL. This will not affect current databases, all that happens is that we actually escape all column names on the table creation query. This should be standarized along the whole query builder. --- TShockAPI/DB/IQueryBuilder.cs | 8 ++++---- TShockAPI/DB/RegionManager.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/TShockAPI/DB/IQueryBuilder.cs b/TShockAPI/DB/IQueryBuilder.cs index 825a2e4a..19af36a9 100644 --- a/TShockAPI/DB/IQueryBuilder.cs +++ b/TShockAPI/DB/IQueryBuilder.cs @@ -192,12 +192,12 @@ namespace TShockAPI.DB var columns = table.Columns.Select( c => - "{0} {1} {2} {3} {4} {5}".SFormat(c.Name, DbTypeToString(c.Type, c.Length), + "`{0}` {1} {2} {3} {4} {5}".SFormat(c.Name, DbTypeToString(c.Type, c.Length), c.Primary ? "PRIMARY KEY" : "", c.AutoIncrement ? "AUTO_INCREMENT" : "", c.NotNull ? "NOT NULL" : "", c.DefaultCurrentTimestamp ? "DEFAULT CURRENT_TIMESTAMP" : "")); - var uniques = table.Columns.Where(c => c.Unique).Select(c => c.Name); + var uniques = table.Columns.Where(c => c.Unique).Select(c => $"`{c.Name}`"); return "CREATE TABLE {0} ({1} {2})".SFormat(EscapeTableName(table.Name), string.Join(", ", columns), uniques.Count() > 0 ? ", UNIQUE({0})".SFormat(string.Join(", ", uniques)) @@ -299,7 +299,7 @@ namespace TShockAPI.DB var create = CreateTable(to); // combine all columns in the 'from' variable excluding ones that aren't in the 'to' variable. // exclude the ones that aren't in 'to' variable because if the column is deleted, why try to import the data? - var columns = string.Join(", ", from.Columns.Where(c => to.Columns.Any(c2 => c2.Name == c.Name)).Select(c => c.Name)); + var columns = string.Join(", ", from.Columns.Where(c => to.Columns.Any(c2 => c2.Name == c.Name)).Select(c => $"`{c.Name}`")); var insert = "INSERT INTO {0} ({1}) SELECT {1} FROM {2}".SFormat(escapedTable, columns, tmpTable); var drop = "DROP TABLE {0}".SFormat(tmpTable); return "{0}; {1}; {2}; {3};".SFormat(alter, create, insert, drop); @@ -396,7 +396,7 @@ namespace TShockAPI.DB if (0 == wheres.Count) return string.Empty; - return "WHERE {0}".SFormat(string.Join(", ", wheres.Select(v => v.Name + " = " + v.Value))); + return "WHERE {0}".SFormat(string.Join(", ", wheres.Select(v => $"{v.Name}" + " = " + v.Value))); } } } diff --git a/TShockAPI/DB/RegionManager.cs b/TShockAPI/DB/RegionManager.cs index ee62b8d3..eaf8f1ba 100644 --- a/TShockAPI/DB/RegionManager.cs +++ b/TShockAPI/DB/RegionManager.cs @@ -51,7 +51,7 @@ namespace TShockAPI.DB new SqlColumn("WorldID", MySqlDbType.VarChar, 50) { Unique = true }, new SqlColumn("UserIds", MySqlDbType.Text), new SqlColumn("Protected", MySqlDbType.Int32), - new SqlColumn("`Groups`", MySqlDbType.Text), + new SqlColumn("Groups", MySqlDbType.Text), new SqlColumn("Owner", MySqlDbType.VarChar, 50), new SqlColumn("Z", MySqlDbType.Int32){ DefaultValue = "0" } ); From 3e8a2cfb411a0888d9a3fba8adff1e2c52f5d508 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Sun, 24 May 2020 02:04:54 +0200 Subject: [PATCH 04/64] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d890326..62a10221 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming changes * Update player spawn related things to 1.4. `Terraria.Player.Spawn` method now has a required argument, `PlayerSpawnContext context`. (@AxeelAnder) * Make sqlite db path configurable. (@AxeelAnder) -* Make TShock database MySQL 8 compatible by backticking `Group` column name in Region table. +* Make TShock database MySQL 8 compatible by escaping column names in our IQueryBuilder code. (Name `Groups` is a reserved element in this version, which is used in our `Region` table.) ## TShock 4.4.0 (Pre-release 4) * Debug logging now provides ConsoleDebug and ILog has been updated to support the concept of debug logs. Debug logs are now controlled by `config.json` instead of by preprocessor debug flag. (@hakusaro) From 37e65b64dc5038006b4fa86e32815c5959095336 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 May 2020 23:47:50 -0700 Subject: [PATCH 05/64] 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 06/64] 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 07/64] 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 08/64] 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 09/64] 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 10/64] 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 11/64] 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 12/64] 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 13/64] 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 14/64] 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 15/64] 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 16/64] 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 17/64] 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 18/64] 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 19/64] 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 20/64] 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 21/64] 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 22/64] 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 23/64] 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 24/64] 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 25/64] 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 26/64] 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 27/64] 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 28/64] 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 29/64] 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 30/64] 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 31/64] 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 32/64] 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 33/64] 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 34/64] 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 35/64] 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 36/64] 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)"); } } From 7b8bbd1e1696e4ebbae707d41d569cb96dcc88bd Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 25 May 2020 00:48:57 -0700 Subject: [PATCH 37/64] Fix typos in journey permission checks --- TShockAPI/GetDataHandlers.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 3eee034f..0dbb3547 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3221,7 +3221,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_setdifficulty)) { - args.Player.SendErrorMessage("You don't have permission to modify the world dificulty of the server!"); + args.Player.SendErrorMessage("You don't have permission to modify the world difficulty of the server!"); return true; } break; @@ -3230,7 +3230,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_biomespreadfreeze)) { - args.Player.SendErrorMessage("You don't have permission to freeze the biome spread of server!"); + args.Player.SendErrorMessage("You don't have permission to freeze the biome spread of the server!"); return true; } break; @@ -3239,7 +3239,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_setspawnrate)) { - args.Player.SendErrorMessage("You don't have permission to modify the NPC spawn rate of server!"); + args.Player.SendErrorMessage("You don't have permission to modify the NPC spawn rate of the server!"); return true; } break; From fb418095fe01b644450abc7f0559465e45cb41eb Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 25 May 2020 00:49:57 -0700 Subject: [PATCH 38/64] Fix changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0f1e421..b7bd0a64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming Release * Fix pet licenses. (@Olink) * Initial support for Journey mode in SSC worlds. (@Olink) - +* Make TShock database MySQL 8 compatible by escaping column names in our IQueryBuilder code. (Name `Groups` is a reserved element in this version, which is used in our `Region` table.) (@Patrikkk) + ## 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) @@ -49,7 +50,6 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## TShock 4.4.0 (Pre-release 5) * Update player spawn related things to 1.4. `Terraria.Player.Spawn` method now has a required argument, `PlayerSpawnContext context`. (@AxeelAnder) * Make sqlite db path configurable. (@AxeelAnder) -* Make TShock database MySQL 8 compatible by escaping column names in our IQueryBuilder code. (Name `Groups` is a reserved element in this version, which is used in our `Region` table.) * Terraria 1.4.0.3 experimental support. (@Patrikkk) * Updated changelog. (@hakusaro) From d1b27d8b7aa17cc33ab6a9e0e794878c43f5ba76 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 25 May 2020 01:01:47 -0700 Subject: [PATCH 39/64] Only process journey research updates for SSC mode This commit changes the logic for sending and accepting journey research requests -- only processing those requests in SSC makes sense. This stops sending extra data to clients that may not know what to do with it when it's not relevant (not in both SSC and journey mode). This also stops us from accepting erroneous journey mode NPC spawn rate update requests when journey mode isn't on but SSC is on due to a weird client glitch in 1.4.0.4. --- TShockAPI/GetDataHandlers.cs | 8 +++++++- TShockAPI/PlayerData.cs | 20 +++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 0dbb3547..e7fa1874 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3237,6 +3237,12 @@ namespace TShockAPI } case CreativePowerTypes.SetSpawnRate: { + // This is a monkeypatch because the 1.4.0.4 seemingly at random sends NPC spawn rate changes even outside of journey mode + // (with SSC on) -- particles, May 25, 2 Reiwa + if (!Main.GameModeInfo.IsJourneyMode) + { + return true; + } if (!args.Player.HasPermission(Permissions.journey_setspawnrate)) { args.Player.SendErrorMessage("You don't have permission to modify the NPC spawn rate of the server!"); @@ -3249,7 +3255,7 @@ namespace TShockAPI return true; } } - } else if (moduleId == (int)NetModulesTypes.CreativeUnlocksPlayerReport) + } else if (moduleId == (int)NetModulesTypes.CreativeUnlocksPlayerReport && Main.GameModeInfo.IsJourneyMode) { var unknownField = args.Data.ReadByte(); diff --git a/TShockAPI/PlayerData.cs b/TShockAPI/PlayerData.cs index 6e649768..562dea80 100644 --- a/TShockAPI/PlayerData.cs +++ b/TShockAPI/PlayerData.cs @@ -484,18 +484,20 @@ namespace TShockAPI NetMessage.SendData(39, player.Index, -1, NetworkText.Empty, 400); - - var sacrificedItems = TShock.ResearchDatastore.GetSacrificedItems(); - for(int i = 0; i < ItemID.Count; i++) + if (Main.GameModeInfo.IsJourneyMode) { - var amount = 0; - if (sacrificedItems.ContainsKey(i)) + var sacrificedItems = TShock.ResearchDatastore.GetSacrificedItems(); + for(int i = 0; i < ItemID.Count; i++) { - amount = sacrificedItems[i]; - } + var amount = 0; + if (sacrificedItems.ContainsKey(i)) + { + amount = sacrificedItems[i]; + } - var response = NetCreativeUnlocksModule.SerializeItemSacrifice(i, amount); - NetManager.Instance.SendToClient(response, player.TPlayer.whoAmI); + var response = NetCreativeUnlocksModule.SerializeItemSacrifice(i, amount); + NetManager.Instance.SendToClient(response, player.TPlayer.whoAmI); + } } } } From 3874c04a72b15717fd8681b95d354adfe5be91a3 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 25 May 2020 11:55:54 -0700 Subject: [PATCH 40/64] Replace -worldpath with -worldselectpath This reverts commit 7ad46abced17113ca4338598c73c172828e43355. This reintroduces the worldpath argument as per request from #1914, but at a different name. This is because users have configurations like this, which no longer work: -world + -worldpath = crash If you want to use -worldselectionpath to specify a world, you should be able to use -worldname, but don't use -world unless you specify an absolute path to a world. No matter how we solve this we get a support headache (-worldpath + -world = crash). This temporary stopgap should work to help address issue #1914 until we can figure out a final solution. Since users are impacted by this change, temporarily adding this back is the best move. To be 100% clear, though: -world + -worldselectpath without specifying an absolute path will result in a crash that is unhelpful. Please don't do that. --- TShockAPI/TShock.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index aa1791d5..0d19a6fb 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -689,6 +689,16 @@ namespace TShockAPI } }) + .AddFlag("-worldselectpath", pathChecker) + .After(() => + { + if (path != null) + { + Main.WorldPath = path; + ServerApi.LogWriter.PluginWriteLine(this, "World path has been set to " + path, TraceLevel.Info); + } + }) + .AddFlag("-logpath", pathChecker) .After(() => { From 5a4526b10afae0b01b95efa4204239f04900cb3d Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 25 May 2020 12:22:58 -0700 Subject: [PATCH 41/64] Update changelog with worldpath changes --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7bd0a64..4b0eb992 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fix pet licenses. (@Olink) * Initial support for Journey mode in SSC worlds. (@Olink) * Make TShock database MySQL 8 compatible by escaping column names in our IQueryBuilder code. (Name `Groups` is a reserved element in this version, which is used in our `Region` table.) (@Patrikkk) +* Reintroduce `-worldselectpath` per feedback from @fjfnaranjo. This command line argument should be used to specify the place where the interactive server startup will look for worlds to show on the world select screen. The original version of this argument, `-worldpath`, was removed because several game service providers have broken configurations that stop the server from running with an unhelpful error. This specific configuration was `-world` and `-worldpath`. In the new world, you can do the following: + * `-worldselectpath` should be used if you want to customize the server interactive boot world list (so that you can select from a number of worlds in non-standard locations). + * `-world` will behave as an absolute path to the world to load. This is the most common thing you want if you're starting the server and have a specific world in mind. + * `-worldselectpath` and `-worldname` should work together enabling you to select from a world from the list that you specify. This is *not* a world file name, but a world name as described by Terraria. + * `-worldselectpath` is identical to the old `-worldpath`. If you specify `-worldselectpath` and `-world` without specifying an absolute path the server will crash for sure. + * Thank you again to @fjfnaranjo for supplying a [detailed feature request](https://github.com/Pryaxis/TShock/issues/1914) explaining precisely why this option should be available. Without this, we would have had no context as to why this feature was useful or important. Thank you, @fjfnaranjo! + * This change was implemented by (@QuiCM, @hakusaro). ## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) From 0d2b59176047bc6777241c7a44b29adfe7b4d6e6 Mon Sep 17 00:00:00 2001 From: moisterrific <57187883+moisterrific@users.noreply.github.com> Date: Tue, 26 May 2020 13:45:31 -0400 Subject: [PATCH 42/64] Update NPCAddBuff to include Sparkle Slime debuff It's a new cosmetic debuff added in 1.4, like Wet and Slimed that can be applied to Town NPCs. Wiki: https://terraria.gamepedia.com/Sparkle_Slime_Balloon --- TShockAPI/Bouncer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index ad6e516a..b58681a4 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -1537,7 +1537,7 @@ namespace TShockAPI if (npc.townNPC && npc.netID != NPCID.Guide && npc.netID != NPCID.Clothier) { if (type != BuffID.Lovestruck && type != BuffID.Stinky && type != BuffID.DryadsWard && - type != BuffID.Wet && type != BuffID.Slimed) + type != BuffID.Wet && type != BuffID.Slimed && type != BuffID.GelBalloonBuff) { detectedNPCBuffTimeCheat = true; } From 1f045c9a92373aa2195358c6c1d06d6a7c5623a2 Mon Sep 17 00:00:00 2001 From: moisterrific <57187883+moisterrific@users.noreply.github.com> Date: Tue, 26 May 2020 15:53:58 -0400 Subject: [PATCH 43/64] Update /spawnboss to include the 2 new bosses Added Empress of Light and Queen Slime to the list of bosses that can be spawned individually and "all". Also removed the queen case because there are two bosses with queen in their name now. --- TShockAPI/Commands.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 8d131588..8b5db356 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -2378,7 +2378,7 @@ namespace TShockAPI { case "*": case "all": - int[] npcIds = { 4, 13, 35, 50, 125, 126, 127, 134, 222, 245, 262, 266, 370, 398 }; + int[] npcIds = { 4, 13, 35, 50, 125, 126, 127, 134, 222, 245, 262, 266, 370, 398, 636, 657 }; TSPlayer.Server.SetTime(false, 0.0); foreach (int i in npcIds) { @@ -2442,7 +2442,6 @@ namespace TShockAPI TSPlayer.Server.SpawnNPC(npc.type, npc.FullName, amount, args.Player.TileX, args.Player.TileY); TSPlayer.All.SendSuccessMessage("{0} has spawned Skeletron Prime {1} time(s).", args.Player.Name, amount); return; - case "queen": case "queen bee": npc.SetDefaults(222); TSPlayer.Server.SpawnNPC(npc.type, npc.FullName, amount, args.Player.TileX, args.Player.TileY); @@ -2483,6 +2482,17 @@ namespace TShockAPI TSPlayer.Server.SpawnNPC(npc.type, npc.FullName, amount, args.Player.TileX, args.Player.TileY); TSPlayer.All.SendSuccessMessage("{0} has spawned the Moon Lord {1} time(s).", args.Player.Name, amount); return; + case "empress": + case "empress of light": + npc.SetDefaults(636); + TSPlayer.Server.SpawnNPC(npc.type, npc.FullName, amount, args.Player.TileX, args.Player.TileY); + TSPlayer.All.SendSuccessMessage("{0} has spawned the Empress of Light {1} time(s).", args.Player.Name, amount); + return; + case "queen slime": + npc.SetDefaults(657); + TSPlayer.Server.SpawnNPC(npc.type, npc.FullName, amount, args.Player.TileX, args.Player.TileY); + TSPlayer.All.SendSuccessMessage("{0} has spawned the Queen Slime {1} time(s).", args.Player.Name, amount); + return; default: args.Player.SendErrorMessage("Invalid boss type!"); return; From 2c384aaaeb70f6b284676ae8890e864763ef1045 Mon Sep 17 00:00:00 2001 From: moisterrific <57187883+moisterrific@users.noreply.github.com> Date: Tue, 26 May 2020 17:17:01 -0400 Subject: [PATCH 44/64] Add journey permissions to trustedadmin and owner hope im doing this right lol --- TShockAPI/DB/GroupManager.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/TShockAPI/DB/GroupManager.cs b/TShockAPI/DB/GroupManager.cs index 6405b5bc..b843f119 100644 --- a/TShockAPI/DB/GroupManager.cs +++ b/TShockAPI/DB/GroupManager.cs @@ -172,7 +172,19 @@ namespace TShockAPI.DB Permissions.settempgroup, Permissions.spawnrate, Permissions.tpoverride, - Permissions.createdumps)); + Permissions.createdumps, + Permissions.journey_timefreeze, + Permissions.journey_timeset, + Permissions.journey_timespeed, + Permissions.journey_godmode, + Permissions.journey_windstrength, + Permissions.journey_windfreeze, + Permissions.journey_rainstrength, + Permissions.journey_rainfreeze, + Permissions.journey_placementrange, + Permissions.journey_setdifficulty, + Permissions.journey_biomespreadfreeze, + Permissions.journey_setdawn)); } // Load Permissions from the DB From 51d2d9af6907ec3a357faac28298a2faeb696959 Mon Sep 17 00:00:00 2001 From: moisterrific <57187883+moisterrific@users.noreply.github.com> Date: Tue, 26 May 2020 18:51:15 -0400 Subject: [PATCH 45/64] Fix error in previous change there's no setdawn, made the mistake of looking at a prev commit instead of the most current version of permissions --- TShockAPI/DB/GroupManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/DB/GroupManager.cs b/TShockAPI/DB/GroupManager.cs index b843f119..8c9515a6 100644 --- a/TShockAPI/DB/GroupManager.cs +++ b/TShockAPI/DB/GroupManager.cs @@ -184,7 +184,7 @@ namespace TShockAPI.DB Permissions.journey_placementrange, Permissions.journey_setdifficulty, Permissions.journey_biomespreadfreeze, - Permissions.journey_setdawn)); + Permissions.journey_setspawnrate)); } // Load Permissions from the DB From 54aa2dc070490c28390819866fca7f84b720af73 Mon Sep 17 00:00:00 2001 From: moisterrific <57187883+moisterrific@users.noreply.github.com> Date: Tue, 26 May 2020 19:00:24 -0400 Subject: [PATCH 46/64] updated the changelog with my stuff --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b0eb992..697b8d89 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 * `-worldselectpath` is identical to the old `-worldpath`. If you specify `-worldselectpath` and `-world` without specifying an absolute path the server will crash for sure. * Thank you again to @fjfnaranjo for supplying a [detailed feature request](https://github.com/Pryaxis/TShock/issues/1914) explaining precisely why this option should be available. Without this, we would have had no context as to why this feature was useful or important. Thank you, @fjfnaranjo! * This change was implemented by (@QuiCM, @hakusaro). +* Updated Bouncer to include Sparkle Slime debuff that can be applied to town NPCs. +* Updated /spawnboss command to include Empress of Light and Queen Slime. +* Added journey mode permissions to owner group by default. ## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) From 720feed7af46f12c4d23adda822621ec71e9057e Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Tue, 26 May 2020 22:22:41 -0700 Subject: [PATCH 47/64] Fix journey mode / kick on death conflict This fixes an issue where kick/ban on hardcore/mediumcore death penalties applied to journey mode characters unintentionally. Fixes #1901. --- CHANGELOG.md | 1 + TShockAPI/GetDataHandlers.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b0eb992..7c321eac 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 * `-worldselectpath` is identical to the old `-worldpath`. If you specify `-worldselectpath` and `-world` without specifying an absolute path the server will crash for sure. * Thank you again to @fjfnaranjo for supplying a [detailed feature request](https://github.com/Pryaxis/TShock/issues/1914) explaining precisely why this option should be available. Without this, we would have had no context as to why this feature was useful or important. Thank you, @fjfnaranjo! * This change was implemented by (@QuiCM, @hakusaro). +* Fix kick on hardcore death / kick on mediumcore death / ban on either from taking action against journey mode players. (@hakusaro) ## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index e7fa1874..09667f33 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3524,7 +3524,7 @@ namespace TShockAPI } // Handle kicks/bans on mediumcore/hardcore deaths. - if (args.TPlayer.difficulty != 0) // Player is not softcore + if (args.TPlayer.difficulty == 1 || args.TPlayer.difficulty == 2) // Player is not softcore { bool mediumcore = args.TPlayer.difficulty == 1; bool shouldBan = mediumcore ? TShock.Config.BanOnMediumcoreDeath : TShock.Config.BanOnHardcoreDeath; From 7ee9541ea115ef3c735bda655e3ad91cf10bdcdf Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Wed, 27 May 2020 01:41:52 -0700 Subject: [PATCH 48/64] Add devs who've enabled github sponsors to funding --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 32f48df7..4c84987b 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,3 @@ # These are supported funding model platforms - +github: [QuiCM, hakusaro] custom: https://www.givedirectly.org/ From 073088156cb28b0d30e1cd6badae9103849ff285 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Wed, 27 May 2020 01:51:12 -0700 Subject: [PATCH 49/64] Undo the last change related to funding file :S --- .github/FUNDING.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 4c84987b..b8e325e5 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,2 @@ # These are supported funding model platforms -github: [QuiCM, hakusaro] custom: https://www.givedirectly.org/ From 814801d894e83f03b98bbdf1db2d61bcbfc12849 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Wed, 27 May 2020 20:21:29 -0700 Subject: [PATCH 50/64] Experimentally change spawn rules for #1849 This change applies @AxeelAnder's suggeted patch from #1845 to attempt to resolve spawn point issues. If you remove your bed spawn point it should send you back to the map spawn point with this. --- CHANGELOG.md | 3 ++- TShockAPI/GetDataHandlers.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c321eac..bbae6522 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * `-worldselectpath` is identical to the old `-worldpath`. If you specify `-worldselectpath` and `-world` without specifying an absolute path the server will crash for sure. * Thank you again to @fjfnaranjo for supplying a [detailed feature request](https://github.com/Pryaxis/TShock/issues/1914) explaining precisely why this option should be available. Without this, we would have had no context as to why this feature was useful or important. Thank you, @fjfnaranjo! * This change was implemented by (@QuiCM, @hakusaro). -* Fix kick on hardcore death / kick on mediumcore death / ban on either from taking action against journey mode players. (@hakusaro) +* Fixed kick on hardcore death / kick on mediumcore death / ban on either from taking action against journey mode players. (@hakusaro) +* Attempted to fix the problem with the magic mirror spawn problems. You should be able to remove your spawn point in SSC by right clicking on a bed now. (@hakusaro, @AxeelAnder) ## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 09667f33..1f90f29e 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2118,7 +2118,7 @@ namespace TShockAPI TShock.Log.ConsoleDebug("GetDataHandlers / HandleSpawn force teleport 'vanilla spawn' {0}", args.Player.Name); } - if ((Main.ServerSideCharacter) && (args.Player.sX > 0) && (args.Player.sY > 0) && (args.TPlayer.SpawnX > 0) && ((args.TPlayer.SpawnX != args.Player.sX) && (args.TPlayer.SpawnY != args.Player.sY))) + else if ((Main.ServerSideCharacter) && (args.Player.sX > 0) && (args.Player.sY > 0) && (args.TPlayer.SpawnX > 0) && ((args.TPlayer.SpawnX != args.Player.sX) && (args.TPlayer.SpawnY != args.Player.sY))) { args.Player.sX = args.TPlayer.SpawnX; From 0fa8ae13d79ec4acdce9d3943ebb3d02573dea4b Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Thu, 28 May 2020 19:24:28 +0200 Subject: [PATCH 51/64] Implement FoodPlatter placing event. This is called when a player is placing a fruit (item) in a plate. Adding checks to see if they have permission to place or replace a fruit in the item. Checks if they are within range. And a check to see if they are legitimately placing the item from their hand, and not by sending a raw packet. --- TShockAPI/Bouncer.cs | 49 +++++++++++++++++++++++++++++ TShockAPI/GetDataHandlers.cs | 61 +++++++++++++++++++++++++++++++++++- TShockAPI/TShockAPI.csproj | 4 +-- 3 files changed, 111 insertions(+), 3 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index ad6e516a..abd5fe05 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -67,6 +67,7 @@ namespace TShockAPI GetDataHandlers.MassWireOperation += OnMassWireOperation; GetDataHandlers.PlayerDamage += OnPlayerDamage; GetDataHandlers.KillMe += OnKillMe; + GetDataHandlers.FoodPlatterTryPlacing += OnFoodPlatterTryPlacing; } internal void OnGetSection(object sender, GetDataHandlers.GetSectionEventArgs args) @@ -2062,6 +2063,54 @@ namespace TShockAPI } } + /// + /// Called when a player is trying to place an item into a food plate. + /// + /// + /// + internal void OnFoodPlatterTryPlacing(object sender, GetDataHandlers.FoodPlatterTryPlacingEventArgs args) + { + if (args.Player.ItemInHand.type != args.ItemID) + { + TShock.Log.ConsoleDebug("Bouncer / OnFoodPlatterTryPlacing rejected item not placed by hand from {0}", args.Player.Name); + args.Player.SendTileSquare(args.TileX, args.TileY, 1); + args.Handled = true; + return; + } + if (args.Player.IsBeingDisabled()) + { + TShock.Log.ConsoleDebug("Bouncer / OnFoodPlatterTryPlacing rejected disabled from {0}", args.Player.Name); + Item item = new Item(); + item.netDefaults(args.ItemID); + args.Player.GiveItemCheck(args.ItemID, item.Name, args.Stack, args.Prefix); + args.Player.SendTileSquare(args.TileX, args.TileY, 1); + args.Handled = true; + return; + } + + if (!args.Player.HasBuildPermission(args.TileX, args.TileY)) + { + TShock.Log.ConsoleDebug("Bouncer / OnFoodPlatterTryPlacing rejected permissions from {0}", args.Player.Name); + Item item = new Item(); + item.netDefaults(args.ItemID); + args.Player.GiveItemCheck(args.ItemID, item.Name, args.Stack, args.Prefix); + args.Player.SendTileSquare(args.TileX, args.TileY, 1); + args.Handled = true; + return; + } + + if (!args.Player.IsInRange(args.TileX, args.TileY)) + { + TShock.Log.ConsoleDebug("Bouncer / OnFoodPlatterTryPlacing rejected range checks from {0}", args.Player.Name); + Item item = new Item(); + item.netDefaults(args.ItemID); + args.Player.GiveItemCheck(args.ItemID, item.Name, args.Stack, args.Prefix); + args.Player.SendTileSquare(args.TileX, args.TileY, 1); + args.Handled = true; + return; + } + } + internal void OnSecondUpdate() { Task.Run(() => diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 1f90f29e..74dbff85 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -150,7 +150,8 @@ namespace TShockAPI { PacketTypes.ToggleParty, HandleToggleParty }, { PacketTypes.CrystalInvasionStart, HandleOldOnesArmy }, { PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 }, - { PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 } + { PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 }, + { PacketTypes.FoodPlatterTryPlacing, HandleFoodPlatterTryPlacing } }; } @@ -1863,6 +1864,52 @@ namespace TShockAPI return args.Handled; } + public class FoodPlatterTryPlacingEventArgs : GetDataHandledEventArgs + { + /// + /// The X tile position of the placement action. + /// + public short TileX { get; set; } + /// + /// The Y tile position of the placement action. + /// + public short TileY { get; set; } + /// + /// The Item ID that is being placed in the plate. + /// + public short ItemID { get; set; } + /// + /// The prefix of the item that is being placed in the plate. + /// + public byte Prefix { get; set; } + /// + /// The stack of the item that is being placed in the plate. + /// + public short Stack { get; set; } + } + /// + /// Called when a player is placing an item in a food plate. + /// + public static HandlerList FoodPlatterTryPlacing = new HandlerList(); + private static bool OnFoodPlatterTryPlacing(TSPlayer player, MemoryStream data, short tileX, short tileY, short itemID, byte prefix, short stack) + { + if (FoodPlatterTryPlacing == null) + return false; + + var args = new FoodPlatterTryPlacingEventArgs + { + Player = player, + Data = data, + TileX = tileX, + TileY = tileY, + ItemID = itemID, + Prefix = prefix, + Stack = stack, + }; + FoodPlatterTryPlacing.Invoke(null, args); + return args.Handled; + } + #endregion private static bool HandlePlayerInfo(GetDataHandlerArgs args) @@ -3559,7 +3606,19 @@ namespace TShockAPI return false; } + private static bool HandleFoodPlatterTryPlacing(GetDataHandlerArgs args) + { + short tileX = args.Data.ReadInt16(); + short tileY = args.Data.ReadInt16(); + short itemID = args.Data.ReadInt16(); + byte prefix = args.Data.ReadInt8(); + short stack = args.Data.ReadInt16(); + if (OnFoodPlatterTryPlacing(args.Player, args.Data, tileX, tileY, itemID, prefix, stack)) + return true; + + return false; + } public enum EditAction { diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index c941ea0a..ab982025 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -31,7 +31,7 @@ true full false - bin\Debug\ + ..\..\..\Debug\ServerPlugins\ DEBUG;TRACE prompt 4 @@ -221,4 +221,4 @@ --> - + \ No newline at end of file From 3c0a990de650c9e8d56643d325c13a440b808d58 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Thu, 28 May 2020 20:47:21 +0200 Subject: [PATCH 52/64] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbae6522..94b9e1ba 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 * This change was implemented by (@QuiCM, @hakusaro). * Fixed kick on hardcore death / kick on mediumcore death / ban on either from taking action against journey mode players. (@hakusaro) * Attempted to fix the problem with the magic mirror spawn problems. You should be able to remove your spawn point in SSC by right clicking on a bed now. (@hakusaro, @AxeelAnder) +* Add HandleFoodPlatterTryPlacing event, which is called whenever a player places a food in a plate. Add antihack to bouncer, to prevent removing food from plates if the region is protected; To prevent placement if they are not in range; To prevent placement if the item is not placed from player hand. (@Patrikkk) ## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) From a4075fd590cc07fa3f7e171591f48a6dcdd11a90 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Fri, 29 May 2020 00:10:57 +0200 Subject: [PATCH 53/64] Revert TShockAPI.csproj to original. --- TShockAPI/TShockAPI.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index ab982025..f6a2d81c 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -31,7 +31,7 @@ true full false - ..\..\..\Debug\ServerPlugins\ + bin\Debug\ DEBUG;TRACE prompt 4 From 6e4b6e1f5ef4e278bfbb5cd08be8a1ad91204dfe Mon Sep 17 00:00:00 2001 From: Chris <2648373+QuiCM@users.noreply.github.com> Date: Fri, 29 May 2020 13:58:44 +0930 Subject: [PATCH 54/64] Fix paint permission check --- TShockAPI/TSPlayer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 3d7deaae..1a204594 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -685,7 +685,7 @@ namespace TShockAPI /// True if they can paint. public bool HasPaintPermission(int x, int y) { - return HasBuildPermission(x, y) || HasPermission(Permissions.canpaint); + return HasBuildPermission(x, y) && HasPermission(Permissions.canpaint); } /// Checks if a player can place ice, and if they can, tracks ice placements and removals. From ecb1a8a4e724fbd305af6d09de8550b8d72d94c0 Mon Sep 17 00:00:00 2001 From: Chris <2648373+QuiCM@users.noreply.github.com> Date: Fri, 29 May 2020 17:14:56 +0930 Subject: [PATCH 55/64] Update GetDataHandlers.cs --- TShockAPI/GetDataHandlers.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 74dbff85..b6d35d62 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2316,6 +2316,14 @@ namespace TShockAPI { var player = args.Player; var size = args.Data.ReadInt16(); + + var changeType = TileChangeType.None; + bool hasChangeType = ((size & 0x7FFF) & 0x8000) != 0; + if (hasChangeType) + { + changeType = (TileChangeType)args.Data.ReadInt8(); + } + var tileX = args.Data.ReadInt16(); var tileY = args.Data.ReadInt16(); var data = args.Data; From 2e0e5596b0df770cdb94de5d1251716aa02c4fa1 Mon Sep 17 00:00:00 2001 From: Chris <2648373+QuiCM@users.noreply.github.com> Date: Fri, 29 May 2020 17:17:24 +0930 Subject: [PATCH 56/64] Fix wall read bug in NetTile --- TShockAPI/Net/NetTile.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TShockAPI/Net/NetTile.cs b/TShockAPI/Net/NetTile.cs index 76d8e943..62896c10 100644 --- a/TShockAPI/Net/NetTile.cs +++ b/TShockAPI/Net/NetTile.cs @@ -30,7 +30,7 @@ namespace TShockAPI.Net public short FrameX { get; set; } public short FrameY { get; set; } public bool Lighted { get; set; } - public byte Wall { get; set; } + public ushort Wall { get; set; } public byte Liquid { get; set; } public byte LiquidType { get; set; } public bool Wire { get; set; } @@ -175,7 +175,7 @@ namespace TShockAPI.Net } if (HasWall) - stream.WriteInt8(Wall); + stream.WriteInt16((short)Wall);; if (HasLiquid) { @@ -218,7 +218,7 @@ namespace TShockAPI.Net if (flags[2]) { - Wall = stream.ReadInt8(); + Wall = stream.ReadUInt16(); } if (flags[3]) From cdeac344b8fbf6a4db73335cefd4c2ef242f2764 Mon Sep 17 00:00:00 2001 From: Chris <2648373+QuiCM@users.noreply.github.com> Date: Fri, 29 May 2020 17:18:11 +0930 Subject: [PATCH 57/64] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94b9e1ba..169d1271 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 kick on hardcore death / kick on mediumcore death / ban on either from taking action against journey mode players. (@hakusaro) * Attempted to fix the problem with the magic mirror spawn problems. You should be able to remove your spawn point in SSC by right clicking on a bed now. (@hakusaro, @AxeelAnder) * Add HandleFoodPlatterTryPlacing event, which is called whenever a player places a food in a plate. Add antihack to bouncer, to prevent removing food from plates if the region is protected; To prevent placement if they are not in range; To prevent placement if the item is not placed from player hand. (@Patrikkk) +* Fixed an offset error in NetTile that impacted SendTileSquare ## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) From 0c3242a6f543c88622a0d788219bf5ad0eb02a6a Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 29 May 2020 10:56:40 -0700 Subject: [PATCH 58/64] Tuned changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 169d1271..02cdc3b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,8 +15,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * This change was implemented by (@QuiCM, @hakusaro). * Fixed kick on hardcore death / kick on mediumcore death / ban on either from taking action against journey mode players. (@hakusaro) * Attempted to fix the problem with the magic mirror spawn problems. You should be able to remove your spawn point in SSC by right clicking on a bed now. (@hakusaro, @AxeelAnder) -* Add HandleFoodPlatterTryPlacing event, which is called whenever a player places a food in a plate. Add antihack to bouncer, to prevent removing food from plates if the region is protected; To prevent placement if they are not in range; To prevent placement if the item is not placed from player hand. (@Patrikkk) -* Fixed an offset error in NetTile that impacted SendTileSquare +* Added HandleFoodPlatterTryPlacing event, which is called whenever a player places a food in a plate. Add antihack to bouncer, to prevent removing food from plates if the region is protected; To prevent placement if they are not in range; To prevent placement if the item is not placed from player hand. (@Patrikkk) +* Fixed an offset error in NetTile that impacted `SendTileSquare`. It was being read as a `byte` and not a `ushort`. (@QuiCM) ## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) From fd6913f7dfad0a9982c301977510c2a0b38bcb75 Mon Sep 17 00:00:00 2001 From: Olink Date: Fri, 29 May 2020 16:44:03 -0400 Subject: [PATCH 59/64] Update GetDataHandlers ExtraValue packet handling to match the network protocol. Update the validation logic to be accurate: * use pixels and not tiles * allow master mode * use npc position and not player position Cleanup some style inconsistencies in NetHooks_SendData. --- TShockAPI/GetDataHandlers.cs | 44 ++++++++++++++++++++++++++++++------ TShockAPI/TShock.cs | 4 ++-- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index b6d35d62..a81ff597 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -151,7 +151,8 @@ namespace TShockAPI { PacketTypes.CrystalInvasionStart, HandleOldOnesArmy }, { PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 }, { PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 }, - { PacketTypes.FoodPlatterTryPlacing, HandleFoodPlatterTryPlacing } + { PacketTypes.FoodPlatterTryPlacing, HandleFoodPlatterTryPlacing }, + { PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker } }; } @@ -3383,24 +3384,38 @@ namespace TShockAPI private static bool HandleSyncExtraValue(GetDataHandlerArgs args) { var npcIndex = args.Data.ReadInt16(); - var extraValue = args.Data.ReadSingle(); + var extraValue = args.Data.ReadInt32(); var position = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); - if (position.X < 0 || position.X >= Main.maxTilesX || position.Y < 0 || position.Y >= Main.maxTilesY) + if (position.X < 0 || position.X >= (Main.maxTilesX * 16.0f) || position.Y < 0 || position.Y >= (Main.maxTilesY * 16.0f)) { TShock.Log.ConsoleDebug("GetDataHandlers / HandleSyncExtraValue rejected extents check {0}", args.Player.Name); return true; } - if (!Main.expertMode) + if (!Main.expertMode && !Main.masterMode) { - TShock.Log.ConsoleDebug("GetDataHandlers / HandleSyncExtraValue rejected expert mode check {0}", args.Player.Name); + TShock.Log.ConsoleDebug("GetDataHandlers / HandleSyncExtraValue rejected expert/master mode check {0}", args.Player.Name); return true; } - if (!args.Player.IsInRange((int)position.X, (int)position.Y)) + if (npcIndex < 0 || npcIndex >= Main.npc.Length) { - TShock.Log.ConsoleDebug("GetDataHandlers / HandleSyncExtraValue rejected range check {0}", args.Player.Name); + TShock.Log.ConsoleDebug("GetDataHandlers / HandleSyncExtraValue rejected npc id out of bounds check - NPC ID: {0}", npcIndex); + return true; + } + + var npc = Main.npc[npcIndex]; + if (npc == null) + { + TShock.Log.ConsoleDebug("GetDataHandlers / HandleSyncExtraValue rejected npc is null - NPC ID: {0}", npcIndex); + return true; + } + + var distanceFromCoinPacketToNpc = Utils.Distance(position, npc.position); + if (distanceFromCoinPacketToNpc >= (5*16f)) //5 tile range + { + TShock.Log.ConsoleDebug("GetDataHandlers / HandleSyncExtraValue rejected range check {0},{1} vs {2},{3} which is {4}", npc.position.X, npc.position.Y, position.X, position.Y, distanceFromCoinPacketToNpc); return true; } @@ -3628,6 +3643,21 @@ namespace TShockAPI return false; } + private static bool HandleSyncRevengeMarker(GetDataHandlerArgs args) + { + int uniqueID = args.Data.ReadInt32(); + Vector2 location = args.Data.ReadVector2(); + int netId = args.Data.ReadInt32(); + float npcHpPercent = args.Data.ReadSingle(); + int npcTypeAgainstDiscouragement = args.Data.ReadInt32(); //tfw the argument is Type Against Discouragement + int npcAiStyleAgainstDiscouragement = args.Data.ReadInt32(); //see ^ + int coinsValue = args.Data.ReadInt32(); + float baseValue = args.Data.ReadSingle(); + bool spawnedFromStatus = args.Data.ReadBoolean(); + + return false; + } + public enum EditAction { KillTile = 0, diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 0d19a6fb..9d14ba24 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1635,7 +1635,8 @@ namespace TShockAPI e.Handled = true; return; } - } else if (e.MsgId == PacketTypes.ProjectileNew) + } + else if (e.MsgId == PacketTypes.ProjectileNew) { if (e.number >= 0 && e.number < Main.projectile.Length) { @@ -1660,7 +1661,6 @@ namespace TShockAPI } } } - } } From 7d467224074d43b372ad9ddc70ffe0fbcdca196c Mon Sep 17 00:00:00 2001 From: Olink Date: Fri, 29 May 2020 16:47:43 -0400 Subject: [PATCH 60/64] Update changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02cdc3b2..6282150e 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 * Attempted to fix the problem with the magic mirror spawn problems. You should be able to remove your spawn point in SSC by right clicking on a bed now. (@hakusaro, @AxeelAnder) * Added HandleFoodPlatterTryPlacing event, which is called whenever a player places a food in a plate. Add antihack to bouncer, to prevent removing food from plates if the region is protected; To prevent placement if they are not in range; To prevent placement if the item is not placed from player hand. (@Patrikkk) * Fixed an offset error in NetTile that impacted `SendTileSquare`. It was being read as a `byte` and not a `ushort`. (@QuiCM) +* Fixed coins not dropping after being picked up by npcs. The ExtraValue packet was not being read correctly. (@Olink) ## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) From 44ad2d2effcc2c0e3e82c1944c8737586a78c532 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 29 May 2020 19:50:07 -0700 Subject: [PATCH 61/64] Remove extra debug info from OnGetData Per packet debug logs are redundant for people with the packet monitor plugin. If you need packet monitoring, please install the packet monitor plugin. --- CHANGELOG.md | 9 +++++---- TShockAPI/TShock.cs | 2 -- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02cdc3b2..d409b244 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,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 -* Fix pet licenses. (@Olink) -* Initial support for Journey mode in SSC worlds. (@Olink) -* Make TShock database MySQL 8 compatible by escaping column names in our IQueryBuilder code. (Name `Groups` is a reserved element in this version, which is used in our `Region` table.) (@Patrikkk) -* Reintroduce `-worldselectpath` per feedback from @fjfnaranjo. This command line argument should be used to specify the place where the interactive server startup will look for worlds to show on the world select screen. The original version of this argument, `-worldpath`, was removed because several game service providers have broken configurations that stop the server from running with an unhelpful error. This specific configuration was `-world` and `-worldpath`. In the new world, you can do the following: +* Fixed pet licenses. (@Olink) +* Added initial support for Journey mode in SSC worlds. (@Olink) +* Made TShock database MySQL 8 compatible by escaping column names in our IQueryBuilder code. (Name `Groups` is a reserved element in this version, which is used in our `Region` table.) (@Patrikkk) +* Reintroduced `-worldselectpath` per feedback from @fjfnaranjo. This command line argument should be used to specify the place where the interactive server startup will look for worlds to show on the world select screen. The original version of this argument, `-worldpath`, was removed because several game service providers have broken configurations that stop the server from running with an unhelpful error. This specific configuration was `-world` and `-worldpath`. In the new world, you can do the following: * `-worldselectpath` should be used if you want to customize the server interactive boot world list (so that you can select from a number of worlds in non-standard locations). * `-world` will behave as an absolute path to the world to load. This is the most common thing you want if you're starting the server and have a specific world in mind. * `-worldselectpath` and `-worldname` should work together enabling you to select from a world from the list that you specify. This is *not* a world file name, but a world name as described by Terraria. @@ -17,6 +17,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Attempted to fix the problem with the magic mirror spawn problems. You should be able to remove your spawn point in SSC by right clicking on a bed now. (@hakusaro, @AxeelAnder) * Added HandleFoodPlatterTryPlacing event, which is called whenever a player places a food in a plate. Add antihack to bouncer, to prevent removing food from plates if the region is protected; To prevent placement if they are not in range; To prevent placement if the item is not placed from player hand. (@Patrikkk) * Fixed an offset error in NetTile that impacted `SendTileSquare`. It was being read as a `byte` and not a `ushort`. (@QuiCM) +* Removed packet monitoring from debug logs. To achieve the same results, install @QuiCM's packet monitor plugin (it does better things). (@hakusaro) ## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 0d19a6fb..3839a5ec 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1493,8 +1493,6 @@ namespace TShockAPI PacketTypes type = e.MsgID; - Log.ConsoleDebug("Recv: {0:X}: {2} ({1:XX})", e.Msg.whoAmI, (byte)type, type); - var player = Players[e.Msg.whoAmI]; if (player == null || !player.ConnectionAlive) { From f82ab41a254f893f332900e5f22d6bc8cf5f08a2 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 29 May 2020 21:04:48 -0700 Subject: [PATCH 62/64] Add /sync command to alleviate door related sadness Run /sync if your doors disappear. This will resync your local client with the server state. For more information, please see the associated changelog entry. --- CHANGELOG.md | 6 ++++++ TShockAPI/Bouncer.cs | 6 ++++-- TShockAPI/Commands.cs | 11 +++++++++++ TShockAPI/DB/GroupManager.cs | 3 ++- TShockAPI/Permissions.cs | 3 +++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d409b244..fd59e1e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,12 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added HandleFoodPlatterTryPlacing event, which is called whenever a player places a food in a plate. Add antihack to bouncer, to prevent removing food from plates if the region is protected; To prevent placement if they are not in range; To prevent placement if the item is not placed from player hand. (@Patrikkk) * Fixed an offset error in NetTile that impacted `SendTileSquare`. It was being read as a `byte` and not a `ushort`. (@QuiCM) * Removed packet monitoring from debug logs. To achieve the same results, install @QuiCM's packet monitor plugin (it does better things). (@hakusaro) +* Updated packet monitoring in send tile square handler for Bouncer debugging. (@hakusaro) +* Added `/sync`, activated with `tshock.synclocalarea`. This is a default guest permission. When the command is issued, the server will resync area around the player in the event of a desync issue. (@hakusaro) + * If your doors disappear, this command will allow a player to resync without having to disconnect from the server. + * The default group that gets this permission is `Guest` for the time being. + * To add this command to your guest group, give them `tshock.synclocalarea`, with `/group addperm guest tshock.synclocalarea`. + * This command may be removed at any time in the future (and will likely be removed when send tile square handling is fixed). ## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index abd5fe05..c3a62dae 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -558,6 +558,8 @@ namespace TShockAPI return; } + bool changed = false; + bool failed = false; try { var tiles = new NetTile[size, size]; @@ -569,7 +571,6 @@ namespace TShockAPI } } - bool changed = false; for (int x = 0; x < size; x++) { int realx = tileX + x; @@ -709,9 +710,10 @@ namespace TShockAPI catch { args.Player.SendTileSquare(tileX, tileY, size); + failed = true; } - TShock.Log.ConsoleDebug("Bouncer / SendTileSquare reimplemented from spaghetti from {0}", args.Player.Name); + TShock.Log.ConsoleDebug("Bouncer / SendTileSquare from {0} {1} {2}", args.Player.Name, changed, failed); args.Handled = true; } diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 8d131588..fd3f5e9e 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -589,6 +589,10 @@ namespace TShockAPI { HelpText = "Creates a reference tables for Terraria data types and the TShock permission system in the server folder." }); + add(new Command(Permissions.synclocalarea, SyncLocalArea, "sync") + { + HelpText = "Sends all tiles from the server to the player to resync the client with the actual world state." + }); #endregion add(new Command(Aliases, "aliases") @@ -5302,6 +5306,13 @@ namespace TShockAPI return; } + private static void SyncLocalArea(CommandArgs args) + { + args.Player.SendTileSquare((int) args.Player.TileX, (int) args.Player.TileY, 32); + args.Player.SendWarningMessage("Sync'd!"); + return; + } + #endregion General Commands #region Cheat Commands diff --git a/TShockAPI/DB/GroupManager.cs b/TShockAPI/DB/GroupManager.cs index 6405b5bc..c9a3b760 100644 --- a/TShockAPI/DB/GroupManager.cs +++ b/TShockAPI/DB/GroupManager.cs @@ -64,7 +64,8 @@ namespace TShockAPI.DB Permissions.canlogin, Permissions.canpartychat, Permissions.cantalkinthird, - Permissions.canchat)); + Permissions.canchat, + Permissions.synclocalarea)); AddDefaultGroup("default", "guest", string.Join(",", diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index 322b1199..baf21a73 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -465,6 +465,9 @@ namespace TShockAPI [Description("Player can see advanced information about any user account.")] public static readonly string advaccountinfo = "tshock.accountinfo.details"; + + [Description("Player can resync themselves with server state.")] + public static readonly string synclocalarea = "tshock.synclocalarea"; #endregion /// /// Lists all commands associated with a given permission From 52365078b61184485b3cb5779df79c33efb680b0 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 30 May 2020 00:28:40 -0700 Subject: [PATCH 63/64] Remove extra space from sentence in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6282150e..88173ecd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Attempted to fix the problem with the magic mirror spawn problems. You should be able to remove your spawn point in SSC by right clicking on a bed now. (@hakusaro, @AxeelAnder) * Added HandleFoodPlatterTryPlacing event, which is called whenever a player places a food in a plate. Add antihack to bouncer, to prevent removing food from plates if the region is protected; To prevent placement if they are not in range; To prevent placement if the item is not placed from player hand. (@Patrikkk) * Fixed an offset error in NetTile that impacted `SendTileSquare`. It was being read as a `byte` and not a `ushort`. (@QuiCM) -* Fixed coins not dropping after being picked up by npcs. The ExtraValue packet was not being read correctly. (@Olink) +* Fixed coins not dropping after being picked up by npcs. The ExtraValue packet was not being read correctly. (@Olink) ## TShock 4.4.0 (Pre-release 8) * Update for OTAPI 2.0.0.36 and Terraria 1.4.0.4. (@hakusaro, @Patrikkk, @DeathCradle) From 791a6be8319fb14310585c33a5e6ed3424880395 Mon Sep 17 00:00:00 2001 From: Patrikkk <58985873+Patrikkk@users.noreply.github.com> Date: Sat, 30 May 2020 09:39:40 +0200 Subject: [PATCH 64/64] Add additional FoodPlatter event check. Update range check. (#1941) This is a combination of 3 commits: * @Olink was right. Adding additional check. Modifying range check. There are two ways to place food into a plate. One is by having it in hand (mouse) and right clicking, the other is by having the item selected in the... "inventory bar"(?) and right clicking the plate. Tested range, if player is outside the range, they should not get their item back. * FoodPlatterHotfix - Update IsInRange range value. To suggestion of Olink, to consider player lag and increase the range check. Co-authored-by: Lucas Nicodemus --- TShockAPI/Bouncer.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 68089abc..edf05800 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -2072,7 +2072,7 @@ namespace TShockAPI /// internal void OnFoodPlatterTryPlacing(object sender, GetDataHandlers.FoodPlatterTryPlacingEventArgs args) { - if (args.Player.ItemInHand.type != args.ItemID) + if ((args.Player.SelectedItem.type != args.ItemID && args.Player.ItemInHand.type != args.ItemID)) { TShock.Log.ConsoleDebug("Bouncer / OnFoodPlatterTryPlacing rejected item not placed by hand from {0}", args.Player.Name); args.Player.SendTileSquare(args.TileX, args.TileY, 1); @@ -2101,12 +2101,9 @@ namespace TShockAPI return; } - if (!args.Player.IsInRange(args.TileX, args.TileY)) + if (!args.Player.IsInRange(args.TileX, args.TileY, range: 13)) // To my knowledge, max legit tile reach with accessories. { TShock.Log.ConsoleDebug("Bouncer / OnFoodPlatterTryPlacing rejected range checks from {0}", args.Player.Name); - Item item = new Item(); - item.netDefaults(args.ItemID); - args.Player.GiveItemCheck(args.ItemID, item.Name, args.Stack, args.Prefix); args.Player.SendTileSquare(args.TileX, args.TileY, 1); args.Handled = true; return;