live player info in client

This commit is contained in:
Vinzenz Schroeter 2024-04-22 19:03:07 +02:00
parent fb675e59ff
commit a50a9770c9
14 changed files with 193 additions and 70 deletions

View file

@ -33,11 +33,18 @@ internal static class Endpoints
: Results.Unauthorized();
});
app.MapGet("/player", ([FromQuery] Guid id) =>
playerService.TryGet(id, out var foundPlayer)
? Results.Ok((object?)foundPlayer)
: Results.NotFound()
);
app.MapGet("/player", async (HttpContext context, [FromQuery] Guid id) =>
{
if (!playerService.TryGet(id, out var foundPlayer))
return Results.NotFound();
if (!context.WebSockets.IsWebSocketRequest)
return Results.Ok((object?)foundPlayer);
using var ws = await context.WebSockets.AcceptWebSocketAsync();
await playerService.HandleClientAsync(ws, foundPlayer);
return Results.Empty;
});
app.MapGet("/scores", () => playerService.GetAll());