Beispiel #1
0
        public async Task LobbySocket()
        {
            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")
                };
            }
            LobbySocketHandler handler = new LobbySocketHandler(ws, client, lobbySocketHandlerRepository, seekRepository, gameRepository, randomProvider, userRepository);

            lobbySocketHandlerRepository.Add(handler);
            await handler.LobbyLoop();
        }
 public void Add(LobbySocketHandler handler)
 {
     handlers.Add(handler);
 }