Advertisement
Guest User

Untitled

a guest
May 10th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. var SteamCommunity = require('steamcommunity');
  2. var ReadLine = require('readline');
  3. var fs = require('fs');
  4. var SteamTotp = require('steam-totp');
  5. var SteamcommunityMobileConfirmations = require('steamcommunity-mobile-confirmations');
  6.  
  7. var botData;
  8. var botName = "locatoad";
  9. var community = new SteamCommunity();
  10. var rl = ReadLine.createInterface({
  11. "input": process.stdin,
  12. "output": process.stdout
  13. });
  14.  
  15. fs.readFile("settings."+botName+".json", (err, data) => {
  16. if (err)
  17. {
  18. console.log("Failed to load settings from file, exiting");
  19. process.exit();
  20. }
  21. else
  22. {
  23. try
  24. {
  25. botData = JSON.parse(data);
  26. }
  27. catch(e)
  28. {
  29. console.log("Failed to parse settings to json, exiting. Exception: "+ e);
  30. process.exit();
  31. }
  32.  
  33. if(typeof botData.username === "undefined" || typeof botData.password === "undefined" || typeof botData.deviceId === "undefined" || typeof botData.identitySecret === "undefined" || typeof botData.sharedSecret === "undefined")
  34. {
  35. console.log("Missing variables in json object, check the config for missing settings.");
  36. process.exit();
  37. }
  38.  
  39. if(typeof botData.cookies === "object")
  40. {
  41. doCookieLogin(botData.cookies);
  42. }
  43. else
  44. {
  45. doLogin(botData.username, botData.password, null, SteamTotp.generateAuthCode(botData.sharedSecret));
  46. }
  47. }
  48.  
  49. });
  50.  
  51. function doLogin(accountName, password, authCode, twoFactorCode, captcha)
  52. {
  53. community.login({
  54. "accountName": accountName,
  55. "password": password,
  56. "authCode": authCode,
  57. "twoFactorCode": twoFactorCode,
  58. "captcha": captcha
  59. }, function(err, sessionID, cookies, steamguard)
  60. {
  61. if(err)
  62. {
  63. if(err.message == 'SteamGuardMobile')
  64. {
  65. doLogin(accountName, password, null, SteamTotp.generateAuthCode(botData.sharedSecret));
  66. return;
  67. }
  68.  
  69. if(err.message == 'SteamGuard')
  70. {
  71. console.log("An email has been sent to your address at " + err.emaildomain);
  72. rl.question("Steam Guard Code: ", function(code)
  73. {
  74. doLogin(accountName, password, code);
  75. });
  76.  
  77. return;
  78. }
  79.  
  80. if(err.message == 'CAPTCHA')
  81. {
  82. console.log(err.captchaurl);
  83. rl.question("CAPTCHA: ", function(captchaInput)
  84. {
  85. doLogin(accountName, password, authCode, twoFactorCode, captchaInput);
  86. });
  87.  
  88. return;
  89. }
  90.  
  91. console.log(err);
  92. process.exit();
  93. return;
  94. }
  95.  
  96. console.log("Logged on!");
  97.  
  98. botData.cookies = cookies;
  99. fs.writeFile("settings."+botName+".json", JSON.stringify(botData), function(err)
  100. {
  101. if(err)
  102. {
  103. console.log("Failed to save new cookies to the settings file");
  104. }
  105. console.log("Saved cookies to the settings file for " + botName);
  106. });
  107.  
  108. startConfirmationPolling(community, cookies);
  109. });
  110. }
  111.  
  112.  
  113.  
  114. function doCookieLogin(cookies) {
  115. community.setCookies(cookies);
  116. community.loggedIn(function(err, loggedIn, familyView) {
  117. if(err) {
  118. console.log("A error occured while checking login status: Error: " + err);
  119. }
  120.  
  121. if(loggedIn)
  122. {
  123. console.log("Logged in with cookies!");
  124. startConfirmationPolling(community, cookies);
  125. }
  126. else
  127. {
  128. doLogin(botData.username, botData.password, null, SteamTotp.generateAuthCode(botData.sharedSecret));
  129. }
  130. });
  131.  
  132. }
  133.  
  134.  
  135. function startConfirmationPolling(community, cookies)
  136. {
  137. var steamcommunityMobileConfirmations = new SteamcommunityMobileConfirmations(
  138. {
  139. steamid: community.steamID,
  140. identity_secret: botData.identitySecret,
  141. device_id: botData.deviceId,
  142. webCookie: cookies,
  143. });
  144.  
  145. var mobileConfirmationsInterval = setInterval(function()
  146. {
  147. steamcommunityMobileConfirmations.FetchConfirmations((function (err, confirmations)
  148. {
  149. if (err)
  150. {
  151. console.log("FetchConfirmationsError " +err);
  152. return;
  153. }
  154. console.log('received ' + confirmations.length + ' confirmations');
  155. console.log(confirmations);
  156.  
  157. if ( ! confirmations.length)
  158. {
  159. return;
  160. }
  161.  
  162. steamcommunityMobileConfirmations.generateConfirmationTradeId(confirmations[0], (function (err, tradeId)
  163. {
  164. if (err)
  165. {
  166. console.log(err);
  167. return;
  168. }
  169.  
  170. //DO mysql check for trade id.
  171. var inDB = true;;
  172.  
  173. if(inDB) {
  174. steamcommunityMobileConfirmations.AcceptConfirmation(confirmations[0], (function (err, result)
  175. {
  176. if (err)
  177. {
  178. console.log("AcceptConfirmationError " + err);
  179. return;
  180. }
  181. console.log('steamcommunityMobileConfirmations.AcceptConfirmation result: ' + result);
  182. }).bind(this));
  183. }
  184. }).bind(this));
  185.  
  186.  
  187.  
  188. }).bind(steamcommunityMobileConfirmations));
  189. },
  190. 10000);
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement