Advertisement
Guest User

cawcaw

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