Guest User

Untitled

a guest
May 15th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. var fs = require('fs');
  2. var crypto = require('crypto');
  3. var Steam = require('steam');
  4. var moment = require('moment');
  5.  
  6. /*
  7. Hour idle script.
  8. */
  9.  
  10. /*
  11. Bot info:
  12. */
  13.  
  14. var logOnOptions = {
  15. account_name: '',
  16. password: ''
  17. };
  18.  
  19. var authCode = '';
  20.  
  21. /*
  22. Bot settings:
  23. */
  24.  
  25. var games = {
  26. games_played: [
  27. { game_id: '440' }
  28. { game_id: '730' }
  29. ]
  30. }
  31.  
  32.  
  33.  
  34.  
  35.  
  36. console.log(" _ ____ __ __ ");
  37. console.log(" (_)___/ / /__ / /_ ____ / /_");
  38. console.log(" / / __ / / _ \\ / __ \\/ __ \\/ __/");
  39. console.log(" / / /_/ / / __/ / /_/ / /_/ / /_ ");
  40. console.log("/_/\\__,_/_/\\___/ /_.___/\\____/\\__/ ");
  41.  
  42. function hourMinuteSecond() {
  43. var date = new moment();
  44. var result = date.format('HH:mm:ss');
  45. return result;
  46. }
  47.  
  48. function getSHA1(bytes) {
  49. var shasum = crypto.createHash('sha1');
  50. shasum.end(bytes);
  51. return shasum.read();
  52. }
  53.  
  54. var steamClient = new Steam.SteamClient();
  55. var steamUser = new Steam.SteamUser(steamClient);
  56. var steamFriends = new Steam.SteamFriends(steamClient);
  57.  
  58. try {
  59. console.log("[" + hourMinuteSecond() + "] " + '[LOGIN] Searching for sentry file...');
  60. logOnOptions['sha_sentryfile'] = getSHA1(fs.readFileSync('sentry'));
  61. console.log("[" + hourMinuteSecond() + "] " + '[LOGIN] Sentry file found, attempting login...');
  62. } catch (e) {
  63. console.log("[" + hourMinuteSecond() + "] " + '[LOGIN] Sentry file was not found.');
  64. if (authCode != '') {
  65. logOnOptions['auth_code'] = authCode;
  66. console.log("[" + hourMinuteSecond() + "] " + '[LOGIN] Attempting login via the provided Steam Guard code...');
  67. } else {
  68. console.log("[" + hourMinuteSecond() + "] " + '[LOGIN] No authentication method was found, attempting Steam Guard code request.');
  69. }
  70. }
  71.  
  72. if (fs.existsSync('servers')) {
  73. Steam.servers = JSON.parse(fs.readFileSync('servers'));
  74. }
  75.  
  76. steamClient.connect();
  77. steamClient.on('connected', function() {
  78. console.log("[" + hourMinuteSecond() + "] " + '[LOGIN] Successfully connected to Steam servers.');
  79. console.log("[" + hourMinuteSecond() + "] " + '[LOGIN] Attempting login...');
  80. steamUser.logOn(logOnOptions);
  81. });
  82.  
  83. steamClient.on('logOnResponse', function(logonResp) {
  84. if (logonResp.eresult == Steam.EResult.OK) {
  85. console.log("[" + hourMinuteSecond() + "] " + '[LOGIN] Successfully logged in.');
  86. steamFriends.setPersonaState(Steam.EPersonaState.Online);
  87. steamUser.gamesPlayed(games);
  88. console.log("[" + hourMinuteSecond() + "] " + '[IDLE] Started idling selected games.');
  89. } else {
  90. console.log("[" + hourMinuteSecond() + "] " + '[LOGIN] An error occurred while trying to login.');
  91. }
  92. });
  93.  
  94. steamClient.on('servers', function(servers) {
  95. fs.writeFile('servers', JSON.stringify(servers));
  96. });
  97.  
  98. steamUser.on('updateMachineAuth', function(sentry, callback) {
  99. fs.writeFileSync('sentry', sentry.bytes);
  100. callback({ sha_file: getSHA1(sentry.bytes) });
  101. });
  102.  
  103. steamClient.on('error', function(error) {
  104. console.log("[" + hourMinuteSecond() + "] " + '[ERROR] Disconnected from Steam servers.');
  105. if (authCode != '' || fs.existsSync('sentry')) {
  106. setTimeout(function() {
  107. console.log("[" + hourMinuteSecond() + "] " + '[ERROR] Attempting to reconnect...');
  108. steamClient.connect();
  109. }, 5000);
  110. } else {
  111. console.log("[" + hourMinuteSecond() + "] " + '[ERROR] Sent a Steam Guard code to your email.');
  112. console.log("[" + hourMinuteSecond() + "] " + '[ERROR] Exiting app. Enter auth code above in the code.');
  113. process.exit();
  114. }
  115. });
Add Comment
Please, Sign In to add comment