Minor refactors
This commit is contained in:
parent
93a7b0aafe
commit
c7a6d044f4
5 changed files with 18 additions and 25 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1954,7 +1954,7 @@ namespace TShockAPI
|
|||
/// <summary>
|
||||
/// Used when a net module is loaded
|
||||
/// </summary>
|
||||
public class LoadNetModuleEventArgs : GetDataHandledEventArgs
|
||||
public class ReadNetModuleEventArgs : GetDataHandledEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of net module being loaded
|
||||
|
|
@ -1963,25 +1963,25 @@ namespace TShockAPI
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when a net module is loaded
|
||||
/// Called when a net module is received
|
||||
/// </summary>
|
||||
public static HandlerList<LoadNetModuleEventArgs> LoadNetModule = new HandlerList<LoadNetModuleEventArgs>();
|
||||
public static HandlerList<ReadNetModuleEventArgs> ReadNetModule = new HandlerList<ReadNetModuleEventArgs>();
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace TShockAPI.Handlers.NetModules
|
|||
/// <param name="rejectPacket"></param>
|
||||
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
|
|||
/// <param name="powerType"></param>
|
||||
/// <param name="player"></param>
|
||||
/// <returns></returns>
|
||||
public static bool CheckPermission(CreativePowerTypes powerType, TSPlayer player)
|
||||
public static bool HasPermission(CreativePowerTypes powerType, TSPlayer player)
|
||||
{
|
||||
if (!PowerToPermissionMap.ContainsKey(powerType))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@ namespace TShockAPI.Handlers.NetModules
|
|||
/// <param name="data"></param>
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace TShockAPI.Handlers.NetModules
|
|||
/// <summary>
|
||||
/// Handles packet 82 - Load Net Module packets
|
||||
/// </summary>
|
||||
public class NetModulePacketHandler : IPacketHandler<LoadNetModuleEventArgs>
|
||||
public class NetModulePacketHandler : IPacketHandler<ReadNetModuleEventArgs>
|
||||
{
|
||||
/// <summary>
|
||||
/// 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
|
|||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue