Advertisement
Guest User

Untitled

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