private void UpdateFromTargetedOfferSummary(TargetedOfferSummary offerSummary)
        {
            DateTime         serverDateTime   = Service.Get <ServerAPI>().ServerDateTime;
            IDataController  dataController   = Service.Get <IDataController>();
            bool             flag             = false;
            TargetedBundleVO targetedBundleVO = null;

            if (!string.IsNullOrEmpty(offerSummary.AvailableOffer))
            {
                string availableOffer = offerSummary.AvailableOffer;
                targetedBundleVO = dataController.GetOptional <TargetedBundleVO>(availableOffer);
                if (targetedBundleVO != null)
                {
                    flag = targetedBundleVO.IgnoreCooldown;
                }
            }
            int  secondsFromEpoch        = DateUtils.GetSecondsFromEpoch(serverDateTime);
            uint globalCooldownExpiresAt = offerSummary.GlobalCooldownExpiresAt;

            if (!flag && globalCooldownExpiresAt != 0u && (long)secondsFromEpoch < (long)((ulong)globalCooldownExpiresAt))
            {
                Service.Get <StaRTSLogger>().DebugFormat("Offer global cooldown is in effect until {0}", new object[]
                {
                    LangUtils.FormatTime((long)offerSummary.GlobalCooldownExpiresAt)
                });
                this.GlobalCooldownExpiresAt = offerSummary.GlobalCooldownExpiresAt;
                this.OfferExpiresAt          = 0u;
                this.NextOfferAvailableAt    = 0u;
                this.SetBoundedTimer((long)((ulong)this.GlobalCooldownExpiresAt - (ulong)((long)secondsFromEpoch)), new TimerDelegate(this.CheckForNewOffer), false);
            }
            else if (targetedBundleVO != null)
            {
                Service.Get <StaRTSLogger>().DebugFormat("Available offer: {0}", new object[]
                {
                    offerSummary.AvailableOffer
                });
                if (targetedBundleVO.StartTime <= serverDateTime && serverDateTime < targetedBundleVO.EndTime && AudienceConditionUtils.IsValidForClient(targetedBundleVO.AudienceConditions))
                {
                    this.InitializeTriggerOffer(targetedBundleVO);
                }
                else
                {
                    Service.Get <StaRTSLogger>().WarnFormat("Server provided offer {0} was outside of date range {1} to {2}.", new object[]
                    {
                        offerSummary.AvailableOffer,
                        targetedBundleVO.StartTime,
                        targetedBundleVO.EndTime
                    });
                }
            }
            else if (offerSummary.NextOfferAvailableAt > 0u)
            {
                Service.Get <StaRTSLogger>().DebugFormat("Next offer available at {0}.", new object[]
                {
                    LangUtils.FormatTime((long)offerSummary.NextOfferAvailableAt)
                });
                this.NextOfferAvailableAt    = offerSummary.NextOfferAvailableAt;
                this.GlobalCooldownExpiresAt = 0u;
                this.OfferExpiresAt          = 0u;
                this.SetBoundedTimer((long)((ulong)this.NextOfferAvailableAt - (ulong)((long)DateUtils.GetSecondsFromEpoch(serverDateTime))), new TimerDelegate(this.CheckForNewOffer), false);
            }
            else
            {
                this.GlobalCooldownExpiresAt = 0u;
                this.OfferExpiresAt          = 0u;
                this.NextOfferAvailableAt    = 0u;
            }
            this.lastKnownTargetedOffer = null;
            this.FetchingNewOffer       = false;
            if (this.CurrentTargetedOffer != null)
            {
                Service.Get <EventManager>().SendEvent(EventId.TargetedBundleContentPrepared, null);
            }
        }
Exemple #2
0
        public bool CanDisplaySPDButton()
        {
            bool   flag   = !this.FetchingNewOffer && this.CurrentTargetedOffer != null && AudienceConditionUtils.IsPlatformValid(this.CurrentTargetedOffer.AudienceConditions);
            string empty  = string.Empty;
            string empty2 = string.Empty;

            return((!flag || this.CurrentTargetedOffer == null || this.CurrentTargetedOffer.LinkedIAPs.Count <= 0 || this.FindAvailableIAP(this.CurrentTargetedOffer, out empty, out empty2)) && flag);
        }