Advertisement
Guest User

night

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