Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.ComponentModel;
- using System.Configuration;
- using System.IO;
- using System.Net;
- using System.Threading;
- using System.Windows.Forms;
- using robotManager.Helpful;
- using robotManager.Products;
- public class Authentication
- {
- private readonly string orderId;
- private readonly string productId;
- private readonly string wRobotAuthKey;
- private readonly BackgroundWorker _validationThread = new BackgroundWorker();
- private bool _isRunning = false;
- private string authUrl;
- public Authentication(string orderId, string productId)
- {
- if (orderId == null)
- {
- MessageBox.Show("You need to enter your transaction id (from your Rocketr email) into the plugin settings to use this!");
- }
- this.orderId = orderId;
- this.productId = productId;
- this.wRobotAuthKey = robotManager.Helpful.Others.StringBetween(authManager.LoginServer.GetSubcriptionInfoThread(), robotManager.Translate.Get("License Key") + ": ", "... - " + robotManager.Translate.Get("Subscription time expire"));
- authUrl = "http://51.38.126.73:8080/authenticate?orderId=" + orderId.Trim() + "&productId=" + productId + "&wRobotAuthKey=" + wRobotAuthKey;
- _isRunning = true;
- _validationThread.DoWork += CheckValidiation;
- _validationThread.RunWorkerAsync();
- }
- ~Authentication()
- {
- _isRunning = false;
- _validationThread.DoWork -= CheckValidiation;
- _validationThread.Dispose();
- }
- private void CheckValidiation(object sender, DoWorkEventArgs e)
- {
- while (Products.IsStarted && _isRunning)
- {
- try
- {
- bool timedOut = false;
- HttpWebResponse content = null;
- try
- {
- var request = (HttpWebRequest)WebRequest.Create(authUrl);
- request.Timeout = 30000;
- request.ReadWriteTimeout = 30000;
- content = (HttpWebResponse)request.GetResponse();
- }
- catch (Exception ex)
- {
- timedOut = true;
- }
- //give it another try
- if ((content != null && content.StatusCode != HttpStatusCode.OK) || timedOut)
- {
- Thread.Sleep(3 * 60 * 1000);
- try
- {
- var request = (HttpWebRequest)WebRequest.Create(authUrl);
- request.Timeout = 30000;
- request.ReadWriteTimeout = 30000;
- content = (HttpWebResponse)request.GetResponse();
- timedOut = false;
- }
- catch (Exception ex)
- {
- timedOut = true;
- }
- }
- string result = content != null ? new StreamReader(content.GetResponseStream()).ReadToEnd() : "false";
- if (!bool.Parse(result) || (content != null && content.StatusCode != HttpStatusCode.OK) || timedOut)
- {
- Products.ProductStop();
- _isRunning = false;
- _validationThread.DoWork -= CheckValidiation;
- _validationThread.Dispose();
- MessageBox.Show(@"You are trying to use a transaction id for a different product or another IP is already using this transaction id.
- If you changed your IP (one on wRobot session), wait 30 minutes.
- This error was produced by the vanilla horde quester of bambo.
- ");
- return;
- }
- Thread.Sleep(60 * 1000);
- }
- catch (Exception exp)
- {
- Logging.WriteError("" + exp);
- }
- }
- }
- }
- public class ControlAuthentication
- {
- private static volatile int _controlVariable = 0;
- private static int _timeout = 0;
- private static bool _isRunning = true;
- private static bool disposeAuthThread = false;
- private static string profileName = "";
- public static void SetControl(int control)
- {
- _controlVariable = control;
- }
- static ControlAuthentication()
- {
- new Thread(() =>
- {
- profileName = wManager.Wow.Helpers.Quest.QuesterCurrentContext.ProfileName;
- while(_isRunning && !disposeAuthThread && (wManager.Wow.Helpers.Conditions.ProductIsStarted || wManager.Wow.Helpers.Conditions.ProductInPause))
- {
- if(!wManager.Wow.Helpers.Quest.QuesterCurrentContext.ProfileName.Equals(profileName))
- {
- disposeAuthThread = true;
- break;
- }
- if(!wManager.Wow.Helpers.Conditions.ProductIsStarted)
- {
- disposeAuthThread = true;
- break;
- }
- while(wManager.Wow.Helpers.Quest.QuesterCurrentContext.CurrentStep < 2)
- {
- Thread.Sleep(500);
- if(_controlVariable == 5 || !wManager.Wow.Helpers.Conditions.ProductIsStarted)
- break;
- _timeout += 500;
- if(_timeout >= 910000)
- {
- Products.ProductStop();
- MessageBox.Show("[BambosVanillaHordeQuester]: Timeout error. Unable to authenticate for more than 15 minutes. \n\nBot name: " + ObjectManager.Me.Name);
- break;
- }
- }
- _isRunning = false;
- if(wManager.Wow.Helpers.Conditions.ProductIsStarted || wManager.Wow.Helpers.Conditions.ProductInPause)
- {
- Thread.Sleep(60000);
- if(_controlVariable != 5)
- {
- Products.ProductStop();
- MessageBox.Show("[BambosVanillaHordeQuester]: Please enter your ID faster or make sure the authentication step is enabled. \nRestart the Bot now. \n\nBot name: " + ObjectManager.Me.Name);
- }
- _timeout = 0;
- _isRunning = true;
- }
- }
- }).Start();
- }
- }
- [Serializable]
- public class HordeQuesterAuthSettings : robotManager.Helpful.Settings
- {
- [Setting]
- [Category("__IMPORTANT__")]
- [DisplayName("Rocketr ORDER ID")]
- [Description("You can find this ID at the top of the Email that you have received after your purchase.")]
- public string TransactionId { get; set; }
- public HordeQuesterAuthSettings()
- {
- TransactionId = null;
- }
- public static HordeQuesterAuthSettings CurrentSetting { get; set; }
- public bool Save()
- {
- try
- {
- return Save(AdviserFilePathAndName("HordeQuesterAuthSettings", "Vanilla"));
- }
- catch (Exception e)
- {
- robotManager.Helpful.Logging.Write("HordeQuesterAuthSettings > Save(): " + e);
- return false;
- }
- }
- public static bool Load()
- {
- try
- {
- if (File.Exists(AdviserFilePathAndName("HordeQuesterAuthSettings", "Vanilla")))
- {
- CurrentSetting =
- Load<HordeQuesterAuthSettings>(AdviserFilePathAndName("HordeQuesterAuthSettings", "Vanilla"));
- return true;
- }
- CurrentSetting = new HordeQuesterAuthSettings();
- }
- catch (Exception e)
- {
- robotManager.Helpful.Logging.Write("HordeQuesterAuthSettings > Load(): " + e);
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement