teeworlds 2.3.9 → 2.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.
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Game = void 0;
4
+ var MsgPacker_1 = require("../MsgPacker");
5
+ var NETMSGTYPE;
6
+ (function (NETMSGTYPE) {
7
+ NETMSGTYPE[NETMSGTYPE["EX"] = 0] = "EX";
8
+ NETMSGTYPE[NETMSGTYPE["SV_MOTD"] = 1] = "SV_MOTD";
9
+ NETMSGTYPE[NETMSGTYPE["SV_BROADCAST"] = 2] = "SV_BROADCAST";
10
+ NETMSGTYPE[NETMSGTYPE["SV_CHAT"] = 3] = "SV_CHAT";
11
+ NETMSGTYPE[NETMSGTYPE["SV_KILLMSG"] = 4] = "SV_KILLMSG";
12
+ NETMSGTYPE[NETMSGTYPE["SV_SOUNDGLOBAL"] = 5] = "SV_SOUNDGLOBAL";
13
+ NETMSGTYPE[NETMSGTYPE["SV_TUNEPARAMS"] = 6] = "SV_TUNEPARAMS";
14
+ NETMSGTYPE[NETMSGTYPE["SV_EXTRAPROJECTILE"] = 7] = "SV_EXTRAPROJECTILE";
15
+ NETMSGTYPE[NETMSGTYPE["SV_READYTOENTER"] = 8] = "SV_READYTOENTER";
16
+ NETMSGTYPE[NETMSGTYPE["SV_WEAPONPICKUP"] = 9] = "SV_WEAPONPICKUP";
17
+ NETMSGTYPE[NETMSGTYPE["SV_EMOTICON"] = 10] = "SV_EMOTICON";
18
+ NETMSGTYPE[NETMSGTYPE["SV_VOTECLEAROPTIONS"] = 11] = "SV_VOTECLEAROPTIONS";
19
+ NETMSGTYPE[NETMSGTYPE["SV_VOTEOPTIONLISTADD"] = 12] = "SV_VOTEOPTIONLISTADD";
20
+ NETMSGTYPE[NETMSGTYPE["SV_VOTEOPTIONADD"] = 13] = "SV_VOTEOPTIONADD";
21
+ NETMSGTYPE[NETMSGTYPE["SV_VOTEOPTIONREMOVE"] = 14] = "SV_VOTEOPTIONREMOVE";
22
+ NETMSGTYPE[NETMSGTYPE["SV_VOTESET"] = 15] = "SV_VOTESET";
23
+ NETMSGTYPE[NETMSGTYPE["SV_VOTESTATUS"] = 16] = "SV_VOTESTATUS";
24
+ NETMSGTYPE[NETMSGTYPE["CL_SAY"] = 17] = "CL_SAY";
25
+ NETMSGTYPE[NETMSGTYPE["CL_SETTEAM"] = 18] = "CL_SETTEAM";
26
+ NETMSGTYPE[NETMSGTYPE["CL_SETSPECTATORMODE"] = 19] = "CL_SETSPECTATORMODE";
27
+ NETMSGTYPE[NETMSGTYPE["CL_STARTINFO"] = 20] = "CL_STARTINFO";
28
+ NETMSGTYPE[NETMSGTYPE["CL_CHANGEINFO"] = 21] = "CL_CHANGEINFO";
29
+ NETMSGTYPE[NETMSGTYPE["CL_KILL"] = 22] = "CL_KILL";
30
+ NETMSGTYPE[NETMSGTYPE["CL_EMOTICON"] = 23] = "CL_EMOTICON";
31
+ NETMSGTYPE[NETMSGTYPE["CL_VOTE"] = 24] = "CL_VOTE";
32
+ NETMSGTYPE[NETMSGTYPE["CL_CALLVOTE"] = 25] = "CL_CALLVOTE";
33
+ NETMSGTYPE[NETMSGTYPE["CL_ISDDNETLEGACY"] = 26] = "CL_ISDDNETLEGACY";
34
+ NETMSGTYPE[NETMSGTYPE["SV_DDRACETIMELEGACY"] = 27] = "SV_DDRACETIMELEGACY";
35
+ NETMSGTYPE[NETMSGTYPE["SV_RECORDLEGACY"] = 28] = "SV_RECORDLEGACY";
36
+ NETMSGTYPE[NETMSGTYPE["UNUSED"] = 29] = "UNUSED";
37
+ NETMSGTYPE[NETMSGTYPE["SV_TEAMSSTATELEGACY"] = 30] = "SV_TEAMSSTATELEGACY";
38
+ NETMSGTYPE[NETMSGTYPE["CL_SHOWOTHERSLEGACY"] = 31] = "CL_SHOWOTHERSLEGACY";
39
+ NETMSGTYPE[NETMSGTYPE["NUM"] = 32] = "NUM";
40
+ })(NETMSGTYPE || (NETMSGTYPE = {}));
41
+ ;
42
+ var Game = /** @class */ (function () {
43
+ function Game(_client) {
44
+ // this.SendMsgEx = callback;
45
+ this._client = _client;
46
+ this._ping_resolve = function () { };
47
+ }
48
+ Game.prototype.send = function (packer) {
49
+ var _a;
50
+ if (!((_a = this._client.options) === null || _a === void 0 ? void 0 : _a.lightweight))
51
+ this._client.QueueChunkEx(packer);
52
+ else
53
+ this._client.SendMsgEx(packer);
54
+ };
55
+ Game.prototype.Say = function (message, team) {
56
+ if (team === void 0) { team = false; }
57
+ var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SAY, false, 1);
58
+ packer.AddInt(team ? 1 : 0); // team
59
+ packer.AddString(message);
60
+ this.send(packer);
61
+ };
62
+ /* Set the team of an bot. (-1 spectator team, 0 team red/normal team, 1 team blue) */
63
+ Game.prototype.SetTeam = function (team) {
64
+ var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SETTEAM, false, 1);
65
+ packer.AddInt(team);
66
+ this.send(packer);
67
+ };
68
+ /* Spectate an player, taking their id as parameter. pretty useless */
69
+ Game.prototype.SpectatorMode = function (SpectatorID) {
70
+ var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SETSPECTATORMODE, false, 1);
71
+ packer.AddInt(SpectatorID);
72
+ this.send(packer);
73
+ };
74
+ /* Change the player info */
75
+ Game.prototype.ChangePlayerInfo = function (playerInfo) {
76
+ var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_CHANGEINFO, false, 1);
77
+ packer.AddString(playerInfo.name);
78
+ packer.AddString(playerInfo.clan);
79
+ packer.AddInt(playerInfo.country);
80
+ packer.AddString(playerInfo.skin);
81
+ packer.AddInt(playerInfo.use_custom_color ? 1 : 0);
82
+ packer.AddInt(playerInfo.color_body);
83
+ packer.AddInt(playerInfo.color_feet);
84
+ this.send(packer);
85
+ };
86
+ /* Kill */
87
+ Game.prototype.Kill = function () {
88
+ var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_KILL, false, 1);
89
+ this.send(packer);
90
+ };
91
+ /* Send emote */
92
+ Game.prototype.Emote = function (emote) {
93
+ var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_EMOTICON, false, 1);
94
+ packer.AddInt(emote);
95
+ this.send(packer);
96
+ };
97
+ /* Vote for an already running vote (f3 / f4) */
98
+ Game.prototype.Vote = function (vote) {
99
+ var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_VOTE, false, 1);
100
+ packer.AddInt(vote ? 1 : -1);
101
+ this.send(packer);
102
+ };
103
+ Game.prototype.CallVote = function (Type, Value, Reason) {
104
+ var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_CALLVOTE, false, 1);
105
+ packer.AddString(Type);
106
+ packer.AddString(String(Value));
107
+ packer.AddString(Reason);
108
+ this.send(packer);
109
+ };
110
+ /* Call a vote for an server option (for example ddnet maps) */
111
+ Game.prototype.CallVoteOption = function (Value, Reason) {
112
+ this.CallVote("option", Value, Reason);
113
+ };
114
+ /* Call a vote to kick a player. Requires the player id */
115
+ Game.prototype.CallVoteKick = function (PlayerID, Reason) {
116
+ this.CallVote("kick", PlayerID, Reason);
117
+ };
118
+ /* Call a vote to set a player in spectator mode. Requires the player id */
119
+ Game.prototype.CallVoteSpectate = function (PlayerID, Reason) {
120
+ this.CallVote("spectate", PlayerID, Reason);
121
+ };
122
+ /** probably some verification of using ddnet client.*/
123
+ Game.prototype.IsDDNetLegacy = function () {
124
+ var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_ISDDNETLEGACY, false, 1);
125
+ this.send(packer);
126
+ };
127
+ /* returns the ping in ms */
128
+ Game.prototype.Ping = function () {
129
+ var _this = this;
130
+ return new Promise(function (resolve, reject) {
131
+ var packer = new MsgPacker_1.MsgPacker(22, true, 0);
132
+ var startTime = new Date().getTime();
133
+ _this.send(packer);
134
+ var callback = function (_time) {
135
+ resolve(_time - startTime);
136
+ _this._ping_resolve = function () { };
137
+ };
138
+ _this._ping_resolve = callback;
139
+ });
140
+ };
141
+ return Game;
142
+ }());
143
+ exports.Game = Game;
@@ -0,0 +1,122 @@
1
+
2
+ import { MsgPacker } from "../MsgPacker";
3
+
4
+ import { Client } from "../client";
5
+ enum NETMSGTYPE { EX, SV_MOTD, SV_BROADCAST, SV_CHAT, SV_KILLMSG, SV_SOUNDGLOBAL, SV_TUNEPARAMS, SV_EXTRAPROJECTILE, SV_READYTOENTER, SV_WEAPONPICKUP, SV_EMOTICON, SV_VOTECLEAROPTIONS, SV_VOTEOPTIONLISTADD, SV_VOTEOPTIONADD, SV_VOTEOPTIONREMOVE, SV_VOTESET, SV_VOTESTATUS, CL_SAY, CL_SETTEAM, CL_SETSPECTATORMODE, CL_STARTINFO, CL_CHANGEINFO, CL_KILL, CL_EMOTICON, CL_VOTE, CL_CALLVOTE, CL_ISDDNETLEGACY, SV_DDRACETIMELEGACY, SV_RECORDLEGACY, UNUSED, SV_TEAMSSTATELEGACY, CL_SHOWOTHERSLEGACY, NUM };
6
+
7
+ export class Game {
8
+ // SendMsgEx: (Msgs: MsgPacker[] | MsgPacker) => void;
9
+ private _client: Client;
10
+ _ping_resolve: (_time: number) => void;
11
+ constructor(_client: Client) {
12
+ // this.SendMsgEx = callback;
13
+ this._client = _client;
14
+ this._ping_resolve = () => {};
15
+
16
+ }
17
+ private send(packer: MsgPacker) {
18
+ if (!this._client.options?.lightweight)
19
+ this._client.QueueChunkEx(packer);
20
+ else
21
+ this._client.SendMsgEx(packer);
22
+
23
+ }
24
+
25
+ Say(message: string, team = false) {
26
+ var packer = new MsgPacker(NETMSGTYPE.CL_SAY, false, 1);
27
+ packer.AddInt(team ? 1 : 0); // team
28
+ packer.AddString(message);
29
+ this.send(packer);
30
+ }
31
+
32
+ /* Set the team of an bot. (-1 spectator team, 0 team red/normal team, 1 team blue) */
33
+ SetTeam(team: number) {
34
+ var packer = new MsgPacker(NETMSGTYPE.CL_SETTEAM, false, 1);
35
+ packer.AddInt(team);
36
+ this.send(packer);
37
+ }
38
+
39
+ /* Spectate an player, taking their id as parameter. pretty useless */
40
+ SpectatorMode(SpectatorID: number) {
41
+ var packer = new MsgPacker(NETMSGTYPE.CL_SETSPECTATORMODE, false, 1);
42
+ packer.AddInt(SpectatorID);
43
+ this.send(packer);
44
+ }
45
+
46
+
47
+ /* Change the player info */
48
+ ChangePlayerInfo(playerInfo: ClientInfo) {
49
+ var packer = new MsgPacker(NETMSGTYPE.CL_CHANGEINFO, false, 1);
50
+ packer.AddString(playerInfo.name);
51
+ packer.AddString(playerInfo.clan);
52
+ packer.AddInt(playerInfo.country);
53
+ packer.AddString(playerInfo.skin);
54
+ packer.AddInt(playerInfo.use_custom_color ? 1 : 0);
55
+ packer.AddInt(playerInfo.color_body);
56
+ packer.AddInt(playerInfo.color_feet);
57
+ this.send(packer);
58
+ }
59
+
60
+ /* Kill */
61
+ Kill() {
62
+ var packer = new MsgPacker(NETMSGTYPE.CL_KILL, false, 1);
63
+ this.send(packer);
64
+ }
65
+
66
+ /* Send emote */
67
+ Emote(emote: number) {
68
+ var packer = new MsgPacker(NETMSGTYPE.CL_EMOTICON, false, 1);
69
+ packer.AddInt(emote);
70
+ this.send(packer);
71
+ }
72
+
73
+ /* Vote for an already running vote (f3 / f4) */
74
+ Vote(vote: boolean) {
75
+ var packer = new MsgPacker(NETMSGTYPE.CL_VOTE, false, 1);
76
+ packer.AddInt(vote ? 1 : -1);
77
+ this.send(packer);
78
+ }
79
+
80
+ private CallVote(Type: "option" | "kick" | "spectate", Value: string|number, Reason: string) {
81
+ var packer = new MsgPacker(NETMSGTYPE.CL_CALLVOTE, false, 1);
82
+ packer.AddString(Type);
83
+ packer.AddString(String(Value));
84
+ packer.AddString(Reason);
85
+ this.send(packer);
86
+ }
87
+ /* Call a vote for an server option (for example ddnet maps) */
88
+ CallVoteOption(Value: string, Reason: string) {
89
+ this.CallVote("option", Value, Reason)
90
+ }
91
+ /* Call a vote to kick a player. Requires the player id */
92
+ CallVoteKick(PlayerID: string|number, Reason: string) {
93
+ this.CallVote("kick", PlayerID, Reason)
94
+ }
95
+ /* Call a vote to set a player in spectator mode. Requires the player id */
96
+ CallVoteSpectate(PlayerID: string|number, Reason: string) {
97
+ this.CallVote("spectate", PlayerID, Reason)
98
+ }
99
+
100
+
101
+ /** probably some verification of using ddnet client.*/
102
+ IsDDNetLegacy() {
103
+ var packer = new MsgPacker(NETMSGTYPE.CL_ISDDNETLEGACY, false, 1);
104
+ this.send(packer);
105
+ }
106
+ /* returns the ping in ms */
107
+ Ping(): Promise<number> {
108
+ return new Promise((resolve, reject) => {
109
+ var packer = new MsgPacker(22, true, 0);
110
+ let startTime = new Date().getTime();
111
+ this.send(packer);
112
+
113
+ let callback = (_time: number) => {
114
+ resolve(_time - startTime);
115
+ this._ping_resolve = () => {};
116
+ }
117
+ this._ping_resolve = callback;
118
+ })
119
+ }
120
+
121
+
122
+ }
package/lib/movement.js CHANGED
@@ -19,7 +19,7 @@ var Movement = /** @class */ (function () {
19
19
  this.input.m_Jump = state ? 1 : 0;
20
20
  };
21
21
  Movement.prototype.Fire = function () {
22
- this.input.m_Fire = 1;
22
+ this.input.m_Fire++;
23
23
  };
24
24
  Movement.prototype.Hook = function (state) {
25
25
  if (state === void 0) { state = true; }
package/lib/movement.ts CHANGED
@@ -30,7 +30,7 @@ class Movement {
30
30
  this.input.m_Jump = state ? 1 : 0;
31
31
  }
32
32
  Fire() {
33
- this.input.m_Fire = 1;
33
+ this.input.m_Fire++;
34
34
  }
35
35
  Hook(state = true) {
36
36
  this.input.m_Hook = state ? 1 : 0;
package/lib/snapshot.js CHANGED
@@ -74,7 +74,7 @@ var Snapshot = /** @class */ (function () {
74
74
  pStr = pStr.replace(/\0.*/g, ''); // Remove content from first null char to end.
75
75
  return pStr;
76
76
  };
77
- Snapshot.prototype.parseItem = function (data, Type) {
77
+ Snapshot.prototype.parseItem = function (data, Type, id) {
78
78
  var _item = {};
79
79
  switch (Type) {
80
80
  case items.OBJ_EX:
@@ -212,6 +212,7 @@ var Snapshot = /** @class */ (function () {
212
212
  use_custom_color: Number(data.slice(14, 15)),
213
213
  color_body: Number(data.slice(15, 16)),
214
214
  color_feet: Number(data.slice(16, 17)),
215
+ id: id
215
216
  };
216
217
  break;
217
218
  case items.OBJ_SPECTATOR_INFO:
@@ -381,7 +382,7 @@ var Snapshot = /** @class */ (function () {
381
382
  data = out;
382
383
  } // else no previous, use new data
383
384
  }
384
- var parsed = this_2.parseItem(data, type_id);
385
+ var parsed = this_2.parseItem(data, type_id, id);
385
386
  this_2.eSnapHolder.push({ Snapshot: { Data: data, Key: key }, ack: recvTick });
386
387
  items.items.push({ data: data, parsed: parsed, type_id: type_id, id: id, key: key });
387
388
  };
@@ -396,11 +397,11 @@ var Snapshot = /** @class */ (function () {
396
397
  if (deltatick > -1) {
397
398
  var ____index = this_3.deltas.findIndex(function (delta) { return delta.key == newSnap.Snapshot.Key; });
398
399
  if (____index > -1) {
399
- this_3.deltas[____index] = { data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this_3.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff)) };
400
+ this_3.deltas[____index] = { data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this_3.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff), ((newSnap.Snapshot.Key) & 0xffff)) };
400
401
  return "continue";
401
402
  }
402
403
  } // else
403
- this_3.deltas.push({ data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this_3.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff)) });
404
+ this_3.deltas.push({ data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this_3.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff), ((newSnap.Snapshot.Key) & 0xffff)) });
404
405
  };
405
406
  var this_3 = this;
406
407
  for (var _i = 0, newSnaps_1 = newSnaps; _i < newSnaps_1.length; _i++) {
package/lib/snapshot.ts CHANGED
@@ -77,7 +77,7 @@ export class Snapshot {
77
77
  pStr = pStr.replace(/\0.*/g, ''); // Remove content from first null char to end.
78
78
  return pStr;
79
79
  }
80
- private parseItem(data: number[], Type: number): Item {
80
+ private parseItem(data: number[], Type: number, id: number): Item {
81
81
  var _item = {} as Item;
82
82
  switch (Type) {
83
83
  case items.OBJ_EX:
@@ -216,6 +216,7 @@ export class Snapshot {
216
216
  use_custom_color: Number(data.slice(14, 15)),
217
217
  color_body: Number(data.slice(15, 16)),
218
218
  color_feet: Number(data.slice(16, 17)),
219
+ id: id
219
220
  } as ClientInfo
220
221
  break;
221
222
  case items.OBJ_SPECTATOR_INFO:
@@ -375,7 +376,7 @@ export class Snapshot {
375
376
  } else
376
377
  _size = unpacker.unpackInt();
377
378
 
378
- let data = [];
379
+ let data: number[] = [];
379
380
  for (let j = 0; j < _size; j++) {
380
381
  if (unpacker.remaining.length > 0)
381
382
  data.push(unpacker.unpackInt());
@@ -393,7 +394,7 @@ export class Snapshot {
393
394
  } // else no previous, use new data
394
395
  }
395
396
 
396
- let parsed = this.parseItem(data, type_id)
397
+ let parsed = this.parseItem(data, type_id, id)
397
398
  this.eSnapHolder.push({Snapshot: {Data: data, Key: key}, ack: recvTick});
398
399
 
399
400
  items.items.push({data, parsed, type_id, id, key})
@@ -409,11 +410,11 @@ export class Snapshot {
409
410
  let ____index = this.deltas.findIndex(delta => delta.key == newSnap.Snapshot.Key)
410
411
 
411
412
  if (____index > -1) {
412
- this.deltas[____index] = {data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff))};
413
+ this.deltas[____index] = {data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff), ((newSnap.Snapshot.Key) & 0xffff))};
413
414
  continue;
414
415
  }
415
416
  } // else
416
- this.deltas.push({data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff))});
417
+ this.deltas.push({data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff), ((newSnap.Snapshot.Key) & 0xffff))});
417
418
  }
418
419
 
419
420
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teeworlds",
3
- "version": "2.3.9",
3
+ "version": "2.4.1",
4
4
  "description": "Library for (ingame) teeworlds bots.",
5
5
  "license": "MIT",
6
6
  "main": "index.js",