コード例 #1
0
ファイル: GameActive.cs プロジェクト: chrisw000/BingoServer
        public override async Task PushSelectionAsync(IEndPlayerInfo endPlayerInfo, int draw)
        {
            Logger.LogWarning("{class}.{method} called when {gamemode} = {mode:G}",
                              nameof(IGame), nameof(PushSelectionAsync), nameof(GameMode), Mode);

            await Task.CompletedTask.ConfigureAwait(false);
        }
コード例 #2
0
        public IEndPlayerInfo StoreConnection(IEndPlayerInfo endPlayerInfo)
        {
            if (endPlayerInfo == null)
            {
                throw new ArgumentNullException(nameof(endPlayerInfo));
            }

            if (_players.TryGetValue(endPlayerInfo.PlayerId, out var player))
            {
                if (string.IsNullOrEmpty(player.ConnectionId) ||
                    _connections.TryRemove(player.ConnectionId, out var id))
                {
                    if (_connections.TryAdd(endPlayerInfo.ConnectionId, endPlayerInfo.PlayerId))
                    {
                        player.ConnectionId = endPlayerInfo.ConnectionId;
                        return(player);
                    }
                }
                _logger.LogWarning("Cannot find cached _connections to store connection {@endPlayerInfo}", endPlayerInfo);
            }
            else
            {
                _logger.LogWarning("Cannot find cached _players to store connection {@endPlayerInfo}", endPlayerInfo);
            }

            return(player);
        }
コード例 #3
0
        public async Task AddPlayerAsync(IEndPlayerInfo endPlayerInfo)
        {
            Logger.LogInformation("Game.AddPlayer {@endPlayerInfo}", endPlayerInfo);

            var newPlayer = (Status == GameStatus.WaitingForPlayers)
                ? new Player(endPlayerInfo, CheeseCount, _allNumbers)
                : new Player(endPlayerInfo);

            if (PlayerDictionary.TryAdd(endPlayerInfo.PlayerId, newPlayer))
            {
                if (Status == GameStatus.WaitingForPlayers && PlayerDictionary.Count >= Size)
                {
                    Status = GameStatus.Playing;
                }

                await LobbyHubContext.Groups.AddToGroupAsync(endPlayerInfo.ConnectionId, GameId.ToString()).ConfigureAwait(false);

                if (newPlayer.Status == PlayerStatus.Playing)
                {
                    // Tell the player their numbers
                    await LobbyHubContext.Clients.Client(endPlayerInfo.ConnectionId).LobbyPlayerNumbers(this, newPlayer as IPlayerData).ConfigureAwait(false);

                    // Tell everyone else in the game the text message version
                    await LobbyHubContext.Clients.GroupExcept(GameId.ToString(), endPlayerInfo.ConnectionId).LobbyUserJoinedGame(this, $"{newPlayer.Info.User} joined game with numbers {string.Join(",", newPlayer.Draws.Select(d => d.Number))}").ConfigureAwait(false);
                }
            }
            else
            {
                Logger.LogWarning("Unable to add player {user} on {connectionId} to {gameId}",
                                  newPlayer.Info.User,
                                  endPlayerInfo.ConnectionId,
                                  GameId);
            }
        }
コード例 #4
0
        public Player(IEndPlayerInfo userIdentity, int cheeseCount, NumberCollection numbers)
        {
            if (userIdentity == null)
            {
                throw new ArgumentNullException(nameof(userIdentity));
            }
            if (numbers == null)
            {
                throw new ArgumentNullException(nameof(numbers));
            }
            if (cheeseCount >= numbers.Count)
            {
                throw new ArgumentOutOfRangeException(nameof(cheeseCount), "You can't have more cheese than there is in the game.");
            }
            if (cheeseCount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(cheeseCount), "You need some cheese in the game to be a player.");
            }

            _userIdentity = userIdentity;
            Status        = PlayerStatus.Playing;

            _cheeseCount = cheeseCount;
            _draws.AddRange(from i in ThreadSafeRandom.Pick(cheeseCount, numbers.CountInUse)
                            select new Draw(i, numbers[i].Name));
        }
コード例 #5
0
        public async Task ClientReconnectedAsync(IEndPlayerInfo endPlayerInfo)
        {
            if (endPlayerInfo == null)
            {
                throw new ArgumentNullException(nameof(endPlayerInfo));
            }

            _logger.LogTrace("GameManager.ClientReconnected {@endPlayerInfo}", endPlayerInfo);

            if (!_endPlayerManager.CheckUserAgainstId(endPlayerInfo))
            {
                return; // TODO - return some error state?
            }
            foreach (var(g, p) in from g in _games.Values
                     from p in g.Players.Where(p => p.Info.PlayerId == endPlayerInfo.PlayerId)
                     select(g, p))
            {
                await _lobbyHubContext.Groups.RemoveFromGroupAsync(((IEndPlayerInfo)p).ConnectionId, g.GameId.ToString()).ConfigureAwait(false);
            }

            _endPlayerManager.StoreConnection(endPlayerInfo);

            foreach (var(g, p) in from g in _games.Values
                     from p in g.Players.Where(p => p.Info.PlayerId == endPlayerInfo.PlayerId)
                     select(g, p))
            {
                await _lobbyHubContext.Groups.AddToGroupAsync(((IEndPlayerInfo)p).ConnectionId, g.GameId.ToString()).ConfigureAwait(false);
            }
        }
コード例 #6
0
 public Player(IEndPlayerInfo userIdentity)
 {
     if (userIdentity == null)
     {
         throw new ArgumentNullException(nameof(userIdentity));
     }
     _userIdentity = userIdentity;
     Status        = PlayerStatus.Spectator;
 }
コード例 #7
0
ファイル: LobbyHub.cs プロジェクト: chrisw000/BingoServer
        public async Task ClientReconnected(IEndPlayerInfo endPlayerInfo)
        {
            if (endPlayerInfo == null)
            {
                throw new ArgumentNullException(nameof(endPlayerInfo));
            }
            endPlayerInfo.ConnectionId = Context.ConnectionId;

            _logger.LogInformation("LobbyHub.ClientReconnected {@endPlayerInfo}", endPlayerInfo);

            await _gameManager.ClientReconnectedAsync(endPlayerInfo).ConfigureAwait(false);
        }
コード例 #8
0
 public abstract Task PushSelectionAsync(IEndPlayerInfo endPlayerInfo, int draw);
コード例 #9
0
ファイル: GamePassive.cs プロジェクト: chrisw000/BingoServer
 public override async Task PushSelectionAsync(IEndPlayerInfo endPlayerInfo, int draw)
 {
     await PlayRoundAsync(draw).ConfigureAwait(false);
 }