private void GetServerConfig() { this.configRequested = true; string url = this.adsUrl + this.adsUrlQueue; WebGetTask task = new WebGetTask(url, delegate(bool success, string text) { if (!this.IsEnabled()) { FMLogger.vAds("recieved ads config, but ads is off"); return; } if (success && !string.IsNullOrEmpty(text)) { try { byte[] bytes = Convert.FromBase64String(text); text = Encoding.UTF8.GetString(bytes); char[] array = text.ToCharArray(); Array.Reverse(array); text = new string(array); byte[] bytes2 = Convert.FromBase64String(text); text = Encoding.UTF8.GetString(bytes2); AdsServerResponse adsServerResponse = JsonUtility.FromJson <AdsServerResponse>(text); if (adsServerResponse != null) { if (adsServerResponse.ad_module_active == 0) { FMLogger.vAds("disable ads from config"); this.DisableAds(); this.config.DisableAds(); this.config.UpdateReward(AdConfig.FromRespone(adsServerResponse.rewarded_config, true), adsServerResponse.adUnit_rewarded); this.SaveConfig(this.config); } else { AdConfig adConfig = AdConfig.FromResponse(adsServerResponse, this.isTablet); this.SaveConfig(adConfig); this.config.UpdateFsParamsFromServer(adConfig); this.fsDisabled = !this.config.FsIsOn(); this.bannerDisabled = !adConfig.BannerIsOn(); } } } catch (Exception ex) { FMLogger.vAds("config parse ex. msg:" + ex.Message); } } else { FMLogger.vAds("config req server error. reschedule request"); base.StartCoroutine(this.DelayAction(20f, new Action(this.GetServerConfig))); } }); WebLoader.Instance.LoadText(task); }
public static AdConfig FromResponse(AdsServerResponse response, bool isTablet) { AdConfig adConfig = new AdConfig(); if (!string.IsNullOrEmpty(response.adUnit_banner)) { adConfig.bannerAdUnit = response.adUnit_banner; } else { adConfig.bannerAdUnit = ((!isTablet) ? "f22e60410d82403aa5e0fb791ef9c153" : "1253b5589a4d45869288611de14229d6"); } if (!string.IsNullOrEmpty(response.adUnit_fullscreen)) { adConfig.fsAdUnit = response.adUnit_fullscreen; } else { adConfig.fsAdUnit = ((!isTablet) ? "72bb0678c400487b8d1a941944fa6888" : "8cae328870984a9987623f9c6e52b25d"); } if (!string.IsNullOrEmpty(response.adUnit_rewarded)) { adConfig.rewardAdUnit = response.adUnit_rewarded; } else { adConfig.rewardAdUnit = ((!isTablet) ? "6bc3898062484e71a114d0ab59cb1c78" : "0543e571406140dd96252ac1351b99f5"); } adConfig.adsDisabled = (response.ad_module_active == 0); adConfig.interval = response.interstitial_delay / 1000; adConfig.startInterval = response.interstitial_delay_onstart / 1000; adConfig.appLaunchDelay = (float)response.applaunch_delay / 1000f; adConfig.fsInternalOnReward = Mathf.Max(0, response.interstitial_delay_onreward / 1000); adConfig.bannerShowTime = Mathf.Max(10, response.banner_show_time / 1000); adConfig.bannerLoadDelay = Mathf.Max(1, response.banner_load_delay / 1000); adConfig.adsTest = (response.ad_module_test_mode == 1); adConfig.placements = new List <AdPlacement>(); adConfig.chances = new List <int>(); if (response.fullscreen_showing_config != null) { for (int i = 0; i < response.fullscreen_showing_config.Length; i++) { AdsFsPlacementConfig adsFsPlacementConfig = response.fullscreen_showing_config[i]; AdPlacement adPlacement = AdConfig.ParsePlacement(adsFsPlacementConfig.id); if (adPlacement != AdPlacement.Unknown) { adConfig.placements.Add(adPlacement); adConfig.chances.Add(Mathf.Clamp(adsFsPlacementConfig.chance, 0, 100)); } } } if (response.banner_showing_config != null && response.banner_showing_config.id != null) { adConfig.bannerPos = AdConfig.ParseBannerPosition(response.banner_showing_config.show); if (adConfig.bannerPos != BannerPosition.None) { adConfig.bannerPlaces = new List <BannerPlacement>(); for (int j = 0; j < response.banner_showing_config.id.Length; j++) { BannerPlacement bannerPlacement = AdConfig.ParseBannerPlacement(response.banner_showing_config.id[j]); if (bannerPlacement != BannerPlacement.Unknown) { adConfig.bannerPlaces.Add(bannerPlacement); } } } } else { adConfig.bannerPos = BannerPosition.None; } adConfig.rewardConfig = AdConfig.FromRespone(response.rewarded_config, false); return(adConfig); }