servicepoint-tanks/tanks-backend/TanksServer/Interactivity/ClientScreenServer.cs

26 lines
920 B
C#
Raw Normal View History

2024-04-06 16:38:26 +02:00
using System.Net.WebSockets;
using DisplayCommands;
using TanksServer.Graphics;
2024-04-06 16:38:26 +02:00
2024-04-10 19:25:45 +02:00
namespace TanksServer.Interactivity;
2024-04-06 16:38:26 +02:00
2024-04-06 20:32:54 +02:00
internal sealed class ClientScreenServer(
ILogger<ClientScreenServer> logger,
ILoggerFactory loggerFactory,
IOptions<HostConfiguration> hostConfig
2024-04-21 23:00:44 +02:00
) : WebsocketServer<ClientScreenServerConnection>(logger), IFrameConsumer
2024-04-06 16:38:26 +02:00
{
private readonly TimeSpan _minFrameTime = TimeSpan.FromMilliseconds(hostConfig.Value.ClientDisplayMinFrameTimeMs);
2024-04-06 16:38:26 +02:00
2024-04-21 23:00:44 +02:00
public Task HandleClientAsync(WebSocket socket, Guid? playerGuid)
=> base.HandleClientAsync(new(
socket,
loggerFactory.CreateLogger<ClientScreenServerConnection>(),
_minFrameTime,
2024-04-21 23:00:44 +02:00
playerGuid
));
public Task OnFrameDoneAsync(GamePixelGrid gamePixelGrid, PixelGrid observerPixels)
2024-04-21 23:00:44 +02:00
=> ParallelForEachConnectionAsync(c => c.SendAsync(observerPixels, gamePixelGrid));
2024-04-13 12:33:08 +02:00
}