From c7a6d044f4af28dcd7bdda88400979050f2d3464 Mon Sep 17 00:00:00 2001 From: Chris <2648373+QuiCM@users.noreply.github.com> Date: Tue, 2 Jun 2020 17:19:00 +0930 Subject: [PATCH] Minor refactors --- TShockAPI/Bouncer.cs | 2 +- TShockAPI/GetDataHandlers.cs | 17 ++++++++--------- .../Handlers/NetModules/CreativePowerHandler.cs | 4 ++-- .../NetModules/CreativeUnlocksHandler.cs | 3 +++ .../NetModules/NetModulePacketHandler.cs | 17 ++++------------- 5 files changed, 18 insertions(+), 25 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index fa928eb4..8bf5a11a 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -47,7 +47,7 @@ namespace TShockAPI GetDataHandlers.SendTileSquare += STSHandler.OnReceive; NetModuleHandler = new Handlers.NetModules.NetModulePacketHandler(); - GetDataHandlers.LoadNetModule += NetModuleHandler.OnReceive; + GetDataHandlers.ReadNetModule += NetModuleHandler.OnReceive; // Setup hooks GetDataHandlers.GetSection += OnGetSection; diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index cc4174d0..a39c3aa6 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1954,7 +1954,7 @@ namespace TShockAPI /// /// Used when a net module is loaded /// - public class LoadNetModuleEventArgs : GetDataHandledEventArgs + public class ReadNetModuleEventArgs : GetDataHandledEventArgs { /// /// The type of net module being loaded @@ -1963,25 +1963,25 @@ namespace TShockAPI } /// - /// Called when a net module is loaded + /// Called when a net module is received /// - public static HandlerList LoadNetModule = new HandlerList(); + public static HandlerList ReadNetModule = new HandlerList(); private static bool OnLoadNetModule(TSPlayer player, MemoryStream data, NetModuleType moduleType) { - if (LoadNetModule == null) + if (ReadNetModule == null) { return false; } - var args = new LoadNetModuleEventArgs + var args = new ReadNetModuleEventArgs { Player = player, Data = data, ModuleType = moduleType }; - LoadNetModule.Invoke(null, args); + ReadNetModule.Invoke(null, args); return args.Handled; } @@ -2242,11 +2242,10 @@ namespace TShockAPI 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; args.Player.sY = args.TPlayer.SpawnY; - if (((Main.tile[args.Player.sX, args.Player.sY - 1].active() && Main.tile[args.Player.sX, args.Player.sY - 1].type == 79)) && (WorldGen.StartRoomCheck(args.Player.sX, args.Player.sY - 1))) + if (((Main.tile[args.Player.sX, args.Player.sY - 1].active() && Main.tile[args.Player.sX, args.Player.sY - 1].type == TileID.Beds)) && (WorldGen.StartRoomCheck(args.Player.sX, args.Player.sY - 1))) { args.Player.Teleport(args.Player.sX * 16, (args.Player.sY * 16) - 48); TShock.Log.ConsoleDebug("GetDataHandlers / HandleSpawn force teleport phase 1 {0}", args.Player.Name); @@ -2255,7 +2254,7 @@ namespace TShockAPI else if ((Main.ServerSideCharacter) && (args.Player.sX > 0) && (args.Player.sY > 0)) { - if (((Main.tile[args.Player.sX, args.Player.sY - 1].active() && Main.tile[args.Player.sX, args.Player.sY - 1].type == 79)) && (WorldGen.StartRoomCheck(args.Player.sX, args.Player.sY - 1))) + if (((Main.tile[args.Player.sX, args.Player.sY - 1].active() && Main.tile[args.Player.sX, args.Player.sY - 1].type == TileID.Beds)) && (WorldGen.StartRoomCheck(args.Player.sX, args.Player.sY - 1))) { args.Player.Teleport(args.Player.sX * 16, (args.Player.sY * 16) - 48); TShock.Log.ConsoleDebug("GetDataHandlers / HandleSpawn force teleport phase 2 {0}", args.Player.Name); diff --git a/TShockAPI/Handlers/NetModules/CreativePowerHandler.cs b/TShockAPI/Handlers/NetModules/CreativePowerHandler.cs index 06e43107..470890d1 100644 --- a/TShockAPI/Handlers/NetModules/CreativePowerHandler.cs +++ b/TShockAPI/Handlers/NetModules/CreativePowerHandler.cs @@ -31,7 +31,7 @@ namespace TShockAPI.Handlers.NetModules /// public void HandlePacket(TSPlayer player, out bool rejectPacket) { - if (!CheckPermission(PowerType, player)) + if (!HasPermission(PowerType, player)) { rejectPacket = true; return; @@ -46,7 +46,7 @@ namespace TShockAPI.Handlers.NetModules /// /// /// - public static bool CheckPermission(CreativePowerTypes powerType, TSPlayer player) + public static bool HasPermission(CreativePowerTypes powerType, TSPlayer player) { if (!PowerToPermissionMap.ContainsKey(powerType)) { diff --git a/TShockAPI/Handlers/NetModules/CreativeUnlocksHandler.cs b/TShockAPI/Handlers/NetModules/CreativeUnlocksHandler.cs index 77e9d6d2..68fe4f1a 100644 --- a/TShockAPI/Handlers/NetModules/CreativeUnlocksHandler.cs +++ b/TShockAPI/Handlers/NetModules/CreativeUnlocksHandler.cs @@ -30,6 +30,9 @@ namespace TShockAPI.Handlers.NetModules /// public void Deserialize(MemoryStream data) { + // For whatever reason Terraria writes '0' to the stream at the beginning of this packet. + // If this value is not 0 then its been crafted by a non-vanilla client. + // We don't actually know why the 0 is written, so we're just going to call this UnknownField for now UnknownField = data.ReadInt8(); if (UnknownField == 0) { diff --git a/TShockAPI/Handlers/NetModules/NetModulePacketHandler.cs b/TShockAPI/Handlers/NetModules/NetModulePacketHandler.cs index 9fe5c30f..16d58640 100644 --- a/TShockAPI/Handlers/NetModules/NetModulePacketHandler.cs +++ b/TShockAPI/Handlers/NetModules/NetModulePacketHandler.cs @@ -8,7 +8,7 @@ namespace TShockAPI.Handlers.NetModules /// /// Handles packet 82 - Load Net Module packets /// - public class NetModulePacketHandler : IPacketHandler + public class NetModulePacketHandler : IPacketHandler { /// /// Maps net module types to handlers for the net module type. Add to or edit this dictionary to customise handling @@ -29,7 +29,7 @@ namespace TShockAPI.Handlers.NetModules /// /// /// - public void OnReceive(object sender, LoadNetModuleEventArgs args) + public void OnReceive(object sender, ReadNetModuleEventArgs args) { INetModuleHandler handler; @@ -39,17 +39,8 @@ namespace TShockAPI.Handlers.NetModules } else { - // As of 1.4.x.x, this is now used for more things: - // NetCreativePowersModule - // NetCreativePowerPermissionsModule - // NetLiquidModule - // NetParticlesModule - // NetPingModule - // NetTeleportPylonModule - // NetTextModule - // I (particles) have disabled the original return here, which means that we need to - // handle this more. In the interm, this unbreaks parts of vanilla. Originally - // we just blocked this because it was a liquid exploit. + // We don't have handlers for NetModuleType.Ping and NetModuleType.Particles. + // These net modules are fairly innocuous and can be processed normally by the game args.Handled = false; return; }