-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathtest.js
175 lines (147 loc) · 8.35 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
var Steam = require('steam'),
CSGO = require('../'),
steamClient = new Steam.SteamClient(),
steamUser = new Steam.SteamUser(steamClient),
steamFriends = new Steam.SteamFriends(steamClient),
steamGC = new Steam.SteamGameCoordinator(steamClient, 730),
CSGOCli = new CSGO.CSGOClient(steamUser, steamGC, false),
should = require('should'),
crypto = require('crypto');
function MakeSha(bytes) {
var hash = crypto.createHash('sha1');
hash.update(bytes);
return hash.digest();
}
Steam.servers = JSON.parse(`[{"host":"162.254.195.47","port":27019},{"host":"162.254.195.47","port":27018},{"host":"162.254.195.46","port":27017},{"host":"162.254.195.44","port":27018},{"host":"162.254.195.45","port":27018},{"host":"162.254.195.44","port":27019},{"host":"162.254.195.45","port":27019},{"host":"162.254.195.44","port":27017},{"host":"162.254.195.46","port":27019},{"host":"162.254.195.45","port":27017},{"host":"162.254.195.46","port":27018},{"host":"162.254.195.47","port":27017},{"host":"162.254.193.47","port":27018},{"host":"162.254.193.6","port":27017},{"host":"162.254.193.46","port":27017},{"host":"162.254.193.7","port":27019},{"host":"162.254.193.6","port":27018},{"host":"162.254.193.6","port":27019},{"host":"162.254.193.47","port":27017},{"host":"162.254.193.46","port":27019},{"host":"162.254.193.7","port":27018},{"host":"162.254.193.47","port":27019},{"host":"162.254.193.7","port":27017},{"host":"162.254.193.46","port":27018},{"host":"155.133.254.132","port":27017},{"host":"155.133.254.132","port":27018},{"host":"205.196.6.75","port":27017},{"host":"155.133.254.133","port":27019},{"host":"155.133.254.133","port":27017},{"host":"155.133.254.133","port":27018},{"host":"155.133.254.132","port":27019},{"host":"205.196.6.67","port":27018},{"host":"205.196.6.67","port":27017},{"host":"205.196.6.75","port":27019},{"host":"205.196.6.67","port":27019},{"host":"205.196.6.75","port":27018},{"host":"162.254.192.108","port":27018},{"host":"162.254.192.100","port":27017},{"host":"162.254.192.101","port":27017},{"host":"162.254.192.108","port":27019},{"host":"162.254.192.109","port":27019},{"host":"162.254.192.100","port":27018},{"host":"162.254.192.108","port":27017},{"host":"162.254.192.101","port":27019},{"host":"162.254.192.109","port":27018},{"host":"162.254.192.101","port":27018},{"host":"162.254.192.109","port":27017},{"host":"162.254.192.100","port":27019},{"host":"162.254.196.68","port":27019},{"host":"162.254.196.83","port":27019},{"host":"162.254.196.68","port":27017},{"host":"162.254.196.67","port":27017},{"host":"162.254.196.67","port":27019},{"host":"162.254.196.83","port":27017},{"host":"162.254.196.84","port":27019},{"host":"162.254.196.84","port":27017},{"host":"162.254.196.83","port":27018},{"host":"162.254.196.68","port":27018},{"host":"162.254.196.84","port":27018},{"host":"162.254.196.67","port":27018},{"host":"155.133.248.53","port":27017},{"host":"155.133.248.50","port":27017},{"host":"155.133.248.51","port":27017},{"host":"155.133.248.52","port":27019},{"host":"155.133.248.53","port":27019},{"host":"155.133.248.52","port":27018},{"host":"155.133.248.52","port":27017},{"host":"155.133.248.51","port":27019},{"host":"155.133.248.53","port":27018},{"host":"155.133.248.50","port":27018},{"host":"155.133.248.51","port":27018},{"host":"155.133.248.50","port":27019},{"host":"155.133.246.69","port":27017},{"host":"155.133.246.68","port":27018},{"host":"155.133.246.68","port":27017},{"host":"155.133.246.69","port":27018},{"host":"155.133.246.68","port":27019},{"host":"155.133.246.69","port":27019},{"host":"162.254.197.42","port":27018},{"host":"146.66.152.10","port":27018}]`);
var connectedToSteam = false,
connectedToGC = false,
loggedInToSteam = false;
function beConnectedToSteam(done) {
if (connectedToSteam) return done();
setTimeout(() => beConnectedToSteam(done), 1000);
}
function beLoggedInToSteam(done) {
if (loggedInToSteam) return done();
setTimeout(() => beLoggedInToSteam(done), 1000);
}
function beConnectedToGC(done) {
if (connectedToGC) return done();
setTimeout(() => beConnectedToGC(done), 1000);
}
CSGOCli.on('unready', () => {
steamClient.disconnect();
console.error("Connection to GC has been lost. Failing.");
process.exit(1);
});
after((done) => {
steamClient.disconnect();
done();
});
describe('Steam', () => {
describe('#connect', () => {
it('should connect to Steam', (done) => {
steamClient.connect();
steamClient.on('connected', () => {
connectedToSteam = true;
done();
});
});
});
describe('#login', () => {
it('should login to Steam', (done) => {
before(beConnectedToSteam);
steamUser.logOn({
"account_name": process.env.steam_username,
"password": process.env.steam_password,
"sha_sentryfile": MakeSha(Buffer.from(process.env.steam_sentry, 'base64')),
});
steamClient.on('logOnResponse', (resp) => {
if (resp.eresult == Steam.EResult.OK) {
loggedInToSteam = true;
done();
} else {
console.error('Failed to log on to Steam.');
console.error(resp);
}
});
});
});
});
describe('CSGO', () => {
before(beLoggedInToSteam);
describe('#launch', () => {
it('should launch CSGO and connect to the GC', function(done) {
this.timeout(20000);
steamFriends.setPersonaState(Steam.EPersonaState.Invisible);
CSGOCli.launch();
CSGOCli.on('ready', () => {
connectedToGC = true;
done();
});
});
});
describe('#utils', () => {
before(beConnectedToGC);
it('should convert a steam ID to an account ID', (done) => {
should.exist(steamClient.steamID)
should.equal(CSGOCli.ToAccountID(steamClient.steamID), 51829904);
done();
});
});
var mmStatsChecked = false;
describe('#mmstats', () => {
before(beConnectedToGC);
it('should request and receive matchmaking stats', (done) => {
CSGOCli.matchmakingStatsRequest();
CSGOCli.on('matchmakingStatsData', (data) => {
if (mmStatsChecked) return;
mmStatsChecked = true;
should.exist(data.global_stats);
done();
});
});
});
describe('#profile', () => {
before(beConnectedToGC);
var profileStatsChecked = false;
it('should request and receive profile stats', (done) => {
CSGOCli.playerProfileRequest(CSGOCli.ToAccountID(steamClient.steamID));
CSGOCli.on('playerProfile', function(profile) {
if (profileStatsChecked) return;
profileStatsChecked = true;
should.exist(profile.account_profiles[0]);
should.equal(profile.account_profiles[0].account_id, CSGOCli.ToAccountID(steamClient.steamID));
done();
});
});
var matchListChecked = false;
it('should request recent games', (done) => {
CSGOCli.requestRecentGames();
CSGOCli.on('matchList', (list) => {
if (matchListChecked) return;
matchListChecked = true;
should.equal(list.accountid, CSGOCli.ToAccountID(steamClient.steamID));
(list.matches).should.be.a.Array();
done();
});
});
});
describe('#items', () => {
before(beConnectedToGC);
it('should request item data', (done) => {
CSGOCli.itemDataRequest('76561198084749846', '6768147729', '12557175561287951743', '0');
CSGOCli.on('itemData', (itemdata) => {
const itemInfo = itemdata.iteminfo;
should(itemInfo.defindex).be.a.Number()
should(itemInfo.paintindex).be.a.Number()
should(itemInfo.rarity).be.a.Number()
should(itemInfo.quality).be.a.Number()
should(itemInfo.paintwear).be.a.Number()
should(itemInfo.paintseed).be.a.Number()
should(itemInfo.stickers).be.a.Array()
should(itemInfo.inventory).be.a.Number()
done();
});
});
});
});