~ruther/NosSmooth.Comms

ref: 77c8ef1efe7650ba8602edd5c53415706878b5ec NosSmooth.Comms/src/Local/NosSmooth.Comms.Inject/MessageResponders/PacketResponder.cs -rw-r--r-- 1.6 KiB
77c8ef1e — Rutherther ci: remove --output from dotnet pack, put output directory to Directory.Build.props 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
//  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;

/// <summary>
/// A responder to <see cref="RawPacketMessage"/> and <see cref="PacketMessage"/>.
/// </summary>
public class PacketResponder : IMessageResponder<RawPacketMessage>, IMessageResponder<PacketMessage>
{
    private readonly ManagedNostaleClient _client;

    /// <summary>
    /// Initializes a new instance of the <see cref="PacketResponder"/> class.
    /// </summary>
    /// <param name="client">The NosTale client.</param>
    public PacketResponder(ManagedNostaleClient client)
    {
        _client = client;
    }

    /// <inheritdoc />
    public Task<Result> Respond(RawPacketMessage message, CancellationToken ct = default)
    {
        if (message.Source == PacketSource.Client)
        {
            return _client.SendPacketAsync(message.Packet, ct);
        }

        return _client.ReceivePacketAsync(message.Packet, ct);
    }

    /// <inheritdoc />
    public Task<Result> Respond(PacketMessage message, CancellationToken ct = default)
    {
        if (message.Source == PacketSource.Client)
        {
            return _client.SendPacketAsync(message.Packet, ct);
        }

        return _client.ReceivePacketAsync(message.Packet, ct);
    }
}
Do not follow this link