continuity/Server/PacketHandlers/IPacketHandler.cs

31 lines
761 B
C#

// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
using JetBrains.Annotations;
using NetCoreServer;
using Wonderking.Packets;
namespace Server.PacketHandlers;
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
public interface IPacketHandler<in T> : IPacketHandler where T : IPacket
{
[UsedImplicitly]
public Task HandleAsync(T packet, TcpSession session);
async Task<bool> IPacketHandler.TryHandleAsync(IPacket packet, TcpSession session)
{
if (packet is not T tPacket)
{
return false;
}
await HandleAsync(tPacket, session);
return true;
}
}
public interface IPacketHandler
{
Task<bool> TryHandleAsync(IPacket packet, TcpSession session);
}