TShock/TShockAPI/Handlers/NetModules/PylonHandler.cs
Chris 48d610d33f Move netmodule handling into handlers namespace
Add handler for teleport pylons, and permission for teleport pylons
2020-06-02 12:59:14 +09:30

62 lines
1.6 KiB
C#

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;
}
}
}