1 | var Steam = require("steam"),
|
2 | util = require("util"),
|
3 | fs = require("fs"),
|
4 | csgo = require("../"),
|
5 | bot = new Steam.SteamClient(),
|
6 | steamUser = new Steam.SteamUser(bot),
|
7 | steamFriends = new Steam.SteamFriends(bot),
|
8 | steamGC = new Steam.SteamGameCoordinator(bot, 730);
|
9 | CSGOCli = new csgo.CSGOClient(steamUser, steamGC, false),
|
10 | readlineSync = require("readline-sync"),
|
11 | crypto = require("crypto");
|
12 |
|
13 |
|
14 | var scDecoder = new csgo.SharecodeDecoder("CSGO-U6MWi-hYFWJ-opPwD-JciHm-qOijD");
|
15 | console.log("Sharecode CSGO-U6MWi-hYFWJ-opPwD-JciHm-qOijD decodes into: ");
|
16 | console.log(scDecoder.decode());
|
17 |
|
18 | function MakeSha(bytes) {
|
19 | var hash = crypto.createHash('sha1');
|
20 | hash.update(bytes);
|
21 | return hash.digest();
|
22 | }
|
23 |
|
24 | var onSteamLogOn = function onSteamLogOn(response){
|
25 | if (response.eresult == Steam.EResult.OK) {
|
26 | util.log('Logged in!');
|
27 | }
|
28 | else
|
29 | {
|
30 | util.log('error, ', response);
|
31 | process.exit();
|
32 | }
|
33 | steamFriends.setPersonaState(Steam.EPersonaState.Busy);
|
34 | util.log("Logged on.");
|
35 |
|
36 | util.log("Current SteamID64: " + bot.steamID);
|
37 | util.log("Account ID: " + CSGOCli.ToAccountID(bot.steamID));
|
38 |
|
39 | CSGOCli.launch();
|
40 |
|
41 | CSGOCli.on("unhandled", function(message) {
|
42 | util.log("Unhandled msg");
|
43 | util.log(message);
|
44 | });
|
45 |
|
46 | CSGOCli.on("ready", function() {
|
47 | util.log("node-csgo ready.");
|
48 |
|
49 | CSGOCli.matchmakingStatsRequest();
|
50 | CSGOCli.on("matchmakingStatsData", function(matchmakingStatsResponse) {
|
51 | util.log("Avg. Wait Time: " + matchmakingStatsResponse.global_stats.search_time_avg);
|
52 | util.log("Players Online: " + matchmakingStatsResponse.global_stats.players_online);
|
53 | util.log("Players Searching: " + matchmakingStatsResponse.global_stats.players_searching);
|
54 | util.log("Servers Online: " + matchmakingStatsResponse.global_stats.servers_online);
|
55 | util.log("Servers Available: " + matchmakingStatsResponse.global_stats.servers_available);
|
56 | util.log("Matches in Progress: " + matchmakingStatsResponse.global_stats.ongoing_matches);
|
57 | console.log(JSON.stringify(matchmakingStatsResponse, null, 4));
|
58 |
|
59 | CSGOCli.playerProfileRequest(CSGOCli.ToAccountID(bot.steamID));
|
60 | CSGOCli.on("playerProfile", function(profile) {
|
61 | console.log("Profile");
|
62 | console.log("Player Rank: " + CSGOCli.Rank.getString(profile.account_profiles[0].ranking.rank_id))
|
63 | console.log(JSON.stringify(profile, null, 2));
|
64 | });
|
65 |
|
66 | CSGOCli.requestRecentGames();
|
67 | CSGOCli.on("matchList", function(list) {
|
68 | console.log("Match List");
|
69 | if (list.matches && list.matches.length > 0) {
|
70 | console.log(list.matches[0]);
|
71 | }
|
72 | });
|
73 |
|
74 | CSGOCli.richPresenceUpload({
|
75 | RP: {
|
76 | status: "Hello World!",
|
77 | version: 13503,
|
78 | time: 161.164087
|
79 | }
|
80 | });
|
81 |
|
82 |
|
83 | CSGOCli.itemDataRequest("76561198084749846", "6768147729", "12557175561287951743", "0");
|
84 |
|
85 | CSGOCli.on("itemData", function(itemdata) {
|
86 | console.log(itemdata);
|
87 | });
|
88 | });
|
89 | });
|
90 |
|
91 | CSGOCli.on("unready", function onUnready(){
|
92 | util.log("node-csgo unready.");
|
93 | });
|
94 |
|
95 | CSGOCli.on("unhandled", function(kMsg) {
|
96 | util.log("UNHANDLED MESSAGE " + kMsg);
|
97 | });
|
98 | },
|
99 | onSteamSentry = function onSteamSentry(sentry) {
|
100 | util.log("Received sentry.");
|
101 | require('fs').writeFileSync('sentry', sentry);
|
102 | },
|
103 | onSteamServers = function onSteamServers(servers) {
|
104 | util.log("Received servers.");
|
105 | fs.writeFile('servers.json', JSON.stringify(servers, null, 2));
|
106 | }
|
107 |
|
108 | var username = readlineSync.question('Username: ');
|
109 | var password = readlineSync.question('Password: ', {noEchoBack: true});
|
110 | var authCode = readlineSync.question('AuthCode: ');
|
111 |
|
112 | var logOnDetails = {
|
113 | "account_name": username,
|
114 | "password": password,
|
115 | };
|
116 | if (authCode !== "") {
|
117 | logOnDetails.auth_code = authCode;
|
118 | }
|
119 | var sentry = fs.readFileSync('sentry');
|
120 | if (sentry.length) {
|
121 | logOnDetails.sha_sentryfile = MakeSha(sentry);
|
122 | }
|
123 | bot.connect();
|
124 | steamUser.on('updateMachineAuth', function(response, callback){
|
125 | fs.writeFileSync('sentry', response.bytes);
|
126 | callback({ sha_file: MakeSha(response.bytes) });
|
127 | });
|
128 | bot.on("logOnResponse", onSteamLogOn)
|
129 | .on('sentry', onSteamSentry)
|
130 | .on('servers', onSteamServers)
|
131 | .on('connected', function(){
|
132 | steamUser.logOn(logOnDetails);
|
133 | });
|