public async Task TryJoinGame(string groupName) { Game game = _games.FirstOrDefault(x => x.Id == groupName); int numberOfConnections = _matchListItemsService.GetNumberOfConnections(groupName); bool gameIsFull = (numberOfConnections == 2) ? true : false; if (gameIsFull) { await Clients.Caller.SendAsync("RedirectToHomeGameWasFull"); return; } _matchListItemsService.AddConnection(groupName); await SendNotificationAboutOpponentJoinedToTheGameIfGroupExist(groupName); _groups.Add(Context.ConnectionId, groupName); await Groups.AddToGroupAsync(Context.ConnectionId, groupName); bool firstConnection = (game == null) ? true : false; if (firstConnection) { _games.Add(new Game() { Id = groupName }); return; } bool gameIsPaused = (game.Status != null && game.Status != GameStatus.Ended) ? true : false; if (gameIsPaused) { ReconnectToTheGame(game); } else if (!gameIsPaused) { game = await CreateGame(groupName); SetGameToCharacterSelect(game); } }
private bool CheckIfGameIsFull(string groupName) { int numberOfConnections = _matchListItemsService.GetNumberOfConnections(groupName); return(numberOfConnections == 2); }
public async Task <int> Handle(GetNumberOfConnectionsByUrlQuery request, CancellationToken cancellationToken) { return(_matchListItemsService.GetNumberOfConnections(request.Url)); }