diff --git a/tanks-backend/TanksServer/Interactivity/SendToServicePointDisplay.cs b/tanks-backend/TanksServer/Interactivity/SendToServicePointDisplay.cs index 5625566..fc64cc9 100644 --- a/tanks-backend/TanksServer/Interactivity/SendToServicePointDisplay.cs +++ b/tanks-backend/TanksServer/Interactivity/SendToServicePointDisplay.cs @@ -18,6 +18,7 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer private readonly PlayerServer _players; private readonly Cp437Grid _scoresBuffer; private readonly TimeSpan _minFrameTime; + private readonly IOptionsMonitor _options; private DateTime _nextFailLogAfter = DateTime.Now; private DateTime _nextFrameAfter = DateTime.Now; @@ -27,7 +28,8 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer ILogger logger, IDisplayConnection displayConnection, IOptions hostOptions, - MapService mapService + MapService mapService, + IOptionsMonitor options ) { _players = players; @@ -35,6 +37,7 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer _displayConnection = displayConnection; _mapService = mapService; _minFrameTime = TimeSpan.FromMilliseconds(hostOptions.Value.ServicePointDisplayMinFrameTimeMs); + _options = options; var localIp = _displayConnection.GetLocalIPv4().Split('.'); Debug.Assert(localIp.Length == 4); @@ -50,6 +53,9 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer public async Task OnFrameDoneAsync(GamePixelGrid gamePixelGrid, PixelGrid observerPixels) { + if (!_options.CurrentValue.EnableServicePointDisplay) + return; + if (DateTime.Now < _nextFrameAfter) return; diff --git a/tanks-backend/TanksServer/Program.cs b/tanks-backend/TanksServer/Program.cs index 91c14fe..efe9bb4 100644 --- a/tanks-backend/TanksServer/Program.cs +++ b/tanks-backend/TanksServer/Program.cs @@ -1,7 +1,6 @@ using System.IO; using DisplayCommands; using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using TanksServer.GameLogic; @@ -54,11 +53,6 @@ public static class Program var healthCheckBuilder = builder.Services.AddHealthChecks(); healthCheckBuilder.AddCheck("updates check"); - builder.Services.Configure(builder.Configuration.GetSection("Host")); - var hostConfiguration = builder.Configuration.GetSection("Host").Get(); - if (hostConfiguration == null) - throw new InvalidOperationException("'Host' configuration missing"); - builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); @@ -99,12 +93,10 @@ public static class Program sp.GetRequiredService()); builder.Services.Configure(builder.Configuration.GetSection("GameRules")); + builder.Services.Configure(builder.Configuration.GetSection("Host")); - if (hostConfiguration.EnableServicePointDisplay) - { - builder.Services.AddSingleton(); - builder.Services.AddDisplay(builder.Configuration.GetSection("ServicePointDisplay")); - } + builder.Services.AddSingleton(); + builder.Services.AddDisplay(builder.Configuration.GetSection("ServicePointDisplay")); var app = builder.Build();