yolkbot 0.1.1-alpha.35 → 0.1.1-alpha.37

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.1-alpha.35",
4
+ "version": "0.1.1-alpha.37",
5
5
  "keywords": [
6
6
  "shell shockers",
7
7
  "shellshock.io",
package/src/api.js CHANGED
@@ -13,6 +13,11 @@ const queryServices = async (request, proxy = '', instance = 'shellshock.io') =>
13
13
  const attempt = async () => {
14
14
  try {
15
15
  ws = new yolkws(`wss://${instance}/services/`, proxy);
16
+ ws.onerror = async (e) => {
17
+ console.error(e);
18
+ await new Promise((resolve) => setTimeout(resolve, 100));
19
+ return await attempt();
20
+ }
16
21
  } catch {
17
22
  await new Promise((resolve) => setTimeout(resolve, 100));
18
23
  await attempt();
@@ -23,7 +28,7 @@ const queryServices = async (request, proxy = '', instance = 'shellshock.io') =>
23
28
 
24
29
  return new Promise((resolve) => {
25
30
  ws.onopen = () => {
26
- // console.log('opened')
31
+ ws.onerror = null;
27
32
  ws.send(JSON.stringify(request));
28
33
  }
29
34
 
package/src/bot.js CHANGED
@@ -548,6 +548,11 @@ export class Bot {
548
548
  const attempt = async () => {
549
549
  try {
550
550
  this.game.socket = new yolkws(`wss://${this.game.raw.subdomain}.${this.instance}/game/${this.game.raw.id}`, this.proxy);
551
+ this.game.socket.onerror = async (e) => {
552
+ console.error(e);
553
+ await new Promise((resolve) => setTimeout(resolve, 100));
554
+ return await attempt();
555
+ }
551
556
  } catch {
552
557
  await new Promise((resolve) => setTimeout(resolve, 100));
553
558
  await attempt();
@@ -559,7 +564,7 @@ export class Bot {
559
564
  this.game.socket.binaryType = 'arraybuffer';
560
565
 
561
566
  this.game.socket.onopen = () => {
562
- // console.log('Successfully connected to game server.');
567
+ this.game.socket.onerror = null;
563
568
  }
564
569
 
565
570
  this.game.socket.onmessage = this.#onGameMesssage.bind(this);
package/src/matchmaker.js CHANGED
@@ -10,11 +10,11 @@ export class Matchmaker {
10
10
  proxy = null;
11
11
  sessionId = '';
12
12
 
13
- forceClose = false;
14
-
15
13
  onListeners = new Map();
16
14
  onceListeners = new Map();
17
15
 
16
+ #forceClose = false;
17
+
18
18
  // sessionId: string, a custom session id
19
19
  // proxy: a socks5 proxy string
20
20
  // instance: a custom game instance
@@ -34,6 +34,11 @@ export class Matchmaker {
34
34
  const attempt = async () => {
35
35
  try {
36
36
  this.ws = new yolkws(`wss://${instance}/matchmaker/`, this.proxy);
37
+ this.ws.onerror = async (e) => {
38
+ console.error(e);
39
+ await new Promise((resolve) => setTimeout(resolve, 100));
40
+ return await attempt();
41
+ }
37
42
  } catch {
38
43
  await new Promise((resolve) => setTimeout(resolve, 100));
39
44
  await attempt();
@@ -44,6 +49,8 @@ export class Matchmaker {
44
49
 
45
50
  this.ws.onopen = () => {
46
51
  this.connected = true;
52
+ this.ws.onerror = null;
53
+
47
54
  if (this.sessionId) {
48
55
  this.onceConnected.forEach(func => func());
49
56
  }
@@ -55,7 +62,7 @@ export class Matchmaker {
55
62
  }
56
63
 
57
64
  this.ws.onclose = () => {
58
- if (this.forceClose) return;
65
+ if (this.#forceClose) return;
59
66
 
60
67
  this.connected = false;
61
68
  this.#createSocket(instance);
@@ -159,7 +166,7 @@ export class Matchmaker {
159
166
  }
160
167
 
161
168
  close() {
162
- this.forceClose = true;
169
+ this.#forceClose = true;
163
170
  this.ws.close();
164
171
  }
165
172
 
@@ -40,20 +40,26 @@ type CommandSend = {
40
40
  export declare class Matchmaker {
41
41
  connected: boolean;
42
42
  onceConnected: Function[];
43
+
43
44
  proxy: string | null;
44
45
  sessionId: string;
45
- forceClose: boolean;
46
46
  onListeners: Map<string, Function[]>;
47
47
  onceListeners: Map<string, Function[]>;
48
48
 
49
+ regionList: Region[] | null;
50
+ ws: yolkws;
51
+
49
52
  constructor(params?: MatchmakerParams);
50
53
 
51
54
  send(msg: CommandSend): void;
52
- waitForConnect(): Promise<void>;
55
+
53
56
  getRegions(): Promise<Region[]>;
54
57
  findPublicGame(params: FindGameParams): Promise<RawGameData>;
58
+
55
59
  getRandomRegion(): string;
56
60
  getRandomGameMode(): keyof typeof GameModes;
61
+
62
+ waitForConnect(): Promise<void>;
57
63
  close(): void;
58
64
 
59
65
  on(event: string, callback: Function): void;