Пример #1
0
        private static IEnumerator ProcessTask(AnticaptchaTask task, Action <string> callback)
        {
            AnticaptchaResult response;

            do
            {
                response = AnticaptchaApiWrapper.GetTaskResult(Host, ClientKey, task);

                if (response == null || response.GetStatus().Equals(AnticaptchaResult.Status.ready))
                {
                    break;
                }

                if (response.GetStatus().Equals(AnticaptchaResult.Status.processing))
                {
                    yield return(new WaitForSeconds(1f));
                }
            } while (response.GetStatus().Equals(AnticaptchaResult.Status.processing));

            if (response?.GetSolution() == null)
            {
                Interface.Oxide.RootLogger.Write(LogType.Info, "Unfortunately we got the following error from the API: " +
                                                 (response != null ? response.GetErrorDescription() : "/empty/"));
            }
            else
            {
                Interface.Oxide.NextTick(() => callback(response.GetSolution()));
            }
        }
Пример #2
0
            public static AnticaptchaResult GetTaskResult(string host, string clientKey, AnticaptchaTask task)
            {
                var jObj = new JObject
                {
                    ["clientKey"] = clientKey,
                    ["taskId"]    = task.GetTaskId()
                };


                try
                {
                    JObject resultJson = JsonPostRequest(host, "getTaskResult",
                                                         JsonConvert.SerializeObject(jObj, Formatting.Indented));

                    var status = AnticaptchaResult.Status.unknown;

                    try
                    {
                        status = resultJson["status"].ToString().Equals("ready")
                            ? AnticaptchaResult.Status.ready
                            : AnticaptchaResult.Status.processing;
                    }
                    catch
                    {
                        // ignored
                    }

                    string solution;
                    int?   errorId          = null;
                    string errorCode        = null;
                    string errorDescription = null;
                    double?cost             = null;
                    string ip         = null;
                    int?   createTime = null;
                    int?   endTime    = null;
                    int?   solveCount = null;

                    try
                    {
                        solution = resultJson["solution"]["gRecaptchaResponse"].ToString();
                    }
                    catch
                    {
                        try
                        {
                            solution = resultJson["solution"]["text"].ToString();
                        }
                        catch
                        {
                            solution = null;
                        }
                    }

                    try
                    {
                        errorId = resultJson["errorId"].ToObject <int>();
                    }
                    catch
                    {
                        // ignored
                    }

                    try
                    {
                        errorCode = resultJson["errorCode"].ToString();
                    }
                    catch
                    {
                        // ignored
                    }

                    try
                    {
                        errorDescription = resultJson["errorDescription"].ToString();
                    }
                    catch
                    {
                        // ignored
                    }

                    try
                    {
                        cost = double.Parse(resultJson["cost"].ToString().Replace(',', '.'), CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                        // ignored
                    }

                    try
                    {
                        createTime = resultJson["createTime"].ToObject <int>();
                    }
                    catch
                    {
                        // ignored
                    }

                    try
                    {
                        endTime = resultJson["endTime"].ToObject <int>();
                    }
                    catch
                    {
                        // ignored
                    }

                    try
                    {
                        solveCount = resultJson["solveCount"].ToObject <int>();
                    }
                    catch
                    {
                        // ignored
                    }

                    try
                    {
                        ip = resultJson["ip"].ToString();
                    }
                    catch
                    {
                        // ignored
                    }

                    return(new AnticaptchaResult(
                               status,
                               solution,
                               errorId,
                               errorCode,
                               errorDescription,
                               cost,
                               ip,
                               createTime,
                               endTime,
                               solveCount
                               ));
                }
                catch
                {
                    // ignored
                }

                return(null);
            }