//
// PacketResponder.cs
//
// Copyright (c) František Boháček. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using NosSmooth.Comms.Data.Messages;
using NosSmooth.Comms.Data.Responders;
using NosSmooth.Core.Client;
using NosSmooth.PacketSerializer.Abstractions.Attributes;
using Remora.Results;
namespace NosSmooth.Comms.Inject.MessageResponders;
///
/// A responder to and .
///
public class PacketResponder : IMessageResponder, IMessageResponder
{
private readonly ManagedNostaleClient _client;
///
/// Initializes a new instance of the class.
///
/// The NosTale client.
public PacketResponder(ManagedNostaleClient client)
{
_client = client;
}
///
public Task Respond(RawPacketMessage message, CancellationToken ct = default)
{
if (message.Source == PacketSource.Client)
{
return _client.SendPacketAsync(message.Packet, ct);
}
return _client.ReceivePacketAsync(message.Packet, ct);
}
///
public Task Respond(PacketMessage message, CancellationToken ct = default)
{
if (message.Source == PacketSource.Client)
{
return _client.SendPacketAsync(message.Packet, ct);
}
return _client.ReceivePacketAsync(message.Packet, ct);
}
}