Exemple #1
0
        public override Task OnDisconnectedAsync(Exception exception)
        {
            Game game = _triviaService.GetCurrentGame(Context.ConnectionId);

            if (game != null)
            {
                Player player = _triviaService.GetCurrentPlayer(Context.ConnectionId);
                game.Players.Remove(player);

                if (game.Players.Count == 0)
                {
                    _triviaService.DeleteGame(game);
                }
                else
                {
                    SendDataToPlayers(game, "gameStateChange", game);
                }
            }

            _triviaService.CheckForStaleGames(); //Unrelated to this game, but safety check to avoid memory leak

            return(base.OnDisconnectedAsync(exception));
        }