2023-11-21 20:37:50 +00:00
|
|
|
// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
|
2023-11-20 18:58:30 +00:00
|
|
|
|
2023-11-25 13:58:58 +00:00
|
|
|
using System.Diagnostics;
|
2023-11-19 16:07:28 +00:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
using NetCoreServer;
|
2023-10-27 17:47:17 +00:00
|
|
|
using Wonderking.Packets;
|
|
|
|
|
2024-01-29 07:39:18 +00:00
|
|
|
namespace Continuity.AuthServer.PacketHandlers;
|
2023-08-10 08:47:35 +00:00
|
|
|
|
2023-08-13 12:12:04 +00:00
|
|
|
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
|
2023-11-22 13:55:46 +00:00
|
|
|
public interface IPacketHandler<in T> : IPacketHandler where T : IPacket
|
2023-08-09 14:23:41 +00:00
|
|
|
{
|
2023-08-12 21:02:59 +00:00
|
|
|
[UsedImplicitly]
|
2023-08-10 23:16:51 +00:00
|
|
|
public Task HandleAsync(T packet, TcpSession session);
|
2023-11-22 13:55:46 +00:00
|
|
|
|
|
|
|
async Task<bool> IPacketHandler.TryHandleAsync(IPacket packet, TcpSession session)
|
|
|
|
{
|
2023-11-24 17:29:57 +00:00
|
|
|
if (packet is not T tPacket)
|
2023-11-22 13:55:46 +00:00
|
|
|
{
|
2023-11-24 17:29:57 +00:00
|
|
|
return false;
|
2023-11-22 13:55:46 +00:00
|
|
|
}
|
|
|
|
|
2023-11-25 13:58:58 +00:00
|
|
|
using (var activity = new ActivitySource(nameof(Server)).StartActivity("HandleAsync"))
|
|
|
|
{
|
|
|
|
activity?.SetTag("Handler", this.ToString());
|
2023-11-25 14:15:34 +00:00
|
|
|
activity?.SetTag("PacketId", packet.ToString());
|
2023-11-25 13:58:58 +00:00
|
|
|
await HandleAsync(tPacket, session);
|
|
|
|
}
|
2023-11-24 17:29:57 +00:00
|
|
|
|
|
|
|
return true;
|
2023-11-22 13:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface IPacketHandler
|
|
|
|
{
|
|
|
|
Task<bool> TryHandleAsync(IPacket packet, TcpSession session);
|
2023-08-11 09:31:30 +00:00
|
|
|
}
|