Пример #1
0
        protected virtual void ProcessFastFoldNoticeGameReset(FastFoldImportDto fastFoldImportDto)
        {
            var noticeGameSnapshot = fastFoldImportDto.HandBuilder.GetNoticeRoomSnapShot(fastFoldImportDto.Package);

            if (noticeGameSnapshot == null ||
                fastFoldImportDto.NoticeResetGame.Players == null ||
                !long.TryParse(fastFoldImportDto.NoticeResetGame.GameId, out long handId))
            {
                LogProvider.Log.Error(Logger, $"Failed to get snapshot for {fastFoldImportDto.Package.UserId} of {fastFoldImportDto.Package.RoomId} (Fast Fold).");
                return;
            }

            // load players from db
            var playersToAdd = fastFoldImportDto.NoticeResetGame.Players
                               .Select(x => x.Playerid.ToString())
                               .Where(x => !fastFoldImportDto.PlayerNamePlayerIdMap.ContainsKey(x))
                               .ToArray();

            if (playersToAdd.Length > 0)
            {
                using (var session = ModelEntities.OpenSession())
                {
                    var playerNamePlayerIdToAdd = session.Query <Players>()
                                                  .Where(x => x.PokersiteId == (short)Site && playersToAdd.Contains(x.Playername))
                                                  .Select(x => new { x.Playername, x.PlayerId })
                                                  .ToArray();

                    playerNamePlayerIdToAdd.ForEach(x => fastFoldImportDto.PlayerNamePlayerIdMap.Add(x.Playername, x.PlayerId));
                }
            }

            var fastFoldRoomId = fastFoldImportDto.HandBuilder
                                 .GetFastFoldRoomByUser(fastFoldImportDto.Package.UserId);

            if (fastFoldRoomId == 0)
            {
                fastFoldRoomId = fastFoldImportDto.Package.RoomId;
            }

            var gameInfo = new GameInfo
            {
                Session      = $"{fastFoldRoomId}{fastFoldImportDto.Package.UserId}",
                WindowHandle = fastFoldImportDto.WindowHandle.ToInt32(),
                PokerSite    = Site,
                GameType     = Bovada.GameType.Holdem,
                TableType    = (EnumTableType)noticeGameSnapshot.Params.PlayerCountMax,
                GameFormat   = GameFormat.FastFold,
                GameNumber   = handId
            };

            // Initialize cache
            gameInfo.ResetPlayersCacheInfo();

            var players = new PlayerList(fastFoldImportDto.NoticeResetGame.Players.Select(x =>
                                                                                          new Player(x.Playerid.ToString(), 0, x.Seatid + 1)
            {
                PlayerId = fastFoldImportDto.PlayerNamePlayerIdMap.ContainsKey(x.Playerid.ToString()) ?
                           fastFoldImportDto.PlayerNamePlayerIdMap[x.Playerid.ToString()] : 0,
                PlayerNick = x.Name
            }));

            Player heroPlayer = null;

            foreach (var player in players)
            {
                if (player.PlayerId == 0)
                {
                    continue;
                }

                var isHero = false;

                if (player.PlayerName.Equals(fastFoldImportDto.Package.UserId.ToString()))
                {
                    heroPlayer = player;
                    isHero     = true;
                }

                var playerCollectionItem = new PlayerCollectionItem
                {
                    PlayerId  = player.PlayerId,
                    Name      = player.PlayerName,
                    PokerSite = Site
                };

                var playerCacheStatistic = fastFoldImportDto.ImporterSessionCacheService.GetPlayerStats(gameInfo.Session, playerCollectionItem, out bool exists);

                if (exists && playerCacheStatistic.IsHero)
                {
                    heroPlayer          = player;
                    gameInfo.GameFormat = playerCacheStatistic.GameFormat;
                    break;
                }
                else if (!exists && gameInfo.GameFormat == GameFormat.FastFold)
                {
                    var playerCacheInfo = new PlayerStatsSessionCacheInfo
                    {
                        Session    = gameInfo.Session,
                        GameFormat = gameInfo.GameFormat,
                        Player     = playerCollectionItem,
                        IsHero     = isHero,
                        Stats      = new Playerstatistic
                        {
                            SessionCode     = gameInfo.Session,
                            PokergametypeId = (short)HandHistories.Objects.GameDescription.GameType.NoLimitHoldem
                        }
                    };

                    if (playerCacheInfo.Stats.PokergametypeId != 0)
                    {
                        gameInfo.AddToPlayersCacheInfo(playerCacheInfo);
                    }
                }
            }

            PreparePlayerList(players,
                              noticeGameSnapshot.Params.PlayerCountMax,
                              heroPlayer != null ? heroPlayer.SeatNumber : 0);

            var importedArgs = new DataImportedEventArgs(players, gameInfo, heroPlayer, 0);

            eventAggregator.GetEvent <DataImportedEvent>().Publish(importedArgs);
        }
        private Player ProcessPlayers(GameInfo gameInfo, PlayerList players, PokerStarsZoomDataObject catcherDataObject)
        {
            Player heroPlayer = null;

            var heroName = catcherDataObject.HeroName;

            foreach (var player in players)
            {
                if (player.PlayerId == 0)
                {
                    continue;
                }

                var isHero = false;

                if (player.PlayerName.Equals(heroName))
                {
                    heroPlayer = player;
                    isHero     = true;
                }

                var playerCollectionItem = new PlayerCollectionItem
                {
                    PlayerId  = player.PlayerId,
                    Name      = player.PlayerName,
                    PokerSite = EnumPokerSites.PokerStars
                };

                var playerCacheStatistic = importerSessionCacheService.GetPlayerStats(gameInfo.Session, playerCollectionItem, out bool exists);

                if (exists && playerCacheStatistic.IsHero)
                {
                    heroPlayer          = player;
                    gameInfo.GameFormat = playerCacheStatistic.GameFormat;
                    break;
                }
                else if (!exists && gameInfo.GameFormat == GameFormat.Zoom)
                {
                    var playerCacheInfo = new PlayerStatsSessionCacheInfo
                    {
                        Session    = gameInfo.Session,
                        GameFormat = gameInfo.GameFormat,
                        Player     = playerCollectionItem,
                        IsHero     = isHero,
                        Stats      = new Playerstatistic
                        {
                            SessionCode     = gameInfo.Session,
                            PokergametypeId = ParsePokergametypeIdFromTitle(catcherDataObject.Title)
                        }
                    };

                    if (playerCacheInfo.Stats.PokergametypeId != 0)
                    {
                        gameInfo.AddToPlayersCacheInfo(playerCacheInfo);
                    }
                }
            }

            if (heroPlayer == null)
            {
                return(null);
            }

            int prefferedSeatNumber = 0;

            if (gameInfo.GameFormat == GameFormat.Zoom)
            {
                // zoom is always auto-centered
                switch (gameInfo.TableType)
                {
                case EnumTableType.HU:
                    prefferedSeatNumber = 2;
                    break;

                case EnumTableType.Six:
                    prefferedSeatNumber = 3;
                    break;

                case EnumTableType.Nine:
                    prefferedSeatNumber = 5;
                    break;
                }
            }
            else
            {
                var preferredSeats = ServiceLocator.Current.GetInstance <ISettingsService>().GetSettings().
                                     SiteSettings.SitesModelList.FirstOrDefault(x => x.PokerSite == EnumPokerSites.PokerStars)?.PrefferedSeats;

                var prefferedSeat = preferredSeats?.FirstOrDefault(x => x.TableType == catcherDataObject.TableType && x.IsPreferredSeatEnabled);

                if (prefferedSeat != null)
                {
                    prefferedSeatNumber = prefferedSeat.PreferredSeat;
                }
            }

            if (prefferedSeatNumber > 0)
            {
                var shift = (prefferedSeatNumber - heroPlayer.SeatNumber) % catcherDataObject.MaxPlayers;

                foreach (var player in players)
                {
                    player.SeatNumber = GeneralHelpers.ShiftPlayerSeat(player.SeatNumber, shift, catcherDataObject.MaxPlayers);
                }
            }

            return(heroPlayer);
        }
Пример #3
0
        /// <summary>
        /// Exports captured hand history to the supported DB
        /// </summary>
        protected virtual void ExportHandHistory(List <HandHistoryData> handHistories)
        {
            // merge hands
            var playerWithHoleCards = handHistories
                                      .SelectMany(x => x.HandHistory.Players)
                                      .Where(x => x.hasHoleCards)
                                      .DistinctBy(x => x.SeatNumber)
                                      .ToDictionary(x => x.SeatNumber, x => x.HoleCards);

            GameInfo mainGameInfo = null;

            foreach (var handHistoryData in handHistories)
            {
                handHistoryData.HandHistory.Players.ForEach(player =>
                {
                    if (!player.hasHoleCards && playerWithHoleCards.ContainsKey(player.SeatNumber))
                    {
                        player.HoleCards = playerWithHoleCards[player.SeatNumber];
                    }
                });

                var handHistoryText = SerializationHelper.SerializeObject(handHistoryData.HandHistory);

#if DEBUG
                if (!Directory.Exists("Hands"))
                {
                    Directory.CreateDirectory("Hands");
                }

                File.WriteAllText($"Hands\\{HandHistoryFilePrefix}_hand_exported_{handHistoryData.Uuid}_{handHistoryData.HandHistory.HandId}.xml", handHistoryText);
#endif
                var gameInfo = new GameInfo
                {
                    PokerSite    = Site,
                    WindowHandle = handHistoryData.WindowHandle.ToInt32(),
                    GameNumber   = handHistoryData.HandHistory.HandId,
                    Session      = GetSession(handHistoryData)
                };

                if (mainGameInfo == null)
                {
                    mainGameInfo = gameInfo;
                }
                else
                {
                    var playersCashInfo = mainGameInfo.GetPlayersCacheInfo();

                    if (playersCashInfo != null)
                    {
                        gameInfo.ResetPlayersCacheInfo();
                        gameInfo.DoNotReset = true;

                        foreach (var playerCashInfo in playersCashInfo)
                        {
                            var cacheInfo = new PlayerStatsSessionCacheInfo
                            {
                                Session = gameInfo.Session,
                                Player  = new PlayerCollectionItem
                                {
                                    PlayerId  = playerCashInfo.Player.PlayerId,
                                    Name      = playerCashInfo.Player.Name,
                                    PokerSite = playerCashInfo.Player.PokerSite,
                                },
                                Stats  = playerCashInfo.Stats.Copy(),
                                IsHero = handHistoryData.HandHistory.HeroName != null &&
                                         handHistoryData.HandHistory.HeroName.Equals(playerCashInfo.Player.Name),
                                GameFormat = playerCashInfo.GameFormat,
                                GameNumber = playerCashInfo.GameNumber
                            };

                            gameInfo.AddToPlayersCacheInfo(cacheInfo);
                        }
                    }
                }

                ProcessHand(handHistoryText, gameInfo);
            }
        }