Advertisement
spyermoo

node.js script

Apr 3rd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. var steam = require('steam');
  2. var fs = require('fs');
  3. var readlineSync = require('readline-sync');
  4. var promptAuthCode = function(account) {
  5. var code = readlineSync.question('[STEAM][' + account.username + '][AUTHCODE]: Enter authcode: ');
  6. account.authcode = code;
  7. }
  8. var shuffleArray = function(array) {
  9. for (var i = array.length - 1; i > 0; i--) {
  10. var j = Math.floor(Math.random() * (i + 1));
  11. var temp = array[i];
  12. array[i] = array[j];
  13. array[j] = temp;
  14. }
  15.  
  16. return array;
  17. }
  18.  
  19. var accounts = [
  20. {
  21. username: "blank",
  22. password: "blank",
  23. games: [
  24. 730,
  25. 240,
  26. 10,
  27. 70,
  28. 130,
  29. 50,
  30. 80,
  31. 440,
  32. ],
  33. loggedIn: false
  34. },
  35. {
  36. username: "blank",
  37. password: "blank",
  38. games: [
  39. 730,
  40. ],
  41. loggedIn: false
  42. }
  43. ];
  44.  
  45. var build = function() {
  46. for (var index in accounts) {
  47. buildBot(index);
  48. }
  49. }
  50.  
  51. var buildBot = function(index) {
  52. var account = accounts[index];
  53. var username = account.username;
  54. var password = account.password;
  55. var authcode = account.authcode;
  56. var sentryFileHash = new Buffer(username).toString('base64');
  57. var bot = new steam.SteamClient();
  58.  
  59. if (fs.existsSync(sentryFileHash)) {
  60. var sentry = fs.readFileSync(sentryFileHash);
  61. console.log("[STEAM][" + username + "]: Logging in with sentry. (" + sentryFileHash + ")");
  62. bot.logOn({
  63. accountName: username,
  64. password: password,
  65. shaSentryfile: sentry
  66. });
  67. } else {
  68. console.log("[STEAM][" + username + "]: Logging in without sentry.");
  69. bot.logOn({
  70. accountName: username,
  71. password: password,
  72. authCode: authcode
  73. });
  74. }
  75.  
  76. bot.on('loggedOn', function() {
  77. console.log("[STEAM][" + username + "]: Logged In.");
  78. account.loggedIn = true;
  79. bot.setPersonaState(steam.EPersonaState.Online); // our bot needs to be in an online state for our idling to work.
  80. bot.gamesPlayed(shuffleArray(account.games)); // idle games
  81.  
  82. setInterval(function() {
  83. //
  84. if (account.loggedIn) {
  85. try {
  86. console.log("[STEAM][" + username + "]: Changing games");
  87. bot.gamesPlayed([]); // empty array, we aren't playing anything.
  88. bot.gamesPlayed(shuffleArray(account.games));
  89. } catch (ex) {}
  90. }
  91. //
  92. }, 7200000); // 2 hours
  93. });
  94.  
  95. bot.on('sentry', function(sentryHash) {
  96. console.log("[STEAM][" + username + "]: Received sentry file.");
  97. fs.writeFile(sentryFileHash, sentryHash, function(err) {
  98. if (err){
  99. console.log("[STEAM][" + username + "]: " + err);
  100. } else {
  101. console.log("[STEAM][" + username + "]: Wrote sentry file.");
  102. }
  103. });
  104. });
  105.  
  106. bot.on('error', function(e) {
  107. if (e.eresult == steam.EResult.InvalidPassword) {
  108. console.log("[STEAM][" + username + "]: " + 'Login Failed. Reason: invalid password');
  109. } else if (e.eresult == steam.EResult.AlreadyLoggedInElsewhere) {
  110. console.log("[STEAM][" + username + "]: " + 'Login Failed. Reason: already logged in elsewhere');
  111. } else if (e.eresult == steam.EResult.AccountLogonDenied) {
  112. console.log("[STEAM][" + username + "]: " + 'Login Failed. Reason: logon denied - steam guard needed');
  113. promptAuthCode(accounts[index]);
  114. buildBot(index);
  115. } else {
  116. if (account.loggedIn) {
  117. account.loggedIn = false;
  118. bot.logOff();
  119. // change log in status to false to prevent exceptions
  120. // a logout reason of 'unknown' happens when ever you cannot access the account
  121. // or when you're logged out.
  122. console.log("[STEAM][" + username + "]: -----------------------------------------------------------");
  123. console.log("[STEAM][" + username + "]: Cannot log in at this time.");
  124. console.log("[STEAM][" + username + "]: !!! The script will try to log in again in 5 minutes. !!!");
  125. console.log("[STEAM][" + username + "]: If you're currently logged into the account log out.");
  126. console.log("[STEAM][" + username + "]: You are able to log into an account whilst it's idling, just don't play games.");
  127. setTimeout(function() {
  128. // try again.
  129. buildBot(index);
  130. }, 300000);
  131. console.log("[STEAM][" + username + "]: -----------------------------------------------------------");
  132. } else {
  133. console.log("[STEAM][" + username + "]: Login Failed. Reason: " + e.eresult);
  134. }
  135. }
  136. });
  137. }
  138.  
  139. // run the idle script.
  140. build();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement