ddbot.js-0374 4.3.1 → 4.4.1

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/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  npm i ddbot.js-0374
12
12
  ```
13
13
 
14
- експорт
14
+ импорт
15
15
  ```ts
16
16
  import * as ddbot from 'ddbot.js-0374';
17
17
  ```
@@ -250,9 +250,5 @@ myModule.start();
250
250
 
251
251
  **DDUtils.DefaultIdentity(name?)** - возвращает дефолтный identity `Identity`, если имени нет, то 'nameless tee'
252
252
 
253
- **DDUtils.connectionInfo()** - возвращает дефолтный `ConnectionInfo`,
254
- 'ConnectionInfo = {
255
- addr: 'string', port: 8303
256
- }'
257
253
 
258
254
  **DDUtils.reconstructPlayerInput(char, ddnetChar?, tick?)** - реконструирует инпут игрока из snapshot. NOT FULL. `Types.SnapshotItemTypes.PlayerInput`
@@ -7,12 +7,12 @@ bot.on('connect', () => {
7
7
  console.log('Connected to server!');
8
8
  });
9
9
 
10
- bot.on('disconnect', () => {
11
- console.log('Disconnected from server!');
10
+ bot.on('disconnect', (reason) => {
11
+ console.log('Disconnected from server!', reason);
12
12
  });
13
13
 
14
14
  (async () => {
15
- await bot.connect('45.141.57.22', 8303, 20000); // IP, port, timeout (IP is of ddnet server)
15
+ await bot.connect('26.230.124.233', 8303, 20000); // IP, port, timeout (IP is of ddnet server)
16
16
  bot.bot_client?.game.Say('DDNet!'); // from teeworlds
17
17
  setTimeout(async () => {
18
18
  await bot.disconnect();
@@ -3,8 +3,11 @@ import { EventEmitter } from 'events';
3
3
  import * as Types from '../types.js';
4
4
  interface BotEvents {
5
5
  error: (...args: any[]) => void;
6
+ destroy: () => void;
6
7
  connect: (info: Types.ConnectionInfo) => void;
7
8
  disconnect: (reason: string | null, info: Types.ConnectionInfo) => void;
9
+ rawconnect: (info: Types.ConnectionInfo) => void;
10
+ rawdisconnect: (reason: string, info: Types.ConnectionInfo) => void;
8
11
  broadcast: (message: string) => void;
9
12
  capabilities: (message: {
10
13
  ChatTimeoutCode: boolean;
package/lib/core/core.js CHANGED
@@ -36,17 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.Bot = void 0;
37
37
  const Teeworlds = __importStar(require("teeworlds"));
38
38
  const events_1 = require("events");
39
- function DefaultIdentity(name = 'nameless tee') {
40
- return {
41
- name: name,
42
- clan: "",
43
- skin: "default",
44
- use_custom_color: 0,
45
- color_body: 0,
46
- color_feet: 0,
47
- country: 0
48
- };
49
- }
39
+ const ddutils_js_1 = require("../ddutils.js");
50
40
  class Bot extends events_1.EventEmitter {
51
41
  teeworlds;
52
42
  client = null;
@@ -71,7 +61,7 @@ class Bot extends events_1.EventEmitter {
71
61
  super();
72
62
  this.teeworlds = CustomTeeworlds;
73
63
  this.options = options;
74
- this.identity = identity ? identity : DefaultIdentity('nameless tee');
64
+ this.identity = identity ? identity : (0, ddutils_js_1.DefaultIdentity)('nameless tee');
75
65
  }
76
66
  error(...err) {
77
67
  //console.error(err);
@@ -206,7 +196,7 @@ class Bot extends events_1.EventEmitter {
206
196
  this.identity =
207
197
  typeof identity === 'object' && identity !== null
208
198
  ? { ...this.identity, ...identity }
209
- : DefaultIdentity(this.identity.name);
199
+ : (0, ddutils_js_1.DefaultIdentity)(this.identity.name);
210
200
  if (this.client && this.status.connect.connected) {
211
201
  this.client.game.ChangePlayerInfo(this.identity);
212
202
  }
@@ -229,17 +219,28 @@ class Bot extends events_1.EventEmitter {
229
219
  return;
230
220
  // Connection events
231
221
  this.client.on('connected', () => {
232
- this.status.connect.connected = true;
233
- this.emit('connect', { addr: this.status.addr, port: this.status.port });
234
- this.setup_snapshot_events();
222
+ if (this.status.connect.connected) {
223
+ this.error('connection received when already connected');
224
+ }
225
+ else {
226
+ this.status.connect.connected = true;
227
+ this.emit('connect', { addr: this.status.addr, port: this.status.port });
228
+ this.setup_snapshot_events();
229
+ }
235
230
  });
236
- this.client.on('disconnect', (reason = null) => {
231
+ this.client.on('disconnect', (reason) => {
237
232
  this.status.connect.connected = false;
238
233
  this.clean(true);
239
234
  if (!!reason) {
240
235
  this.emit('disconnect', reason, { addr: this.status.addr, port: this.status.port });
241
236
  }
242
237
  });
238
+ this.client.on('connected', () => {
239
+ this.emit('rawconnect', { addr: this.status.addr, port: this.status.port });
240
+ });
241
+ this.client.on('disconnect', (reason) => {
242
+ this.emit('rawdisconnect', reason, { addr: this.status.addr, port: this.status.port });
243
+ });
243
244
  // Game events
244
245
  this.client.on('broadcast', (msg) => this.emit('broadcast', msg));
245
246
  this.client.on('capabilities', (msg) => this.emit('capabilities', msg));
@@ -283,8 +284,6 @@ class Bot extends events_1.EventEmitter {
283
284
  * Get proxied client instance for safe access
284
285
  */
285
286
  get bot_client() {
286
- if (!this.client)
287
- return null;
288
287
  if (!this._clientProxy) {
289
288
  const self = this;
290
289
  this._clientProxy = new Proxy({}, {
@@ -311,6 +310,7 @@ class Bot extends events_1.EventEmitter {
311
310
  await this.disconnect();
312
311
  this.removeAllListeners();
313
312
  this._clientProxy = null;
313
+ this.emit('destroy');
314
314
  }
315
315
  on(event, listener) {
316
316
  return super.on(event, listener);
@@ -18,6 +18,7 @@ class BaseModule extends events_1.EventEmitter {
18
18
  if (options.offonDisconnect !== false) {
19
19
  this.bot.on('disconnect', this._onDisconnect);
20
20
  }
21
+ this.bot.on('destroy', () => this.destroy());
21
22
  }
22
23
  /**
23
24
  * Запускает модуль, если он ещё не запущен
package/lib/ddutils.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type * as Types from './types.js';
2
2
  export declare function DefaultIdentity(name?: string): Types.SnapshotItemTypes.Identity;
3
- export declare function connectionInfo(): Types.ConnectionInfo;
4
3
  /**
5
4
  * NOT FULL. baze.
6
5
  */
package/lib/ddutils.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultIdentity = DefaultIdentity;
4
- exports.connectionInfo = connectionInfo;
5
4
  exports.reconstructPlayerInput = reconstructPlayerInput;
6
5
  function DefaultIdentity(name = 'nameless tee') {
7
6
  return {
@@ -14,12 +13,6 @@ function DefaultIdentity(name = 'nameless tee') {
14
13
  country: 0
15
14
  };
16
15
  }
17
- function connectionInfo() {
18
- return {
19
- addr: 'string',
20
- port: 8303
21
- };
22
- }
23
16
  /**
24
17
  * NOT FULL. baze.
25
18
  */
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "teeworlds": "^2.5.11"
4
4
  },
5
5
  "name": "ddbot.js-0374",
6
- "version": "4.3.1",
6
+ "version": "4.4.1",
7
7
  "description": "ddbot.js — это Node.js проект для автоматизации и управления ботами.",
8
8
  "main": "./lib/index.js",
9
9
  "scripts": {