Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.84 KB | None | 0 0
  1.  
  2. using System;
  3. using System.ComponentModel;
  4. using System.Configuration;
  5. using System.IO;
  6. using System.Net;
  7. using System.Threading;
  8. using System.Windows.Forms;
  9. using robotManager.Helpful;
  10. using robotManager.Products;
  11.  
  12. public class Authentication
  13. {
  14. private readonly string orderId;
  15. private readonly string productId;
  16. private readonly string wRobotAuthKey;
  17.  
  18. private readonly BackgroundWorker _validationThread = new BackgroundWorker();
  19. private bool _isRunning = false;
  20. private string authUrl;
  21.  
  22. public Authentication(string orderId, string productId)
  23. {
  24. if (orderId == null)
  25. {
  26. MessageBox.Show("You need to enter your transaction id (from your Rocketr email) into the plugin settings to use this!");
  27. }
  28.  
  29. this.orderId = orderId;
  30. this.productId = productId;
  31. this.wRobotAuthKey = robotManager.Helpful.Others.StringBetween(authManager.LoginServer.GetSubcriptionInfoThread(), robotManager.Translate.Get("License Key") + ": ", "... - " + robotManager.Translate.Get("Subscription time expire"));
  32. authUrl = "http://51.38.126.73:8080/authenticate?orderId=" + orderId.Trim() + "&productId=" + productId + "&wRobotAuthKey=" + wRobotAuthKey;
  33.  
  34. _isRunning = true;
  35. _validationThread.DoWork += CheckValidiation;
  36. _validationThread.RunWorkerAsync();
  37. }
  38.  
  39. ~Authentication()
  40. {
  41. _isRunning = false;
  42. _validationThread.DoWork -= CheckValidiation;
  43. _validationThread.Dispose();
  44. }
  45.  
  46. private void CheckValidiation(object sender, DoWorkEventArgs e)
  47. {
  48. while (Products.IsStarted && _isRunning)
  49. {
  50. try
  51. {
  52. bool timedOut = false;
  53. HttpWebResponse content = null;
  54. try
  55. {
  56. var request = (HttpWebRequest)WebRequest.Create(authUrl);
  57. request.Timeout = 30000;
  58. request.ReadWriteTimeout = 30000;
  59. content = (HttpWebResponse)request.GetResponse();
  60. }
  61. catch (Exception ex)
  62. {
  63. timedOut = true;
  64. }
  65.  
  66. //give it another try
  67. if ((content != null && content.StatusCode != HttpStatusCode.OK) || timedOut)
  68. {
  69. Thread.Sleep(3 * 60 * 1000);
  70. try
  71. {
  72. var request = (HttpWebRequest)WebRequest.Create(authUrl);
  73. request.Timeout = 30000;
  74. request.ReadWriteTimeout = 30000;
  75. content = (HttpWebResponse)request.GetResponse();
  76. timedOut = false;
  77. }
  78. catch (Exception ex)
  79. {
  80. timedOut = true;
  81. }
  82. }
  83.  
  84. string result = content != null ? new StreamReader(content.GetResponseStream()).ReadToEnd() : "false";
  85.  
  86. if (!bool.Parse(result) || (content != null && content.StatusCode != HttpStatusCode.OK) || timedOut)
  87. {
  88. Products.ProductStop();
  89. _isRunning = false;
  90. _validationThread.DoWork -= CheckValidiation;
  91. _validationThread.Dispose();
  92. MessageBox.Show(@"You are trying to use a transaction id for a different product or another IP is already using this transaction id.
  93.  
  94. If you changed your IP (one on wRobot session), wait 30 minutes.
  95.  
  96. This error was produced by the vanilla horde quester of bambo.
  97. ");
  98. return;
  99. }
  100.  
  101. Thread.Sleep(60 * 1000);
  102. }
  103. catch (Exception exp)
  104. {
  105. Logging.WriteError("" + exp);
  106. }
  107. }
  108. }
  109. }
  110.  
  111. public class ControlAuthentication
  112. {
  113. private static volatile int _controlVariable = 0;
  114. private static int _timeout = 0;
  115. private static bool _isRunning = true;
  116. private static bool disposeAuthThread = false;
  117. private static string profileName = "";
  118.  
  119. public static void SetControl(int control)
  120. {
  121. _controlVariable = control;
  122. }
  123.  
  124. static ControlAuthentication()
  125. {
  126. new Thread(() =>
  127. {
  128. profileName = wManager.Wow.Helpers.Quest.QuesterCurrentContext.ProfileName;
  129.  
  130. while(_isRunning && !disposeAuthThread && (wManager.Wow.Helpers.Conditions.ProductIsStarted || wManager.Wow.Helpers.Conditions.ProductInPause))
  131. {
  132. if(!wManager.Wow.Helpers.Quest.QuesterCurrentContext.ProfileName.Equals(profileName))
  133. {
  134. disposeAuthThread = true;
  135. break;
  136. }
  137.  
  138. if(!wManager.Wow.Helpers.Conditions.ProductIsStarted)
  139. {
  140. disposeAuthThread = true;
  141. break;
  142. }
  143.  
  144. while(wManager.Wow.Helpers.Quest.QuesterCurrentContext.CurrentStep < 2)
  145. {
  146. Thread.Sleep(500);
  147.  
  148. if(_controlVariable == 5 || !wManager.Wow.Helpers.Conditions.ProductIsStarted)
  149. break;
  150.  
  151. _timeout += 500;
  152.  
  153. if(_timeout >= 910000)
  154. {
  155. Products.ProductStop();
  156. MessageBox.Show("[BambosVanillaHordeQuester]: Timeout error. Unable to authenticate for more than 15 minutes. \n\nBot name: " + ObjectManager.Me.Name);
  157. break;
  158. }
  159. }
  160.  
  161. _isRunning = false;
  162.  
  163. if(wManager.Wow.Helpers.Conditions.ProductIsStarted || wManager.Wow.Helpers.Conditions.ProductInPause)
  164. {
  165. Thread.Sleep(60000);
  166.  
  167. if(_controlVariable != 5)
  168. {
  169. Products.ProductStop();
  170. 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);
  171. }
  172. _timeout = 0;
  173. _isRunning = true;
  174. }
  175. }
  176.  
  177. }).Start();
  178. }
  179.  
  180. }
  181.  
  182. [Serializable]
  183. public class HordeQuesterAuthSettings : robotManager.Helpful.Settings
  184. {
  185. [Setting]
  186. [Category("__IMPORTANT__")]
  187. [DisplayName("Rocketr ORDER ID")]
  188. [Description("You can find this ID at the top of the Email that you have received after your purchase.")]
  189. public string TransactionId { get; set; }
  190.  
  191. public HordeQuesterAuthSettings()
  192. {
  193. TransactionId = null;
  194. }
  195.  
  196. public static HordeQuesterAuthSettings CurrentSetting { get; set; }
  197.  
  198. public bool Save()
  199. {
  200. try
  201. {
  202. return Save(AdviserFilePathAndName("HordeQuesterAuthSettings", "Vanilla"));
  203. }
  204. catch (Exception e)
  205. {
  206. robotManager.Helpful.Logging.Write("HordeQuesterAuthSettings > Save(): " + e);
  207. return false;
  208. }
  209. }
  210.  
  211. public static bool Load()
  212. {
  213. try
  214. {
  215. if (File.Exists(AdviserFilePathAndName("HordeQuesterAuthSettings", "Vanilla")))
  216. {
  217. CurrentSetting =
  218. Load<HordeQuesterAuthSettings>(AdviserFilePathAndName("HordeQuesterAuthSettings", "Vanilla"));
  219. return true;
  220. }
  221. CurrentSetting = new HordeQuesterAuthSettings();
  222. }
  223. catch (Exception e)
  224. {
  225. robotManager.Helpful.Logging.Write("HordeQuesterAuthSettings > Load(): " + e);
  226. }
  227. return false;
  228. }
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement