forked from BeepIsla/CSGO-Overwatch-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
843 lines (721 loc) · 26.4 KB
/
index.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
const fs = require("fs");
const path = require("path");
const Stream = require("stream");
const SteamTotp = require("steam-totp");
const SteamID = require("steamid");
const unbzip2 = require("unbzip2-stream");
const cliTable = require("cli-table3");
const demofile = require("demofile");
const Helper = require("./helpers/Helper.js");
const Coordinator = require("./helpers/Coordinator.js");
const Protobufs = require("./helpers/Protobufs.js");
const Translate = require("./helpers/Translate.js");
const Demo = require("./helpers/Demo.js");
const Steamworks = require("./helpers/Steamworks.js");
const SteamUser = require("./helpers/SteamUser.js");
const config = require("./config.json");
const USING_STEAMWORKS = process.argv.join(" ").toUpperCase().includes("STEAMWORKS");
if (USING_STEAMWORKS) {
console.log("WARNING: Using Steamworks - This is experimental");
}
function randomIntFromIntervall(min, max) {
return Math.floor(Math.random() * (max - min) + min); //randomize and add 3 Seconds.
}
const steam = USING_STEAMWORKS ? new Steamworks() : new SteamUser();
const coordinator = new Coordinator(steam, 730);
const objectHandler = {};
const notifications = []; // To be sent to console between cases
let notifiedOfOverwatchBonusXP = false; // Only notify once per session at most
let protobufs = undefined;
let playStateBlocked = false;
let loginPersonaCheck = false;
let tempLoginKey = undefined;
let casesCompleted = 0;
let verdictNumber = config.verdict.verdictNumber;
let verdictNumberDone = 0;
let timings = {
Downloading: 0,
Unpacking: 0,
Parsing: 0
};
process.on("SIGINT", () => {
console.log(USING_STEAMWORKS ? "Shutting down..." : "Logging off...");
steam.logOff();
setTimeout(process.exit, 1000, 0).unref();
});
(async () => {
console.log("Checking protobufs...");
let foundProtobufs = Helper.VerifyProtobufs();
if (foundProtobufs) {
console.log("Found protobufs");
} else {
console.log("Failed to find protobufs, downloading and extracting...");
await Helper.DownloadProtobufs(__dirname);
}
protobufs = new Protobufs([
{
name: "csgo",
protos: path.join(__dirname, "protobufs", "csgo")
}
]);
objectHandler[protobufs.data.csgo.ESOMsg.k_ESOMsg_Create] = "CMsgSOSingleObject";
objectHandler[protobufs.data.csgo.ESOMsg.k_ESOMsg_Update] = "CMsgSOSingleObject";
objectHandler[protobufs.data.csgo.ESOMsg.k_ESOMsg_UpdateMultiple] = "CMsgSOMultipleObjects";
console.log("Checking for updates...");
try {
let pkg = JSON.parse(fs.readFileSync("./package.json"));
let res = await Helper.GetLatestVersion().catch(console.error);
if (pkg.version !== res) {
let repoURL = pkg.repository.url.split(".");
repoURL.pop();
console.log("A new version is available on Github @ " + repoURL.join("."));
console.log("Downloading is optional but recommended. Make sure to check if there are any new values to be added in your old \"config.json\"");
} else {
console.log("Up to date!");
}
} catch {
console.log("Update check failed");
}
console.log("Fetching CSGO translation file...");
await Translate.fetchTokens("csgo_english.txt");
// Get login key if we have one
let dataPath = path.join(__dirname, "data");
if (!fs.existsSync(dataPath)) {
fs.mkdirSync(dataPath);
}
let loginkeyPath = path.join(dataPath, "loginkey");
let keyData = fs.existsSync(loginkeyPath) ? fs.readFileSync(loginkeyPath).toString() : undefined;
try {
keyData = keyData ? JSON.parse(keyData) : undefined;
} catch {
console.log("Failed to parse loginKey from previous session.");
}
let useLoginKey = keyData && keyData.account === config.account.username && config.account.saveSteamGuard;
console.log("Logging into Steam...");
steam.logOn({
accountName: config.account.username,
password: useLoginKey ? undefined : config.account.password,
twoFactorCode: useLoginKey ? undefined : (config.account.sharedSecret && config.account.sharedSecret.length > 5 ? SteamTotp.getAuthCode(config.account.sharedSecret) : undefined),
loginKey: useLoginKey ? keyData.loginKey : undefined,
rememberPassword: true
});
})();
steam.on("loggedOn", () => {
console.log("Successfully logged into " + steam.steamID.toString());
steam.setPersona(config.account.invisible ? SteamUser.EPersonaState.Invisible : SteamUser.EPersonaState.Online);
loginPersonaCheck = false;
});
steam.on("user", (sid, user) => {
if (sid.accountid !== steam.steamID.accountid) {
return;
}
if (loginPersonaCheck) {
return;
}
loginPersonaCheck = true;
if (user.gameid !== "0") {
// Someone else is already playing
// No need to log here as "playingState" will emit as well
return;
}
// Nobody is currently playing on any session
steam.gamesPlayed([730]);
});
steam.on("appLaunched", async (appID) => {
if (appID !== 730) {
return;
}
console.log("Establishing CSGO GameCoordinator connection...");
let helloBuf = protobufs.encodeProto("CMsgClientHello", {});
while (true) {
if (playStateBlocked) {
// We are blocked
return;
}
let welcome = await coordinator.sendMessage(
730,
protobufs.data.csgo.EGCBaseClientMsg.k_EMsgGCClientHello,
{},
helloBuf,
protobufs.data.csgo.EGCBaseClientMsg.k_EMsgGCClientWelcome,
5000
).catch(() => { });
if (welcome) {
if (!config.account.notifyXPReward) {
// Skip
break;
}
// Parse response and get flags from it
welcome = protobufs.decodeProto("CMsgClientWelcome", welcome);
let flags = Helper.GetXPFlags(welcome.outofdate_subscribed_caches || []);
// The above parses various things but we only care about the Overwatch one so ignore everything else
for (let flag of flags) {
if (!flag.title.includes("Overwatch")) {
continue;
}
let table = new cliTable({
head: [flag.title]
});
table.push([flag.description]);
console.log(table.toString());
notifiedOfOverwatchBonusXP = true;
}
break;
}
}
console.log("Established CSGO connection, getting rank information...");
let mmWelcome = await coordinator.sendMessage(
730,
protobufs.data.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_MatchmakingClient2GCHello,
{},
protobufs.encodeProto("CMsgGCCStrike15_v2_MatchmakingClient2GCHello", {}),
protobufs.data.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_MatchmakingGC2ClientHello,
30000
);
mmWelcome = protobufs.decodeProto("CMsgGCCStrike15_v2_MatchmakingGC2ClientHello", mmWelcome);
if (playStateBlocked) {
// We are blocked
return;
}
if (Helper.MatchmakingKickBanReason.IsPermanent(mmWelcome.penalty_reason)) {
console.log("Cannot do Overwatch cases while game banned.");
steam.logOff();
return;
}
if (Helper.MatchmakingKickBanReason.IsGlobal(mmWelcome.penalty_reason)) {
console.log("Cannot do Overwatch cases while on global cooldown.");
steam.logOff();
return;
}
if (Helper.MatchmakingKickBanReason.IsGreen(mmWelcome.penalty_reason)) {
console.log("Cannot do Overwatch cases while on temporary cooldown.");
steam.logOff();
return;
}
/* Since the last update you can also use OW with temporary ban
if (typeof mmWelcome.penalty_reason === "number" && mmWelcome.penalty_reason > 0) {
console.log("Cannot do Overwatch cases while on cooldown.");
steam.logOff();
return;
}
*/
if (typeof mmWelcome.vac_banned === "number" && mmWelcome.vac_banned > 0) {
console.log("Cannot do Overwatch cases while VAC banned.");
steam.logOff();
return;
}
let rank = mmWelcome.ranking;
if (!rank || rank.rank_type_id !== 6) { // Competitive ID
rank = await coordinator.sendMessage(
730,
protobufs.data.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientGCRankUpdate,
{},
protobufs.encodeProto("CMsgGCCStrike15_v2_ClientGCRankUpdate", {
rankings: {
rank_type_id: 6
}
}),
protobufs.data.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientGCRankUpdate,
30000
);
rank = protobufs.decodeProto("CMsgGCCStrike15_v2_ClientGCRankUpdate", rank);
if (rank.rankings && rank.rankings[0]) {
rank = rank.rankings[0];
} else {
rank = undefined;
}
}
if (playStateBlocked) {
// We are blocked
return;
}
if (rank) {
console.log("We are \"" + Translate("RankName_" + rank.rank_id) + "\" with " + rank.wins + " win" + (rank.wins === 1 ? "" : "s"));
if (rank.rank_id < 7 || rank.wins < 150) {
console.log((rank.rank_id < 7 ? "Our rank is too low" : "We do not have enough wins") + " in order to request Overwatch cases. You need at least 150 wins and " + Translate("skillgroup_7") + ".");
steam.logOff();
return;
}
} else {
console.log("Failed to receive rank - Assuming we have access to Overwatch");
}
console.log("Checking for Overwatch access...");
await coordinator.sendMessage(
730,
protobufs.data.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_PlayerOverwatchCaseUpdate,
{},
protobufs.encodeProto("CMsgGCCStrike15_v2_PlayerOverwatchCaseUpdate", {
reason: Helper.OverwatchConstants.EMMV2OverwatchCasesUpdateReason_t.k_EMMV2OverwatchCasesUpdateReason_Poll
})
);
if (playStateBlocked) {
// We are blocked
return;
}
steam.uploadRichPresence(730, {
steam_display: "#display_Menu"
});
});
steam.on("disconnected", (eresult, msg) => {
console.log("Disconnected from Steam with EResult " + eresult + " and message " + msg);
process.exitCode = 1;
// Steam-User keeps the connection alive for a really long time some reason
setTimeout(() => process.exit, 1, 15 * 1000).unref();
});
steam.on("loginKey", (key) => {
tempLoginKey = key;
if (!config.account.saveSteamGuard) {
return;
}
let dataPath = path.join(__dirname, "data");
if (!fs.existsSync(dataPath)) {
fs.mkdirSync(dataPath);
}
fs.writeFileSync(path.join(dataPath, "loginKey"), JSON.stringify({
loginKey: key,
account: config.account.username
}));
});
steam.on("playingState", (blocked, playingApp) => {
if (playStateBlocked === blocked) {
return;
}
playStateBlocked = blocked;
if (playStateBlocked) {
console.log("App " + playingApp + " was started on another Steam client. Waiting...");
steam.gamesPlayed([]);
} else {
console.log("Other Steam client stopped playing. Resuming...");
steam.gamesPlayed([730]);
}
});
steam.on("error", (err) => {
switch (err.eresult) {
case 5: {
console.log("Login with saved loginKey failed. Logging in without loginKey...");
steam.logOn({
accountName: config.account.username,
password: config.account.password,
twoFactorCode: config.account.sharedSecret && config.account.sharedSecret.length > 5 ? SteamTotp.getAuthCode(config.account.sharedSecret) : undefined,
rememberPassword: true
});
break;
}
case 6: {
console.log("Another client started a game and kicked us off, logging back into Steam...");
steam.logOn({
accountName: config.account.username,
password: tempLoginKey ? undefined : config.account.password,
twoFactorCode: tempLoginKey ? undefined : (config.account.sharedSecret && config.account.sharedSecret.length > 5 ? SteamTotp.getAuthCode(config.account.sharedSecret) : undefined),
loginKey: tempLoginKey ? tempLoginKey : undefined,
rememberPassword: true
});
break;
}
default: {
throw err;
}
}
});
coordinator.on("receivedFromGC", async (msgType, payload) => {
if (playStateBlocked) {
// We are blocked
return;
}
if (config.account.notifyXPReward && !notifiedOfOverwatchBonusXP && objectHandler[msgType]) {
let body = protobufs.decodeProto(objectHandler[msgType], payload);
if (!Array.isArray(body.objects_modified) && body.type_id && body.object_data) {
// Single - Make fake multi
body = {
objects_modified: [
{
type_id: body.type_id,
object_data: [
body.object_data
]
}
]
};
}
// Pass as fake cache
let flags = Helper.GetXPFlags([
{
objects: body.objects_modified
}
]);
// The above parses various things but we only care about the Overwatch one so ignore everything else
for (let flag of flags) {
if (!flag.title.includes("Overwatch")) {
continue;
}
let table = new cliTable({
head: [flag.title]
});
table.push([flag.description]);
if (notifications.includes("Overwatch")) {
// A notification about this is already pending
continue;
}
notifications.push(table.toString());
notifiedOfOverwatchBonusXP = true;
}
}
if (msgType !== protobufs.data.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_PlayerOverwatchCaseAssignment) {
return;
}
let body = protobufs.decodeProto("CMsgGCCStrike15_v2_PlayerOverwatchCaseAssignment", payload);
if (body.reason === Helper.OverwatchConstants.EMMV2OverwatchCasesUpdateReason_t.k_EMMV2OverwatchCasesUpdateReason_Assign &&
typeof body.verdict === "undefined"
) {
// We have access to Overwatch! Lets request a little case
console.log("Access confirmed by CSGO Network");
console.log("Attempt to get Overwatch case...");
await coordinator.sendMessage(
730,
protobufs.data.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_PlayerOverwatchCaseUpdate,
{},
protobufs.encodeProto("CMsgGCCStrike15_v2_PlayerOverwatchCaseUpdate", {
reason: Helper.OverwatchConstants.EMMV2OverwatchCasesUpdateReason_t.k_EMMV2OverwatchCasesUpdateReason_Assign
})
);
} else if (typeof body.reason === "undefined" &&
body.verdict === Helper.OverwatchConstants.EMMV2OverwatchCasesVerdict_t.k_EMMV2OverwatchCasesVerdict_Pending
) {
// No "reason" but "verdict" is pending -> Parse demo
let sid = SteamID.fromIndividualAccountID(body.suspectid);
console.log("-".repeat(50));
console.log(" Case ID: " + body.caseid.toString());
console.log(" Download URL: " + body.caseurl);
console.log(" Total Rounds: " + body.numrounds);
console.log(" Rounds to watch: " + body.fractionrounds);
console.log("Overwatch starting round: " + (body.fractionid + 1)); // FractionID 0 = Round 1 (Pistol round)
console.log(" Suspect: https://steamcommunity.com/profiles/" + sid.getSteamID64());
console.log("----- The whole demo will be analyzed ----");
console.log("Downloading demo...");
timings.Downloading = Date.now();
let response = await Helper.Fetch(body.caseurl).catch(() => { });
if (playStateBlocked) {
// We are blocked
return;
}
if (!response || !response.ok) {
// Something failed while downloading - Tell the GC about it and abandon
console.error(new Error("Failed to download case. Check your internet connection"));
await coordinator.sendMessage(
730,
protobufs.data.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_PlayerOverwatchCaseStatus,
{},
protobufs.encodeProto("CMsgGCCStrike15_v2_PlayerOverwatchCaseStatus", {
caseid: body.caseid,
statusid: Helper.OverwatchConstants.EMMV2OverwatchCasesStatus_t.k_EMMV2OverwatchCasesStatus_ErrorDownloading
})
);
// Log off and set exit code to failure - Hopefully our user uses something like PM2 or similar
steam.logOff();
process.exitCode = 1;
return;
}
let buffer = await response.buffer().catch(() => { });
timings.Downloading = Date.now() - timings.Downloading;
if (playStateBlocked) {
// We are blocked
return;
}
console.log("Unpacking demo...");
timings.Unpacking = Date.now();
// Shitty way to unpack the demo thanks to the library being synchronous
let demoBuffer = await new Promise((resolve, reject) => {
let readable = new Stream.Readable();
readable._read = () => { };
readable.push(buffer);
readable.push(null);
let data = Buffer.alloc(0);
readable.pipe(unbzip2()).on("data", (chunk) => {
data = Buffer.concat([data, chunk]);
}).on("error", (err) => {
reject(err);
}).on("end", () => {
resolve(data);
});
}).catch((err) => {
if (!buffer) {
console.error(new Error("Failed to get buffer from download response"));
} else {
console.error(err);
}
return coordinator.sendMessage(
730,
protobufs.data.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_PlayerOverwatchCaseStatus,
{},
protobufs.encodeProto("CMsgGCCStrike15_v2_PlayerOverwatchCaseStatus", {
caseid: body.caseid,
statusid: Helper.OverwatchConstants.EMMV2OverwatchCasesStatus_t.k_EMMV2OverwatchCasesStatus_ErrorExtracting
})
).finally(() => {
// Log off and set exit code to failure - Hopefully our user uses something like PM2 or similar
steam.logOff();
process.exitCode = 1;
});
});
if (!demoBuffer) {
return;
}
if (playStateBlocked) {
// We are blocked
return;
}
timings.Unpacking = Date.now() - timings.Unpacking;
if (config.verdict.writeLog || config.verdict.backupDemo) {
if (!fs.existsSync("cases")) {
fs.mkdirSync("cases");
}
if (!fs.existsSync("cases/" + body.caseid)) {
fs.mkdirSync("cases/" + body.caseid);
}
}
console.log("Received a " + (demoBuffer.length / 1024 / 1024).toFixed(2) + "MB demo");
if (config.verdict.backupDemo) {
fs.writeFileSync("cases/" + body.caseid + "/demofile.dem", demoBuffer);
}
if (config.verdict.writeLog) {
fs.writeFileSync("cases/" + body.caseid + "/message.json", JSON.stringify(body, null, "\t"));
}
await coordinator.sendMessage(
730,
protobufs.data.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_PlayerOverwatchCaseStatus,
{},
protobufs.encodeProto("CMsgGCCStrike15_v2_PlayerOverwatchCaseStatus", {
caseid: body.caseid,
statusid: Helper.OverwatchConstants.EMMV2OverwatchCasesStatus_t.k_EMMV2OverwatchCasesStatus_Ready
})
);
if (config.verdict.writeLog) {
fs.writeFileSync("cases/" + body.caseid + "/profile.url", [
"[InternetShortcut]",
"URL=https://steamcommunity.com/profiles/" + sid.getSteamID64()
].join("\n"));
}
let header = demofile.parseHeader(demoBuffer);
console.log("- Server: " + header.serverName);
console.log("- Version: " + header.networkProtocol);
console.log("- Map: " + header.mapName);
console.log("- Length: " + Helper.FormatSeconds(header.playbackTime) + "m");
// Arbitrary number, no idea at which version it works
if (header.networkProtocol < 13700) {
// Use provided time by Valve (Usually 90 minutes) or just fallback to 90
let waitMins = body.throttleseconds ? (body.throttleseconds / 60) : 90;
console.log("");
console.log("Detected demo from pre-2020. These type of demos are not parsable. The bot will now wait " + waitMins + " minute" + (waitMins === 1 ? "" : "s") + " for the case to disappear.");
console.log("NOTE: Starting CSGO during this time might restart the " + waitMins + " minute timer.");
console.log("");
console.log("Current time: " + new Date().toLocaleString());
console.log("Will continue at: " + new Date(Date.now() + waitMins * 60 * 1000).toLocaleString());
// Stop playing and later start playing again - The "appLaunched" event should fire again
steam.gamesPlayed([]);
await new Promise(p => setTimeout(p, waitMins * 60 * 1000).unref());
steam.gamesPlayed([730]);
return;
}
let demo = new Demo(demoBuffer, sid.getSteamID64(), config, body);
let lastVal = 0;
demo.demo.on("progress", (progressFraction) => {
let percentage = Math.round(progressFraction * 100);
if (lastVal === percentage || (percentage % 1) !== 0) {
return;
}
lastVal = percentage;
process.stdout.write("\r\x1b[K"); // Clear current line
process.stdout.write("Parsing: " + percentage + "%");
});
timings.Parsing = Date.now();
process.stdout.write("Parsing: 0%");
let data = await demo.parse(steam).catch((err) => {
process.stdout.write("\n");
// Fail parsing - Log off and set exit code to failure - Hopefully our user uses something like PM2 or similar
console.error(err);
steam.logOff();
process.exitCode = 1;
});
if (!data) {
return;
}
data.header = header;
process.stdout.write("\n");
timings.Parsing = Date.now() - timings.Parsing;
if (playStateBlocked) {
// We are blocked
return;
}
// Force convict?
if (typeof config.parsing.forceConvictOnPreviousBan === "number" && config.parsing.forceConvictOnPreviousBan >= 0) {
data.forceConvictEnabled = false;
let days = await Helper.GetBanStatus(sid).catch(() => { });
if (typeof days !== "number") {
console.log("Suspect has not been banned before");
data.forceConvicted = false;
} else if (days <= config.parsing.forceConvictOnPreviousBan) {
console.log("Suspect has been banned " + days + " day" + (days === 1 ? "" : "s") + " ago, forcefully convicting");
data.verdict.wallhack = true;
data.forceConvicted = true;
} else {
console.log("Suspect has been banned " + days + " day" + (days === 1 ? "" : "s") + " ago, ban too old to convict");
data.forceConvicted = false;
}
} else {
data.forceConvictEnabled = false;
data.forceConvicted = false;
}
let timeTotal = timings.Downloading + timings.Parsing + timings.Unpacking;
if (config.verdict.writeLog) {
data.timings = timings;
data.timings.total = timeTotal;
fs.writeFileSync("cases/" + body.caseid + "/data.json", JSON.stringify(data, null, "\t"));
}
// Demo logs
if (config.verdict.printScoreboard) {
demo.logScoreboard();
}
demo.logResults();
console.log("Cases completed this session: " + ++casesCompleted);
console.log("verdicts Done before pause" + ++verdictNumberDone);
// Log timings
let longestKey = Math.max(Object.keys(timings).map(k => k.length));
let longestTiming = Math.max(Object.keys(timings).map(k => timings[k].toString().length));
console.log("Timings:");
for (let key in timings) {
let name = "\t- " + " ".repeat(longestKey - key.length) + key;
let num = Math.round(timings[key] / 1000).toString();
num = " ".repeat(longestTiming - num.length) + num + " second" + (Number(num) === 1 ? "" : "s");
console.log(name + ": " + num);
}
// Wait a minimum amount of time
let waitTimeMinimum = -1;
if (config.parsing.waitCalculatedDemoTime) {
// Calculate time we need to wait
let speedyTicks = demo.timings.suspectDead + demo.timings.freezeTime;
let normalTicks = demo.timings.totalTicksForWatching - speedyTicks;
let speedMultiplier = 10; // Same as "demo_highlight_fastforwardspeed"
let ticksToWatch = (speedyTicks / speedMultiplier) + normalTicks;
waitTimeMinimum = ticksToWatch * (1 / demo.snapshotrate); // Same as "tv_snapshotrate"
} else if (timeTotal < (config.parsing.minimumTime * 1000)) {
waitTimeMinimum = config.parsing.minimumTime;
}
if (waitTimeMinimum > 0) {
let diff = (waitTimeMinimum * 1000) - timeTotal;
let rawSeconds = Math.ceil(diff / 1000);
let seconds = rawSeconds % 60;
let minutes = Math.round((rawSeconds % 3600) / 60);
if (minutes > 0) {
if (seconds < 10) {
seconds = "0" + seconds;
}
console.log("Waiting " + minutes + ":" + seconds + " minutes before sending verdict...");
} else {
console.log("Waiting " + seconds + " seconds before sending verdict...");
}
await new Promise(p => setTimeout(p, diff));
}
if (playStateBlocked) {
// We are blocked
return;
}
console.log("Sending verdict to CSGO...");
// Send verdict
await coordinator.sendMessage(
730,
protobufs.data.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_PlayerOverwatchCaseUpdate,
{},
protobufs.encodeProto("CMsgGCCStrike15_v2_PlayerOverwatchCaseUpdate", {
caseid: body.caseid,
suspectid: body.suspectid,
fractionid: body.fractionid,
rpt_aimbot: data.verdict.aimbot,
rpt_wallhack: data.verdict.wallhack,
rpt_speedhack: data.verdict.speedhack,
rpt_teamharm: data.verdict.teamharm,
reason: Helper.OverwatchConstants.EMMV2OverwatchCasesUpdateReason_t.k_EMMV2OverwatchCasesUpdateReason_Verdict
})
);
} else if (typeof body.reason === "undefined" &&
body.verdict !== Helper.OverwatchConstants.EMMV2OverwatchCasesVerdict_t.k_EMMV2OverwatchCasesVerdict_Pending
) {
steam.uploadRichPresence(730, {
steam_display: "#display_Menu"
});
while (notifications.length > 0) {
console.log(notifications.shift());
}
if (config.verdict.maxVerdicts > 0 && casesCompleted >= config.verdict.maxVerdicts) {
console.log("Finished doing " + config.verdict.maxVerdicts + " verdict" + (config.verdict.maxVerdicts === 1 ? "" : "s"));
steam.logOff();
process.exitCode = 0; // Success exit code - PM2 or whatever the user uses should not restart the process
return;
}
if (verdictNumber > 0 && verdictNumberDone >= verdictNumber) {
console.log("Finished doing " + verdictNumber + "verdict" + (verdictNumber === 1 ? "" : "s"));
console.log("Waiting 2 hours before attemp a new Overwatch case.");
timeBetween = config.verdict.waitingTime;
verdictNumber = randomIntFromIntervall(3,9);
verdictNumberDone = 0;
await new Promise(p => setTimeout(p, (timeBetween * 1000))); // Wait declared time before requesting a new case. Cases defined in config.json through maxVerdicts
return;
}
// Added waiting time between the Cases to humanize the bot
let minTime = config.verdict.minTimeBetweenCases;
let maxTime = config.verdict.maxTimeBetweenCases;
if (config.verdict.randomizePauseTime) {
const random = randomIntFromIntervall(minTime, maxTime);
delaydiff = (random * 1000);
let delayrawsec = Math.ceil(delaydiff / 1000);
delaysec = delayrawsec % 60;
delaymin = Math.round((delayrawsec % 3600) / 60);
} else {
let delay = body.throttleseconds || 10;
delaydiff = delay * 1000;
let delaydiffrawsec = Math.ceil(delaydiff / 1000);
delaysec = delaydiffrawsec % 60;
delaymin = Math.round((delaydiffrawsec % 3600) / 60);
}
if (delaymin > 0) {
if (delaysec < 10) {
delaysec = "0" + delaysec;
}
console.log("Waiting " + delaymin + ":" + delaysec + " minutes before requesting a new case...");
} else {
console.log("Waiting " + delaysec + " seconds before requesting a new case...");
}
await new Promise(p => setTimeout(p, delaydiff));
if (playStateBlocked) {
// We are blocked
return;
}
console.log("Attempt to get Overwatch case...");
await coordinator.sendMessage(
730,
protobufs.data.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_PlayerOverwatchCaseUpdate,
{},
protobufs.encodeProto("CMsgGCCStrike15_v2_PlayerOverwatchCaseUpdate", {
reason: Helper.OverwatchConstants.EMMV2OverwatchCasesUpdateReason_t.k_EMMV2OverwatchCasesUpdateReason_Assign
})
);
} else if (typeof body.reason === "undefined" &&
typeof body.verdict === "undefined" &&
typeof body.throttleseconds === "number"
) {
console.log("Waiting " + body.throttleseconds + " seconds before requesting a case...");
await new Promise(p => setTimeout(p, body.throttleseconds * 1000));
if (playStateBlocked) {
// We are blocked
return;
}
console.log("Attempt to get Overwatch case...");
await coordinator.sendMessage(
730,
protobufs.data.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_PlayerOverwatchCaseUpdate,
{},
protobufs.encodeProto("CMsgGCCStrike15_v2_PlayerOverwatchCaseUpdate", {
reason: Helper.OverwatchConstants.EMMV2OverwatchCasesUpdateReason_t.k_EMMV2OverwatchCasesUpdateReason_Assign
})
);
}
});