Advertisement
Guest User

Untitled

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