Advertisement
Guest User

Untitled

a guest
Jan 7th, 2018
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.76 KB | None | 0 0
  1. var steam = require("steam"),
  2. util = require("util"),
  3. fs = require("fs"),
  4. crypto = require("crypto"),
  5. dota2 = require("../"),
  6. steamClient = new steam.SteamClient(),
  7. steamUser = new steam.SteamUser(steamClient),
  8. steamFriends = new steam.SteamFriends(steamClient),
  9. Dota2 = new dota2.Dota2Client(steamClient, true);
  10.  
  11.  
  12.  
  13.  
  14. // Load config
  15. global.config = require("./config");
  16.  
  17. /* Steam logic */
  18. var onSteamLogOn = function onSteamLogOn(logonResp) {
  19. if (logonResp.eresult == steam.EResult.OK) {
  20. steamFriends.setPersonaState(steam.EPersonaState.Busy); // to display your steamClient's status as "Online"
  21. steamFriends.setPersonaName(global.config.steam_name); // to change its nickname
  22. util.log("Logged on.");
  23. Dota2.launch();
  24. Dota2.on("ready", function() {
  25. console.log("Node-dota2 ready.");
  26. /* Note: Should not declare new event listeners nested inside of
  27. 'ready', else you could end up with duplicated handlers if 'ready'
  28. is fired multiple times. Exception is made within this test file
  29. for the same of keeping relevant samples together. */
  30. /* INVENTORY */
  31. // Dota2.setItemPositions([[ITEM ID, POSITION]]);
  32. // Dota2.deleteItem(ITEM ID);
  33. /* MATCHES */
  34. // Event based
  35. // Dota2.requestMatchDetails(246546269);
  36. // Dota2.on("matchDetailsData", function (matchId, matchData) {
  37. // console.log(JSON.stringify(matchData, null, 2));
  38. // });
  39. // Dota2.requestMatchmakingStats();
  40. // Dota2.on("matchmakingStatsData", function(searchingPlayersByGroup, disabledGroups, matchmakingStatsResponse) {
  41. // console.log(JSON.stringify(matchmakingStatsResponse, null, 2));
  42. // });
  43. // Callback based
  44. // Dota2.requestMatchDetails(246546269, function(err, body) {
  45. // if (err) throw err;
  46. // console.log(JSON.stringify(body));
  47. // });
  48. /* COMMUNITY */
  49. // Event based
  50. // Dota2.requestProfileCard(28956443);
  51. // Dota2.on("profileCardData", function (accountId, profileData) {
  52. // console.log(JSON.stringify(profileData, null, 2));
  53. // });
  54. // Dota2.requestPassportData(28956443);
  55. // Dota2.on("passportData", function (accountId, passportData) {
  56. // console.log(passportData.league_guesses.stamped_players);
  57. // });
  58. // Dota2.requestHallOfFame();
  59. // Dota2.on("hallOfFameData", function(week, featuredPlayers, featuredFarmer, hallOfFameResponse) {
  60. // console.log(JSON.stringify(hallOfFameResponse, null, 2));
  61. // });
  62. // Dota2.requestPlayerInfo(28956443);
  63. // Dota2.on("playerInfoData", function (playerInfo) {
  64. // console.log(JSON.stringify(playerInfo, null, 2));
  65. // });
  66. // Callback based
  67. // Dota2.requestProfileCard(28956443, function(err, body) {
  68. // if (err) throw err;
  69. // console.log(JSON.stringify(body));
  70. // });
  71. // Dota2.requestPassportData(28956443, function(err, body) {
  72. // console.log(JSON.stringify(body));
  73. // });
  74. // Dota2.requestHallOfFame(null, function(err, body){
  75. // console.log(JSON.stringify(body));
  76. // });
  77. /* CHAT */
  78. // Event based
  79. Dota2.joinChat("navetz");
  80. setTimeout(function(){ Dota2.sendMessage("wowoeagnaeigniaeg", "navetz"); }, 5000);
  81. // setTimeout(function(){ Dota2.leaveChat("rj"); }, 10000);
  82. /* GUILD */
  83. // Dota2.requestGuildData();
  84. // Dota2.on("guildOpenPartyData", function(guildId, openParties){
  85. // Event based
  86. // Dota2.inviteToGuild(guildId, 28956443);
  87. // Dota2.setGuildAccountRole(guildId, 28956443, 2);
  88. // Dota2.cancelInviteToGuild(guildId, 75028261);
  89. // Callback based
  90. // Dota2.inviteToGuild(guildId, 28956443, function(err, body){
  91. // console.log(JSON.stringify(body));
  92. // });
  93. // Dota2.cancelInviteToGuild(guildId, 75028261, function(err, body){
  94. // console.log(JSON.stringify(body));
  95. // });
  96. // Dota2.setGuildAccountRole(guildId, 28956443, 2, function(err, body){
  97. // console.log(JSON.stringify(body));
  98. // });
  99. // Doing chat stuffs.
  100. // var guildChannelName = util.format("Guild_%s", guildId);
  101. // Dota2.joinChat(guildChannelName, Dota2.schema.DOTAChatChannelType_t.DOTAChannelType_Guild);
  102. // setTimeout(function(){ Dota2.sendMessage("wowoeagnaeigniaeg", guildChannelName); }, 5000);
  103. // setTimeout(function(){ Dota2.leaveChat(guildChannelName); }, 10000);
  104. // });
  105. /* LOBBIES */
  106. // Dota2.createPracticeLobby({"game_name": "node-dota2",
  107. // "server_region": dota2.ServerRegion.PERFECTWORLDTELECOM,
  108. // "game_mode": dota2.schema.lookupEnum('DOTA_GameMode').values.DOTA_GAMEMODE_AR,
  109. // "series_type": 2,
  110. // "game_version": 1,
  111. // "allow_cheats": false,
  112. // "fill_with_bots": false,
  113. // "allow_spectating": true,
  114. // "pass_key": "password",
  115. // "radiant_series_wins": 0,
  116. // "dire_series_wins": 0,
  117. // "allchat": true
  118. // },
  119. // function(err, body){
  120. // console.log(JSON.stringify(body));
  121. // });
  122. // setTimeout(function(){
  123. // Dota2.leavePracticeLobby(function(err, body){
  124. // console.log(JSON.stringify(body));
  125. // });
  126. // }, 60000);
  127. /* LEAGUES */
  128. // Dota2.requestLeaguesInMonth(10, 2013, 0, function(err, data) { // November 2013
  129. // console.log('Found ' + data.leagues.length + ' leagues full of schedule data :D');
  130. // });
  131. /* SOURCETV */
  132. // Dota2.requestSourceTVGames({});
  133. // Dota2.on("sourceTVGamesData", function(data) { // May 2015
  134. // console.log('Successfully received SourceTVGames: ' + data.game_list);
  135. // });
  136. });
  137. Dota2.on("unready", function onUnready() {
  138. console.log("Node-dota2 unready.");
  139. });
  140. Dota2.on("chatMessage", function(channel, personaName, message) {
  141. // util.log([channel, personaName, message].join(", "));
  142. });
  143. Dota2.on("guildInvite", function(guildId, guildName, inviter) {
  144. // Dota2.setGuildAccountRole(guildId, 75028261, 3);
  145. });
  146. Dota2.on("unhandled", function(kMsg) {
  147. util.log("UNHANDLED MESSAGE " + dota2._getMessageName(kMsg));
  148. });
  149. // setTimeout(function(){ Dota2.exit(); }, 5000);
  150. }
  151. },
  152. onSteamServers = function onSteamServers(servers) {
  153. util.log("Received servers.");
  154. fs.writeFile('servers', JSON.stringify(servers), (err)=>{
  155. if (err) {if (this.debug) util.log("Error writing ");}
  156. else {if (this.debug) util.log("");}
  157. });
  158. },
  159. onSteamLogOff = function onSteamLogOff(eresult) {
  160. util.log("Logged off from Steam.");
  161. },
  162. onSteamError = function onSteamError(error) {
  163. util.log("Connection closed by server: "+error);
  164. };
  165.  
  166. steamUser.on('updateMachineAuth', function(sentry, callback) {
  167. var hashedSentry = crypto.createHash('sha1').update(sentry.bytes).digest();
  168. fs.writeFileSync('sentry', hashedSentry)
  169. util.log("sentryfile saved");
  170. callback({
  171. sha_file: hashedSentry
  172. });
  173. });
  174.  
  175.  
  176. // Login, only passing authCode if it exists
  177. var logOnDetails = {
  178. "account_name": global.config.steam_user,
  179. "password": global.config.steam_pass,
  180. };
  181. if (global.config.steam_guard_code) logOnDetails.auth_code = global.config.steam_guard_code;
  182. if (global.config.two_factor_code) logOnDetails.two_factor_code = global.config.two_factor_code;
  183.  
  184. try {
  185. var sentry = fs.readFileSync('sentry');
  186. if (sentry.length) logOnDetails.sha_sentryfile = sentry;
  187. } catch (beef) {
  188. util.log("Cannae load the sentry. " + beef);
  189. }
  190.  
  191. steamClient.connect();
  192. steamClient.on('connected', function() {
  193. steamUser.logOn(logOnDetails);
  194. });
  195. steamClient.on('logOnResponse', onSteamLogOn);
  196. steamClient.on('loggedOff', onSteamLogOff);
  197. steamClient.on('error', onSteamError);
  198. steamClient.on('servers', onSteamServers);
  199.  
  200. steamRichPresence = new steam.SteamRichPresence(steamClient, 570);
  201. steamRichPresence.on('info', function (){
  202.  
  203. });
  204. console.log(steamRichPresence);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement