Advertisement
Guest User

Untitled

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