Exemplo n.º 1
0
        private async Task <string> GetCaptchaSolveKey(IRuneScapeForm form, RsWebHelper rsHelper)
        {
            var captchaResult = string.Empty;

            StatusUpdate(ServiceStatusCode.Updated, form, "Requesting captcha solve");

            var googleKey = await rsHelper.GrabGoogleKey(form.RequestUrl);

            if (googleKey == string.Empty ||
                googleKey == "NO_GOOGLE_KEY")
            {
                StatusUpdate(ServiceStatusCode.Updated, form, "Error obtaining Google Key from requested page");
                return(string.Empty);
            }

            var captchaId = await
                            CaptchaHelper.RequestSolveCaptcha(googleKey, form.RequestUrl);

            if (captchaId == string.Empty)
            {
                StatusUpdate(ServiceStatusCode.Updated, form, "An error occured requesting captcha solve");
                return(string.Empty);
            }

            for (int i = 0; i < 60; i++)
            {
                StatusUpdate
                    (ServiceStatusCode.Updated, form, "Waiting for captcha to be solved");

                var response = await CaptchaHelper.GetSolveResult(captchaId);

                if (response != string.Empty &&
                    !response.Contains("CAPCHA_NOT_READY") && !response.Contains("ERROR"))
                {
                    captchaResult = response;
                    break;
                }

                Thread.Sleep(5 * 1000);
            }

            return(captchaResult);
        }