yolkbot 0.1.2-alpha.3 → 0.1.2-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/build/global.js +1 -1
- package/browser/build/module.js +1 -1
- package/package.json +1 -1
- package/src/bot.js +63 -92
package/package.json
CHANGED
package/src/bot.js
CHANGED
|
@@ -387,97 +387,6 @@ export class Bot {
|
|
|
387
387
|
});
|
|
388
388
|
}
|
|
389
389
|
|
|
390
|
-
async #onGameMesssage(msg) {
|
|
391
|
-
CommIn.init(msg.data);
|
|
392
|
-
|
|
393
|
-
let out;
|
|
394
|
-
const cmd = CommIn.unPackInt8U();
|
|
395
|
-
|
|
396
|
-
switch (cmd) {
|
|
397
|
-
case CommCode.socketReady:
|
|
398
|
-
out = CommOut.getBuffer();
|
|
399
|
-
out.packInt8(CommCode.joinGame);
|
|
400
|
-
|
|
401
|
-
out.packString(this.state.name); // name
|
|
402
|
-
out.packString(this.game.raw.uuid); // game id
|
|
403
|
-
|
|
404
|
-
out.packInt8(0); // hidebadge
|
|
405
|
-
out.packInt8(0); // weapon choice
|
|
406
|
-
|
|
407
|
-
out.packInt32(this.account.session); // session int
|
|
408
|
-
out.packString(this.account.firebaseId); // firebase id
|
|
409
|
-
out.packString(this.account.sessionId); // session id
|
|
410
|
-
|
|
411
|
-
out.send(this.game.socket);
|
|
412
|
-
break;
|
|
413
|
-
|
|
414
|
-
case CommCode.gameJoined: {
|
|
415
|
-
this.me.id = CommIn.unPackInt8U();
|
|
416
|
-
// console.log("My id is:", this.me.id);
|
|
417
|
-
this.me.team = CommIn.unPackInt8U();
|
|
418
|
-
// console.log("My team is:", this.me.team);
|
|
419
|
-
this.game.gameModeId = CommIn.unPackInt8U(); // aka gameType
|
|
420
|
-
this.game.gameMode = GameModesById[this.game.gameModeId];
|
|
421
|
-
// console.log("Gametype:", this.game.gameMode, this.game.gameModeId);
|
|
422
|
-
this.game.mapIdx = CommIn.unPackInt8U();
|
|
423
|
-
this.game.map = Maps[this.game.mapIdx];
|
|
424
|
-
if (this.intents.includes(this.Intents.PATHFINDING)) {
|
|
425
|
-
this.game.map.raw = await this.#fetchMap(this.game.map.filename, this.game.map.hash);
|
|
426
|
-
this.pathing.nodeList = new NodeList(this.game.map.raw);
|
|
427
|
-
if (this.game.gameModeId === GameModes.kotc) this.#initKotcZones();
|
|
428
|
-
}
|
|
429
|
-
// console.log("Map:", this.game.map);
|
|
430
|
-
this.game.playerLimit = CommIn.unPackInt8U();
|
|
431
|
-
// console.log("Player limit:", this.game.playerLimit);
|
|
432
|
-
this.game.isGameOwner = CommIn.unPackInt8U() == 1;
|
|
433
|
-
// console.log("Is game owner:", this.game.isGameOwner);
|
|
434
|
-
this.game.isPrivate = CommIn.unPackInt8U() == 1;
|
|
435
|
-
// console.log("Is private game:", this.game.isPrivate);
|
|
436
|
-
|
|
437
|
-
// console.log('Successfully joined game.');
|
|
438
|
-
this.state.joinedGame = true;
|
|
439
|
-
this.lastDeathTime = Date.now();
|
|
440
|
-
|
|
441
|
-
const out = CommOut.getBuffer();
|
|
442
|
-
out.packInt8(CommCode.clientReady);
|
|
443
|
-
out.send(this.game.socket);
|
|
444
|
-
|
|
445
|
-
this.game.socket.onmessage = (msg) => this._packetQueue.push(msg.data);
|
|
446
|
-
|
|
447
|
-
if (this.autoUpdate)
|
|
448
|
-
this.updateIntervalId = setInterval(() => this.update(), this.updateInterval);
|
|
449
|
-
|
|
450
|
-
if (this.intents.includes(this.Intents.PING)) {
|
|
451
|
-
const out = CommOut.getBuffer();
|
|
452
|
-
out.packInt8(CommCode.ping);
|
|
453
|
-
out.send(this.game.socket);
|
|
454
|
-
this.lastPingTime = Date.now();
|
|
455
|
-
}
|
|
456
|
-
break;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
case CommCode.eventModifier:
|
|
460
|
-
// console.log("Echoed eventModifier"); // why the fuck do you need to do this
|
|
461
|
-
out = CommOut.getBuffer();
|
|
462
|
-
out.packInt8(CommCode.eventModifier);
|
|
463
|
-
out.send(this.game.socket);
|
|
464
|
-
break;
|
|
465
|
-
|
|
466
|
-
case CommCode.requestGameOptions:
|
|
467
|
-
this.#processGameRequestOptionsPacket();
|
|
468
|
-
break;
|
|
469
|
-
|
|
470
|
-
default:
|
|
471
|
-
try {
|
|
472
|
-
const inferredCode = Object.entries(CommCode).filter(([, v]) => v == cmd)[0][0];
|
|
473
|
-
console.error('onGameMessage: Received but did not handle a:', inferredCode);
|
|
474
|
-
// packet could potentially not exist, then [0][0] will error
|
|
475
|
-
} catch {
|
|
476
|
-
console.error('onGameMessage: Unexpected packet received during startup: ' + cmd);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
390
|
// region - a region id ('useast', 'germany', etc)
|
|
482
391
|
// mode - a mode name that corresponds to a GameMode id
|
|
483
392
|
// map - the name of a map
|
|
@@ -571,7 +480,7 @@ export class Bot {
|
|
|
571
480
|
this.game.socket.onerror = null;
|
|
572
481
|
}
|
|
573
482
|
|
|
574
|
-
this.game.socket.onmessage = this
|
|
483
|
+
this.game.socket.onmessage = (msg) => this.processPacket(msg.data);
|
|
575
484
|
|
|
576
485
|
this.game.socket.onclose = (e) => {
|
|
577
486
|
// console.log('Game socket closed:', e.code, Object.entries(CloseCode).filter(([, v]) => v == e.code));
|
|
@@ -1547,6 +1456,60 @@ export class Bot {
|
|
|
1547
1456
|
}
|
|
1548
1457
|
}
|
|
1549
1458
|
|
|
1459
|
+
#processSocketReadyPacket() {
|
|
1460
|
+
const out = CommOut.getBuffer();
|
|
1461
|
+
out.packInt8(CommCode.joinGame);
|
|
1462
|
+
|
|
1463
|
+
out.packString(this.state.name);
|
|
1464
|
+
out.packString(this.game.raw.uuid);
|
|
1465
|
+
|
|
1466
|
+
out.packInt8(0); // hidebadge
|
|
1467
|
+
out.packInt8(0); // weapon idx
|
|
1468
|
+
|
|
1469
|
+
out.packInt32(this.account.session);
|
|
1470
|
+
out.packString(this.account.firebaseId);
|
|
1471
|
+
out.packString(this.account.sessionId);
|
|
1472
|
+
|
|
1473
|
+
out.send(this.game.socket);
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
async #processGameJoinedPacket() {
|
|
1477
|
+
this.me.id = CommIn.unPackInt8U();
|
|
1478
|
+
this.me.team = CommIn.unPackInt8U();
|
|
1479
|
+
this.game.gameModeId = CommIn.unPackInt8U(); // aka gameType
|
|
1480
|
+
this.game.gameMode = GameModesById[this.game.gameModeId];
|
|
1481
|
+
this.game.mapIdx = CommIn.unPackInt8U();
|
|
1482
|
+
this.game.map = Maps[this.game.mapIdx];
|
|
1483
|
+
if (this.intents.includes(this.Intents.PATHFINDING)) {
|
|
1484
|
+
this.game.map.raw = await this.#fetchMap(this.game.map.filename, this.game.map.hash);
|
|
1485
|
+
this.pathing.nodeList = new NodeList(this.game.map.raw);
|
|
1486
|
+
if (this.game.gameModeId === GameModes.kotc) this.#initKotcZones();
|
|
1487
|
+
}
|
|
1488
|
+
this.game.playerLimit = CommIn.unPackInt8U();
|
|
1489
|
+
this.game.isGameOwner = CommIn.unPackInt8U() == 1;
|
|
1490
|
+
this.game.isPrivate = CommIn.unPackInt8U() == 1;
|
|
1491
|
+
|
|
1492
|
+
// console.log('Successfully joined game.');
|
|
1493
|
+
this.state.joinedGame = true;
|
|
1494
|
+
this.lastDeathTime = Date.now();
|
|
1495
|
+
|
|
1496
|
+
const out = CommOut.getBuffer();
|
|
1497
|
+
out.packInt8(CommCode.clientReady);
|
|
1498
|
+
out.send(this.game.socket);
|
|
1499
|
+
|
|
1500
|
+
this.game.socket.onmessage = (msg) => this._packetQueue.push(msg.data);
|
|
1501
|
+
|
|
1502
|
+
if (this.autoUpdate)
|
|
1503
|
+
this.updateIntervalId = setInterval(() => this.update(), this.updateInterval);
|
|
1504
|
+
|
|
1505
|
+
if (this.intents.includes(this.Intents.PING)) {
|
|
1506
|
+
const out = CommOut.getBuffer();
|
|
1507
|
+
out.packInt8(CommCode.ping);
|
|
1508
|
+
out.send(this.game.socket);
|
|
1509
|
+
this.lastPingTime = Date.now();
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1550
1513
|
processPacket(packet) {
|
|
1551
1514
|
CommIn.init(packet);
|
|
1552
1515
|
|
|
@@ -1682,6 +1645,14 @@ export class Bot {
|
|
|
1682
1645
|
this.#processChallengeCompletePacket();
|
|
1683
1646
|
break;
|
|
1684
1647
|
|
|
1648
|
+
case CommCode.socketReady:
|
|
1649
|
+
this.#processSocketReadyPacket();
|
|
1650
|
+
break;
|
|
1651
|
+
|
|
1652
|
+
case CommCode.gameJoined:
|
|
1653
|
+
this.#processGameJoinedPacket();
|
|
1654
|
+
break;
|
|
1655
|
+
|
|
1685
1656
|
case CommCode.gameAction:
|
|
1686
1657
|
this.#processGameActionPacket();
|
|
1687
1658
|
break;
|