53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration.Yaml;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Tiger.Communication.Messages;
|
|
using Tiger.Communication.Messages.Interfaces;
|
|
using Tiger.Game.Navigator;
|
|
using Tiger.Game.Rooms;
|
|
using Tiger.Game.Settings;
|
|
using Tiger.Networking.Game;
|
|
using Tiger.Networking.Game.Sessions;
|
|
using Tiger.Storage;
|
|
using Tiger.Utils;
|
|
|
|
var quitEvent = new ManualResetEvent(false);
|
|
|
|
Console.CancelKeyPress += (sender, e) =>
|
|
{
|
|
quitEvent.Set();
|
|
e.Cancel = true;
|
|
};
|
|
|
|
var configuration = new ConfigurationBuilder()
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|
.AddYamlFile("appsettings.yaml")
|
|
.Build();
|
|
|
|
var collection = new ServiceCollection();
|
|
collection.AddLogging(builder => builder.AddConsole());
|
|
collection.AddSingleton<IConfiguration>(configuration);
|
|
collection.AddSingleton<IGameSessionManager, GameSessionManager>();
|
|
collection.AddSingleton<IMessageHandler, MessageHandler>();
|
|
collection.AddSingleton<INhSessionFactory, NhSessionFactory>();
|
|
collection.AddScoped(serviceProvider => serviceProvider.GetRequiredService<INhSessionFactory>().OpenSession());
|
|
collection.AddScoped(typeof(IRepository<>), typeof(Repository<>));
|
|
collection.AddSingleton<ISettingManager, SettingManager>();
|
|
collection.AddSingleton<INavigatorManager, NavigatorManager>();
|
|
collection.AddSingleton<IRoomManager, RoomManager>();
|
|
collection.RegisterOnInherited<IMessageEvent>();
|
|
collection.RegisterOnInherited<TcpServer>();
|
|
|
|
var provider = collection.BuildServiceProvider();
|
|
|
|
await provider.GetRequiredService<ISettingManager>().ReloadSettingsAsync();
|
|
await provider.GetRequiredService<INavigatorManager>().LoadNodesAsync();
|
|
await provider.GetRequiredService<IRoomManager>().LoadModelsAsync();
|
|
|
|
foreach (var server in provider.GetServices<TcpServer>())
|
|
{
|
|
server.Start();
|
|
}
|
|
|
|
quitEvent.WaitOne(); |