public PlayerInfo ConnectToGame(string gameId, string playerName, ISidiBarraniClientApi clientApi)
        {
            Log.Verbose($"{this}: ConnectToGame({gameId},{playerName},{clientApi})");
            if (!_gameServiceDictionary.ContainsKey(gameId))
            {
                return(null);
            }
            var gameService = _gameServiceDictionary[gameId];

            if (gameService.PlayerGroupInfo.GetPlayerList().Count >= 4)
            {
                return(null);
            }
            var team1 = gameService.PlayerGroupInfo.Team1;
            var team2 = gameService.PlayerGroupInfo.Team2;

            if (team1.GetPlayerList().Count == 2)
            {
                return(ConnectToTeam(gameId, team2.TeamId, playerName, clientApi));
            }
            if (team2.GetPlayerList().Count == 2)
            {
                return(ConnectToTeam(gameId, team1.TeamId, playerName, clientApi));
            }
            var randomTeam = _random.Next(1) == 0 ? team1 : team2;

            return(ConnectToTeam(gameId, randomTeam.TeamId, playerName, clientApi));
        }
        public PlayerInfo ConnectToTeam(string gameId, string teamId, string playerName, ISidiBarraniClientApi clientApi)
        {
            Log.Verbose($"{this}: ConnectToTeam({gameId},{teamId},{playerName},{clientApi})");
            if (!_gameServiceDictionary.ContainsKey(gameId))
            {
                return(null);
            }
            var gameService = _gameServiceDictionary[gameId];
            var teamInfo    = gameService.PlayerGroupInfo.GetTeamInfo(teamId);

            if (teamInfo == null || teamInfo.GetPlayerList().Count >= 2)
            {
                return(null);
            }
            var playerInfo = new PlayerInfo
            {
                PlayerName = playerName,
                PlayerId   = Guid.NewGuid().ToString()
            };

            if (teamInfo.Player1 == null)
            {
                teamInfo.Player1 = playerInfo;
            }
            else
            {
                teamInfo.Player2 = playerInfo;
            }
            gameService.ClientApiDictionary[playerInfo.PlayerId] = clientApi;
            return((PlayerInfo)playerInfo?.Clone());
        }