yolkbot 1.4.8 → 1.5.0

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.
Files changed (129) hide show
  1. package/README.md +1 -1
  2. package/browser/build/global.js +1 -1
  3. package/browser/build/module.js +1 -1
  4. package/dist/api.d.ts +34 -16
  5. package/dist/api.js +164 -121
  6. package/dist/bot/GamePlayer.d.ts +2 -2
  7. package/dist/bot/GamePlayer.js +15 -5
  8. package/dist/bot.d.ts +121 -83
  9. package/dist/bot.js +624 -1077
  10. package/dist/comm/CommIn.js +14 -17
  11. package/dist/comm/CommOut.js +15 -15
  12. package/dist/constants/CommCode.js +1 -1
  13. package/dist/constants/findItemById.js +2 -1
  14. package/dist/constants/guns.d.ts +16 -41
  15. package/dist/constants/guns.js +137 -259
  16. package/dist/constants/index.d.ts +7 -9
  17. package/dist/constants/index.js +15 -13
  18. package/dist/dispatches/BanPlayerDispatch.d.ts +3 -1
  19. package/dist/dispatches/BootPlayerDispatch.d.ts +3 -1
  20. package/dist/dispatches/ChatDispatch.d.ts +3 -1
  21. package/dist/dispatches/ChatDispatch.js +3 -3
  22. package/dist/dispatches/FireDispatch.d.ts +3 -1
  23. package/dist/dispatches/GameOptionsDispatch.d.ts +3 -1
  24. package/dist/dispatches/GoToAmmoDispatch.d.ts +2 -0
  25. package/dist/dispatches/GoToAmmoDispatch.js +15 -16
  26. package/dist/dispatches/GoToCoopDispatch.d.ts +2 -0
  27. package/dist/dispatches/GoToCoopDispatch.js +19 -20
  28. package/dist/dispatches/GoToGrenadeDispatch.d.ts +2 -0
  29. package/dist/dispatches/GoToGrenadeDispatch.js +15 -16
  30. package/dist/dispatches/GoToPlayerDispatch.d.ts +3 -1
  31. package/dist/dispatches/GoToPlayerDispatch.js +16 -21
  32. package/dist/dispatches/GoToSpatulaDispatch.d.ts +2 -0
  33. package/dist/dispatches/GoToSpatulaDispatch.js +11 -14
  34. package/dist/dispatches/LookAtDispatch.d.ts +3 -1
  35. package/dist/dispatches/LookAtDispatch.js +8 -6
  36. package/dist/dispatches/LookAtPosDispatch.d.ts +3 -1
  37. package/dist/dispatches/LookAtPosDispatch.js +1 -1
  38. package/dist/dispatches/MeleeDispatch.d.ts +2 -0
  39. package/dist/dispatches/MeleeDispatch.js +4 -4
  40. package/dist/dispatches/MovementDispatch.d.ts +3 -1
  41. package/dist/dispatches/MovementDispatch.js +1 -1
  42. package/dist/dispatches/PauseDispatch.d.ts +2 -0
  43. package/dist/dispatches/ReloadDispatch.d.ts +2 -0
  44. package/dist/dispatches/ReloadDispatch.js +17 -10
  45. package/dist/dispatches/ReportPlayerDispatch.d.ts +4 -2
  46. package/dist/dispatches/ReportPlayerDispatch.js +8 -6
  47. package/dist/dispatches/ResetGameDispatch.d.ts +2 -0
  48. package/dist/dispatches/SaveLoadoutDispatch.d.ts +4 -2
  49. package/dist/dispatches/SaveLoadoutDispatch.js +9 -8
  50. package/dist/dispatches/SpawnDispatch.d.ts +2 -0
  51. package/dist/dispatches/SpawnDispatch.js +5 -1
  52. package/dist/dispatches/SwapWeaponDispatch.d.ts +3 -1
  53. package/dist/dispatches/SwapWeaponDispatch.js +1 -1
  54. package/dist/dispatches/SwitchTeamDispatch.d.ts +2 -0
  55. package/dist/dispatches/SwitchTeamDispatch.js +2 -1
  56. package/dist/dispatches/ThrowGrenadeDispatch.d.ts +3 -1
  57. package/dist/dispatches/index.d.ts +105 -182
  58. package/dist/dispatches/index.js +24 -25
  59. package/dist/enums.d.ts +154 -0
  60. package/dist/enums.js +114 -0
  61. package/dist/env/fetch.d.ts +15 -0
  62. package/dist/env/fetch.js +113 -79
  63. package/dist/env/globals.d.ts +9 -0
  64. package/dist/env/globals.js +11 -9
  65. package/dist/index.d.ts +31 -0
  66. package/dist/index.js +24 -14
  67. package/dist/packets/addPlayer.js +63 -0
  68. package/dist/packets/beginShellStreak.js +44 -0
  69. package/dist/packets/challengeCompleted.js +16 -0
  70. package/dist/packets/changeCharacter.js +46 -0
  71. package/dist/packets/chat.js +10 -0
  72. package/dist/packets/collectItem.js +26 -0
  73. package/dist/packets/die.js +40 -0
  74. package/dist/packets/endShellStreak.js +21 -0
  75. package/dist/packets/eventModifier.js +8 -0
  76. package/dist/packets/explode.js +19 -0
  77. package/dist/packets/fire.js +21 -0
  78. package/dist/packets/gameAction.js +33 -0
  79. package/dist/packets/gameJoined.js +64 -0
  80. package/dist/packets/gameOptions.js +27 -0
  81. package/dist/packets/hitMe.js +12 -0
  82. package/dist/packets/hitMeHardBoiled.js +18 -0
  83. package/dist/packets/hitThem.js +12 -0
  84. package/dist/packets/melee.js +8 -0
  85. package/dist/packets/metaGameState.js +62 -0
  86. package/dist/packets/pause.js +17 -0
  87. package/dist/packets/ping.js +19 -0
  88. package/dist/packets/playerInfo.js +15 -0
  89. package/dist/packets/reload.js +17 -0
  90. package/dist/packets/removePlayer.js +10 -0
  91. package/dist/packets/respawn.js +31 -0
  92. package/dist/packets/socketReady.js +16 -0
  93. package/dist/packets/spawnItem.js +11 -0
  94. package/dist/packets/swapWeapon.js +11 -0
  95. package/dist/packets/switchTeam.js +13 -0
  96. package/dist/packets/syncMe.js +25 -0
  97. package/dist/packets/syncThem.js +63 -0
  98. package/dist/packets/throwGrenade.js +17 -0
  99. package/dist/packets/updateBalance.js +8 -0
  100. package/dist/pathing/astar.js +33 -20
  101. package/dist/pathing/mapnode.d.ts +3 -1
  102. package/dist/pathing/mapnode.js +170 -65
  103. package/dist/socket.d.ts +21 -6
  104. package/dist/socket.js +48 -38
  105. package/dist/util.d.ts +4 -1
  106. package/dist/util.js +102 -44
  107. package/dist/wasm/bytes.d.ts +1 -1
  108. package/dist/wasm/bytes.js +1 -1
  109. package/dist/wasm/direct.d.ts +1 -1
  110. package/dist/wasm/direct.js +13 -13
  111. package/dist/wasm/legacy.d.ts +7 -6
  112. package/dist/wasm/legacy.js +14 -8
  113. package/package.json +43 -30
  114. package/dist/comm/index.d.ts +0 -12
  115. package/dist/comm/index.js +0 -11
  116. package/dist/constants/changelog.d.ts +0 -7
  117. package/dist/constants/housePromo.d.ts +0 -40
  118. package/dist/constants/language.d.ts +0 -3
  119. package/dist/constants/notices.d.ts +0 -4
  120. package/dist/constants/shellNews.d.ts +0 -12
  121. package/dist/constants/shellYoutube.d.ts +0 -12
  122. package/dist/constants/shopItems.d.ts +0 -15
  123. package/dist/constants/sounds.d.ts +0 -10
  124. package/dist/matchmaker.d.ts +0 -50
  125. package/dist/matchmaker.js +0 -141
  126. package/dist/pathing/binaryheap.d.ts +0 -18
  127. package/dist/pathing/binaryheap.js +0 -79
  128. package/dist/wasm/util.d.ts +0 -9
  129. package/dist/wasm/util.js +0 -19
@@ -0,0 +1,154 @@
1
+ // keep enums.js up to date
2
+
3
+ export enum APIErrorEnum {
4
+ WebSocketConnectFail = 'websocket_connect_fail',
5
+ MissingParams = 'missing_params',
6
+ NetworkFail = 'firebase_network_failed',
7
+ ServicesClosedEarly = 'services_closed_early',
8
+ InternalError = 'unknown_error',
9
+ FirebaseRateLimited = 'firebase_rate_limited'
10
+ }
11
+
12
+ export interface APIError { ok: false, error: APIErrorEnum }
13
+
14
+ export enum LoginErrorEnum {
15
+ AccountBanned = 'account_banned'
16
+ }
17
+
18
+ export type LoginError = APIError | { ok: false, error: LoginErrorEnum };
19
+
20
+ export enum BuyItemErrorEnum {
21
+ SessionExpired = 'PLAYER_NOT_FOUND',
22
+ ItemNotFound = 'ITEM_NOT_FOUND',
23
+ ItemAlreadyOwned = 'ALREADY_OWNED',
24
+ CannotAfford = 'INSUFFICIENT_FUNDS',
25
+ InternalError = 'UNKNOWN_ERROR'
26
+ }
27
+
28
+ export type BuyItemError = { ok: false, error: BuyItemErrorEnum };
29
+
30
+ export enum ChicknWinnerErrorEnum {
31
+ OnCooldown = 'on_cooldown',
32
+ HitDailyLimit = 'hit_daily_limit',
33
+ NotAtDailyLimit = 'not_at_limit',
34
+ NotEnoughResetEggs = 'not_enough_eggs',
35
+ SessionExpired = 'session_expired',
36
+ InternalError = 'unknown_error'
37
+ }
38
+
39
+ export type ChicknWinnerError = { ok: false, error: ChicknWinnerErrorEnum };
40
+
41
+ export enum GameFindErrorEnum {
42
+ MissingParams = 'missing_params',
43
+ InvalidRegion = 'region_not_in_list',
44
+ InvalidMode = 'mode_not_in_list',
45
+ InvalidMap = 'map_not_in_list',
46
+ GameNotFound = 'game_not_found',
47
+ SessionExpired = 'session_expired',
48
+ InternalError = 'unknown_error'
49
+ }
50
+
51
+ export type GameFindError = { ok: false, error: GameFindErrorEnum };
52
+
53
+ export enum GameJoinErrorEnum {
54
+ MissingParams = 'missing_params',
55
+ InvalidObject = 'invalid_game_object',
56
+ WebSocketConnectFail = 'websocket_connect_fail',
57
+ GameNotFound = 'game_not_found',
58
+ InternalError = 'unknown_error'
59
+ }
60
+
61
+ export type GameJoinError = { ok: false, error: GameJoinErrorEnum };
62
+
63
+ export enum MatchmakerErrorEnum {
64
+ WebSocketConnectFail = 'websocket_connect_fail'
65
+ }
66
+
67
+ export type MatchmakerError = { ok: false, error: MatchmakerErrorEnum };
68
+
69
+ export enum Intents {
70
+ CHALLENGES = 1,
71
+ BOT_STATS = 2,
72
+ PATHFINDING = 3,
73
+ PING = 5,
74
+ COSMETIC_DATA = 6,
75
+ PLAYER_HEALTH = 7,
76
+ PACKET_HOOK = 8,
77
+ LOG_PACKETS = 10,
78
+ SKIP_LOGIN = 11,
79
+ DEBUG_BUFFER = 12,
80
+ NO_AFK_KICK = 16,
81
+ LOAD_MAP = 17,
82
+ OBSERVE_GAME = 18,
83
+ RENEW_SESSION = 21,
84
+ VIP_HIDE_BADGE = 22,
85
+ SIMULATION = 23,
86
+ MANUAL_UPDATE = 24,
87
+ FASTER_RESPAWN = 25
88
+ }
89
+
90
+ export enum RedeemCodeErrorEnum {
91
+ SessionExpired = 'PLAYER_NOT_FOUND',
92
+ CurrentlyRedeemingElsewhere = 'CODE_DOUBLE_DOUBLE',
93
+ AlreadyRedeemed = 'CODE_PREV_REDEEMED',
94
+ InvalidCode = 'CODE_NOT_FOUND',
95
+ Ratelimited = 'RATE_LIMIT_REACHED',
96
+ InternalError = 'UNKNOWN_ERROR'
97
+ }
98
+
99
+ export type RedeemCodeError = { ok: false, error: RedeemCodeErrorEnum };
100
+
101
+ export enum ClaimSocialErrorEnum {
102
+ SessionExpired = 'reward_expired_session',
103
+ InvalidReward = 'REWARD_NOT_FOUND',
104
+ AlreadyRedeemed = 'REWARD_PREV_GIVEN',
105
+ InternalError = 'unknown_error'
106
+ }
107
+
108
+ export type ClaimSocialError = { ok: false, error: ClaimSocialErrorEnum };
109
+
110
+ export enum ClaimURLErrorEnum {
111
+ SessionExpired = 'urlRewardParams_expired_session',
112
+ InvalidReward = 'REWARD_NOT_FOUND',
113
+ AlreadyRedeemed = 'REWARD_PREV_GIVEN',
114
+ InternalError = 'unknown_error'
115
+ }
116
+
117
+ export type ClaimURLError = { ok: false, error: ClaimURLErrorEnum };
118
+
119
+ export enum ChallengeRerollErrorEnum {
120
+ SessionExpired = 'challengeRerollSlot_expired_session',
121
+ ChallengeNotFound = 'challenge_not_found',
122
+ ChallengeNotAssigned = 'challenge_reroll_not_found',
123
+ NotEnoughEggs = 'insufficient_eggs',
124
+ InternalError = 'unknown_error'
125
+ }
126
+
127
+ export type ChallengeRerollError = { ok: false, error: ChallengeRerollErrorEnum };
128
+
129
+ export enum ChallengeClaimErrorEnum {
130
+ SessionExpired = 'challengeClaimReward_expired_session',
131
+ ChallengeNotFound = 'challenge_claim_not_found',
132
+ ChallengeNotCompleted = 'challenge_not_completed',
133
+ InternalError = 'unknown_error'
134
+ }
135
+
136
+ export type ChallengeClaimError = { ok: false, error: ChallengeClaimErrorEnum };
137
+
138
+ export enum PathfindError {
139
+ NoPathFound = 'no_path_found',
140
+ PathTooShort = 'path_too_short'
141
+ }
142
+
143
+ export enum ZoneLeaveReason {
144
+ Despawned = 'despawned',
145
+ Killed = 'killed',
146
+ WalkedOut = 'exited',
147
+ RoundEnded = 'round_ended'
148
+ }
149
+
150
+ export enum CleanupLevel {
151
+ None = 0,
152
+ Partial = 1,
153
+ Full = 2
154
+ }
package/dist/enums.js ADDED
@@ -0,0 +1,114 @@
1
+ export const APIError = {
2
+ WebSocketConnectFail: "websocket_connect_fail",
3
+ MissingParams: "missing_params",
4
+ NetworkFail: "firebase_network_failed",
5
+ ServicesClosedEarly: "services_closed_early",
6
+ InternalError: "unknown_error",
7
+ FirebaseRateLimited: "firebase_rate_limited"
8
+ };
9
+ export const LoginError = {
10
+ ...APIError,
11
+ AccountBanned: "account_banned"
12
+ };
13
+ export const BuyItemError = {
14
+ SessionExpired: "PLAYER_NOT_FOUND",
15
+ ItemNotFound: "ITEM_NOT_FOUND",
16
+ ItemAlreadyOwned: "ALREADY_OWNED",
17
+ CannotAfford: "INSUFFICIENT_FUNDS",
18
+ InternalError: "UNKNOWN_ERROR"
19
+ };
20
+ export const ChicknWinnerError = {
21
+ OnCooldown: "on_cooldown",
22
+ HitDailyLimit: "hit_daily_limit",
23
+ NotAtDailyLimit: "not_at_limit",
24
+ NotEnoughResetEggs: "not_enough_eggs",
25
+ SessionExpired: "session_expired",
26
+ InternalError: "unknown_error"
27
+ };
28
+ export const GameFindError = {
29
+ MissingParams: "missing_params",
30
+ InvalidRegion: "region_not_in_list",
31
+ InvalidMode: "mode_not_in_list",
32
+ InvalidMap: "map_not_in_list",
33
+ GameNotFound: "game_not_found",
34
+ SessionExpired: "session_expired",
35
+ InternalError: "unknown_error"
36
+ };
37
+ export const GameJoinError = {
38
+ MissingParams: "missing_params",
39
+ InvalidObject: "invalid_game_object",
40
+ WebSocketConnectFail: "websocket_connect_fail",
41
+ GameNotFound: "game_not_found",
42
+ InternalError: "unknown_error"
43
+ };
44
+ export const MatchmakerError = {
45
+ WebSocketConnectFail: "websocket_connect_fail"
46
+ };
47
+ export const Intents = {
48
+ CHALLENGES: 1,
49
+ BOT_STATS: 2,
50
+ PATHFINDING: 3,
51
+ PING: 5,
52
+ COSMETIC_DATA: 6,
53
+ PLAYER_HEALTH: 7,
54
+ PACKET_HOOK: 8,
55
+ LOG_PACKETS: 10,
56
+ SKIP_LOGIN: 11,
57
+ DEBUG_BUFFER: 12,
58
+ NO_AFK_KICK: 16,
59
+ LOAD_MAP: 17,
60
+ OBSERVE_GAME: 18,
61
+ RENEW_SESSION: 21,
62
+ VIP_HIDE_BADGE: 22,
63
+ SIMULATION: 23,
64
+ MANUAL_UPDATE: 24,
65
+ FASTER_RESPAWN: 25
66
+ };
67
+ export const RedeemCodeError = {
68
+ SessionExpired: "PLAYER_NOT_FOUND",
69
+ CurrentlyRedeemingElsewhere: "CODE_DOUBLE_DOUBLE",
70
+ AlreadyRedeemed: "CODE_PREV_REDEEMED",
71
+ InvalidCode: "CODE_NOT_FOUND",
72
+ Ratelimited: "RATE_LIMIT_REACHED",
73
+ InternalError: "UNKNOWN_ERROR"
74
+ };
75
+ export const ClaimSocialError = {
76
+ SessionExpired: "reward_expired_session",
77
+ InvalidReward: "REWARD_NOT_FOUND",
78
+ AlreadyRedeemed: "REWARD_PREV_GIVEN",
79
+ InternalError: "unknown_error"
80
+ };
81
+ export const ClaimURLError = {
82
+ SessionExpired: "urlRewardParams_expired_session",
83
+ InvalidReward: "REWARD_NOT_FOUND",
84
+ AlreadyRedeemed: "REWARD_PREV_GIVEN",
85
+ InternalError: "unknown_error"
86
+ };
87
+ export const ChallengeRerollError = {
88
+ SessionExpired: "challengeRerollSlot_expired_session",
89
+ ChallengeNotFound: "challenge_not_found",
90
+ ChallengeNotAssigned: "challenge_reroll_not_found",
91
+ NotEnoughEggs: "insufficient_eggs",
92
+ InternalError: "unknown_error"
93
+ };
94
+ export const ChallengeClaimError = {
95
+ SessionExpired: "challengeClaimReward_expired_session",
96
+ ChallengeNotFound: "challenge_claim_not_found",
97
+ ChallengeNotCompleted: "challenge_not_completed",
98
+ InternalError: "unknown_error"
99
+ };
100
+ export const PathfindError = {
101
+ NoPathFound: "no_path_found",
102
+ PathTooShort: "path_too_short"
103
+ };
104
+ export const ZoneLeaveReason = {
105
+ Despawned: "despawned",
106
+ Killed: "killed",
107
+ WalkedOut: "exited",
108
+ RoundEnded: "round_ended"
109
+ };
110
+ export const CleanupLevel = {
111
+ None: 0,
112
+ Partial: 1,
113
+ Full: 2
114
+ };
@@ -0,0 +1,15 @@
1
+ interface HttpResponse {
2
+ json(): any;
3
+ text(): string;
4
+ }
5
+
6
+ interface iFetchOptions {
7
+ method?: string;
8
+ proxy?: string;
9
+ headers?: Record<string, string>;
10
+ body?: string | null;
11
+ timeout?: number;
12
+ }
13
+
14
+ declare function iFetch(url: string, options?: iFetchOptions): Promise<HttpResponse>;
15
+ export default iFetch;
package/dist/env/fetch.js CHANGED
@@ -1,102 +1,136 @@
1
1
  import { socksConnect } from "wwws";
2
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
- `;
3
+ const parseChunkedBody = (body) => {
4
+ const chunks = [];
5
+ let i = 0;
6
+ const len = body.length;
7
+ while (i < len) {
8
+ const rnIdx = body.indexOf(`\r
9
+ `, i);
10
+ if (rnIdx === -1)
11
+ break;
12
+ const sizeHex = body.slice(i, rnIdx).trim();
13
+ if (!sizeHex) {
14
+ i = rnIdx + 2;
15
+ continue;
16
+ }
17
+ const size = parseInt(sizeHex, 16);
18
+ if (Number.isNaN(size) || size === 0)
19
+ break;
20
+ i = rnIdx + 2;
21
+ chunks.push(body.slice(i, i + size));
22
+ i += size + 2;
23
+ }
24
+ return chunks.join("");
25
+ };
26
+ const sendHttpRequest = (socket, { method, pathname, hostname, port, headers, body }, time, resolve, reject) => {
27
+ const timeout = setTimeout(() => {
28
+ socket.destroy();
29
+ reject(new Error(`iFetch timed out: ${method} ${hostname}:${port}${pathname}`));
30
+ }, time);
31
+ let reqHeaders = Object.entries(headers).map(([k, v]) => `${k}: ${v}\r
32
+ `).join("");
8
33
  if (body && !("Content-Length" in headers))
9
34
  reqHeaders += `Content-Length: ${Buffer.byteLength(body)}\r
10
35
  `;
11
- let req = `${method} ${pathname} HTTP/1.1\r
36
+ socket.write(`${method} ${pathname} HTTP/1.1\r
12
37
  Host: ${hostname}:${port}\r
13
38
  ${reqHeaders}Connection: close\r
14
39
  \r
15
- `;
40
+ `);
16
41
  if (body)
17
- req += body;
18
- socket.write(req);
42
+ socket.write(body);
19
43
  let response = "";
44
+ let headersParsed = false;
45
+ let contentLength = 0;
46
+ let bodyStart = 0;
20
47
  socket.on("data", (data) => {
21
48
  response += data.toString();
22
- if (/transfer-encoding:\s*chunked/i.test(response)) {
23
- if (response.includes(`\r
49
+ if (!headersParsed) {
50
+ bodyStart = response.indexOf(`\r
51
+ \r
52
+ `);
53
+ if (bodyStart !== -1) {
54
+ headersParsed = true;
55
+ bodyStart += 4;
56
+ const headersText = response.slice(0, bodyStart - 4);
57
+ const contentLengthMatch = headersText.match(/content-length:\s*(?<length>\d+)/i);
58
+ if (contentLengthMatch)
59
+ contentLength = parseInt(contentLengthMatch.groups.length, 10);
60
+ }
61
+ }
62
+ if (headersParsed) {
63
+ const isChunked = /transfer-encoding:\s*chunked/i.test(response);
64
+ if (isChunked) {
65
+ if (response.includes(`\r
24
66
  0\r
25
67
  \r
26
68
  `))
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
33
- \r
34
- `) + 4;
35
- const body3 = response.slice(bodyStart);
36
- if (body3.length >= contentLength)
37
- socket.end();
69
+ socket.destroy();
70
+ } else if (contentLength > 0) {
71
+ const bodyReceived = response.length - bodyStart;
72
+ if (bodyReceived >= contentLength)
73
+ socket.destroy();
38
74
  }
39
75
  }
40
76
  });
41
- socket.on("end", () => {
42
- const isChunked = /transfer-encoding:\s*chunked/i.test(response);
43
- let parsedBody = response.split(`\r
77
+ socket.on("error", (err) => {
78
+ clearTimeout(timeout);
79
+ reject(err);
80
+ });
81
+ socket.on("close", () => {
82
+ clearTimeout(timeout);
83
+ const headerEnd = response.indexOf(`\r
44
84
  \r
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 });
85
+ `);
86
+ if (headerEnd === -1)
87
+ return reject(new Error("Invalid HTTP response"));
88
+ let parsedBody = response.slice(headerEnd + 4);
89
+ if (/transfer-encoding:\s*chunked/i.test(response))
90
+ parsedBody = parseChunkedBody(parsedBody);
91
+ resolve({
92
+ json: () => JSON.parse(parsedBody),
93
+ text: () => parsedBody
94
+ });
66
95
  });
67
96
  };
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));
97
+ export const iFetch = (url, { method = "GET", proxy, headers = {}, body = null, timeout = 20000 } = {}) => new Promise((resolve, reject) => {
98
+ try {
99
+ if (typeof process === "undefined" || !process.getBuiltinModule)
100
+ return globals.fetch(url, { method, headers, body }).then(resolve).catch(reject);
101
+ const dns = process.getBuiltinModule("node:dns");
102
+ const net = process.getBuiltinModule("node:net");
103
+ const tls = process.getBuiltinModule("node:tls");
104
+ const { hostname, port: rawPort, pathname: path, protocol, search } = new URL(url);
105
+ const isHttps = protocol === "https:";
106
+ const pathname = path + search;
107
+ const port = rawPort ? parseInt(rawPort, 10) : isHttps ? 443 : 80;
108
+ if (!proxy) {
109
+ return dns.lookup(hostname, { family: 4 }, (err, host) => {
110
+ if (err)
111
+ return reject(err);
112
+ const socket = isHttps ? tls.connect({ port, host, servername: hostname }) : net.connect({ port, host });
113
+ socket.on("connect", () => sendHttpRequest(socket, { method, pathname, hostname, port, headers, body }, timeout, resolve, reject));
114
+ });
115
+ }
116
+ const proxyInfo = new URL(proxy);
117
+ const scheme = proxyInfo.protocol.replace(":", "");
118
+ if (scheme !== "socks5" && scheme !== "socks5h")
119
+ return reject(new Error("iFetch only supports socks5 & socks5h proxies"));
120
+ socksConnect({
121
+ proxy: {
122
+ hostname: proxyInfo.hostname,
123
+ port: Number(proxyInfo.port),
124
+ username: proxyInfo.username,
125
+ password: proxyInfo.password
126
+ },
127
+ destHost: hostname,
128
+ destPort: port,
129
+ useTLS: isHttps,
130
+ resolveDnsLocally: proxyInfo.protocol === "socks5"
131
+ }).then((socket) => sendHttpRequest(socket, { method, pathname, hostname, port, headers, body }, timeout, resolve, reject)).catch(reject);
132
+ } catch (err) {
133
+ reject(err);
134
+ }
101
135
  });
102
136
  export default iFetch;
@@ -0,0 +1,9 @@
1
+ import WWWebSocket from 'wwws';
2
+ import iFetch from './fetch';
3
+
4
+ export declare const globals: {
5
+ fetch: typeof globalThis.fetch | typeof iFetch,
6
+ WebSocket: typeof globalThis.WebSocket | typeof WWWebSocket
7
+ };
8
+
9
+ export default globals;
@@ -1,15 +1,17 @@
1
+ import { WWWebSocket } from "wwws";
1
2
  import iFetch from "./fetch.js";
2
- const globals = {};
3
+ export const globals = {};
3
4
  const isBrowser = typeof window !== "undefined" && typeof HTMLElement !== "undefined";
4
- const isWorker = typeof WebSocketPair !== "undefined" && typeof Cloudflare !== "undefined";
5
+ const isWebWorker = typeof self !== "undefined" && typeof DedicatedWorkerGlobalScope !== "undefined" && self instanceof DedicatedWorkerGlobalScope;
6
+ const isCloudflareWorker = typeof WebSocketPair !== "undefined" && typeof Cloudflare !== "undefined";
7
+ const isUnsandboxedElectron = typeof process === "object" && process.versions?.electron && process.versions?.node && typeof window !== "undefined" && typeof window.require !== "undefined";
5
8
  const isNode = typeof process !== "undefined" && process.moduleLoadList?.length > 0;
6
9
  const isDeno = typeof Deno !== "undefined";
7
- const isBun = typeof process !== "undefined" && !!process.versions?.bun;
8
- if (!isBrowser && !isWorker && !isNode && !isDeno && !isBun)
10
+ const isBun = typeof Bun !== "undefined";
11
+ if (!isBrowser && !isCloudflareWorker && !isWebWorker && !isUnsandboxedElectron && !isNode && !isDeno && !isBun)
9
12
  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;
13
+ globals.isBrowser = isBrowser || isWebWorker;
14
+ globals.isIsolated = !isNode && !isDeno && !isBun && !isUnsandboxedElectron;
15
+ globals.fetch = globals.isIsolated ? (...args) => globalThis.fetch(...args) : iFetch;
16
+ globals.WebSocket = globals.isIsolated ? globalThis.WebSocket : WWWebSocket;
15
17
  export default globals;
@@ -0,0 +1,31 @@
1
+ export declare type API = import('./api.js').API;
2
+ export declare type Bot = import('./bot.js').Bot;
3
+ export declare const Enums: typeof import('./enums.js');
4
+ export declare const yolkws: typeof import('./socket.js').default;
5
+ export declare const util: typeof import('./util.js');
6
+
7
+ export declare type GamePlayer = import('./bot/GamePlayer.js').GamePlayer;
8
+
9
+ export declare const Comm: {
10
+ CommIn: typeof import('./comm/CommIn.js').CommIn;
11
+ CommOut: typeof import('./comm/CommOut.js').CommOut;
12
+ };
13
+
14
+ export declare const Constants: typeof import('./constants/index.js');
15
+ export declare const Challenges: typeof import('./constants/challenges.js').Challenges;
16
+ export declare const CloseCode: typeof import('./constants/CloseCode.js').CloseCode;
17
+ export declare const CommCode: typeof import('./constants/CommCode.js').CommCode;
18
+ export declare const Guns: typeof import('./constants/guns.js');
19
+ export declare const Items: typeof import('./constants/items.js').Items;
20
+ export declare const Maps: typeof import('./constants/maps.js').Maps;
21
+ export declare const Regions: typeof import('./constants/regions.js').Regions;
22
+
23
+ export declare const Dispatches: typeof import('./dispatches/index.js').default;
24
+
25
+ export declare const iFetch: typeof import('./env/fetch.js').default;
26
+ export declare const globals: typeof import('./env/globals.js').globals;
27
+
28
+ export declare const WASM: typeof import('./wasm/direct.js');
29
+
30
+ declare const _default: typeof import('./bot.js').Bot;
31
+ export default _default;
package/dist/index.js CHANGED
@@ -1,14 +1,24 @@
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
- `));
1
+ export { API } from "./api.js";
2
+ export { Bot } from "./bot.js";
3
+ export * as Enums from "./enums.js";
4
+ export { yolkws } from "./socket.js";
5
+ export * as util from "./util.js";
6
+ export { GamePlayer } from "./bot/GamePlayer.js";
7
+ import { CommIn } from "./comm/CommIn.js";
8
+ import { CommOut } from "./comm/CommOut.js";
9
+ export const Comm = { CommIn, CommOut };
10
+
11
+ export * as Constants from "./constants/index.js";
12
+ export { Challenges } from "./constants/challenges.js";
13
+ export { CloseCode } from "./constants/CloseCode.js";
14
+ export { CommCode } from "./constants/CommCode.js";
15
+ export * as Guns from "./constants/guns.js";
16
+ export { Items } from "./constants/items.js";
17
+ export { Maps } from "./constants/maps.js";
18
+ export { Regions } from "./constants/regions.js";
19
+ export { default as Dispatches } from "./dispatches/index.js";
20
+ export { iFetch } from "./env/fetch.js";
21
+ export { globals } from "./env/globals.js";
22
+ export * as WASM from "./wasm/direct.js";
23
+ import Bot from "./bot.js";
24
+ export default Bot;