Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
    private IEnumerator LoadTextAsync(WebGetTask task)
    {
        int         timeout     = 60;
        TimeoutTask timeoutTask = new TimeoutTask((float)timeout, delegate()
        {
            if (task != null && task.IsRunning)
            {
                FMLogger.vCore("LoadTextAsync timeout");
                task.Result(false, null);
            }
        });

        timeoutTask.Run();
        for (int i = 0; i < task.BaseUrls.Length; i++)
        {
            using (UnityWebRequest www = UnityWebRequest.Get(task.BaseUrls[i] + task.RelativeUrl))
            {
                yield return(www.Send());

                if (task == null || !task.IsRunning)
                {
                    yield break;
                }
                if (!www.isNetworkError && www.responseCode == 200L)
                {
                    string text = www.downloadHandler.text;
                    if (!string.IsNullOrEmpty(text))
                    {
                        timeoutTask.Cancel();
                        task.Result(true, text);
                    }
                    else
                    {
                        timeoutTask.Cancel();
                        task.Result(false, null);
                    }
                    this.SendConnectionResume();
                    yield break;
                }
            }
        }
        if (task.IsRunning)
        {
            timeoutTask.Cancel();
            task.Result(false, null);
        }
        this.SendConnectionError();
        yield break;
    }
Exemplo n.º 3
0
    private void InternetCheck(Action <bool> result = null)
    {
        WebGetTask task = new WebGetTask("https://coloring-gp.x-flow.app/api/v_2/checker.php", delegate(bool success, string text)
        {
            if (success)
            {
                FMLogger.Log("intrnet resume");
                this.StopCoroutine(this.internetCheckerCoroutine);
                this.SendConnectionResume();
            }
            else
            {
                FMLogger.Log("no internet");
            }
            if (result != null)
            {
                result(success);
            }
        });

        base.StartCoroutine(this.LoadTextAsync(task));
    }
Exemplo n.º 4
0
 public void LoadText(WebGetTask task)
 {
     base.StartCoroutine(this.LoadTextAsync(task));
 }
Exemplo n.º 5
0
    private IEnumerator DownloadPictureWaiter(DownloadPictureTask task)
    {
        PictureData          pd          = task.PictureData;
        int                  id          = pd.Id;
        int                  packId      = pd.PackId;
        int                  iconState   = 0;
        int                  lineState   = 0;
        int                  colorState  = 0;
        int                  jsonState   = 0;
        string               directory   = packId.ToString();
        string               iconPath    = id + "i";
        string               linePath    = id.ToString();
        string               coloredPath = id + "c";
        string               jsonPath    = id + "t";
        RawBytesDownloadTask iconTask    = null;
        RawBytesDownloadTask lineTask    = null;
        RawBytesDownloadTask coloredTask = null;
        WebGetTask           jsonTask    = null;

        if (FileHelper.FileExist(directory, iconPath))
        {
            iconState = 1;
            FMLogger.Log("skip dl icon, already stored");
        }
        else
        {
            iconTask = new RawBytesDownloadTask(pd.WebPath.baseUrls, pd.WebPath.icon, delegate(bool success, byte[] bytes)
            {
                if (success)
                {
                    FileHelper.SaveRawBytesToFile(bytes, directory, iconPath);
                    iconState = 1;
                }
                else
                {
                    iconState = -1;
                }
            });
        }
        if (FileHelper.FileExist(directory, linePath))
        {
            lineState = 1;
            FMLogger.Log("skip dl line, already stored");
        }
        else
        {
            lineTask = new RawBytesDownloadTask(pd.WebPath.baseUrls, pd.WebPath.lineart, delegate(bool success, byte[] bytes)
            {
                if (success)
                {
                    FileHelper.SaveRawBytesToFile(bytes, directory, linePath);
                    lineState = 1;
                }
                else
                {
                    lineState = -1;
                }
            });
        }
        if (pd.FillType == FillAlgorithm.Flood)
        {
            if (FileHelper.FileExist(directory, coloredPath))
            {
                colorState = 1;
                FMLogger.Log("skip dl colormap, already stored");
            }
            else
            {
                coloredTask = new RawBytesDownloadTask(pd.WebPath.baseUrls, pd.WebPath.colored, delegate(bool success, byte[] bytes)
                {
                    if (success)
                    {
                        FileHelper.SaveRawBytesToFile(bytes, directory, coloredPath);
                        colorState = 1;
                    }
                    else
                    {
                        colorState = -1;
                    }
                });
            }
        }
        else
        {
            colorState = 1;
            FMLogger.Log("skip dl colormap, not needed anymore");
        }
        if (FileHelper.FileExist(directory, jsonPath))
        {
            jsonState = 1;
            FMLogger.Log("skip dl json, already stored");
        }
        else
        {
            jsonTask = new WebGetTask(pd.WebPath.baseUrls, pd.WebPath.json, delegate(bool success, string tex)
            {
                if (success && tex != null)
                {
                    FileHelper.SaveStringToFile(tex, directory, jsonPath);
                    jsonState = 1;
                }
                else
                {
                    jsonState = -1;
                }
            });
        }
        if (iconTask != null)
        {
            base.StartCoroutine(this.LoadRawBytesAsync(iconTask));
        }
        if (lineTask != null)
        {
            base.StartCoroutine(this.LoadRawBytesAsync(lineTask));
        }
        if (coloredTask != null)
        {
            base.StartCoroutine(this.LoadRawBytesAsync(coloredTask));
        }
        if (jsonTask != null)
        {
            base.StartCoroutine(this.LoadTextAsync(jsonTask));
        }
        yield return(0);

        bool  wait       = true;
        bool  allFilesOk = false;
        float waitTime   = 0f;

        while (wait)
        {
            waitTime += Time.deltaTime;
            if (waitTime > task.Timeout)
            {
                if (colorState == 0 && coloredTask != null)
                {
                    coloredTask.Cancel();
                }
                if (lineState == 0 && lineTask != null)
                {
                    lineTask.Cancel();
                }
                if (iconState == 0 && iconTask != null)
                {
                    iconTask.Cancel();
                }
                if (jsonState == 0 && jsonTask != null)
                {
                    jsonTask.Cancel();
                }
                wait = false;
            }
            else if (iconState == -1 || lineState == -1 || colorState == -1 || jsonState == -1)
            {
                allFilesOk = false;
                wait       = false;
            }
            else if (iconState == 1 && lineState == 1 && colorState == 1 && jsonState == 1)
            {
                allFilesOk = true;
                wait       = false;
            }
            yield return(0);
        }
        if (allFilesOk)
        {
            FMLogger.Log("pic dl complete " + pd.Id);
            PictureData result = SharedData.Instance.AddPictureToPack(pd);
            task.Result(true, result);
        }
        else
        {
            FMLogger.Log("pic dl error " + pd.Id);
            task.Result(false, null);
        }
        yield return(0);

        yield break;
    }