VanguardReMaster/server/src/Vanguard.Server/Program.cs

55 lines
1.9 KiB
C#

using Microsoft.Extensions.Options;
using Vanguard.Content;
using Vanguard.Rules.Cards;
using Vanguard.Server.Api;
using Vanguard.Server.Configuration;
using Vanguard.Server.Matches;
using Vanguard.Server.Matchmaking;
using Vanguard.Server.Profiles;
using Vanguard.Server.Realtime;
using Vanguard.Server.Tickets;
var builder = WebApplication.CreateBuilder(args);
builder.Services.Configure<GameOptions>(builder.Configuration.GetSection("Game"));
builder.Services.Configure<ContentOptions>(builder.Configuration.GetSection("Content"));
builder.Services.AddSingleton(sp => sp.GetRequiredService<IOptions<GameOptions>>().Value);
builder.Services.AddSingleton(sp => sp.GetRequiredService<IOptions<ContentOptions>>().Value);
builder.Services.AddSingleton(TimeProvider.System);
builder.Services.AddSingleton(sp =>
{
var content = sp.GetRequiredService<ContentOptions>();
var directory = ContentPaths.Resolve(content.Path);
return CatalogLoader.LoadDirectory(directory);
});
builder.Services.AddSingleton<GameTicketService>();
builder.Services.AddSingleton<PlayerProfileStore>();
builder.Services.AddSingleton<IMatchResultSink>(sp => sp.GetRequiredService<PlayerProfileStore>());
builder.Services.AddSingleton<MatchGrainRegistry>();
builder.Services.AddSingleton<MatchmakingService>();
builder.Services.AddHostedService<MatchTicker>();
builder.Services.AddHostedService<MatchmakingWorker>();
var app = builder.Build();
// каталог грузим сразу: сервер без карт бесполезен, лучше упасть на старте
app.Services.GetRequiredService<CardCatalog>();
app.UseWebSockets(new WebSocketOptions
{
KeepAliveInterval = TimeSpan.FromSeconds(30),
});
app.MapGameApi();
app.Map("/game", GameWebSocketEndpoint.HandleAsync);
app.Run();
/// <summary>Точка входа доступна интеграционным тестам через WebApplicationFactory.</summary>
public partial class Program
{
}