34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using Microsoft.Extensions.Options;
|
|
|
|
namespace NeonSprawl.Server.Game.PositionState;
|
|
|
|
/// <summary>Runs DDL and dev-player seed once when the host starts (PostgreSQL path only).</summary>
|
|
internal sealed class PostgresDevPlayerSeedHostedService : IHostedService
|
|
{
|
|
private readonly Npgsql.NpgsqlDataSource _dataSource;
|
|
private readonly GamePositionOptions _options;
|
|
|
|
public PostgresDevPlayerSeedHostedService(
|
|
Npgsql.NpgsqlDataSource dataSource,
|
|
IOptions<GamePositionOptions> options)
|
|
{
|
|
_dataSource = dataSource;
|
|
var o = options.Value;
|
|
if (string.IsNullOrWhiteSpace(o.DevPlayerId))
|
|
{
|
|
throw new InvalidOperationException("Game:DevPlayerId must be non-empty.");
|
|
}
|
|
|
|
_options = o;
|
|
}
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
PostgresPositionBootstrap.EnsureSchema(_dataSource);
|
|
PostgresPositionBootstrap.SeedDevPlayer(_dataSource, _options);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
}
|