~ruther/NosSmooth.Comms

ref: 77c8ef1efe7650ba8602edd5c53415706878b5ec NosSmooth.Comms/src/Samples/ConsolePacketLogger/Program.cs -rw-r--r-- 2.5 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
//  Program.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 ConsolePacketLogger;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NosSmooth.Comms.Core.Extensions;
using NosSmooth.Comms.Local;
using NosSmooth.Comms.Local.Extensions;
using NosSmooth.Core.Extensions;
using NosSmooth.Core.Packets;
using NosSmooth.Data.Abstractions;
using NosSmooth.LocalBinding;
using Spectre.Console;

/// <summary>
/// A class with main.
/// </summary>
public static class Program
{
    /// <summary>
    /// A main.
    /// </summary>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public static async Task Main()
    {
        var processInitResults = CommsInjector.CreateNostaleProcesssesBrowsers().ToArray();

        if (processInitResults.Length == 0)
        {
            Console.WriteLine("Could not find any NosTale processes.");
            return;
        }

        foreach (var initResult in processInitResults.Where(x => !x.IsSuccess))
        {
            Console.WriteLine($"There was an error initializing browser manager for a process.");
            Console.WriteLine(initResult.ToFullString());
        }

        var nostaleProcesses = processInitResults.Where(x => x.IsSuccess).Select(x => x.Entity);

        var selectedProcess = AnsiConsole.Prompt
        (
            new SelectionPrompt<NosBrowserManager>()
                .Title("Choose NosTale process to log packets from.")
                .UseConverter
                (
                    x => x.IsInGame
                        ? $"{x.PlayerManager.Player.Name} ({x.Process.ProcessName} - {x.Process.Id})"
                        : $"Not in game ({x.Process.ProcessName} - {x.Process.Id})"
                )
                .AddChoices(nostaleProcesses)
        );

        var host = new HostBuilder()
            .ConfigureLogging(b => b.ClearProviders().AddConsole())
            .ConfigureServices
            (
                s => s
                    .Configure<PacketLoggerOptions>(o => o.ProcessId = selectedProcess.Process.Id)
                    .AddNostaleCore()
                    .AddSingleClientHandling()
                    .AddLocalComms()
                    .AddHostedService<ClientService>()
                    .AddScoped<IRawPacketResponder, EveryPacketResponder>()
            )
            .Build();

        await host.RunAsync();
    }
}
Do not follow this link