~ruther/NosSmooth

ref: 11c5d9f159e5de5d2b70b363b405d7598632fa73 NosSmooth/Samples/SimpleChat/SayResponder.cs -rw-r--r-- 1.7 KiB
11c5d9f1 — František Boháček feat: pass event args to packet responders instead of plain packets 3 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
53
54
55
56
57
//
//  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 NosCore.Packets.Enumerations;
using NosCore.Packets.ServerPackets.Chats;
using NosCore.Packets.ServerPackets.UI;
using NosCore.Shared.Enumerations;
using NosSmooth.Core.Client;
using NosSmooth.Core.Packets;
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()
            {
                Message = "Hello world from NosSmooth!", VisualType = VisualType.Player, Type = SayColorType.Red, VisualId = 1,
            },
            ct);
    }

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