Пример #1
0
        public async Task Close(long sessionId)
        {
            GameSession session = await GetById(sessionId);

            session.IsOpen = false;
            await _sessionRepository.Update(session);
        }
Пример #2
0
        public IActionResult Continue()
        {
            var sessionCookieData =
                Request.Cookies.Get <SessionCookieData>(Strings.SessionDataCookieName, _dataProtectionProvider);

            if (sessionCookieData != null)
            {
                var gameSession = _gameSessionRepository.GetById(sessionCookieData.Id);
                if (gameSession.State == GameState.Passed || gameSession.State == GameState.Stopped)
                {
                    return(BadRequest(new ErrorResponse(3, "Already passed or stopped this game session.")));
                }
                gameSession.State = GameState.Continued;
                _gameSessionRepository.Update(gameSession);
                sessionCookieData.GameState = GameState.Continued;
                Response.Cookies.Set(Strings.SessionDataCookieName, sessionCookieData, _dataProtectionProvider);
            }

            return(Ok());
        }
Пример #3
0
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            if (Context.Items.TryGetValue("Group", out var groupItem))
            {
                string groupName = (string)groupItem;

                var gameSession = ActiveGameSessions.FirstOrDefault(x => x.GroupName == groupName);
                if (gameSession?.ConnectedClients == 1)
                {
                    gameSession.ConnectedClients--;
                    await sessionsRepository.Update(gameSession);
                }
                else
                {
                    if (gameSession != null)
                    {
                        gameSession.ConnectedClients--;
                    }
                }

                await Groups.RemoveFromGroupAsync(Context.ConnectionId, groupName);
            }
            await base.OnDisconnectedAsync(exception);
        }