~ruther/NosSmooth.Local

ref: e17f06759be04b9bf33005d654a2305eca11d7ac NosSmooth.Local/src/Samples/LowLevel/SimpleChat/SayResponder.cs -rw-r--r-- 1.4 KiB
e17f0675 — Rutherther chore: update to .net 7 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
//
//  SayResponder.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.Core.Client;
using NosSmooth.Core.Packets;
using NosSmooth.Packets.Enums;
using NosSmooth.Packets.Enums.Chat;
using NosSmooth.Packets.Server.Chat;
using Remora.Results;

namespace SimpleChat;

/// <summary>
/// Responds to <see cref="SayPacket"/>.
/// </summary>
public class SayResponder : IPacketResponder<SayPacket>, IPacketResponder<MsgPacket>
{
    private readonly INostaleClient _client;

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

    /// <inheritdoc />
    public Task<Result> Respond(PacketEventArgs<SayPacket> packet, CancellationToken ct = default)
    {
        return _client.ReceivePacketAsync
        (
            new SayPacket(EntityType.Map, 1, SayColor.Red, "Hello world from NosSmooth!"),
            ct
        );
    }

    /// <inheritdoc />
    public Task<Result> Respond(PacketEventArgs<MsgPacket> packet, CancellationToken ct = default)
    {
        return _client.ReceivePacketAsync
        (
            new SayPacket(EntityType.Map, 1, SayColor.Red, "Hello world from NosSmooth!"),
            ct
        );
    }
}
Do not follow this link