Beispiel #1
0
        /// <summary>
        /// Exports captured hand history to the supported DB
        /// </summary>
        protected virtual void ExportHandHistory(HandHistoryData handHistoryData, ConcurrentDictionary <long, List <HandHistoryData> > handHistoriesToProcess)
        {
            LogProvider.Log.Info(this, $"Hand #{handHistoryData.HandHistory.HandId} is being prepared [{handHistoryData.Uuid}].");

            var handId = handHistoryData.HandHistory.HandId;

            if (!handHistoriesToProcess.TryGetValue(handId, out List <HandHistoryData> handHistoriesData))
            {
                handHistoriesData = new List <HandHistoryData>();
                handHistoriesToProcess.AddOrUpdate(handId, handHistoriesData, (key, prev) => handHistoriesData);

                Task.Run(() =>
                {
                    try
                    {
                        Task.Delay(DelayToProcessHands).Wait(cancellationTokenSource.Token);
                        ExportHandHistory(handHistoriesData.ToList());
                    }
                    catch (OperationCanceledException)
                    {
                        return;
                    }
                    finally
                    {
                        handHistoriesToProcess.TryRemove(handId, out List <HandHistoryData> removedData);
                    }
                });
            }

            handHistoriesData.Add(handHistoryData);
        }
Beispiel #2
0
        protected virtual void ExportHandHistory(PokerKingPackage package, HandHistory handHistory, IntPtr windowHandle,
                                                 ConcurrentDictionary <long, List <HandHistoryData> > handHistoriesToProcess, bool unexpectedRoomDetected)
        {
            var handHistoryData = new HandHistoryData
            {
                Uuid         = package.UserId,
                HandHistory  = handHistory,
                WindowHandle = !unexpectedRoomDetected ? windowHandle : IntPtr.Zero
            };

            if (!pkCatcherService.CheckHand(handHistory))
            {
                LogProvider.Log.Info(Logger, $"License doesn't support cash hand {handHistory.HandId}. [BB={handHistory.GameDescription.Limit.BigBlind}]");

                if (handHistoryData.WindowHandle != IntPtr.Zero)
                {
                    SendPreImporedData("Notifications_HudLayout_PreLoadingText_PK_NoLicense", windowHandle);
                }

                return;
            }

            ExportHandHistory(handHistoryData, handHistoriesToProcess);
        }
        /// <summary>
        /// Processes packets in the buffer
        /// </summary>
        protected void ProcessBuffer()
        {
            var tableWindowProvider = ServiceLocator.Current.GetInstance <ITableWindowProvider>();
            var packetManager       = ServiceLocator.Current.GetInstance <IPacketManager <PPPokerPackage> >();
            var handBuilder         = ServiceLocator.Current.GetInstance <IPPPHandBuilder>();

            var connectionsService     = ServiceLocator.Current.GetInstance <INetworkConnectionsService>();
            var detectedTables         = new HashSet <IntPtr>();
            var handHistoriesToProcess = new ConcurrentDictionary <long, List <HandHistoryData> >();

            while (!cancellationTokenSource.IsCancellationRequested)
            {
                try
                {
                    if (!packetBuffer.TryTake(out CapturedPacket capturedPacket))
                    {
                        Task.Delay(NoDataDelay).Wait();
                        continue;
                    }

                    LogPacket(capturedPacket, ".log");

                    if (IsAdvancedLogEnabled)
                    {
                        LogPacket(capturedPacket, ".log");
                    }

                    if (!packetManager.TryParse(capturedPacket, out IList <PPPokerPackage> packages))
                    {
                        continue;
                    }

                    foreach (var package in packages)
                    {
                        if (IsAdvancedLogEnabled)
                        {
                            LogPackage(package);
                        }

                        if (!IsAllowedPackage(package))
                        {
                            continue;
                        }

                        var process      = connectionsService.GetProcess(capturedPacket);
                        var windowHandle = tableWindowProvider.GetTableWindowHandle(process);

                        if (package.PackageType != PackageType.SelUserInfoRSP && !detectedTables.Contains(windowHandle))
                        {
                            detectedTables.Add(windowHandle);

                            if (package.PackageType == PackageType.EnterRoomRSP || handBuilder.IsRoomSnapShotAvailable(package))
                            {
                                LogProvider.Log.Info(this, $"User entered room. [{package.ClientPort}]");
                                SendShowHUDRequest("Notifications_HudLayout_PreLoadingText_Init", windowHandle);
                            }
                            else
                            {
                                SendShowHUDRequest("Notifications_HudLayout_PreLoadingText_CanNotBeCapturedText", windowHandle);
                            }
                        }

                        if (handBuilder.TryBuild(package, out HandHistory handHistory))
                        {
                            if (IsAdvancedLogEnabled)
                            {
                                LogProvider.Log.Info(this, $"Hand #{handHistory.HandId} [{package.ClientPort}]");
                            }

                            var handHistoryData = new HandHistoryData
                            {
                                Uuid         = windowHandle.ToInt32(),
                                HandHistory  = handHistory,
                                WindowHandle = windowHandle
                            };

                            if (!licenseService.IsMatch(handHistory))
                            {
                                LogProvider.Log.Info(this, $"License doesn't support cash hand {handHistory.HandId}. [BB={handHistory.GameDescription.Limit.BigBlind}]");
                                SendShowHUDRequest("Notifications_HudLayout_PreLoadingText_NoLicense", windowHandle);
                                continue;
                            }

                            ExportHandHistory(handHistoryData, handHistoriesToProcess);
                        }

                        if (package.PackageType == PackageType.LeaveRoomRSP || package.PackageType == PackageType.TableGameOverRSP)
                        {
                            SendCloseHUDRequest(windowHandle);
                            detectedTables.Remove(windowHandle);
                        }
                    }
                }
                catch (Exception e)
                {
                    LogProvider.Log.Error(this, $"Could not process captured packet.", e);
                }
            }

            SendCloseHUDRequest(detectedTables.ToArray());
        }
 protected virtual string GetSession(HandHistoryData handHistoryData)
 {
     return($"{handHistoryData.HandHistory.GameDescription.Identifier}{handHistoryData.Uuid}");
 }