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); } }
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); } } }
public async Task <Unit> Handle(RemoveConnectionCommand request, CancellationToken cancellationToken) { _matchListItemsService.RemoveConnection(request.Url); return(Unit.Value); }