yolkbot 0.1.0-alpha.50 → 0.1.0-alpha.52

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "yolkbot",
3
3
  "description": "create a shell shockers (self) bot in under 10 lines.",
4
- "version": "0.1.0-alpha.50",
4
+ "version": "0.1.0-alpha.52",
5
5
  "keywords": [
6
6
  "shell shockers",
7
7
  "shellshock.io",
package/src/api.js CHANGED
@@ -125,6 +125,58 @@ async function loginWithCredentials(email, password, prox = '', instance = 'shel
125
125
  return response;
126
126
  }
127
127
 
128
+ async function loginWithRefreshToken(refreshToken, prox = '', instance = 'shellshock.io') {
129
+ if (!refreshToken) return 'firebase_no_credentials';
130
+
131
+ const formData = new URLSearchParams();
132
+ formData.append('grant_type', 'refresh_token');
133
+ formData.append('refresh_token', refreshToken);
134
+
135
+ let SUCCESS = false;
136
+ let request, body, token;
137
+ let k = 0;
138
+
139
+ while (!SUCCESS) {
140
+ try {
141
+ request = await axios.post(`https://securetoken.googleapis.com/v1/token?key=${FirebaseKey}`, formData, {
142
+ headers: {
143
+ 'user-agent': UserAgent,
144
+ 'x-client-version': 'Chrome/JsCore/9.17.2/FirebaseCore-web'
145
+ },
146
+ httpsAgent: (!IsBrowser && prox) ? new SocksProxyAgent(prox) : false
147
+ })
148
+ body = request.data
149
+ token = body.id_token;
150
+ SUCCESS = true;
151
+ } catch (error) {
152
+ ++k;
153
+ if (error.code == 'auth/network-request-failed') {
154
+ console.error('loginWithRefreshToken: Network req failed (auth/network-request-failed), retrying, k =', k);
155
+ } else if (error.code == 'auth/missing-email') {
156
+ return 'firebase_no_credentials';
157
+ } else {
158
+ console.error('loginWithRefreshToken: Error:', refreshToken);
159
+ console.error('loginWithRefreshToken: Error:', error, 'k =', k);
160
+ }
161
+
162
+ if (k > 5) return 'firebase_too_many_retries';
163
+ else await new Promise((resolve) => setTimeout(resolve, 100));
164
+ }
165
+ }
166
+
167
+ if (!token) {
168
+ console.error('loginWithRefreshToken: the game sent no idToken', body);
169
+ return 'firebase_no_token';
170
+ }
171
+
172
+ const response = await queryServices({
173
+ cmd: 'auth',
174
+ firebaseToken: token
175
+ }, prox, instance);
176
+
177
+ return response;
178
+ }
179
+
128
180
  async function loginAnonymously(prox = '', instance = 'shellshock.io') {
129
181
  const { data: body } = await axios.post('https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=' + FirebaseKey, {
130
182
  returnSecureToken: true
@@ -155,5 +207,6 @@ export {
155
207
  createAccount,
156
208
  loginAnonymously,
157
209
  loginWithCredentials,
210
+ loginWithRefreshToken,
158
211
  queryServices
159
212
  }
package/src/bot.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createAccount, loginAnonymously, loginWithCredentials, queryServices } from '#api';
1
+ import { createAccount, loginAnonymously, loginWithCredentials, loginWithRefreshToken, queryServices } from '#api';
2
2
 
3
3
  import CommIn from './comm/CommIn.js';
4
4
  import CommOut from './comm/CommOut.js';
@@ -40,7 +40,8 @@ const intents = {
40
40
  PATHFINDING: 3,
41
41
  BUFFERS: 4,
42
42
  PING: 5,
43
- COSMETIC_DATA: 6
43
+ COSMETIC_DATA: 6,
44
+ PLAYER_HEALTH: 7
44
45
  }
45
46
 
46
47
  export class Bot {
@@ -256,6 +257,11 @@ export class Bot {
256
257
  return this.#processLoginData(loginData);
257
258
  }
258
259
 
260
+ async loginWithRefreshToken(refreshToken) {
261
+ const loginData = await loginWithRefreshToken(refreshToken, this.proxy, this.instance);
262
+ return this.#processLoginData(loginData);
263
+ }
264
+
259
265
  async loginAnonymously() {
260
266
  delete this.account.email;
261
267
  delete this.account.password;
@@ -659,23 +665,25 @@ export class Bot {
659
665
  if (!IsBrowser) {
660
666
  const { existsSync, mkdirSync, readFileSync, writeFileSync } = await import('node:fs');
661
667
  const { join } = await import('node:path');
668
+ const { homedir } = await import('node:os');
662
669
 
663
- if (existsSync(join(import.meta.dirname, '..', 'data', 'cache', 'maps', `${name}-${hash}.json`))) {
664
- return JSON.parse(readFileSync(join(import.meta.dirname, '..', 'data', 'cache', 'maps', `${name}-${hash}.json`), 'utf-8'));
665
- }
670
+ const yolkbotCache = join(homedir(), '.yolkbot');
671
+ const mapCache = join(yolkbotCache, 'maps');
672
+
673
+ if (!existsSync(yolkbotCache)) mkdirSync(yolkbotCache);
674
+ if (!existsSync(mapCache)) mkdirSync(mapCache);
666
675
 
667
- console.warn(`Map "${name}" not found in cache, fetching...`);
676
+ const mapFile = join(mapCache, `${name}-${hash}.json`);
677
+
678
+ if (existsSync(mapFile))
679
+ return JSON.parse(readFileSync(mapFile, 'utf-8'));
680
+
681
+ console.log('map not in cache, IMPORT!!', name, hash);
668
682
 
669
683
  const data = await (await fetch(`https://${this.instance}/maps/${name}.json?${hash}`)).json();
670
684
 
671
- const dir = join(import.meta.dirname, '..', 'data', 'cache', 'maps');
672
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
685
+ writeFileSync(mapFile, JSON.stringify(data, null, 4), { flag: 'w+' });
673
686
 
674
- writeFileSync(
675
- join(dir, `${name}-${hash}.json`),
676
- JSON.stringify(data, null, 4),
677
- { flag: 'w+' }
678
- );
679
687
  return data;
680
688
  } else {
681
689
  const data = await (await fetch(`https://${this.instance}/maps/${name}.json?${hash}`)).json();
@@ -811,7 +819,7 @@ export class Bot {
811
819
 
812
820
  const player = this.players[playerData.id_];
813
821
 
814
- if (player.playing) {
822
+ if (player.playing && this.intents.includes(this.Intents.PLAYER_HEALTH)) {
815
823
  player.healthInterval = setInterval(() => {
816
824
  if (player.hp < 1) return;
817
825
 
@@ -859,21 +867,22 @@ export class Bot {
859
867
  // console.log(`Player ${player.name} respawned at ${x}, ${y}, ${z}`);
860
868
  this.#emit('playerRespawn', player);
861
869
 
862
- if (player.healthInterval) {
863
- clearInterval(player.healthInterval);
864
- }
870
+ if (this.intents.includes(this.Intents.PLAYER_HEALTH)) {
871
+ if (player.healthInterval)
872
+ clearInterval(player.healthInterval);
865
873
 
866
- player.healthInterval = setInterval(() => {
867
- if (player.hp < 1) return;
874
+ player.healthInterval = setInterval(() => {
875
+ if (player.hp < 1) return;
868
876
 
869
- const regenSpeed = 0.1 * (this.game.isPrivate ? this.game.options[GameOptionFlags.healthRegen] : 1);
877
+ const regenSpeed = 0.1 * (this.game.isPrivate ? this.game.options[GameOptionFlags.healthRegen] : 1);
870
878
 
871
- if (player.streakRewards.includes(ShellStreaks.OverHeal)) {
872
- player.hp = Math.max(100, player.hp - regenSpeed);
873
- } else {
874
- player.hp = Math.min(100, player.hp + regenSpeed);
875
- }
876
- }, 33);
879
+ if (player.streakRewards.includes(ShellStreaks.OverHeal)) {
880
+ player.hp = Math.max(100, player.hp - regenSpeed);
881
+ } else {
882
+ player.hp = Math.min(100, player.hp + regenSpeed);
883
+ }
884
+ }, 33);
885
+ }
877
886
  } else {
878
887
  // console.log(`Player ${id} not found. (me: ${this.me.id}) (respawn)`);
879
888
  }
@@ -17,4 +17,5 @@ export interface QueryResponse {
17
17
 
18
18
  export function queryServices(request: QueryRequest, proxy?: string, instance?: string): Promise<QueryResponse | string>;
19
19
  export function loginWithCredentials(email: string, password: string, prox?: string, instance?: string): Promise<QueryResponse | string>;
20
+ export function loginWithRefreshToken(refreshToken: string, prox?: string, instance?: string): Promise<QueryResponse | string>;
20
21
  export function loginAnonymously(prox?: string, instance?: string): Promise<QueryResponse | string>;
@@ -174,6 +174,7 @@ export class Bot {
174
174
  constructor(params?: BotParams);
175
175
 
176
176
  loginAnonymously(): Promise<Account | false>;
177
+ loginWithRefreshToken(refreshToken: string): Promise<Account | false>;
177
178
  login(email: string, pass: string): Promise<Account | false>;
178
179
  createAccount(email: string, pass: string): Promise<Account | false>;
179
180