2024-02-07 16:40:36 +01:00
|
|
|
// Licensed to Timothy Schenk under the GNU AGPL Version 3 License.
|
2023-11-20 19:58:30 +01:00
|
|
|
|
2024-02-05 18:20:57 +01:00
|
|
|
using System.Diagnostics;
|
2024-01-29 08:39:18 +01:00
|
|
|
using Continuity.AuthServer.Packets;
|
2024-02-05 09:16:42 +01:00
|
|
|
using JetBrains.Annotations;
|
2023-08-12 23:02:59 +02:00
|
|
|
using MassTransit;
|
2024-02-04 19:52:45 +01:00
|
|
|
using Rai.PacketMediator;
|
|
|
|
using Wonderking.Packets;
|
2023-11-19 17:07:28 +01:00
|
|
|
|
2024-01-29 08:39:18 +01:00
|
|
|
namespace Continuity.AuthServer.Consumers;
|
2023-08-09 16:23:41 +02:00
|
|
|
|
2024-02-05 09:16:42 +01:00
|
|
|
[UsedImplicitly]
|
2024-03-02 13:15:13 +01:00
|
|
|
public sealed class PacketConsumer : IConsumer<RawPacket>, IDisposable
|
2023-08-09 16:23:41 +02:00
|
|
|
{
|
2024-02-05 18:20:57 +01:00
|
|
|
private readonly ActivitySource _activitySource;
|
2024-02-07 16:40:36 +01:00
|
|
|
private readonly PacketDistributorService<OperationCode, AuthSession> _distributorService;
|
2024-02-05 11:43:58 +01:00
|
|
|
|
2024-02-05 18:20:57 +01:00
|
|
|
public PacketConsumer(PacketDistributorService<OperationCode, AuthSession> distributorService)
|
2023-11-19 17:07:28 +01:00
|
|
|
{
|
|
|
|
_distributorService = distributorService;
|
2024-02-05 18:20:57 +01:00
|
|
|
_activitySource = new ActivitySource(nameof(PacketConsumer));
|
2023-11-19 17:07:28 +01:00
|
|
|
}
|
2023-08-09 16:23:41 +02:00
|
|
|
|
2024-03-02 13:15:13 +01:00
|
|
|
public async Task Consume(ConsumeContext<RawPacket> context)
|
2023-08-09 16:23:41 +02:00
|
|
|
{
|
2024-02-05 18:20:57 +01: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 11:43:58 +01:00
|
|
|
|
2024-03-02 13:15:13 +01:00
|
|
|
await _distributorService.AddPacketAsync(context.Message.MessageBody, context.Message.OperationCode,
|
2024-02-05 18:20:57 +01:00
|
|
|
context.Message.Session);
|
2023-08-09 16:23:41 +02:00
|
|
|
}
|
2024-02-07 09:42:52 +01:00
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
_activitySource.Dispose();
|
|
|
|
}
|
2023-08-11 11:31:30 +02:00
|
|
|
}
|