From d46f534533a72f1eedfbef8f542c6e266ddd04bf Mon Sep 17 00:00:00 2001 From: Chris <2648373+QuiCM@users.noreply.github.com> Date: Tue, 2 Jun 2020 10:18:40 +0930 Subject: [PATCH 01/15] Standardize permission rejection messages --- TShockAPI/Commands.cs | 8 ++++---- TShockAPI/GetDataHandlers.cs | 32 ++++++++++++++++---------------- TShockAPI/TSPlayer.cs | 6 +++--- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 10d6f0da..4fc949b7 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1987,7 +1987,7 @@ namespace TShockAPI void FailedPermissionCheck() { - args.Player.SendErrorMessage("You do not have sufficient permissions to start the {0} event.", eventType); + args.Player.SendErrorMessage("You do not have permission to start the {0} event.", eventType); return; } @@ -4873,7 +4873,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.tp)) { - args.Player.SendErrorMessage("You don't have the necessary permission to do that."); + args.Player.SendErrorMessage("You do not have permission to teleport."); break; } if (args.Parameters.Count <= 1) @@ -5051,7 +5051,7 @@ namespace TShockAPI } if (displayIdsRequested && !args.Player.HasPermission(Permissions.seeids)) { - args.Player.SendErrorMessage("You don't have the required permission to list player ids."); + args.Player.SendErrorMessage("You do not have permission to list player ids."); return; } @@ -6025,7 +6025,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.godmodeother)) { - args.Player.SendErrorMessage("You do not have permission to god mode another player!"); + args.Player.SendErrorMessage("You do not have permission to god mode another player."); return; } string plStr = String.Join(" ", args.Parameters); diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index b5c9bbb0..60d16b35 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2928,21 +2928,21 @@ namespace TShockAPI if (bosses.Contains(thingType) && !args.Player.HasPermission(Permissions.summonboss)) { TShock.Log.ConsoleDebug("GetDataHandlers / HandleSpawnBoss rejected boss {0} {1}", args.Player.Name, thingType); - args.Player.SendErrorMessage("You don't have permission to summon a boss."); + args.Player.SendErrorMessage("You do not have permission to summon a boss."); return true; } if (invasions.Contains(thingType) && !args.Player.HasPermission(Permissions.startinvasion)) { TShock.Log.ConsoleDebug("GetDataHandlers / HandleSpawnBoss rejected invasion {0} {1}", args.Player.Name, thingType); - args.Player.SendErrorMessage("You don't have permission to start an invasion."); + args.Player.SendErrorMessage("You do not have permission to start an invasion."); return true; } if (pets.Contains(thingType) && !args.Player.HasPermission(Permissions.spawnpets)) { TShock.Log.ConsoleDebug("GetDataHandlers / HandleSpawnBoss rejected pet {0} {1}", args.Player.Name, thingType); - args.Player.SendErrorMessage("You don't have permission to spawn pets."); + args.Player.SendErrorMessage("You do not have permission to spawn pets."); return true; } @@ -3234,7 +3234,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_timefreeze)) { - args.Player.SendErrorMessage("You don't have permission to freeze the time of the server!"); + args.Player.SendErrorMessage("You do not have permission to freeze the time of the server."); return true; } break; @@ -3246,7 +3246,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_timeset)) { - args.Player.SendErrorMessage("You don't have 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; @@ -3255,7 +3255,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_godmode)) { - args.Player.SendErrorMessage("You don't have permission to toggle godmode!"); + args.Player.SendErrorMessage("You do not have permission to toggle godmode."); return true; } break; @@ -3264,7 +3264,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_windstrength)) { - args.Player.SendErrorMessage("You don't have permission to modify the wind strength of the server!"); + args.Player.SendErrorMessage("You do not have permission to modify the wind strength of the server."); return true; } break; @@ -3273,7 +3273,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_rainstrength)) { - args.Player.SendErrorMessage("You don't have permission to modify the rain strength of the server!"); + args.Player.SendErrorMessage("You do not have permission to modify the rain strength of the server."); return true; } break; @@ -3282,7 +3282,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_timespeed)) { - args.Player.SendErrorMessage("You don't have permission to modify the time speed of the server!"); + args.Player.SendErrorMessage("You do not have permission to modify the time speed of the server."); return true; } break; @@ -3291,7 +3291,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_rainfreeze)) { - args.Player.SendErrorMessage("You don't have permission to freeze the rain strength of the server!"); + args.Player.SendErrorMessage("You do not have permission to freeze the rain strength of the server."); return true; } break; @@ -3300,7 +3300,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_windfreeze)) { - args.Player.SendErrorMessage("You don't have permission to freeze the wind strength of the server!"); + args.Player.SendErrorMessage("You do not have permission to freeze the wind strength of the server."); return true; } break; @@ -3309,7 +3309,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_placementrange)) { - args.Player.SendErrorMessage("You don't have permission to modify the tile placement range of your character!"); + args.Player.SendErrorMessage("You do not have permission to modify the tile placement range of your character."); return true; } break; @@ -3318,7 +3318,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_setdifficulty)) { - args.Player.SendErrorMessage("You don't have permission to modify the world difficulty of the server!"); + args.Player.SendErrorMessage("You do not have permission to modify the world difficulty of the server."); return true; } break; @@ -3327,7 +3327,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_biomespreadfreeze)) { - args.Player.SendErrorMessage("You don't have permission to freeze the biome spread of the server!"); + args.Player.SendErrorMessage("You do not have permission to freeze the biome spread of the server."); return true; } break; @@ -3342,7 +3342,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 the server!"); + args.Player.SendErrorMessage("You do not have permission to modify the NPC spawn rate of the server."); return true; } break; @@ -3576,7 +3576,7 @@ namespace TShockAPI if (!args.Player.HasPermission(Permissions.startdd2)) { TShock.Log.ConsoleDebug("GetDataHandlers / HandleOldOnesArmy rejected permissions {0}", args.Player.Name); - args.Player.SendErrorMessage("You don't have permission to start the Old One's Army event."); + args.Player.SendErrorMessage("You do not have permission to start the Old One's Army event."); return true; } diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 54be5041..ade16234 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -664,13 +664,13 @@ namespace TShockAPI switch (failure) { case BuildPermissionFailPoint.GeneralBuild: - SendErrorMessage("You lack permission to build on this server."); + SendErrorMessage("You do not have permission to build on this server."); break; case BuildPermissionFailPoint.SpawnProtect: - SendErrorMessage("You lack permission to build in the spawn point."); + SendErrorMessage("You do not have permission to build in the spawn point."); break; case BuildPermissionFailPoint.Regions: - SendErrorMessage("You lack permission to build in this region."); + SendErrorMessage("You do not have permission to build in this region."); break; } From b5c3b430fa31c1a6c96fd0d8a772adf9b07d4752 Mon Sep 17 00:00:00 2001 From: Chris <2648373+QuiCM@users.noreply.github.com> Date: Tue, 2 Jun 2020 10:20:13 +0930 Subject: [PATCH 02/15] Standardize permission rejection message again --- TShockAPI/GetDataHandlers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 60d16b35..65fe622f 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3246,7 +3246,7 @@ namespace TShockAPI { if (!args.Player.HasPermission(Permissions.journey_timeset)) { - args.Player.SendErrorMessage("You don't have permission to modify the time of the server."); + args.Player.SendErrorMessage("You do not have permission to modify the time of the server."); return true; } break; From 5b72ff6c0a0e5e23ce706c82d19925baa70ff931 Mon Sep 17 00:00:00 2001 From: Chris <2648373+QuiCM@users.noreply.github.com> Date: Tue, 2 Jun 2020 10:44:10 +0930 Subject: [PATCH 03/15] Add IPacketHandler --- TShockAPI/Bouncer.cs | 2 +- TShockAPI/Handlers/IPacketHandler.cs | 16 ++++++++++++++++ TShockAPI/Handlers/SendTileSquareHandler.cs | 18 +++++++++--------- TShockAPI/TShockAPI.csproj | 3 ++- 4 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 TShockAPI/Handlers/IPacketHandler.cs diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 395bfddd..fda85267 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -43,7 +43,7 @@ namespace TShockAPI internal Bouncer() { STSHandler = new Handlers.SendTileSquareHandler(); - GetDataHandlers.SendTileSquare += STSHandler.OnReceiveSendTileSquare; + GetDataHandlers.SendTileSquare += STSHandler.OnReceive; // Setup hooks GetDataHandlers.GetSection += OnGetSection; diff --git a/TShockAPI/Handlers/IPacketHandler.cs b/TShockAPI/Handlers/IPacketHandler.cs new file mode 100644 index 00000000..9b2e0444 --- /dev/null +++ b/TShockAPI/Handlers/IPacketHandler.cs @@ -0,0 +1,16 @@ +namespace TShockAPI.Handlers +{ + /// + /// Describes a packet handler that receives a packet from a GetDataHandler + /// + /// + public interface IPacketHandler where TEventArgs : GetDataHandledEventArgs + { + /// + /// Invoked when the packet is received + /// + /// + /// + void OnReceive(object sender, TEventArgs args); + } +} diff --git a/TShockAPI/Handlers/SendTileSquareHandler.cs b/TShockAPI/Handlers/SendTileSquareHandler.cs index 48462a03..fc252256 100644 --- a/TShockAPI/Handlers/SendTileSquareHandler.cs +++ b/TShockAPI/Handlers/SendTileSquareHandler.cs @@ -14,12 +14,12 @@ namespace TShockAPI.Handlers /// /// Provides processors for handling Tile Square packets /// - public class SendTileSquareHandler + public class SendTileSquareHandler : IPacketHandler { /// /// Maps grass-type blocks to flowers that can be grown on them with flower boots /// - Dictionary> _grassToPlantMap = new Dictionary> + public static Dictionary> GrassToPlantMap = new Dictionary> { { TileID.Grass, new List { TileID.Plants, TileID.Plants2 } }, { TileID.HallowedGrass, new List { TileID.HallowedPlants, TileID.HallowedPlants2 } }, @@ -29,7 +29,7 @@ namespace TShockAPI.Handlers /// /// Item IDs that can spawn flowers while you walk /// - List _flowerBootItems = new List + public static List FlowerBootItems = new List { ItemID.FlowerBoots, ItemID.FairyBoots @@ -40,7 +40,7 @@ namespace TShockAPI.Handlers /// Note: is empty at the time of writing, but entities are dynamically assigned their ID at initialize time /// which is why we can use the _myEntityId field on each entity type /// - Dictionary _tileEntityIdToTileIdMap = new Dictionary + public static Dictionary TileEntityIdToTileIdMap = new Dictionary { { TileID.TargetDummy, TETrainingDummy._myEntityID }, { TileID.ItemFrame, TEItemFrame._myEntityID }, @@ -57,7 +57,7 @@ namespace TShockAPI.Handlers /// /// /// - public void OnReceiveSendTileSquare(object sender, GetDataHandlers.SendTileSquareEventArgs args) + public void OnReceive(object sender, GetDataHandlers.SendTileSquareEventArgs args) { // By default, we'll handle everything args.Handled = true; @@ -196,9 +196,9 @@ namespace TShockAPI.Handlers UpdateMultipleServerTileStates(realX, realY, width, height, newTiles); // Tile entities have special placements that we should let the game deal with - if (_tileEntityIdToTileIdMap.ContainsKey(tileType)) + if (TileEntityIdToTileIdMap.ContainsKey(tileType)) { - TileEntity.PlaceEntityNet(realX, realY, _tileEntityIdToTileIdMap[tileType]); + TileEntity.PlaceEntityNet(realX, realY, TileEntityIdToTileIdMap[tileType]); } } @@ -214,7 +214,7 @@ namespace TShockAPI.Handlers { // Some boots allow growing flowers on grass. This process sends a 1x1 tile square to grow the flowers // The square size must be 1 and the player must have an accessory that allows growing flowers in order for this square to be valid - if (squareSize == 1 && args.Player.Accessories.Any(a => a != null && _flowerBootItems.Contains(a.type))) + if (squareSize == 1 && args.Player.Accessories.Any(a => a != null && FlowerBootItems.Contains(a.type))) { ProcessFlowerBoots(realX, realY, newTile, args); return; @@ -254,7 +254,7 @@ namespace TShockAPI.Handlers } ITile tile = Main.tile[realX, realY + 1]; - if (!_grassToPlantMap.TryGetValue(tile.type, out List plantTiles) && !plantTiles.Contains(newTile.Type)) + if (!GrassToPlantMap.TryGetValue(tile.type, out List plantTiles) && !plantTiles.Contains(newTile.Type)) { // If the tile below the tile square isn't a valid plant tile (eg grass) then we don't update the server tile state return; diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index ea6f4f48..af383252 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -88,6 +88,7 @@ + @@ -212,7 +213,7 @@ - +