refactor(battle-node): distinct WS auth status codes + named handler delegate

This commit is contained in:
gamer147
2026-06-01 11:45:50 -04:00
parent a364f539ad
commit 2588388d9d
2 changed files with 20 additions and 8 deletions

View File

@@ -51,11 +51,19 @@ public static class BattleNodeExtensions
public static IApplicationBuilder UseBattleNode(this IApplicationBuilder app)
{
app.UseWebSockets();
app.Map("/socket.io", branch => branch.Run(async ctx =>
{
var handler = ctx.RequestServices.GetRequiredService<BattleNodeWebSocketHandler>();
await handler.HandleAsync(ctx);
}));
app.Map("/socket.io", branch => branch.Run(HandleSocketIoAsync));
return app;
}
/// <summary>
/// Terminal handler for <c>/socket.io/*</c> — resolves the singleton
/// <see cref="BattleNodeWebSocketHandler"/> from DI and hands the request over.
/// Extracted from the inline lambda in <see cref="UseBattleNode"/> so stack traces
/// show a real method name during WS connect failures.
/// </summary>
private static async Task HandleSocketIoAsync(Microsoft.AspNetCore.Http.HttpContext ctx)
{
var handler = ctx.RequestServices.GetRequiredService<BattleNodeWebSocketHandler>();
await handler.HandleAsync(ctx);
}
}