~ruther/NosSmooth

1b594fcb66a3c5f4b2703aa60e0eec602ddc68ca — František Boháček 3 years ago 0488673
fix: use NosSmooth.Packets in SimpleChat sample
2 files changed, 29 insertions(+), 39 deletions(-)

M Samples/SimpleChat/SayResponder.cs
M Samples/SimpleChat/SimpleChat.cs
M Samples/SimpleChat/SayResponder.cs => Samples/SimpleChat/SayResponder.cs +13 -19
@@ 4,12 4,11 @@
//  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 NosSmooth.Packets.Enums;
using NosSmooth.Packets.Enums.Chat;
using NosSmooth.Packets.Packets.Server.Chat;
using Remora.Results;

namespace SimpleChat;


@@ 33,25 32,20 @@ public class SayResponder : IPacketResponder<SayPacket>, IPacketResponder<MsgPac
    /// <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);
        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()
            {
                Message = "Hello world from NosSmooth!",
                VisualType = VisualType.Player,
                Type = SayColorType.Red,
                VisualId = 1,
            },
            ct);
        return _client.ReceivePacketAsync
        (
            new SayPacket(EntityType.Map, 1, SayColor.Red, "Hello world from NosSmooth!"),
            ct
        );
    }
}
\ No newline at end of file

M Samples/SimpleChat/SimpleChat.cs => Samples/SimpleChat/SimpleChat.cs +16 -20
@@ 6,12 6,11 @@

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NosCore.Packets.Enumerations;
using NosCore.Packets.ServerPackets.Chats;
using NosCore.Shared.Enumerations;
using NosSmooth.Core.Client;
using NosSmooth.Core.Packets;
using NosSmooth.LocalClient.Extensions;
using NosSmooth.Packets.Enums;
using NosSmooth.Packets.Enums.Chat;
using NosSmooth.Packets.Packets.Server.Chat;

namespace SimpleChat;



@@ 30,29 29,26 @@ public class SimpleChat
            .AddLocalClient()

            // .AddPacketResponder<SayResponder>()
            .AddLogging(b =>
            {
                b.ClearProviders();
                b.AddConsole();
                b.SetMinimumLevel(LogLevel.Debug);
            })
            .AddLogging
            (
                b =>
                {
                    b.ClearProviders();
                    b.AddConsole();
                    b.SetMinimumLevel(LogLevel.Debug);
                }
            )
            .BuildServiceProvider();

        var dummy1 = provider.GetRequiredService<PacketSerializerProvider>().ServerSerializer;
        var dummy2 = provider.GetRequiredService<PacketSerializerProvider>().ClientSerializer;

        var logger = provider.GetRequiredService<ILogger<SimpleChat>>();
        logger.LogInformation("Hello world from SimpleChat!");

        var client = provider.GetRequiredService<INostaleClient>();

        await client.ReceivePacketAsync(new SayPacket()
        {
            Message = "Hello world from NosSmooth!",
            VisualType = VisualType.Player,
            Type = SayColorType.Red,
            VisualId = 1,
        });
        await client.ReceivePacketAsync
        (
            new SayPacket(EntityType.Map, 1, SayColor.Red, "Hello world from NosSmooth!")
        );

        await client.RunAsync();
    }

Do not follow this link