Ejemplo n.º 1
0
        private async Task AddConnection(string groupName)
        {
            _matchListItemsService.AddConnection(groupName);
            SendNotificationAboutOpponentJoinedToTheGameIfGroupExist(groupName);

            _groups.Add(Context.ConnectionId, groupName);
            Groups.AddToGroupAsync(Context.ConnectionId, groupName);
        }
Ejemplo n.º 2
0
        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);
            }
        }
            public async Task <Unit> Handle(AddConnectionCommand request, CancellationToken cancellationToken)
            {
                _matchListItemsService.AddConnection(request.Url);

                return(Unit.Value);
            }