// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License. using System.Diagnostics; using JetBrains.Annotations; using NetCoreServer; using Wonderking.Packets; namespace Server.PacketHandlers; [UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)] public interface IPacketHandler : IPacketHandler where T : IPacket { [UsedImplicitly] public Task HandleAsync(T packet, TcpSession session); async Task IPacketHandler.TryHandleAsync(IPacket packet, TcpSession session) { var activitySource = new ActivitySource(nameof(Server)); using var activity = activitySource.StartActivity("PacketHandlerHandleAsync"); if (packet is not T tPacket) { return false; } activity.SetTag("packetName", packet.ToString()); activity.SetTag("handlerName", this.ToString()); await HandleAsync(tPacket, session); return true; } } public interface IPacketHandler { Task TryHandleAsync(IPacket packet, TcpSession session); }