2024-02-04 18:52:45 +00:00
|
|
|
// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
|
|
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
|
|
|
namespace Rai.PacketMediator;
|
|
|
|
|
|
|
|
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
|
|
|
|
public interface IPacketHandler<in T, in S> : IPacketHandler<S> where T : IIncomingPacket
|
|
|
|
{
|
2024-02-05 08:02:27 +00:00
|
|
|
[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
|
2024-02-04 18:52:45 +00:00
|
|
|
public Task HandleAsync(T packet, S session);
|
|
|
|
|
|
|
|
async Task<bool> IPacketHandler<S>.TryHandleAsync(IIncomingPacket packet, S session)
|
|
|
|
{
|
|
|
|
if (packet is not T tPacket)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
using var activity = new ActivitySource(nameof(PacketMediator)).StartActivity(nameof(HandleAsync));
|
|
|
|
activity?.AddTag("Handler", this.ToString());
|
|
|
|
activity?.AddTag("Packet", packet.ToString());
|
|
|
|
await HandleAsync(tPacket, session);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface IPacketHandler<in S>
|
|
|
|
{
|
|
|
|
Task<bool> TryHandleAsync(IIncomingPacket packet, S session);
|
|
|
|
}
|