~ruther/NosSmooth

ref: 2cebbe162d835dc098237a3ce08bccb4173a7c06 NosSmooth/Samples/FileClient/Program.cs -rw-r--r-- 2.1 KiB
2cebbe16 — František Boháček feat(samples): add sample with loading data from a file 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
58
59
60
61
62
63
64
65
66
//
//  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 Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NosSmooth.Core.Client;
using NosSmooth.Core.Commands;
using NosSmooth.Core.Extensions;
using NosSmooth.Core.Packets;
using NosSmooth.Data.Abstractions.Language;
using NosSmooth.Data.NOSFiles.Extensions;
using NosSmooth.Data.NOSFiles.Options;
using NosSmooth.Game.Extensions;
using NosSmooth.Packets;

namespace FileClient;

/// <summary>
/// An entrypoint class.
/// </summary>
public static class Program
{
    // TODO: create console hosting.

    /// <summary>
    /// An entrypoint method.
    /// </summary>
    /// <param name="args">The command line arguments.</param>
    /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
    public static async Task Main(string[] args)
    {
        await using FileStream stream = File.OpenRead(string.Join(' ', args));
        await CreateHost(stream).StartAsync();
    }

    private static IHost CreateHost(Stream fileStream)
    {
        return Host.CreateDefaultBuilder()
            .ConfigureServices(coll =>
            {
                coll.AddHostedService<App>();

                coll.AddNostaleCore()
                    .AddNostaleGame()
                    .AddNostaleDataFiles()
                    .Configure<LanguageServiceOptions>(o => o.Language = Language.Cz)
                    .Configure<NostaleDataOptions>(o => o.SupportedLanguages = new[]
                    {
                        Language.Cz
                    });
                coll.AddSingleton<INostaleClient>(p => new Client(
                    fileStream,
                    p.GetRequiredService<IPacketHandler>(),
                    p.GetRequiredService<CommandProcessor>(),
                    p.GetRequiredService<IPacketSerializer>(),
                    p.GetRequiredService<ILogger<Client>>()
                ));
            })
            .UseConsoleLifetime()
            .Build();
    }
}
Do not follow this link