Advertisement
Guest User

Untitled

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