Ejemplo n.º 1
0
        private async Task Disconnect()
        {
            Game game = _games.FirstOrDefault(x => x.Id == _groups[Context.ConnectionId]);

            _matchListItemsService.RemoveConnection(game.Id);
            await LeaveGroupIfGamesContainsConnectionId();

            if (game is null)
            {
                return;
            }

            RemoveUserInformationsFromTheGame(game);


            bool gameIsEmpty = CheckIfGameIsEmpty(game.Id);

            if (gameIsEmpty)
            {
                _matchListItemsService.RemoveMatchByUrl(game.Id);
                _games.Remove(game);

                return;
            }

            Clients.Group(game.Id).SendAsync("SendNotificationThatYourOpponentLeftTheGame");

            if (game.Status != GameStatus.Ended)
            {
                PuaseTheGame(game);
            }
        }
Ejemplo n.º 2
0
        private async Task Disconnect()
        {
            Game game = _games.FirstOrDefault(x => x.Id == _groups[Context.ConnectionId]);

            _matchListItemsService.RemoveConnection(game.Id);
            await LeaveGroupIfGamesContainsConnectionId();

            if (game == null)
            {
                return;
            }

            RemoveUserInformationsFromTheGame(game);

            int  numberOfConnectionsInCurrentGroup = _groups.Where(x => x.Value == game.Id).Count();
            bool gameIsEmpty = (numberOfConnectionsInCurrentGroup == 0) ? true : false;

            if (gameIsEmpty)
            {
                _matchListItemsService.RemoveMatchByUrl(game.Id);
                _games.Remove(game);
            }
            else if (!gameIsEmpty)
            {
                Clients.Group(game.Id).SendAsync("SendNotificationThatYourOpponentLeftTheGame");

                if (game.Status != GameStatus.Ended)
                {
                    PuaseTheGame(game);
                }
            }
        }
Ejemplo n.º 3
0
            public async Task <Unit> Handle(RemoveMatchByUrlCommand request, CancellationToken cancellationToken)
            {
                _matchListItemsService.RemoveMatchByUrl(request.Url);

                return(Unit.Value);
            }