forked from BeepIsla/csgo-commend-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index_report.js
291 lines (223 loc) · 9.03 KB
/
index_report.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
const fs = require("fs");
const SteamIDParser = require("./helpers/steamIDParser.js");
const Account = require("./helpers/account.js");
const config = require("./config_report.json");
const colors = {
general: "\x1b[37m",
login: "\x1b[36m",
loggedIn: "\x1b[33m",
connectedToGC: "\x1b[35m",
success: "\x1b[32m",
error: "\x1b[31m"
};
// Shittily parse command line arguments
if (process.argv[2]) {
config.AccountToReport = process.argv[2];
}
if (process.argv[3]) {
try {
if (!isNaN(parseInt(process.argv[3]))) {
config.ReportsToSend = parseInt(process.argv[3]);
} else {
throw new Error("Not a number");
}
} catch(e) {
console.log(colors.error + "Failed to parse ReportsToSend via command line argument");
};
}
if (process.argv[4]) {
config.MatchID = process.argv[4];
} else {
// If we do not have a matchID in our arguments just leave it empty
config.MatchID = "";
}
// Add all accounts to the config
config.accounts = require("./accounts.json");
var curProxy = -1;
var proxyChunk = 0;
var reportsSent = 0;
var reportsFailed = 0;
var chunkComplete = 0;
var chunkCompleteLimit = -1;
var hitRatelimit = false;
(async () => {
// Parse "AccountToReport" to accountID
console.log(colors.general + "Parsing account from " + config.AccountToReport);
var output = await SteamIDParser(config.AccountToReport, config.SteamAPIKey).catch((err) => {
console.error(err);
});
// An error occured
if (!output) {
return;
}
config.AccountToReport = output.accountid;
console.log(colors.general + "Successfully parsed account to " + config.AccountToReport);
console.log(colors.general + "Getting " + config.ReportsToSend + " account" + (config.ReportsToSend === 1 ? "" : "s"));
// First we get all available accounts (You can report once every 24 hours)
var available = config.accounts.filter(a => a.operational === true && a.requiresSteamGuard === false && (new Date().getTime() - (a.lastReport ? a.lastReport : -1)) >= config.AccountCooldown);
// Check if we have enough available accounts
if (available.length < config.ReportsToSend) {
console.log(colors.general + available.length + "/" + config.accounts.length + " account" + (config.accounts.length === 1 ? "" : "s") + " available but we need " + config.ReportsToSend + " account" + (config.ReportsToSend === 1 ? "" : "s"));
return;
}
// Get needed accounts
var accountsToUse = available.slice(0, config.ReportsToSend);
// Split accounts into chunks, do "ReportsPerChunk" at a time
var chunks = chunkArray(accountsToUse, config.Chunks.ReportsPerChunk);
// Wait 5 seconds before starting the actual process
await new Promise(r => setTimeout(r, (5 * 1000)));
// Go through all chunks, use await to slow it down
for (let chunk of chunks) {
// If we previously hit the ratelimit then wait "RateLimitedCooldown" ms
if (hitRatelimit === true) {
console.log(colors.general + "We have hit the ratelimit, waiting " + config.RateLimitedCooldown + "ms");
await new Promise(r => setTimeout(r, config.RateLimitedCooldown));
}
chunkCompleteLimit = chunk.length;
// Do 100 at once and await until they are done
var result = await new Promise((resolve, reject) => {
// We are doing a new chunk, set the "hitRatelimit" to false
hitRatelimit = false;
for (let account of chunk) {
accountHandler(account, resolve);
}
});
// Increase our proxyChunk count
proxyChunk++;
// If the result is "true" that means we have another one to do, if its false it means we are at the end and dont need to wait more
if (result === true) {
// Wait "BeautifyDelay" ms so the message actually appears at the bottom and not somewhere in the middle
await new Promise(r => setTimeout(r, config.Chunks.BeautifyDelay));
console.log(colors.general + "Waiting " + parseInt(config.Chunks.TimeBetweenChunks / 1000) + " second" + (parseInt(config.Chunks.TimeBetweenChunks / 60) === 1 ? "" : "s"));
// Wait 60 seconds and then repeat the loop
await new Promise(r => setTimeout(r, config.Chunks.TimeBetweenChunks));
}
}
})();
function accountHandler(account, resolve) {
try {
console.log(colors.login + "[" + account.username + "] Logging into account");
const acc = new Account(account.username, account.password, account.sharedSecret, getProxy());
acc.on("loggedOn", () => {
console.log(colors.loggedIn + "[" + account.username + "] Successfully logged into account");
});
acc.on("ready", async (hello) => {
console.log(colors.connectedToGC + "[" + account.username + "] Connected to CSGO GameCoordinator");
// Wait "TimeBetweenConnectionAndSending" ms before sending the report
await new Promise(r => setTimeout(r, config.Chunks.TimeBetweenConnectionAndSending));
acc.report(config.AccountToReport, config.MatchID, (30 * 1000), config.Report.Aimbot, config.Report.Wallhack, config.Report.Speedhack, config.Report.Teamharm, config.Report.Textabuse, config.Report.Voiceabuse).then((response) => {
reportsSent += 1;
console.log(colors.success + "[" + account.username + "] Successfully sent a report " + reportsSent + "/" + config.ReportsToSend + " - " + response.confirmation_id);
acc.logout();
var index = config.accounts.map(a => a.username).indexOf(account.username);
if (index >= 0) {
config.accounts[index].lastReport = new Date().getTime();
}
delete acc;
checkComplete(resolve);
}).catch((err) => {
// Reporting while not even being connected to the GC... Makes sense
if (typeof err === "string" && err === "previously_timed_out") {
return;
}
reportsFailed += 1;
console.log(colors.error + "[" + account.username + "] Has encountered an error");
console.error(err);
acc.logout();
var index = config.accounts.map(a => a.username).indexOf(account.username);
if (index >= 0) {
config.accounts[index].lastReport = new Date().getTime();
}
delete acc;
checkComplete(resolve);
});
});
acc.on("steamGuard", () => {
reportsFailed += 1;
console.log(colors.error + "[" + account.username + "] Requires a SteamGuard code");
var index = config.accounts.map(a => a.username).indexOf(account.username);
if (index >= 0) {
config.accounts[index].requiresSteamGuard = true;
}
acc.logout();
delete acc;
checkComplete(resolve);
});
acc.on("error", (err) => {
reportsFailed += 1;
console.log(colors.error + "[" + account.username + "] Has encountered an error");
console.error(err);
if (err.eresult === 84) {
// we have hit the ratelimit set "hitRatelimit" to true
hitRatelimit = true;
}
var index = config.accounts.map(a => a.username).indexOf(account.username);
if (index >= 0) {
// If the error is "RateLimitExceeded" just ignore it, we can still use the account just fine after the ratelimit is over
config.accounts[index].operational = isNaN(err.eresult) ? false : (err.eresult === 84 ? true : err.eresult);
}
acc.logout();
delete acc;
checkComplete(resolve);
});
} catch(err) {
reportsFailed += 1;
if (account) {
console.log(colors.error +"[" + account.username + "] Has encountered an error");
var index = config.accounts.map(a => a.username).indexOf(account.username);
if (index >= 0) {
config.accounts[index].operational = isNaN(err.eresult) ? false : err.eresult;
}
}
console.error(err);
if (typeof acc !== "undefined") {
acc.logout();
}
delete acc;
checkComplete(resolve);
}
}
function checkComplete(resolve) {
// Always increment this, as everytime we check one has finished (successfully or not doesnt matter in this case)
chunkComplete++;
// Global complete
if ((reportsSent + reportsFailed) >= config.ReportsToSend) {
resolve(false);
// Update our accounts.json
fs.writeFileSync("./accounts.json", JSON.stringify(config.accounts, null, 4));
// We have successfully sent all reports and are now done here
console.log(colors.general + "Successfully sent " + reportsSent + "/" + config.ReportsToSend + " report" + (config.ReportsToSend === 1 ? "" : "s") + ", " + reportsFailed + " report" + (reportsFailed === 1 ? "" : "s") + " failed");
return;
}
// Chunk complete
if (chunkComplete >= chunkCompleteLimit) {
// Write on every completed chunk
fs.writeFileSync("./accounts.json", JSON.stringify(config.accounts, null, 4));
resolve(true);
}
}
function getProxy() {
// If "config.Chunks.SwitchProxyEvery" many chunks have passed we switch to the next one
if (proxyChunk >= config.Chunks.SwitchProxyEvery) {
proxyChunk = 0;
curProxy += 1;
}
// If we are outside the array bounds go back to 0
if (!config.Proxies[curProxy]) {
curProxy = 0;
}
// If we are still outside the array bounds despite being at 0 then no list is defined
if (!config.Proxies[curProxy]) {
return undefined;
}
return config.Proxies[curProxy];
}
// Copied from: https://ourcodeworld.com/articles/read/278/how-to-split-an-array-into-chunks-of-the-same-size-easily-in-javascript
function chunkArray(myArray, chunk_size) {
var tempArray = [];
for (let index = 0; index < myArray.length; index += chunk_size) {
myChunk = myArray.slice(index, index + chunk_size);
tempArray.push(myChunk);
}
return tempArray;
}