예제 #1
0
        /// <summary>
        /// License validation
        /// </summary>
        public bool Validate()
        {
            licenseInfos.Clear();

            // workaround for obfuscation
            var licenseTypes = new LicenseType[]
            {
                LicenseType.XRayTrial,
                LicenseType.XRayHoldem,
                LicenseType.XRayOmaha,
                LicenseType.XRayCombo
            };

            // validate each possible type
            foreach (LicenseType licenseType in licenseTypes)
            {
                SecureLicense license = null;

                NoLicenseException validationException = null;

                var isExpired = false;
                var serial    = string.Empty;

                var licenseManager = ServiceLocator.Current.GetInstance <ILicenseManager>(licenseType.ToString());

                try
                {
                    var requestInfo = new LicenseValidationRequestInfo
                    {
                        DontShowForms = true
                    };

                    license = licenseManager.Validate(requestInfo);

                    if (!license.IsTrial)
                    {
                        LogProvider.Log.Info(CustomModulesNames.PlayerXRay, string.Format("Found license: {0}-*", license.SerialNumber.Substring(0, 4)));
                    }
                }
                catch (NoLicenseException ex)
                {
                    validationException = ex;

                    var exceptionData = ParseException(ex);

                    if (exceptionData != null &&
                        exceptionData.ContainsKey("errorCode") && exceptionData["errorCode"].Equals("LCS_EXP"))
                    {
                        isExpired = true;
                        serial    = exceptionData["serial"];
                    }
                }
                catch (Exception ex)
                {
                    LogProvider.Log.Error(CustomModulesNames.PlayerXRay, "Validation: License validation error", ex);
                }

                // Trial license - check if real trial is expired or does not exists
                if (license != null && license.IsTrial)
                {
                    licenseManager.ResetCacheForLicense(license);

                    var requestInfo = new LicenseValidationRequestInfo
                    {
                        DontShowForms = true,
                        DisableTrials = true
                    };

                    try
                    {
                        license = licenseManager.Validate(requestInfo);
                    }
                    catch (NoLicenseException ex)
                    {
                        validationException = ex;
                    }
                }

                var licenseInfo = new LicenseInfo(license, licenseType);
                licenseInfo.ValidationException = validationException;

                // if license expired we must specify that
                if (isExpired && license == null)
                {
                    licenseInfo.IsExpired = true;
                    licenseInfo.Serial    = serial;
                }

                if (!licenseInfo.IsTrial || licenseInfos.All(x => !x.IsTrial))
                {
                    licenseInfos.Add(licenseInfo);
                }
            }

            isInitialized = true;

            UpdateExpirationDates(licenseInfos);

            var isValid = licenseInfos.Any(x => x.IsRegistered);

            return(isValid);
        }
예제 #2
0
        /// <summary>
        /// Register with specified serial number
        /// </summary>
        /// <param name="serial">Serial number</param>
        public bool Register(string serial, string email)
        {
            if (string.IsNullOrWhiteSpace(serial))
            {
                throw new DHBusinessException(new NonLocalizableString("Serial is not defined."));
            }

            var licenseType = GetTypeFromSerial(serial);

            if (!licenseType.HasValue)
            {
                throw new DHBusinessException(new NonLocalizableString("Serial is not defined."));
            }

            var licenseManager = ServiceLocator.Current.GetInstance <ILicenseManager>(licenseType.ToString());

            var licenseInfo = licenseInfos.FirstOrDefault(x => x.LicenseType == licenseType);

            var license = licenseInfo != null ? licenseInfo.License : null;

            if (license != null)
            {
                licenseManager.ResetCacheForLicense(license);
            }

            if (licenseInfo != null)
            {
                licenseInfos.Remove(licenseInfo);
            }

            var requestInfo = new LicenseValidationRequestInfo
            {
                DontShowForms            = true,
                SerialNumbers            = new string[] { serial },
                SaveExternalSerials      = true,
                DisableTrials            = true,
                DisableCache             = true,
                ShouldGetNewSerialNumber = true
            };

            requestInfo.AdditionalServerProperties.Add("email", email);

            var isExpired = false;

            try
            {
                license = licenseManager.Validate(requestInfo);

                if (license == null || license.IsTrial)
                {
                    throw new LicenseInvalidSerialException("License not found or expired");
                }

                if (license.IsActivation && !license.IsActivated)
                {
                    throw new LicenseCouldNotActivateException();
                }

                LogProvider.Log.Info(CustomModulesNames.PlayerXRay, $"License has been registered: {license.SerialNumber.Substring(0, 5)}");

                return(true);
            }
            catch (NoLicenseException ex)
            {
                // check for expiration first
                var exceptionData = ParseException(ex);

                if (exceptionData != null &&
                    exceptionData.ContainsKey("errorCode") && exceptionData["errorCode"].Equals("LCS_EXP"))
                {
                    isExpired = true;

                    LogProvider.Log.Error(CustomModulesNames.PlayerXRay, "Registration: License expired", ex);
                    throw new LicenseExpiredException();
                }

                // check for activation errors
                var errorCodes = Utils.GetErrorCodes(ex);

                if (errorCodes.Any(x => x.Equals("E_CouldNotActivateAtServer") || x.Equals("E_CannotValidateAtServer")))
                {
                    LogProvider.Log.Error(CustomModulesNames.PlayerXRay, "Registration: License wasn't activated", ex);
                    throw new LicenseCouldNotActivateException();
                }

                LogProvider.Log.Error(CustomModulesNames.PlayerXRay, "Registration: License not found or expired", ex);
                throw new LicenseInvalidSerialException("License not found or expired", ex);
            }
            catch (LicenseCouldNotActivateException)
            {
                LogProvider.Log.Error(CustomModulesNames.PlayerXRay, "Registration: License wasn't activated");
                throw;
            }
            catch (Exception ex)
            {
                LogProvider.Log.Error(CustomModulesNames.PlayerXRay, "Registration: License validation error", ex);
                throw new LicenseException("Unexpected license validation exception", ex);
            }
            finally
            {
                licenseInfo = new LicenseInfo(license, licenseType.Value);
                licenseInfos.Add(licenseInfo);

                // if license expired we must specify that
                if (isExpired && license == null)
                {
                    licenseInfo.IsExpired = true;
                    licenseInfo.Serial    = serial;
                }

                LogProvider.Log.Info(CustomModulesNames.PlayerXRay, $"License limits: Cash={licenseInfo.CashLimit}, Tournament={licenseInfo.TournamentLimit}");

                UpdateExpirationDates(new[] { licenseInfo });
            }
        }