Advertisement
Guest User

Untitled

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