Move netmodule handling into handlers namespace
Add handler for teleport pylons, and permission for teleport pylons
This commit is contained in:
parent
4d1fd54a7c
commit
48d610d33f
9 changed files with 401 additions and 152 deletions
62
TShockAPI/Handlers/NetModules/PylonHandler.cs
Normal file
62
TShockAPI/Handlers/NetModules/PylonHandler.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using System.IO;
|
||||
using System.IO.Streams;
|
||||
using Terraria.GameContent;
|
||||
using static Terraria.GameContent.NetModules.NetTeleportPylonModule;
|
||||
|
||||
namespace TShockAPI.Handlers.NetModules
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles a pylon net module
|
||||
/// </summary>
|
||||
public class PylonHandler : INetModuleHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Event occuring
|
||||
/// </summary>
|
||||
public SubPacketType PylonEventType { get; set; }
|
||||
/// <summary>
|
||||
/// Tile X coordinate of the pylon
|
||||
/// </summary>
|
||||
public short TileX { get; set; }
|
||||
/// <summary>
|
||||
/// Tile Y coordinate of the pylon
|
||||
/// </summary>
|
||||
public short TileY { get; set; }
|
||||
/// <summary>
|
||||
/// Type of Pylon
|
||||
/// </summary>
|
||||
public TeleportPylonType PylonType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reads the pylon data from the net module
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
public void Deserialize(MemoryStream data)
|
||||
{
|
||||
PylonEventType = (SubPacketType)data.ReadInt8();
|
||||
TileX = data.ReadInt16();
|
||||
TileY = data.ReadInt16();
|
||||
PylonType = (TeleportPylonType)data.ReadInt8();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rejects a pylon teleport request if the player does not have permission
|
||||
/// </summary>
|
||||
/// <param name="player"></param>
|
||||
/// <param name="rejectPacket"></param>
|
||||
public void HandlePacket(TSPlayer player, out bool rejectPacket)
|
||||
{
|
||||
if (PylonEventType == SubPacketType.PlayerRequestsTeleport)
|
||||
{
|
||||
if (!player.HasPermission(Permissions.pylon))
|
||||
{
|
||||
rejectPacket = true;
|
||||
player.SendErrorMessage("You do not have permission to teleport with pylons.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
rejectPacket = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue