Clean up NetModulePacketHandler a little
This commit is contained in:
parent
0af69e2bf2
commit
961c6cd9bc
3 changed files with 47 additions and 55 deletions
|
|
@ -1,4 +1,6 @@
|
|||
using Terraria;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Terraria;
|
||||
using static TShockAPI.GetDataHandlers;
|
||||
|
||||
namespace TShockAPI.Handlers.NetModules
|
||||
|
|
@ -8,6 +10,19 @@ namespace TShockAPI.Handlers.NetModules
|
|||
/// </summary>
|
||||
public class NetModulePacketHandler : IPacketHandler<LoadNetModuleEventArgs>
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps net module types to handlers for the net module type. Add to or edit this dictionary to customise handling
|
||||
/// </summary>
|
||||
public static Dictionary<NetModulesTypes, Type> NetModulesToHandlersMap = new Dictionary<NetModulesTypes, Type>
|
||||
{
|
||||
{ NetModulesTypes.CreativePowers, typeof(CreativePowerHandler) },
|
||||
{ NetModulesTypes.CreativeUnlocksPlayerReport, typeof(CreativeUnlocksHandler) },
|
||||
{ NetModulesTypes.TeleportPylon, typeof(PylonHandler) },
|
||||
{ NetModulesTypes.Liquid, typeof(LiquidHandler) },
|
||||
{ NetModulesTypes.Bestiary, typeof(BestiaryHandler) },
|
||||
{ NetModulesTypes.Ambience, typeof(AmbienceHandler) }
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a load net module packet is received. This method picks a <see cref="INetModuleHandler"/> based on the
|
||||
/// net module type being loaded, then forwards the data to the chosen handler to process
|
||||
|
|
@ -18,61 +33,25 @@ namespace TShockAPI.Handlers.NetModules
|
|||
{
|
||||
INetModuleHandler handler;
|
||||
|
||||
switch (args.ModuleType)
|
||||
if (NetModulesToHandlersMap.ContainsKey(args.ModuleType))
|
||||
{
|
||||
case NetModulesTypes.CreativePowers:
|
||||
{
|
||||
handler = new CreativePowerHandler();
|
||||
break;
|
||||
}
|
||||
|
||||
case NetModulesTypes.CreativeUnlocksPlayerReport:
|
||||
{
|
||||
if (!Main.GameModeInfo.IsJourneyMode)
|
||||
{
|
||||
TShock.Log.ConsoleDebug(
|
||||
"NetModuleHandler received attempt to unlock sacrifice while not in journey mode from",
|
||||
args.Player.Name
|
||||
);
|
||||
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
handler = new CreativeUnlocksHandler();
|
||||
break;
|
||||
}
|
||||
case NetModulesTypes.TeleportPylon:
|
||||
{
|
||||
handler = new PylonHandler();
|
||||
break;
|
||||
}
|
||||
case NetModulesTypes.Liquid:
|
||||
{
|
||||
handler = new LiquidHandler();
|
||||
break;
|
||||
}
|
||||
case NetModulesTypes.Bestiary:
|
||||
{
|
||||
handler = new BestiaryHandler();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// 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.
|
||||
args.Handled = false;
|
||||
return;
|
||||
}
|
||||
handler = (INetModuleHandler)Activator.CreateInstance(NetModulesToHandlersMap[args.ModuleType]);
|
||||
}
|
||||
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.
|
||||
args.Handled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
handler.Deserialize(args.Data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue