This commit is contained in:
skidfire
2026-09-06 19:59:27 -04:00
parent 55d8e11a5d
commit fe3468c65d
247 changed files with 338183 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
using Microsoft.AspNetCore.SignalR;
namespace Vanadium.Hubs
{
public abstract class AuthenticatedHub : Hub
{
protected long PlayerId
{
get
{
var raw = Context.UserIdentifier;
if (raw == null || !long.TryParse(raw, out var id))
throw new HubException("Unauthorized");
return id;
}
}
public override async Task OnConnectedAsync()
{
if (Context.UserIdentifier == null)
{
Context.Abort();
return;
}
await Groups.AddToGroupAsync(Context.ConnectionId, $"player:{PlayerId}");
await base.OnConnectedAsync();
}
public override async Task OnDisconnectedAsync(Exception? exception)
{
await Groups.RemoveFromGroupAsync(Context.ConnectionId, $"player:{PlayerId}");
await base.OnDisconnectedAsync(exception);
}
}
}