public async Task GameSocket(string id) { if (!HttpContext.WebSockets.IsWebSocketRequest) { HttpContext.Response.StatusCode = 418; return; } WebSocket ws = await HttpContext.WebSockets.AcceptWebSocketAsync(); GamePlayer client; int? userId = loginHandler.LoggedInUserId(HttpContext); if (userId.HasValue) { client = new RegisteredPlayer() { UserId = userId.Value }; } else { if (HttpContext.Session.GetString("anonymousIdentifier") == null) { HttpContext.Response.StatusCode = 400; return; } client = new AnonymousPlayer() { AnonymousIdentifier = HttpContext.Session.GetString("anonymousIdentifier") }; } GameSocketHandler handler = new GameSocketHandler(ws, client, gameRepoForSocketHandlers, gameSocketHandlerRepository, moveCollectionTransformer, userRepository, randomProvider, id); if (!handler.GameExists) { HttpContext.Response.StatusCode = 400; return; } gameSocketHandlerRepository.Add(handler); await handler.LobbyLoop(); }
public void Add(GameSocketHandler handler) { handlers.Add(handler); }