yolkbot 1.4.5 → 1.4.6
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/dist/api.js +200 -1
- package/dist/bot/GamePlayer.js +74 -1
- package/dist/bot.js +1679 -1
- package/dist/comm/CommIn.js +79 -1
- package/dist/comm/CommOut.js +60 -1
- package/dist/comm/index.js +11 -1
- package/dist/constants/CloseCode.js +27 -1
- package/dist/constants/CommCode.js +53 -1
- package/dist/constants/challenges.js +1821 -1
- package/dist/constants/findItemById.js +2 -3
- package/dist/constants/guns.js +277 -1
- package/dist/constants/index.js +139 -1
- package/dist/constants/items.js +45042 -1
- package/dist/constants/maps.js +1263 -1
- package/dist/constants/regions.js +30 -1
- package/dist/dispatches/BanPlayerDispatch.js +32 -1
- package/dist/dispatches/BootPlayerDispatch.js +21 -1
- package/dist/dispatches/ChatDispatch.js +32 -1
- package/dist/dispatches/FireDispatch.js +15 -1
- package/dist/dispatches/GameOptionsDispatch.js +66 -1
- package/dist/dispatches/GoToAmmoDispatch.js +38 -1
- package/dist/dispatches/GoToCoopDispatch.js +38 -1
- package/dist/dispatches/GoToGrenadeDispatch.js +38 -1
- package/dist/dispatches/GoToPlayerDispatch.js +39 -1
- package/dist/dispatches/GoToSpatulaDispatch.js +26 -1
- package/dist/dispatches/LookAtDispatch.js +35 -1
- package/dist/dispatches/LookAtPosDispatch.js +29 -1
- package/dist/dispatches/MeleeDispatch.js +26 -1
- package/dist/dispatches/MovementDispatch.js +26 -1
- package/dist/dispatches/PauseDispatch.js +18 -1
- package/dist/dispatches/ReloadDispatch.js +28 -1
- package/dist/dispatches/ReportPlayerDispatch.js +42 -1
- package/dist/dispatches/ResetGameDispatch.js +19 -1
- package/dist/dispatches/SaveLoadoutDispatch.js +105 -1
- package/dist/dispatches/SpawnDispatch.js +22 -1
- package/dist/dispatches/SwapWeaponDispatch.js +25 -1
- package/dist/dispatches/SwitchTeamDispatch.js +33 -1
- package/dist/dispatches/ThrowGrenadeDispatch.js +21 -1
- package/dist/dispatches/index.js +74 -1
- package/dist/env/fetch.js +97 -10
- package/dist/env/globals.js +15 -1
- package/dist/index.js +14 -2
- package/dist/matchmaker.js +141 -1
- package/dist/pathing/astar.js +55 -1
- package/dist/pathing/binaryheap.js +79 -1
- package/dist/pathing/mapnode.js +179 -1
- package/dist/socket.js +97 -1
- package/dist/util.js +68 -1
- package/dist/wasm/bytes.js +8 -1
- package/dist/wasm/direct.js +84 -1
- package/dist/wasm/legacy.js +170 -1
- package/dist/wasm/util.js +19 -1
- package/package.json +38 -39
- /package/dist/{types/api.d.ts → api.d.ts} +0 -0
- /package/dist/{types/bot → bot}/GamePlayer.d.ts +0 -0
- /package/dist/{types/bot.d.ts → bot.d.ts} +0 -0
- /package/dist/{types/comm → comm}/CommIn.d.ts +0 -0
- /package/dist/{types/comm → comm}/CommOut.d.ts +0 -0
- /package/dist/{types/comm → comm}/index.d.ts +0 -0
- /package/dist/{types/constants → constants}/CloseCode.d.ts +0 -0
- /package/dist/{types/constants → constants}/CommCode.d.ts +0 -0
- /package/dist/{types/constants → constants}/challenges.d.ts +0 -0
- /package/dist/{types/constants → constants}/changelog.d.ts +0 -0
- /package/dist/{types/constants → constants}/findItemById.d.ts +0 -0
- /package/dist/{types/constants → constants}/guns.d.ts +0 -0
- /package/dist/{types/constants → constants}/housePromo.d.ts +0 -0
- /package/dist/{types/constants → constants}/index.d.ts +0 -0
- /package/dist/{types/constants → constants}/items.d.ts +0 -0
- /package/dist/{types/constants → constants}/language.d.ts +0 -0
- /package/dist/{types/constants → constants}/maps.d.ts +0 -0
- /package/dist/{types/constants → constants}/notices.d.ts +0 -0
- /package/dist/{types/constants → constants}/regions.d.ts +0 -0
- /package/dist/{types/constants → constants}/shellNews.d.ts +0 -0
- /package/dist/{types/constants → constants}/shellYoutube.d.ts +0 -0
- /package/dist/{types/constants → constants}/shopItems.d.ts +0 -0
- /package/dist/{types/constants → constants}/sounds.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/BanPlayerDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/BootPlayerDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/ChatDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/FireDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/GameOptionsDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/GoToAmmoDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/GoToCoopDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/GoToGrenadeDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/GoToPlayerDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/GoToSpatulaDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/LookAtDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/LookAtPosDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/MeleeDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/MovementDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/PauseDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/ReloadDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/ReportPlayerDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/ResetGameDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/SaveLoadoutDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/SpawnDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/SwapWeaponDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/SwitchTeamDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/ThrowGrenadeDispatch.d.ts +0 -0
- /package/dist/{types/dispatches → dispatches}/index.d.ts +0 -0
- /package/dist/{types/matchmaker.d.ts → matchmaker.d.ts} +0 -0
- /package/dist/{types/pathing → pathing}/astar.d.ts +0 -0
- /package/dist/{types/pathing → pathing}/binaryheap.d.ts +0 -0
- /package/dist/{types/pathing → pathing}/mapnode.d.ts +0 -0
- /package/dist/{types/socket.d.ts → socket.d.ts} +0 -0
- /package/dist/{types/util.d.ts → util.d.ts} +0 -0
- /package/dist/{types/wasm → wasm}/bytes.d.ts +0 -0
- /package/dist/{types/wasm → wasm}/direct.d.ts +0 -0
- /package/dist/{types/wasm → wasm}/legacy.d.ts +0 -0
- /package/dist/{types/wasm → wasm}/util.d.ts +0 -0
|
@@ -1 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from "../comm/CommOut.js";
|
|
2
|
+
import CommCode from "../constants/CommCode.js";
|
|
3
|
+
import { GameAction } from "../constants/index.js";
|
|
4
|
+
|
|
5
|
+
export class ResetGameDispatch {
|
|
6
|
+
validate() {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
check(bot) {
|
|
10
|
+
return bot.game.isGameOwner;
|
|
11
|
+
}
|
|
12
|
+
execute(bot) {
|
|
13
|
+
const out = new CommOut;
|
|
14
|
+
out.packInt8(CommCode.gameAction);
|
|
15
|
+
out.packInt8(GameAction.Reset);
|
|
16
|
+
out.send(bot.game.socket);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export default ResetGameDispatch;
|
|
@@ -1 +1,105 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from "../comm/CommOut.js";
|
|
2
|
+
import CommCode from "../constants/CommCode.js";
|
|
3
|
+
import { findItemById, GunList, ItemType } from "../constants/index.js";
|
|
4
|
+
const isDefault = (itemId) => findItemById(itemId) && findItemById(itemId).unlock === "default";
|
|
5
|
+
const isType = (itemId, type) => findItemById(itemId) && findItemById(itemId).item_type_id === type;
|
|
6
|
+
|
|
7
|
+
export class SaveLoadoutDispatch {
|
|
8
|
+
constructor(opts) {
|
|
9
|
+
this.changes = {
|
|
10
|
+
classIdx: opts.gunId,
|
|
11
|
+
hatId: opts.hatId,
|
|
12
|
+
stampId: opts.stampId,
|
|
13
|
+
grenadeId: opts.grenadeId,
|
|
14
|
+
meleeId: opts.meleeId,
|
|
15
|
+
colorIdx: opts.eggColor,
|
|
16
|
+
primaryId: opts.primaryIds,
|
|
17
|
+
secondaryId: opts.secondaryIds
|
|
18
|
+
};
|
|
19
|
+
this.changes = Object.fromEntries(Object.entries(this.changes).filter(([, v]) => !!v));
|
|
20
|
+
}
|
|
21
|
+
validate(bot) {
|
|
22
|
+
const load = this.changes;
|
|
23
|
+
if (load.colorIdx && load.colorIdx >= 7 && !bot.account.vip)
|
|
24
|
+
return false;
|
|
25
|
+
if (load.colorIdx && load.colorIdx >= 14)
|
|
26
|
+
return false;
|
|
27
|
+
if (isType(load.hatId, ItemType.Hat) && !isDefault(load.hatId) && !bot.account.ownedItemIds.includes(load.hatId))
|
|
28
|
+
return false;
|
|
29
|
+
if (isType(load.stampId, ItemType.Stamp) && !isDefault(load.stampId) && !bot.account.ownedItemIds.includes(load.stampId))
|
|
30
|
+
return false;
|
|
31
|
+
if (isType(load.grenadeId, ItemType.Grenade) && !isDefault(load.grenadeId) && !bot.account.ownedItemIds.includes(load.grenadeId))
|
|
32
|
+
return false;
|
|
33
|
+
if (isType(load.meleeId, ItemType.Melee) && !isDefault(load.meleeId) && !bot.account.ownedItemIds.includes(load.meleeId))
|
|
34
|
+
return false;
|
|
35
|
+
if (typeof load.classIdx === "number" && load.classIdx > 6 || load.classIdx < 0)
|
|
36
|
+
return false;
|
|
37
|
+
if (this.changes.primaryId) {
|
|
38
|
+
for (let i = 0;i < 7; i++) {
|
|
39
|
+
const testingId = this.changes.primaryId[i];
|
|
40
|
+
if (!isType(testingId, ItemType.Primary) || !isDefault(testingId) && !bot.account.ownedItemIds.includes(testingId)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (this.changes.secondaryId) {
|
|
46
|
+
for (let i = 0;i < 7; i++) {
|
|
47
|
+
const testingId = this.changes.secondaryId[i];
|
|
48
|
+
if (!isType(testingId, ItemType.Secondary) || !isDefault(testingId) && !bot.account.ownedItemIds.includes(testingId)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
check(bot) {
|
|
56
|
+
return !bot.me.playing;
|
|
57
|
+
}
|
|
58
|
+
execute(bot) {
|
|
59
|
+
if (bot.me && this.changes.classIdx && this.changes.classIdx !== bot.me.selectedGun) {
|
|
60
|
+
bot.me.weapons[0] = new GunList[this.changes.classIdx];
|
|
61
|
+
}
|
|
62
|
+
bot.state.weaponIdx = this.changes.classIdx || bot.state.weaponIdx;
|
|
63
|
+
const loadout = {
|
|
64
|
+
...bot.account.loadout,
|
|
65
|
+
...this.changes
|
|
66
|
+
};
|
|
67
|
+
const saveLoadout = bot.api.queryServices({
|
|
68
|
+
cmd: "saveLoadout",
|
|
69
|
+
save: true,
|
|
70
|
+
firebaseId: bot.account.firebaseId,
|
|
71
|
+
sessionId: bot.account.sessionId,
|
|
72
|
+
loadout
|
|
73
|
+
});
|
|
74
|
+
bot.account.loadout = loadout;
|
|
75
|
+
if (bot.me)
|
|
76
|
+
saveLoadout.then(() => {
|
|
77
|
+
if (bot.state.inGame) {
|
|
78
|
+
const out = new CommOut;
|
|
79
|
+
out.packInt8(CommCode.changeCharacter);
|
|
80
|
+
out.packInt8(this.changes?.classIdx || bot.me.selectedGun);
|
|
81
|
+
out.send(bot.game.socket);
|
|
82
|
+
}
|
|
83
|
+
const findCosmetics = bot.intents.includes(bot.Intents.COSMETIC_DATA);
|
|
84
|
+
Object.entries(this.changes).forEach(([changeKey, changeValue]) => {
|
|
85
|
+
if (changeKey === "classIdx")
|
|
86
|
+
bot.me.selectedGun = changeValue;
|
|
87
|
+
else if (changeKey === "hatId")
|
|
88
|
+
bot.me.character.hat = findCosmetics ? findItemById(changeValue) : changeValue;
|
|
89
|
+
else if (changeKey === "stampId")
|
|
90
|
+
bot.me.character.stamp = findCosmetics ? findItemById(changeValue) : changeValue;
|
|
91
|
+
else if (changeKey === "grenadeId")
|
|
92
|
+
bot.me.character.grenade = findCosmetics ? findItemById(changeValue) : changeValue;
|
|
93
|
+
else if (changeKey === "meleeId")
|
|
94
|
+
bot.me.character.melee = findCosmetics ? findItemById(changeValue) : changeValue;
|
|
95
|
+
else if (changeKey === "colorIdx")
|
|
96
|
+
bot.me.character.eggColor = changeValue;
|
|
97
|
+
else if (changeKey === "primaryId")
|
|
98
|
+
bot.me.character.primaryGun = findCosmetics ? findItemById(changeValue[bot.me.selectedGun]) : changeValue;
|
|
99
|
+
else if (changeKey === "secondaryId")
|
|
100
|
+
bot.me.character.secondaryGun = findCosmetics ? findItemById(changeValue[bot.me.selectedGun]) : changeValue;
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export default SaveLoadoutDispatch;
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from "../comm/CommOut.js";
|
|
2
|
+
import CommCode from "../constants/CommCode.js";
|
|
3
|
+
|
|
4
|
+
export class SpawnDispatch {
|
|
5
|
+
validate() {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
check(bot) {
|
|
9
|
+
if (bot.me.playing)
|
|
10
|
+
return false;
|
|
11
|
+
if (bot.intents.includes(bot.Intents.OBSERVE_GAME))
|
|
12
|
+
return false;
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
execute(bot) {
|
|
16
|
+
const out = new CommOut;
|
|
17
|
+
out.packInt8(CommCode.requestRespawn);
|
|
18
|
+
out.send(bot.game.socket);
|
|
19
|
+
bot.state.buffer = [];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export default SpawnDispatch;
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from "../comm/CommOut.js";
|
|
2
|
+
import CommCode from "../constants/CommCode.js";
|
|
3
|
+
|
|
4
|
+
export class SwapWeaponDispatch {
|
|
5
|
+
constructor(manualWeapon) {
|
|
6
|
+
this.manualWeapon = manualWeapon;
|
|
7
|
+
}
|
|
8
|
+
validate() {
|
|
9
|
+
return typeof this.manualWeapon === "number" || typeof this.manualWeapon === "undefined";
|
|
10
|
+
}
|
|
11
|
+
check(bot) {
|
|
12
|
+
return bot.me.playing && !bot.state.reloading && !bot.state.swappingGun && !bot.state.usingMelee;
|
|
13
|
+
}
|
|
14
|
+
execute(bot) {
|
|
15
|
+
let chosenWeapon = +!bot.me.activeGun;
|
|
16
|
+
if (typeof this.manualWeapon === "number")
|
|
17
|
+
chosenWeapon = this.manualWeapon;
|
|
18
|
+
bot.me.activeGun = chosenWeapon;
|
|
19
|
+
const out = new CommOut;
|
|
20
|
+
out.packInt8(CommCode.swapWeapon);
|
|
21
|
+
out.packInt8(bot.me.activeGun);
|
|
22
|
+
out.send(bot.game.socket);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export default SwapWeaponDispatch;
|
|
@@ -1 +1,33 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from "../comm/CommOut.js";
|
|
2
|
+
import CommCode from "../constants/CommCode.js";
|
|
3
|
+
|
|
4
|
+
export class SwitchTeamDispatch {
|
|
5
|
+
validate() {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
check(bot) {
|
|
9
|
+
if (!bot.state.inGame || bot.me.playing)
|
|
10
|
+
return false;
|
|
11
|
+
if (bot.game.gameModeId === 0)
|
|
12
|
+
return false;
|
|
13
|
+
if (bot.intents.includes(bot.Intents.OBSERVE_GAME))
|
|
14
|
+
return false;
|
|
15
|
+
if (bot.game.isPrivate)
|
|
16
|
+
return !bot.game.options.noTeamChange;
|
|
17
|
+
const players = bot.players;
|
|
18
|
+
const myTeam = bot.me.team;
|
|
19
|
+
const playersWithMyTeam = players.filter((player) => player.team === myTeam).length;
|
|
20
|
+
const playersWithOtherTeam = players.filter((player) => player.team !== myTeam).length;
|
|
21
|
+
if (playersWithOtherTeam > playersWithMyTeam)
|
|
22
|
+
return false;
|
|
23
|
+
if (playersWithMyTeam === playersWithOtherTeam)
|
|
24
|
+
return false;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
execute(bot) {
|
|
28
|
+
const out = new CommOut;
|
|
29
|
+
out.packInt8(CommCode.switchTeam);
|
|
30
|
+
out.send(bot.game.socket);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export default SwitchTeamDispatch;
|
|
@@ -1 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import CommOut from "../comm/CommOut.js";
|
|
2
|
+
import CommCode from "../constants/CommCode.js";
|
|
3
|
+
|
|
4
|
+
export class ThrowGrenadeDispatch {
|
|
5
|
+
constructor(power = 1) {
|
|
6
|
+
this.power = power;
|
|
7
|
+
}
|
|
8
|
+
validate() {
|
|
9
|
+
return typeof this.power === "number" && this.power >= 0 && this.power <= 1;
|
|
10
|
+
}
|
|
11
|
+
check(bot) {
|
|
12
|
+
return bot.me.playing && !bot.state.reloading && !bot.state.swappingGun && !bot.state.usingMelee;
|
|
13
|
+
}
|
|
14
|
+
execute(bot) {
|
|
15
|
+
const out = new CommOut;
|
|
16
|
+
out.packInt8(CommCode.throwGrenade);
|
|
17
|
+
out.packFloat(this.power);
|
|
18
|
+
out.send(bot.game.socket);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export default ThrowGrenadeDispatch;
|
package/dist/dispatches/index.js
CHANGED
|
@@ -1 +1,74 @@
|
|
|
1
|
-
import BanPlayerDispatch from"./BanPlayerDispatch.js";
|
|
1
|
+
import BanPlayerDispatch from "./BanPlayerDispatch.js";
|
|
2
|
+
import BootPlayerDispatch from "./BootPlayerDispatch.js";
|
|
3
|
+
import ChatDispatch from "./ChatDispatch.js";
|
|
4
|
+
import FireDispatch from "./FireDispatch.js";
|
|
5
|
+
import GameOptionsDispatch from "./GameOptionsDispatch.js";
|
|
6
|
+
import GoToAmmoDispatch from "./GoToAmmoDispatch.js";
|
|
7
|
+
import GoToCoopDispatch from "./GoToCoopDispatch.js";
|
|
8
|
+
import GoToGrenadeDispatch from "./GoToGrenadeDispatch.js";
|
|
9
|
+
import GoToPlayerDispatch from "./GoToPlayerDispatch.js";
|
|
10
|
+
import GoToSpatulaDispatch from "./GoToSpatulaDispatch.js";
|
|
11
|
+
import LookAtDispatch from "./LookAtDispatch.js";
|
|
12
|
+
import LookAtPosDispatch from "./LookAtPosDispatch.js";
|
|
13
|
+
import MeleeDispatch from "./MeleeDispatch.js";
|
|
14
|
+
import MovementDispatch from "./MovementDispatch.js";
|
|
15
|
+
import PauseDispatch from "./PauseDispatch.js";
|
|
16
|
+
import ReloadDispatch from "./ReloadDispatch.js";
|
|
17
|
+
import ReportPlayerDispatch from "./ReportPlayerDispatch.js";
|
|
18
|
+
import ResetGameDispatch from "./ResetGameDispatch.js";
|
|
19
|
+
import SaveLoadoutDispatch from "./SaveLoadoutDispatch.js";
|
|
20
|
+
import SpawnDispatch from "./SpawnDispatch.js";
|
|
21
|
+
import SwapWeaponDispatch from "./SwapWeaponDispatch.js";
|
|
22
|
+
import SwitchTeamDispatch from "./SwitchTeamDispatch.js";
|
|
23
|
+
import ThrowGrenadeDispatch from "./ThrowGrenadeDispatch.js";
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
BanPlayerDispatch,
|
|
27
|
+
BootPlayerDispatch,
|
|
28
|
+
ChatDispatch,
|
|
29
|
+
FireDispatch,
|
|
30
|
+
GameOptionsDispatch,
|
|
31
|
+
GoToAmmoDispatch,
|
|
32
|
+
GoToCoopDispatch,
|
|
33
|
+
GoToGrenadeDispatch,
|
|
34
|
+
GoToPlayerDispatch,
|
|
35
|
+
GoToSpatulaDispatch,
|
|
36
|
+
LookAtDispatch,
|
|
37
|
+
LookAtPosDispatch,
|
|
38
|
+
MeleeDispatch,
|
|
39
|
+
MovementDispatch,
|
|
40
|
+
PauseDispatch,
|
|
41
|
+
ReloadDispatch,
|
|
42
|
+
ReportPlayerDispatch,
|
|
43
|
+
ResetGameDispatch,
|
|
44
|
+
SaveLoadoutDispatch,
|
|
45
|
+
SpawnDispatch,
|
|
46
|
+
SwapWeaponDispatch,
|
|
47
|
+
SwitchTeamDispatch,
|
|
48
|
+
ThrowGrenadeDispatch
|
|
49
|
+
};
|
|
50
|
+
export default {
|
|
51
|
+
BanPlayerDispatch,
|
|
52
|
+
BootPlayerDispatch,
|
|
53
|
+
ChatDispatch,
|
|
54
|
+
FireDispatch,
|
|
55
|
+
GameOptionsDispatch,
|
|
56
|
+
GoToAmmoDispatch,
|
|
57
|
+
GoToCoopDispatch,
|
|
58
|
+
GoToGrenadeDispatch,
|
|
59
|
+
GoToPlayerDispatch,
|
|
60
|
+
GoToSpatulaDispatch,
|
|
61
|
+
LookAtDispatch,
|
|
62
|
+
LookAtPosDispatch,
|
|
63
|
+
MeleeDispatch,
|
|
64
|
+
MovementDispatch,
|
|
65
|
+
PauseDispatch,
|
|
66
|
+
ReloadDispatch,
|
|
67
|
+
ReportPlayerDispatch,
|
|
68
|
+
ResetGameDispatch,
|
|
69
|
+
SaveLoadoutDispatch,
|
|
70
|
+
SpawnDispatch,
|
|
71
|
+
SwapWeaponDispatch,
|
|
72
|
+
SwitchTeamDispatch,
|
|
73
|
+
ThrowGrenadeDispatch
|
|
74
|
+
};
|
package/dist/env/fetch.js
CHANGED
|
@@ -1,15 +1,102 @@
|
|
|
1
|
-
import{socksConnect
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { socksConnect } from "wwws";
|
|
2
|
+
import globals from "./globals.js";
|
|
3
|
+
const sendHttpRequest = (socket, { method, pathname, hostname, port, headers, body }, resolve) => {
|
|
4
|
+
let reqHeaders = "";
|
|
5
|
+
for (const [k, v] of Object.entries(headers))
|
|
6
|
+
reqHeaders += `${k}: ${v}\r
|
|
7
|
+
`;
|
|
8
|
+
if (body && !("Content-Length" in headers))
|
|
9
|
+
reqHeaders += `Content-Length: ${Buffer.byteLength(body)}\r
|
|
10
|
+
`;
|
|
11
|
+
let req = `${method} ${pathname} HTTP/1.1\r
|
|
12
|
+
Host: ${hostname}:${port}\r
|
|
13
|
+
${reqHeaders}Connection: close\r
|
|
6
14
|
\r
|
|
7
|
-
`;
|
|
15
|
+
`;
|
|
16
|
+
if (body)
|
|
17
|
+
req += body;
|
|
18
|
+
socket.write(req);
|
|
19
|
+
let response = "";
|
|
20
|
+
socket.on("data", (data) => {
|
|
21
|
+
response += data.toString();
|
|
22
|
+
if (/transfer-encoding:\s*chunked/i.test(response)) {
|
|
23
|
+
if (response.includes(`\r
|
|
8
24
|
0\r
|
|
9
25
|
\r
|
|
10
|
-
`))
|
|
26
|
+
`))
|
|
27
|
+
socket.end();
|
|
28
|
+
} else {
|
|
29
|
+
const contentLengthMatch = response.match(/content-length:\s*(?<len>\d+)/i);
|
|
30
|
+
if (contentLengthMatch) {
|
|
31
|
+
const contentLength = parseInt(contentLengthMatch.groups.len, 10);
|
|
32
|
+
const bodyStart = response.indexOf(`\r
|
|
11
33
|
\r
|
|
12
|
-
`)+4;
|
|
34
|
+
`) + 4;
|
|
35
|
+
const body3 = response.slice(bodyStart);
|
|
36
|
+
if (body3.length >= contentLength)
|
|
37
|
+
socket.end();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
socket.on("end", () => {
|
|
42
|
+
const isChunked = /transfer-encoding:\s*chunked/i.test(response);
|
|
43
|
+
let parsedBody = response.split(`\r
|
|
13
44
|
\r
|
|
14
|
-
`)[1];
|
|
15
|
-
|
|
45
|
+
`)[1];
|
|
46
|
+
if (isChunked) {
|
|
47
|
+
const body2 = parsedBody;
|
|
48
|
+
const chunks = [];
|
|
49
|
+
let i = 0;
|
|
50
|
+
while (i < body2.length) {
|
|
51
|
+
const rnIdx = body2.indexOf(`\r
|
|
52
|
+
`, i);
|
|
53
|
+
if (rnIdx === -1)
|
|
54
|
+
break;
|
|
55
|
+
const sizeHex = body2.slice(i, rnIdx).trim();
|
|
56
|
+
const size = parseInt(sizeHex, 16);
|
|
57
|
+
if (size === 0)
|
|
58
|
+
break;
|
|
59
|
+
i = rnIdx + 2;
|
|
60
|
+
chunks.push(body2.slice(i, i + size));
|
|
61
|
+
i += size + 2;
|
|
62
|
+
}
|
|
63
|
+
parsedBody = chunks.join("");
|
|
64
|
+
}
|
|
65
|
+
resolve({ json: () => JSON.parse(parsedBody), text: () => parsedBody });
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const iFetch = (url, { method = "GET", proxy, headers = {}, body = null } = {}) => new Promise((resolve) => {
|
|
69
|
+
if (typeof process === "undefined" || !process.getBuiltinModule)
|
|
70
|
+
return globals.fetch(url, { method, headers, body }).then(resolve);
|
|
71
|
+
const dns = process.getBuiltinModule("node:dns");
|
|
72
|
+
const net = process.getBuiltinModule("node:net");
|
|
73
|
+
const tls = process.getBuiltinModule("node:tls");
|
|
74
|
+
const { hostname, port: rawPort, pathname: path, protocol, search } = new URL(url);
|
|
75
|
+
const isHttps = protocol === "https:";
|
|
76
|
+
const pathname = path + search;
|
|
77
|
+
const port = rawPort ? parseInt(rawPort) : isHttps ? 443 : 80;
|
|
78
|
+
if (!proxy)
|
|
79
|
+
return dns.lookup(hostname, { family: 4 }, (err, host) => {
|
|
80
|
+
if (err)
|
|
81
|
+
throw err;
|
|
82
|
+
const socket = isHttps ? tls.connect({ port, host, servername: hostname }) : net.connect({ port, host });
|
|
83
|
+
socket.on("connect", () => sendHttpRequest(socket, { method, pathname, hostname, port, headers, body }, resolve));
|
|
84
|
+
});
|
|
85
|
+
const proxyInfo = new URL(proxy);
|
|
86
|
+
const scheme = proxyInfo.protocol.replace(":", "");
|
|
87
|
+
if (scheme !== "socks5" && scheme !== "socks5h")
|
|
88
|
+
throw new Error("iFetch only supports socks5 & socks5h proxies");
|
|
89
|
+
socksConnect({
|
|
90
|
+
proxy: {
|
|
91
|
+
hostname: proxyInfo.hostname,
|
|
92
|
+
port: Number(proxyInfo.port),
|
|
93
|
+
username: proxyInfo.username,
|
|
94
|
+
password: proxyInfo.password
|
|
95
|
+
},
|
|
96
|
+
destHost: hostname,
|
|
97
|
+
destPort: port,
|
|
98
|
+
useTLS: isHttps,
|
|
99
|
+
resolveDnsLocally: proxyInfo.protocol === "socks5"
|
|
100
|
+
}).then((socket) => sendHttpRequest(socket, { method, pathname, hostname, port, headers, body }, resolve));
|
|
101
|
+
});
|
|
102
|
+
export default iFetch;
|
package/dist/env/globals.js
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import iFetch from "./fetch.js";
|
|
2
|
+
const globals = {};
|
|
3
|
+
const isBrowser = typeof window !== "undefined" && typeof HTMLElement !== "undefined";
|
|
4
|
+
const isWorker = typeof WebSocketPair !== "undefined" && typeof Cloudflare !== "undefined";
|
|
5
|
+
const isNode = typeof process !== "undefined" && process.moduleLoadList?.length > 0;
|
|
6
|
+
const isDeno = typeof Deno !== "undefined";
|
|
7
|
+
const isBun = typeof process !== "undefined" && !!process.versions?.bun;
|
|
8
|
+
if (!isBrowser && !isWorker && !isNode && !isDeno && !isBun)
|
|
9
|
+
throw new Error("yolkbot doesn't know how to run in this environment. Please open an issue on GitHub with information on where you run yolkbot.");
|
|
10
|
+
globals.isBrowser = isBrowser;
|
|
11
|
+
globals.isIsolated = !isNode && !isDeno && !isBun;
|
|
12
|
+
import { WWWebSocket } from "wwws";
|
|
13
|
+
globals.fetch = isBrowser || isWorker ? (...args) => globalThis.fetch(...args) : iFetch;
|
|
14
|
+
globals.WebSocket = isBrowser || isWorker ? globalThis.WebSocket : WWWebSocket;
|
|
15
|
+
export default globals;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const red = "\x1B[31m";
|
|
2
|
+
const green = "\x1B[32m";
|
|
3
|
+
const reset = "\x1B[0m";
|
|
4
|
+
console.error([
|
|
5
|
+
red,
|
|
6
|
+
"how NOT to import yolkbot:",
|
|
7
|
+
'> import yolkbot from "yolkbot";',
|
|
8
|
+
green,
|
|
9
|
+
"how to PROPERLY import yolkbot:",
|
|
10
|
+
'> import yolkbot from "yolkbot/bot";',
|
|
11
|
+
"please adjust your code.",
|
|
12
|
+
reset
|
|
13
|
+
].join(`
|
|
14
|
+
`));
|
package/dist/matchmaker.js
CHANGED
|
@@ -1 +1,141 @@
|
|
|
1
|
-
import
|
|
1
|
+
import API from "./api.js";
|
|
2
|
+
import { validate } from "./wasm/direct.js";
|
|
3
|
+
import globals from "./env/globals.js";
|
|
4
|
+
import yolkws from "./socket.js";
|
|
5
|
+
|
|
6
|
+
export class Matchmaker {
|
|
7
|
+
connected = false;
|
|
8
|
+
onceConnected = [];
|
|
9
|
+
regionList = [];
|
|
10
|
+
proxy = null;
|
|
11
|
+
sessionId = "";
|
|
12
|
+
onListeners = new Map;
|
|
13
|
+
onceListeners = new Map;
|
|
14
|
+
#noExitOnError = false;
|
|
15
|
+
#forceClose = false;
|
|
16
|
+
constructor(params = {}) {
|
|
17
|
+
this.#noExitOnError = params.noExitOnError || false;
|
|
18
|
+
if (!params.instance)
|
|
19
|
+
params.instance = "shellshock.io";
|
|
20
|
+
if (!params.protocol)
|
|
21
|
+
params.protocol = "wss";
|
|
22
|
+
if (params.api)
|
|
23
|
+
this.api = params.api;
|
|
24
|
+
else
|
|
25
|
+
this.api = new API({
|
|
26
|
+
proxy: params.proxy,
|
|
27
|
+
protocol: params.protocol,
|
|
28
|
+
instance: params.instance,
|
|
29
|
+
connectionTimeout: params.connectionTimeout
|
|
30
|
+
});
|
|
31
|
+
if (params.sessionId || params.noLogin)
|
|
32
|
+
this.sessionId = params.sessionId;
|
|
33
|
+
else
|
|
34
|
+
this.#createSessionId();
|
|
35
|
+
if (params.proxy && globals.isBrowser)
|
|
36
|
+
this.#processError("proxies do not work and hence are not supported in the browser");
|
|
37
|
+
else if (params.proxy)
|
|
38
|
+
this.proxy = params.proxy;
|
|
39
|
+
this.#createSocket(params.instance, params.protocol, params.noLogin, params.connectionTimeout);
|
|
40
|
+
}
|
|
41
|
+
async#createSocket(instance, protocol, noLogin, connectionTimeout) {
|
|
42
|
+
this.ws = new yolkws(`${protocol}://${instance}/matchmaker/`, this.proxy);
|
|
43
|
+
this.ws.connectionTimeout = connectionTimeout || 5000;
|
|
44
|
+
const didConnect = await this.ws.tryConnect();
|
|
45
|
+
if (!didConnect)
|
|
46
|
+
return this.#processError("WebSocket did not connect...");
|
|
47
|
+
this.ws.onmessage = async (e) => {
|
|
48
|
+
const data = JSON.parse(e.data);
|
|
49
|
+
if (data.command === "validateUUID")
|
|
50
|
+
return this.ws.send(JSON.stringify({ command: "validateUUID", hash: await validate(data.uuid) }));
|
|
51
|
+
this.#emit("msg", data);
|
|
52
|
+
};
|
|
53
|
+
this.ws.onclose = () => {
|
|
54
|
+
this.connected = false;
|
|
55
|
+
if (!this.#forceClose)
|
|
56
|
+
this.#createSocket(instance, protocol, noLogin, connectionTimeout);
|
|
57
|
+
};
|
|
58
|
+
this.connected = true;
|
|
59
|
+
if (this.sessionId || noLogin)
|
|
60
|
+
this.onceConnected.forEach((func) => func());
|
|
61
|
+
}
|
|
62
|
+
async#createSessionId() {
|
|
63
|
+
const anonLogin = await this.api.loginAnonymously();
|
|
64
|
+
if (!anonLogin || typeof anonLogin === "string")
|
|
65
|
+
this.#emit("authFail", anonLogin);
|
|
66
|
+
this.sessionId = anonLogin.sessionId;
|
|
67
|
+
if (this.connected)
|
|
68
|
+
this.onceConnected.forEach((func) => func());
|
|
69
|
+
}
|
|
70
|
+
send(msg) {
|
|
71
|
+
this.ws.send(JSON.stringify(msg));
|
|
72
|
+
}
|
|
73
|
+
async waitForConnect() {
|
|
74
|
+
return new Promise((res) => {
|
|
75
|
+
if (this.connected) {
|
|
76
|
+
res();
|
|
77
|
+
} else {
|
|
78
|
+
this.onceConnected.push(res);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async getRegions() {
|
|
83
|
+
await this.waitForConnect();
|
|
84
|
+
const that = this;
|
|
85
|
+
return new Promise((res) => {
|
|
86
|
+
const listener = (data2) => {
|
|
87
|
+
if (data2.command === "regionList") {
|
|
88
|
+
this.regionList = data2.regionList;
|
|
89
|
+
this.off("msg", listener);
|
|
90
|
+
res(data2.regionList);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
this.on("msg", listener);
|
|
94
|
+
this.ws.onerror = (e2) => that.#processError("failed to get regions", e2);
|
|
95
|
+
this.ws.send(JSON.stringify({ command: "regionList" }));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
close() {
|
|
99
|
+
this.#forceClose = true;
|
|
100
|
+
this.connected = false;
|
|
101
|
+
this.ws.close();
|
|
102
|
+
}
|
|
103
|
+
on(event, callback) {
|
|
104
|
+
if (!this.onListeners.has(event)) {
|
|
105
|
+
this.onListeners.set(event, []);
|
|
106
|
+
}
|
|
107
|
+
this.onListeners.get(event).push(callback);
|
|
108
|
+
}
|
|
109
|
+
once(event, callback) {
|
|
110
|
+
if (!this.onceListeners.has(event)) {
|
|
111
|
+
this.onceListeners.set(event, []);
|
|
112
|
+
}
|
|
113
|
+
this.onceListeners.get(event).push(callback);
|
|
114
|
+
}
|
|
115
|
+
off(event, callback) {
|
|
116
|
+
if (this.onListeners.has(event)) {
|
|
117
|
+
this.onListeners.set(event, this.onListeners.get(event).filter((func) => func !== callback));
|
|
118
|
+
}
|
|
119
|
+
if (this.onceListeners.has(event)) {
|
|
120
|
+
this.onceListeners.set(event, this.onceListeners.get(event).filter((func) => func !== callback));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
#emit(event, ...args) {
|
|
124
|
+
if (this.onListeners.has(event)) {
|
|
125
|
+
this.onListeners.get(event).forEach((func) => func(...args));
|
|
126
|
+
}
|
|
127
|
+
if (this.onceListeners.has(event)) {
|
|
128
|
+
this.onceListeners.get(event).forEach((func) => func(...args));
|
|
129
|
+
this.onceListeners.delete(event);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
#processError(error) {
|
|
133
|
+
if (this.onListeners.has("error"))
|
|
134
|
+
this.#emit("error", error);
|
|
135
|
+
else if (this.#noExitOnError)
|
|
136
|
+
console.error(error);
|
|
137
|
+
else
|
|
138
|
+
throw new Error(error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export default Matchmaker;
|