ddbot.js-0374 4.3.1 → 4.4.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.
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();
@@ -5,6 +5,8 @@ interface BotEvents {
5
5
  error: (...args: any[]) => void;
6
6
  connect: (info: Types.ConnectionInfo) => void;
7
7
  disconnect: (reason: string | null, info: Types.ConnectionInfo) => void;
8
+ rawconnect: (info: Types.ConnectionInfo) => void;
9
+ rawdisconnect: (reason: string, info: Types.ConnectionInfo) => void;
8
10
  broadcast: (message: string) => void;
9
11
  capabilities: (message: {
10
12
  ChatTimeoutCode: boolean;
package/lib/core/core.js CHANGED
@@ -229,17 +229,28 @@ class Bot extends events_1.EventEmitter {
229
229
  return;
230
230
  // Connection events
231
231
  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();
232
+ if (this.status.connect.connected) {
233
+ this.error('connection received when already connected');
234
+ }
235
+ else {
236
+ this.status.connect.connected = true;
237
+ this.emit('connect', { addr: this.status.addr, port: this.status.port });
238
+ this.setup_snapshot_events();
239
+ }
235
240
  });
236
- this.client.on('disconnect', (reason = null) => {
241
+ this.client.on('disconnect', (reason) => {
237
242
  this.status.connect.connected = false;
238
243
  this.clean(true);
239
244
  if (!!reason) {
240
245
  this.emit('disconnect', reason, { addr: this.status.addr, port: this.status.port });
241
246
  }
242
247
  });
248
+ this.client.on('connected', () => {
249
+ this.emit('rawconnect', { addr: this.status.addr, port: this.status.port });
250
+ });
251
+ this.client.on('disconnect', (reason) => {
252
+ this.emit('rawdisconnect', reason, { addr: this.status.addr, port: this.status.port });
253
+ });
243
254
  // Game events
244
255
  this.client.on('broadcast', (msg) => this.emit('broadcast', msg));
245
256
  this.client.on('capabilities', (msg) => this.emit('capabilities', msg));
@@ -283,8 +294,6 @@ class Bot extends events_1.EventEmitter {
283
294
  * Get proxied client instance for safe access
284
295
  */
285
296
  get bot_client() {
286
- if (!this.client)
287
- return null;
288
297
  if (!this._clientProxy) {
289
298
  const self = this;
290
299
  this._clientProxy = new Proxy({}, {
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.0",
7
7
  "description": "ddbot.js — это Node.js проект для автоматизации и управления ботами.",
8
8
  "main": "./lib/index.js",
9
9
  "scripts": {