teeworlds 2.4.7 → 2.4.9

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
@@ -1,6 +1,7 @@
1
1
  # tw-chatonly
2
2
  Library to connect a bot to a Teeworlds server.
3
3
 
4
+ https://gitlab.com/swarfey/teeworlds-client/-/tree/main/
4
5
  https://www.npmjs.com/package/teeworlds
5
6
 
6
7
 
@@ -87,3 +88,7 @@ process.stdin.on("data", data => {
87
88
 
88
89
  })
89
90
  ```
91
+
92
+ # Documentation
93
+ You can find an documentation to what most components do in the [docs/documentation.md](https://gitlab.com/swarfey/teeworlds-client/-/blob/main/docs/documentation.md).
94
+ You can also find a few examples inside of the [docs/examples](https://gitlab.com/swarfey/teeworlds-client/-/tree/main/docs/examples) directory.
@@ -299,7 +299,7 @@ The movement component is accessable using `client.movement`.
299
299
  * RunRight()
300
300
  * makes the client run right
301
301
  * RunStop()
302
- * makes the client stop running (if he is)
302
+ * makes the client stop running (if he is)
303
303
  * Jump(state?: boolean)
304
304
  * makes the client Jump. if the parameter is false, the bot will stop holding jump.
305
305
  * Fire()
@@ -359,9 +359,10 @@ client.connect();
359
359
  ```
360
360
 
361
361
  # Examples
362
- there are some examples under docs/examples.
362
+ You can find some of the examples in the [docs/examples](docs/examples/) folder.
363
363
 
364
364
  # Projects using this library
365
365
  *Note:* If you have or know any projects running using this library, please contact me so i can add them, or PR them yourself.
366
366
 
367
- * A discord which is bridging all discord messages and ingame messages (currently closed source): https://discord.gg/MSYcjYvU6e
367
+ * A discord which is bridging all discord messages and ingame messages (currently closed source): https://discord.gg/MSYcjYvU6e
368
+
package/lib/client.js CHANGED
@@ -23,6 +23,7 @@ var crypto_1 = require("crypto");
23
23
  var dgram_1 = __importDefault(require("dgram"));
24
24
  var stream_1 = require("stream");
25
25
  var MsgUnpacker_1 = require("./MsgUnpacker");
26
+ var version = require('../package.json').version;
26
27
  var movement_1 = __importDefault(require("./components/movement"));
27
28
  var MsgPacker_1 = require("./MsgPacker");
28
29
  var snapshot_1 = require("./snapshot");
@@ -125,6 +126,8 @@ var NETMSG_Sys;
125
126
  NETMSG_Sys[NETMSG_Sys["NETMSG_CHECKSUM_REQUEST"] = 65545] = "NETMSG_CHECKSUM_REQUEST";
126
127
  NETMSG_Sys[NETMSG_Sys["NETMSG_CHECKSUM_RESPONSE"] = 65546] = "NETMSG_CHECKSUM_RESPONSE";
127
128
  NETMSG_Sys[NETMSG_Sys["NETMSG_CHECKSUM_ERROR"] = 65547] = "NETMSG_CHECKSUM_ERROR";
129
+ NETMSG_Sys[NETMSG_Sys["NETMSG_REDIRECT"] = 65548] = "NETMSG_REDIRECT";
130
+ NETMSG_Sys[NETMSG_Sys["NETMSG_I_AM_NPM_PACKAGE"] = 65549] = "NETMSG_I_AM_NPM_PACKAGE";
128
131
  })(NETMSG_Sys || (NETMSG_Sys = {}));
129
132
  var messageTypes = [
130
133
  ["none, starts at 1", "SV_MOTD", "SV_BROADCAST", "SV_CHAT", "SV_KILL_MSG", "SV_SOUND_GLOBAL", "SV_TUNE_PARAMS", "SV_EXTRA_PROJECTILE", "SV_READY_TO_ENTER", "SV_WEAPON_PICKUP", "SV_EMOTICON", "SV_VOTE_CLEAR_OPTIONS", "SV_VOTE_OPTION_LIST_ADD", "SV_VOTE_OPTION_ADD", "SV_VOTE_OPTION_REMOVE", "SV_VOTE_SET", "SV_VOTE_STATUS", "CL_SAY", "CL_SET_TEAM", "CL_SET_SPECTATOR_MODE", "CL_START_INFO", "CL_CHANGE_INFO", "CL_KILL", "CL_EMOTICON", "CL_VOTE", "CL_CALL_VOTE", "CL_IS_DDNET", "SV_DDRACE_TIME", "SV_RECORD", "UNUSED", "SV_TEAMS_STATE", "CL_SHOW_OTHERS_LEGACY"],
@@ -165,6 +168,7 @@ var Client = /** @class */ (function (_super) {
165
168
  _this.game = new game_1.Game(_this);
166
169
  _this.SnapshotUnpacker = new snapshot_2.SnapshotWrapper(_this);
167
170
  _this.UUIDManager = new UUIDManager_1.UUIDManager();
171
+ _this.UUIDManager.RegisterName("i-dont-know@ddnet.tw", NETMSG_Sys.NETMSG_IDONTKNOW);
168
172
  _this.UUIDManager.RegisterName("what-is@ddnet.tw", NETMSG_Sys.NETMSG_WHATIS);
169
173
  _this.UUIDManager.RegisterName("it-is@ddnet.tw", NETMSG_Sys.NETMSG_ITIS);
170
174
  _this.UUIDManager.RegisterName("i-dont-know@ddnet.tw", NETMSG_Sys.NETMSG_IDONTKNOW);
@@ -177,6 +181,8 @@ var Client = /** @class */ (function (_super) {
177
181
  _this.UUIDManager.RegisterName("checksum-request@ddnet.tw", NETMSG_Sys.NETMSG_CHECKSUM_REQUEST);
178
182
  _this.UUIDManager.RegisterName("checksum-response@ddnet.tw", NETMSG_Sys.NETMSG_CHECKSUM_RESPONSE);
179
183
  _this.UUIDManager.RegisterName("checksum-error@ddnet.tw", NETMSG_Sys.NETMSG_CHECKSUM_ERROR);
184
+ _this.UUIDManager.RegisterName("redirect@ddnet.org", NETMSG_Sys.NETMSG_REDIRECT);
185
+ _this.UUIDManager.RegisterName("i-am-npm-package@swarfey.gitlab.io", NETMSG_Sys.NETMSG_I_AM_NPM_PACKAGE);
180
186
  return _this;
181
187
  }
182
188
  Client.prototype.ResendAfter = function (lastAck) {
@@ -428,13 +434,16 @@ var Client = /** @class */ (function (_super) {
428
434
  client_version.AddBuffer(randomUuid);
429
435
  if (((_d = _this.options) === null || _d === void 0 ? void 0 : _d.ddnet_version) !== undefined) {
430
436
  client_version.AddInt((_e = _this.options) === null || _e === void 0 ? void 0 : _e.ddnet_version.version);
431
- client_version.AddString("DDNet " + ((_f = _this.options) === null || _f === void 0 ? void 0 : _f.ddnet_version.release_version));
437
+ client_version.AddString("DDNet ".concat((_f = _this.options) === null || _f === void 0 ? void 0 : _f.ddnet_version.release_version, "; https://www.npmjs.com/package/teeworlds/v/").concat(version));
432
438
  }
433
439
  else {
434
440
  client_version.AddInt(16050);
435
- client_version.AddString("DDNet 16.5.0");
441
+ client_version.AddString("DDNet 16.5.0; https://www.npmjs.com/package/teeworlds/v/".concat(version));
436
442
  }
437
- _this.SendMsgEx([client_version, info]);
443
+ var i_am_npm_package = new MsgPacker_1.MsgPacker(0, true, 1);
444
+ i_am_npm_package.AddBuffer(_this.UUIDManager.LookupType(NETMSG_Sys.NETMSG_I_AM_NPM_PACKAGE).hash);
445
+ i_am_npm_package.AddString("https://www.npmjs.com/package/teeworlds/v/".concat(version));
446
+ _this.SendMsgEx([client_version, info, i_am_npm_package]);
438
447
  }
439
448
  else if (packet[3] == 0x4) {
440
449
  // disconnected
package/lib/client.ts CHANGED
@@ -4,6 +4,7 @@ import net from 'dgram';
4
4
  import { EventEmitter } from 'stream';
5
5
 
6
6
  import { unpackString, MsgUnpacker } from "./MsgUnpacker";
7
+ let { version } = require('../package.json');
7
8
 
8
9
  import Movement from './components/movement';
9
10
  import { PlayerInput, PlayerInfo, Projectile, Laser, Pickup, Flag, GameInfo, GameData, CharacterCore, Character, ClientInfo, SpectatorInfo, Common, Explosion, Spawn, HammerHit, Death, SoundGlobal, SoundWorld, DamageInd } from "./snapshots";
@@ -121,7 +122,11 @@ enum NETMSG_Sys {
121
122
  NETMSG_PONGEX,
122
123
  NETMSG_CHECKSUM_REQUEST,
123
124
  NETMSG_CHECKSUM_RESPONSE,
124
- NETMSG_CHECKSUM_ERROR
125
+ NETMSG_CHECKSUM_ERROR,
126
+
127
+ NETMSG_REDIRECT,
128
+
129
+ NETMSG_I_AM_NPM_PACKAGE
125
130
 
126
131
  }
127
132
 
@@ -290,7 +295,7 @@ export class Client extends EventEmitter {
290
295
 
291
296
  this.UUIDManager = new UUIDManager();
292
297
 
293
-
298
+ this.UUIDManager.RegisterName("i-dont-know@ddnet.tw", NETMSG_Sys.NETMSG_IDONTKNOW);
294
299
  this.UUIDManager.RegisterName("what-is@ddnet.tw", NETMSG_Sys.NETMSG_WHATIS);
295
300
  this.UUIDManager.RegisterName("it-is@ddnet.tw", NETMSG_Sys.NETMSG_ITIS);
296
301
  this.UUIDManager.RegisterName("i-dont-know@ddnet.tw", NETMSG_Sys.NETMSG_IDONTKNOW);
@@ -304,6 +309,9 @@ export class Client extends EventEmitter {
304
309
  this.UUIDManager.RegisterName("checksum-request@ddnet.tw", NETMSG_Sys.NETMSG_CHECKSUM_REQUEST);
305
310
  this.UUIDManager.RegisterName("checksum-response@ddnet.tw", NETMSG_Sys.NETMSG_CHECKSUM_RESPONSE);
306
311
  this.UUIDManager.RegisterName("checksum-error@ddnet.tw", NETMSG_Sys.NETMSG_CHECKSUM_ERROR);
312
+ this.UUIDManager.RegisterName("redirect@ddnet.org", NETMSG_Sys.NETMSG_REDIRECT);
313
+
314
+ this.UUIDManager.RegisterName("i-am-npm-package@swarfey.gitlab.io", NETMSG_Sys.NETMSG_I_AM_NPM_PACKAGE);
307
315
 
308
316
  }
309
317
 
@@ -581,13 +589,19 @@ export class Client extends EventEmitter {
581
589
  client_version.AddBuffer(randomUuid);
582
590
  if (this.options?.ddnet_version !== undefined) {
583
591
  client_version.AddInt(this.options?.ddnet_version.version);
584
- client_version.AddString("DDNet " + this.options?.ddnet_version.release_version);
592
+ client_version.AddString(`DDNet ${this.options?.ddnet_version.release_version}; https://www.npmjs.com/package/teeworlds/v/${version}`);
585
593
  } else {
586
594
  client_version.AddInt(16050);
587
- client_version.AddString("DDNet 16.5.0");
595
+ client_version.AddString(`DDNet 16.5.0; https://www.npmjs.com/package/teeworlds/v/${version}`);
588
596
  }
589
597
 
590
- this.SendMsgEx([client_version, info])
598
+ var i_am_npm_package = new MsgPacker(0, true, 1);
599
+ i_am_npm_package.AddBuffer(this.UUIDManager.LookupType(NETMSG_Sys.NETMSG_I_AM_NPM_PACKAGE)!.hash);
600
+
601
+ i_am_npm_package.AddString(`https://www.npmjs.com/package/teeworlds/v/${version}`);
602
+
603
+
604
+ this.SendMsgEx([client_version, info, i_am_npm_package])
591
605
  } else if (packet[3] == 0x4) {
592
606
  // disconnected
593
607
  this.State = States.STATE_OFFLINE;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teeworlds",
3
- "version": "2.4.7",
3
+ "version": "2.4.9",
4
4
  "description": "Library for (ingame) teeworlds bots.",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
package/test.js DELETED
@@ -1,57 +0,0 @@
1
- let crypto = require('crypto');
2
- let list = {
3
- "WHAT_IS": Buffer.from([0x24, 0x5e, 0x50, 0x97, 0x9f, 0xe0, 0x39, 0xd6, 0xbf, 0x7d, 0x9a, 0x29, 0xe1, 0x69, 0x1e, 0x4c]),
4
- "IT_IS": Buffer.from([0x69, 0x54, 0x84, 0x7e, 0x2e, 0x87, 0x36, 0x03, 0xb5, 0x62, 0x36, 0xda, 0x29, 0xed, 0x1a, 0xca]),
5
- "I_DONT_KNOW": Buffer.from([0x41, 0x69, 0x11, 0xb5, 0x79, 0x73, 0x33, 0xbf, 0x8d, 0x52, 0x7b, 0xf0, 0x1e, 0x51, 0x9c, 0xf0]),
6
- "RCON_TYPE": Buffer.from([0x12, 0x81, 0x0e, 0x1f, 0xa1, 0xdb, 0x33, 0x78, 0xb4, 0xfb, 0x16, 0x4e, 0xd6, 0x50, 0x59, 0x26]),
7
- "MAP_DETAILS": Buffer.from([0xf9, 0x11, 0x7b, 0x3c, 0x80, 0x39, 0x34, 0x16, 0x9f, 0xc0, 0xae, 0xf2, 0xbc, 0xb7, 0x5c, 0x03]),
8
- "CAPABILITIES": Buffer.from([0xf6, 0x21, 0xa5, 0xa1, 0xf5, 0x85, 0x37, 0x75, 0x8e, 0x73, 0x41, 0xbe, 0xee, 0x79, 0xf2, 0xb2]),
9
- "CLIENT_VERSION": Buffer.from([0x8c, 0x00, 0x13, 0x04, 0x84, 0x61, 0x3e, 0x47, 0x87, 0x87, 0xf6, 0x72, 0xb3, 0x83, 0x5b, 0xd4]),
10
- // "PING_EX": Buffer.from([]),
11
- // "PONG_EX": Buffer.from([]),
12
- // "CHECKSUM_REQUEST": Buffer.from([]),
13
- // "CHECKSUM_RESPONSE": Buffer.from([]),
14
- // "CHECKSUM_ERROR": Buffer.from([])
15
- }
16
- let newList = {
17
- "what_is": ("what-is@ddnet.tw"),
18
- "it_is": ("it-is@ddnet.tw"),
19
- "i_dont_know": ("i-dont-know@ddnet.tw"),
20
- "rcon_type": ("rcon-type@ddnet.tw"),
21
- "map_details": ("map-details@ddnet.tw"),
22
- "capabilities": ("capabilities@ddnet.tw"),
23
- "client_version": ("clientver@ddnet.tw"),
24
- "ping": ("ping@ddnet.tw"),
25
- "pong": ("pong@ddnet.tw"),
26
- "checksum_request": ("checksum-request@ddnet.tw"),
27
- "checksum_response": ("checksum-response@ddnet.tw"),
28
- "checksum_error": ("checksum-error@ddnet.tw")
29
- }
30
-
31
- const createTwMD5Hash = (name) => { // https://github.com/ddnet/ddnet/blob/6d9284adc1e0be4b5348447d857eae575e06e654/src/engine/shared/uuid_manager.cpp#L26
32
- let hash = crypto.createHash("md5")
33
- .update(Buffer.from([0xe0, 0x5d, 0xda, 0xaa, 0xc4, 0xe6, 0x4c, 0xfb, 0xb6, 0x42, 0x5d, 0x48, 0xe8, 0x0c, 0x00, 0x29]))
34
- .update(name)
35
- .digest()
36
- hash[6] &= 0x0f;
37
- hash[6] |= 0x30;
38
- hash[8] &= 0x3f;
39
- hash[8] |= 0x80;
40
- return hash;
41
- }
42
-
43
- Object.keys(newList).forEach(name => {
44
- let el = newList[name];
45
- let el_old = list[name.toUpperCase()];
46
- if (el_old == undefined)
47
- return;
48
- // let hash = crypto.createHash("md5")
49
- // .update(Buffer.from([0xe0, 0x5d, 0xda, 0xaa, 0xc4, 0xe6, 0x4c, 0xfb, 0xb6, 0x42, 0x5d, 0x48, 0xe8, 0x0c, 0x00, 0x29]))
50
- // .update(name).digest()
51
-
52
- let hash = createTwMD5Hash(el);
53
- console.log(hash.compare(el_old), name)
54
- if (hash.compare(el_old) !== 0)
55
- console.log(name, hash, el_old)
56
- // it_is <Buffer 69 54 84 7e 2e 87 c6 03 75 62 36 da 29 ed 1a ca> <Buffer 69 54 84 7e 2e 87 36 03 b5 62 36 da 29 ed 1a ca>
57
- });