continuity/Continuity.AuthServer/Consumers/PacketConsumer.cs

41 lines
1.4 KiB
C#
Raw Normal View History

2024-02-07 15:40:36 +00:00
// Licensed to Timothy Schenk under the GNU AGPL Version 3 License.
2023-11-20 18:58:30 +00:00
2024-02-05 17:20:57 +00:00
using System.Diagnostics;
using Continuity.AuthServer.Packets;
2024-02-05 08:16:42 +00:00
using JetBrains.Annotations;
using MassTransit;
using Rai.PacketMediator;
using Wonderking.Packets;
2023-11-19 16:07:28 +00:00
namespace Continuity.AuthServer.Consumers;
2023-08-09 14:23:41 +00:00
2024-02-05 08:16:42 +00:00
[UsedImplicitly]
2024-02-07 08:42:52 +00:00
public class PacketConsumer : IConsumer<RawPacket>, IDisposable
2023-08-09 14:23:41 +00:00
{
2024-02-05 17:20:57 +00:00
private readonly ActivitySource _activitySource;
2024-02-07 15:40:36 +00:00
private readonly PacketDistributorService<OperationCode, AuthSession> _distributorService;
2024-02-05 10:43:58 +00:00
2024-02-05 17:20:57 +00:00
public PacketConsumer(PacketDistributorService<OperationCode, AuthSession> distributorService)
2023-11-19 16:07:28 +00:00
{
_distributorService = distributorService;
2024-02-05 17:20:57 +00:00
_activitySource = new ActivitySource(nameof(PacketConsumer));
2023-11-19 16:07:28 +00:00
}
2023-08-09 14:23:41 +00:00
2023-08-09 18:14:14 +00:00
public Task Consume(ConsumeContext<RawPacket> context)
2023-08-09 14:23:41 +00:00
{
2024-02-05 17:20:57 +00:00
using var activity = _activitySource?.StartActivity("PacketConsumption");
activity?.SetTag("PacketId", context.Message.OperationCode.ToString());
activity?.SetTag("SessionId", context.Message.Session.Id.ToString());
activity?.SetTag("PacketSize", context.Message.MessageBody.Length);
2024-02-05 10:43:58 +00:00
2024-02-05 17:20:57 +00:00
return _distributorService.AddPacketAsync(context.Message.MessageBody, context.Message.OperationCode,
context.Message.Session);
2023-08-09 14:23:41 +00:00
}
2024-02-07 08:42:52 +00:00
public void Dispose()
{
_activitySource.Dispose();
GC.SuppressFinalize(this);
}
2023-08-11 09:31:30 +00:00
}