teeworlds 2.5.4 → 2.5.5

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/lib/client.ts CHANGED
@@ -191,6 +191,16 @@ export class Client extends EventEmitter {
191
191
  this.UUIDManager.RegisterName("checksum-error@ddnet.tw", NETMSG.System.NETMSG_CHECKSUM_ERROR);
192
192
  this.UUIDManager.RegisterName("redirect@ddnet.org", NETMSG.System.NETMSG_REDIRECT);
193
193
 
194
+
195
+ this.UUIDManager.RegisterName("rcon-cmd-group-start@ddnet.org", NETMSG.System.NETMSG_RCON_CMD_GROUP_START) // not implemented
196
+ this.UUIDManager.RegisterName("rcon-cmd-group-end@ddnet.org", NETMSG.System.NETMSG_RCON_CMD_GROUP_END) // not implemented
197
+ this.UUIDManager.RegisterName("map-reload@ddnet.org", NETMSG.System.NETMSG_MAP_RELOAD) // not implemented
198
+ this.UUIDManager.RegisterName("reconnect@ddnet.org", NETMSG.System.NETMSG_RECONNECT) // implemented
199
+ this.UUIDManager.RegisterName("sv-maplist-add@ddnet.org", NETMSG.System.NETMSG_MAPLIST_ADD) // not implemented
200
+ this.UUIDManager.RegisterName("sv-maplist-start@ddnet.org", NETMSG.System.NETMSG_MAPLIST_GROUP_START) // not implemented
201
+ this.UUIDManager.RegisterName("sv-maplist-end@ddnet.org", NETMSG.System.NETMSG_MAPLIST_GROUP_END) // not implemented
202
+
203
+
194
204
  this.UUIDManager.RegisterName("i-am-npm-package@swarfey.gitlab.io", NETMSG.System.NETMSG_I_AM_NPM_PACKAGE);
195
205
 
196
206
  }
@@ -429,10 +439,9 @@ export class Client extends EventEmitter {
429
439
  dnsLookup(this.host, 4, (err, address, family) => {
430
440
  if (err) throw err;
431
441
  this.host = address;
432
- console.log(err, address, family)
433
442
  })
434
443
  }
435
-
444
+
436
445
  this.State = States.STATE_CONNECTING;
437
446
 
438
447
  let predTimer = setInterval(() => {
@@ -451,8 +460,9 @@ export class Client extends EventEmitter {
451
460
  else
452
461
  clearInterval(connectInterval)
453
462
  }, 500);
463
+ let inputInterval: NodeJS.Timeout;
454
464
  if (!this.options?.lightweight) {
455
- let inputInterval = setInterval(() => {
465
+ inputInterval = setInterval(() => {
456
466
  if (this.State == States.STATE_OFFLINE) {
457
467
  clearInterval(inputInterval)
458
468
  // console.log("???");
@@ -761,6 +771,17 @@ export class Client extends EventEmitter {
761
771
  packer.AddBuffer(this.UUIDManager.LookupType(NETMSG.System.NETMSG_PONGEX)!.hash);
762
772
 
763
773
  this.SendMsgEx(packer, 2);
774
+ } else if (chunk.msgid == NETMSG.System.NETMSG_RECONNECT) {
775
+ this.SendControlMsg(4) // sends disconnect packet
776
+ clearInterval(predTimer);
777
+ clearInterval(inputInterval);
778
+ clearInterval(resendTimeout);
779
+ clearInterval(Timeout);
780
+ this.socket?.removeAllListeners("message");
781
+ this.connect();
782
+
783
+
784
+ return;
764
785
  }
765
786
 
766
787
  }
@@ -1,106 +1,103 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Game = void 0;
4
- var MsgPacker_1 = require("../MsgPacker");
5
- var Game = /** @class */ (function () {
6
- function Game(_client) {
7
- // this.SendMsgEx = callback;
8
- this._client = _client;
9
- this._ping_resolve = function () { };
10
- }
11
- Game.prototype.send = function (packer) {
12
- var _a;
13
- if (!((_a = this._client.options) === null || _a === void 0 ? void 0 : _a.lightweight))
14
- this._client.QueueChunkEx(packer);
15
- else
16
- this._client.SendMsgEx(packer);
17
- };
18
- Game.prototype.Say = function (message, team) {
19
- if (team === void 0) { team = false; }
20
- var packer = new MsgPacker_1.MsgPacker(17 /* NETMSG.Game.CL_SAY */, false, 1);
21
- packer.AddInt(team ? 1 : 0); // team
22
- packer.AddString(message);
23
- this.send(packer);
24
- };
25
- /** Set the team of an bot. (-1 spectator team, 0 team red/normal team, 1 team blue) */
26
- Game.prototype.SetTeam = function (team) {
27
- var packer = new MsgPacker_1.MsgPacker(18 /* NETMSG.Game.CL_SETTEAM */, false, 1);
28
- packer.AddInt(team);
29
- this.send(packer);
30
- };
31
- /** Spectate an player, taking their id as parameter. pretty useless */
32
- Game.prototype.SpectatorMode = function (SpectatorID) {
33
- var packer = new MsgPacker_1.MsgPacker(19 /* NETMSG.Game.CL_SETSPECTATORMODE */, false, 1);
34
- packer.AddInt(SpectatorID);
35
- this.send(packer);
36
- };
37
- /** Change the player info */
38
- Game.prototype.ChangePlayerInfo = function (playerInfo) {
39
- var packer = new MsgPacker_1.MsgPacker(21 /* NETMSG.Game.CL_CHANGEINFO */, false, 1);
40
- packer.AddString(playerInfo.name);
41
- packer.AddString(playerInfo.clan);
42
- packer.AddInt(playerInfo.country);
43
- packer.AddString(playerInfo.skin);
44
- packer.AddInt(playerInfo.use_custom_color ? 1 : 0);
45
- packer.AddInt(playerInfo.color_body);
46
- packer.AddInt(playerInfo.color_feet);
47
- this.send(packer);
48
- };
49
- /** Kill */
50
- Game.prototype.Kill = function () {
51
- var packer = new MsgPacker_1.MsgPacker(22 /* NETMSG.Game.CL_KILL */, false, 1);
52
- this.send(packer);
53
- };
54
- /** Send emote */
55
- Game.prototype.Emote = function (emote) {
56
- var packer = new MsgPacker_1.MsgPacker(23 /* NETMSG.Game.CL_EMOTICON */, false, 1);
57
- packer.AddInt(emote);
58
- this.send(packer);
59
- };
60
- /** Vote for an already running vote (true = f3 / false = f4) */
61
- Game.prototype.Vote = function (vote) {
62
- var packer = new MsgPacker_1.MsgPacker(24 /* NETMSG.Game.CL_VOTE */, false, 1);
63
- packer.AddInt(vote ? 1 : -1);
64
- this.send(packer);
65
- };
66
- Game.prototype.CallVote = function (Type, Value, Reason) {
67
- var packer = new MsgPacker_1.MsgPacker(25 /* NETMSG.Game.CL_CALLVOTE */, false, 1);
68
- packer.AddString(Type);
69
- packer.AddString(String(Value));
70
- packer.AddString(Reason);
71
- this.send(packer);
72
- };
73
- /** Call a vote for an server option (for example ddnet maps) */
74
- Game.prototype.CallVoteOption = function (Value, Reason) {
75
- this.CallVote("option", Value, Reason);
76
- };
77
- /** Call a vote to kick a player. Requires the player id */
78
- Game.prototype.CallVoteKick = function (PlayerID, Reason) {
79
- this.CallVote("kick", PlayerID, Reason);
80
- };
81
- /** Call a vote to set a player in spectator mode. Requires the player id */
82
- Game.prototype.CallVoteSpectate = function (PlayerID, Reason) {
83
- this.CallVote("spectate", PlayerID, Reason);
84
- };
85
- /** probably some verification of using ddnet client. */
86
- Game.prototype.IsDDNetLegacy = function () {
87
- var packer = new MsgPacker_1.MsgPacker(26 /* NETMSG.Game.CL_ISDDNETLEGACY */, false, 1);
88
- this.send(packer);
89
- };
90
- /** returns the ping in ms (as a promise) */
91
- Game.prototype.Ping = function () {
92
- var _this = this;
93
- return new Promise(function (resolve, reject) {
94
- var packer = new MsgPacker_1.MsgPacker(22, true, 0);
95
- var startTime = new Date().getTime();
96
- _this.send(packer);
97
- var callback = function (_time) {
98
- resolve(_time - startTime);
99
- _this._ping_resolve = function () { };
100
- };
101
- _this._ping_resolve = callback;
102
- });
103
- };
104
- return Game;
105
- }());
106
- exports.Game = Game;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Game = void 0;
4
+ const MsgPacker_1 = require("../MsgPacker");
5
+ class Game {
6
+ constructor(_client) {
7
+ // this.SendMsgEx = callback;
8
+ this._client = _client;
9
+ this._ping_resolve = () => { };
10
+ }
11
+ send(packer) {
12
+ var _a;
13
+ if (!((_a = this._client.options) === null || _a === void 0 ? void 0 : _a.lightweight))
14
+ this._client.QueueChunkEx(packer);
15
+ else
16
+ this._client.SendMsgEx(packer);
17
+ }
18
+ Say(message, team = false) {
19
+ var packer = new MsgPacker_1.MsgPacker(17 /* NETMSG.Game.CL_SAY */, false, 1);
20
+ packer.AddInt(team ? 1 : 0); // team
21
+ packer.AddString(message);
22
+ this.send(packer);
23
+ }
24
+ /** Set the team of an bot. (-1 spectator team, 0 team red/normal team, 1 team blue) */
25
+ SetTeam(team) {
26
+ var packer = new MsgPacker_1.MsgPacker(18 /* NETMSG.Game.CL_SETTEAM */, false, 1);
27
+ packer.AddInt(team);
28
+ this.send(packer);
29
+ }
30
+ /** Spectate an player, taking their id as parameter. pretty useless */
31
+ SpectatorMode(SpectatorID) {
32
+ var packer = new MsgPacker_1.MsgPacker(19 /* NETMSG.Game.CL_SETSPECTATORMODE */, false, 1);
33
+ packer.AddInt(SpectatorID);
34
+ this.send(packer);
35
+ }
36
+ /** Change the player info */
37
+ ChangePlayerInfo(playerInfo) {
38
+ var packer = new MsgPacker_1.MsgPacker(21 /* NETMSG.Game.CL_CHANGEINFO */, false, 1);
39
+ packer.AddString(playerInfo.name);
40
+ packer.AddString(playerInfo.clan);
41
+ packer.AddInt(playerInfo.country);
42
+ packer.AddString(playerInfo.skin);
43
+ packer.AddInt(playerInfo.use_custom_color ? 1 : 0);
44
+ packer.AddInt(playerInfo.color_body);
45
+ packer.AddInt(playerInfo.color_feet);
46
+ this.send(packer);
47
+ }
48
+ /** Kill */
49
+ Kill() {
50
+ var packer = new MsgPacker_1.MsgPacker(22 /* NETMSG.Game.CL_KILL */, false, 1);
51
+ this.send(packer);
52
+ }
53
+ /** Send emote */
54
+ Emote(emote) {
55
+ var packer = new MsgPacker_1.MsgPacker(23 /* NETMSG.Game.CL_EMOTICON */, false, 1);
56
+ packer.AddInt(emote);
57
+ this.send(packer);
58
+ }
59
+ /** Vote for an already running vote (true = f3 / false = f4) */
60
+ Vote(vote) {
61
+ var packer = new MsgPacker_1.MsgPacker(24 /* NETMSG.Game.CL_VOTE */, false, 1);
62
+ packer.AddInt(vote ? 1 : -1);
63
+ this.send(packer);
64
+ }
65
+ CallVote(Type, Value, Reason) {
66
+ var packer = new MsgPacker_1.MsgPacker(25 /* NETMSG.Game.CL_CALLVOTE */, false, 1);
67
+ packer.AddString(Type);
68
+ packer.AddString(String(Value));
69
+ packer.AddString(Reason);
70
+ this.send(packer);
71
+ }
72
+ /** Call a vote for an server option (for example ddnet maps) */
73
+ CallVoteOption(Value, Reason) {
74
+ this.CallVote("option", Value, Reason);
75
+ }
76
+ /** Call a vote to kick a player. Requires the player id */
77
+ CallVoteKick(PlayerID, Reason) {
78
+ this.CallVote("kick", PlayerID, Reason);
79
+ }
80
+ /** Call a vote to set a player in spectator mode. Requires the player id */
81
+ CallVoteSpectate(PlayerID, Reason) {
82
+ this.CallVote("spectate", PlayerID, Reason);
83
+ }
84
+ /** probably some verification of using ddnet client. */
85
+ IsDDNetLegacy() {
86
+ var packer = new MsgPacker_1.MsgPacker(26 /* NETMSG.Game.CL_ISDDNETLEGACY */, false, 1);
87
+ this.send(packer);
88
+ }
89
+ /** returns the ping in ms (as a promise) */
90
+ Ping() {
91
+ return new Promise((resolve, reject) => {
92
+ var packer = new MsgPacker_1.MsgPacker(22, true, 0);
93
+ let startTime = new Date().getTime();
94
+ this.send(packer);
95
+ let callback = (_time) => {
96
+ resolve(_time - startTime);
97
+ this._ping_resolve = () => { };
98
+ };
99
+ this._ping_resolve = callback;
100
+ });
101
+ }
102
+ }
103
+ exports.Game = Game;
@@ -1,82 +1,74 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- ;
4
- var Movement = /** @class */ (function () {
5
- function Movement() {
6
- this.input = { m_Direction: 0, m_Fire: 0, m_Hook: 0, m_Jump: 0, m_NextWeapon: 0, m_PlayerFlags: 1, m_PrevWeapon: 0, m_TargetX: 0, m_TargetY: 0, m_WantedWeapon: 1 };
7
- }
8
- Movement.prototype.RunLeft = function () {
9
- this.input.m_Direction = -1;
10
- };
11
- Movement.prototype.RunRight = function () {
12
- this.input.m_Direction = 1;
13
- };
14
- Movement.prototype.RunStop = function () {
15
- this.input.m_Direction = 0;
16
- };
17
- Movement.prototype.Jump = function (state) {
18
- if (state === void 0) { state = true; }
19
- this.input.m_Jump = state ? 1 : 0;
20
- };
21
- Movement.prototype.Fire = function () {
22
- this.input.m_Fire++;
23
- };
24
- Movement.prototype.Hook = function (state) {
25
- if (state === void 0) { state = true; }
26
- this.input.m_Hook = state ? 1 : 0;
27
- };
28
- Movement.prototype.NextWeapon = function () {
29
- this.input.m_NextWeapon = 1;
30
- this.WantedWeapon(0);
31
- };
32
- Movement.prototype.PrevWeapon = function () {
33
- this.input.m_PrevWeapon = 1;
34
- this.WantedWeapon(0);
35
- };
36
- Movement.prototype.WantedWeapon = function (weapon) {
37
- this.input.m_WantedWeapon = weapon;
38
- };
39
- Movement.prototype.SetAim = function (x, y) {
40
- this.input.m_TargetX = x;
41
- this.input.m_TargetY = y;
42
- };
43
- Movement.prototype.Flag = function (toggle, num) {
44
- if (toggle) {
45
- this.input.m_PlayerFlags |= num;
46
- }
47
- else {
48
- this.input.m_PlayerFlags &= ~num;
49
- }
50
- };
51
- Movement.prototype.FlagPlaying = function (toggle) {
52
- if (toggle === void 0) { toggle = true; }
53
- this.Flag(toggle, 1);
54
- };
55
- Movement.prototype.FlagInMenu = function (toggle) {
56
- if (toggle === void 0) { toggle = true; }
57
- this.Flag(toggle, 2);
58
- };
59
- Movement.prototype.FlagChatting = function (toggle) {
60
- if (toggle === void 0) { toggle = true; }
61
- this.Flag(toggle, 4);
62
- };
63
- Movement.prototype.FlagScoreboard = function (toggle) {
64
- if (toggle === void 0) { toggle = true; }
65
- this.Flag(toggle, 8);
66
- };
67
- Movement.prototype.FlagHookline = function (toggle) {
68
- if (toggle === void 0) { toggle = true; }
69
- this.Flag(toggle, 16);
70
- };
71
- Movement.prototype.Reset = function () {
72
- this.input.m_Direction = 0;
73
- this.input.m_Jump = 0;
74
- this.input.m_Fire = 0;
75
- this.input.m_Hook = 0;
76
- this.input.m_PlayerFlags = 0;
77
- this.input.m_NextWeapon = 0;
78
- this.input.m_PrevWeapon = 0;
79
- };
80
- return Movement;
81
- }());
82
- exports.default = Movement;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
4
+ class Movement {
5
+ constructor() {
6
+ this.input = { m_Direction: 0, m_Fire: 0, m_Hook: 0, m_Jump: 0, m_NextWeapon: 0, m_PlayerFlags: 1, m_PrevWeapon: 0, m_TargetX: 0, m_TargetY: 0, m_WantedWeapon: 1 };
7
+ }
8
+ RunLeft() {
9
+ this.input.m_Direction = -1;
10
+ }
11
+ RunRight() {
12
+ this.input.m_Direction = 1;
13
+ }
14
+ RunStop() {
15
+ this.input.m_Direction = 0;
16
+ }
17
+ Jump(state = true) {
18
+ this.input.m_Jump = state ? 1 : 0;
19
+ }
20
+ Fire() {
21
+ this.input.m_Fire++;
22
+ }
23
+ Hook(state = true) {
24
+ this.input.m_Hook = state ? 1 : 0;
25
+ }
26
+ NextWeapon() {
27
+ this.input.m_NextWeapon = 1;
28
+ this.WantedWeapon(0);
29
+ }
30
+ PrevWeapon() {
31
+ this.input.m_PrevWeapon = 1;
32
+ this.WantedWeapon(0);
33
+ }
34
+ WantedWeapon(weapon) {
35
+ this.input.m_WantedWeapon = weapon;
36
+ }
37
+ SetAim(x, y) {
38
+ this.input.m_TargetX = x;
39
+ this.input.m_TargetY = y;
40
+ }
41
+ Flag(toggle, num) {
42
+ if (toggle) {
43
+ this.input.m_PlayerFlags |= num;
44
+ }
45
+ else {
46
+ this.input.m_PlayerFlags &= ~num;
47
+ }
48
+ }
49
+ FlagPlaying(toggle = true) {
50
+ this.Flag(toggle, 1);
51
+ }
52
+ FlagInMenu(toggle = true) {
53
+ this.Flag(toggle, 2);
54
+ }
55
+ FlagChatting(toggle = true) {
56
+ this.Flag(toggle, 4);
57
+ }
58
+ FlagScoreboard(toggle = true) {
59
+ this.Flag(toggle, 8);
60
+ }
61
+ FlagHookline(toggle = true) {
62
+ this.Flag(toggle, 16);
63
+ }
64
+ Reset() {
65
+ this.input.m_Direction = 0;
66
+ this.input.m_Jump = 0;
67
+ this.input.m_Fire = 0;
68
+ this.input.m_Hook = 0;
69
+ this.input.m_PlayerFlags = 0;
70
+ this.input.m_NextWeapon = 0;
71
+ this.input.m_PrevWeapon = 0;
72
+ }
73
+ }
74
+ exports.default = Movement;
@@ -1,122 +1,91 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
- if (ar || !(i in from)) {
20
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
- ar[i] = from[i];
22
- }
23
- }
24
- return to.concat(ar || Array.prototype.slice.call(from));
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.Rcon = void 0;
28
- var stream_1 = require("stream");
29
- var MsgPacker_1 = require("../MsgPacker");
30
- var MsgUnpacker_1 = require("../MsgUnpacker");
31
- var Rcon = /** @class */ (function (_super) {
32
- __extends(Rcon, _super);
33
- function Rcon(_client) {
34
- var _this = _super.call(this) || this;
35
- _this.CommandList = [];
36
- _this._client = _client;
37
- return _this;
38
- }
39
- Rcon.prototype.on = function (event, listener) {
40
- return _super.prototype.on.call(this, event, listener);
41
- };
42
- Rcon.prototype.emit = function (event) {
43
- var args = [];
44
- for (var _i = 1; _i < arguments.length; _i++) {
45
- args[_i - 1] = arguments[_i];
46
- }
47
- return _super.prototype.emit.apply(this, __spreadArray([event], args, false));
48
- };
49
- // SendMsgEx: (Msgs: MsgPacker[] | MsgPacker) => void;
50
- Rcon.prototype.send = function (packer) {
51
- var _a;
52
- if (!((_a = this._client.options) === null || _a === void 0 ? void 0 : _a.lightweight))
53
- this._client.QueueChunkEx(packer);
54
- else
55
- this._client.SendMsgEx(packer);
56
- };
57
- /** Rcon auth, set the `username` to empty string for authentication w/o username **/
58
- Rcon.prototype.auth = function (usernameOrPassword, password) {
59
- var rconAuthMsg = new MsgPacker_1.MsgPacker(18 /* NETMSG.System.NETMSG_RCON_AUTH */, true, 1);
60
- if (password == undefined) {
61
- rconAuthMsg.AddString("");
62
- rconAuthMsg.AddString(usernameOrPassword);
63
- }
64
- else {
65
- rconAuthMsg.AddString(usernameOrPassword);
66
- rconAuthMsg.AddString(password);
67
- }
68
- rconAuthMsg.AddInt(1);
69
- this.send(rconAuthMsg);
70
- };
71
- /** Send rcon command **/
72
- Rcon.prototype.rcon = function (cmds) {
73
- var _cmds;
74
- if (cmds instanceof Array)
75
- _cmds = cmds;
76
- else
77
- _cmds = [cmds];
78
- var msgs = [];
79
- _cmds.forEach(function (cmd) {
80
- var rconCmdMsg = new MsgPacker_1.MsgPacker(17 /* NETMSG.System.NETMSG_RCON_CMD */, true, 1);
81
- rconCmdMsg.AddString(cmd);
82
- msgs.push(rconCmdMsg);
83
- });
84
- this.send(msgs);
85
- };
86
- /** This method is called by the Client to handle the chunks. It should not be called directly. */
87
- Rcon.prototype._checkChunks = function (chunk) {
88
- if (chunk.msgid == 11 /* NETMSG.System.NETMSG_RCON_LINE */) {
89
- var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
90
- var msg = unpacker.unpackString();
91
- this.emit('rcon_line', msg);
92
- }
93
- else if (chunk.msgid == 10 /* NETMSG.System.NETMSG_RCON_AUTH_STATUS */) {
94
- var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
95
- var AuthLevel = unpacker.unpackInt();
96
- var ReceiveCommands = unpacker.unpackInt();
97
- this.emit('rcon_auth_status', { AuthLevel: AuthLevel, ReceiveCommands: ReceiveCommands });
98
- }
99
- else if (chunk.msgid == 25 /* NETMSG.System.NETMSG_RCON_CMD_ADD */) {
100
- var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
101
- var command = unpacker.unpackString();
102
- var description = unpacker.unpackString();
103
- var params = unpacker.unpackString();
104
- this.CommandList.push({ command: command, description: description, params: params });
105
- this.emit('rcon_cmd_add', { command: command, description: description, params: params });
106
- }
107
- else if (chunk.msgid == 26 /* NETMSG.System.NETMSG_RCON_CMD_REM */) {
108
- var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
109
- var command_1 = unpacker.unpackString();
110
- this.emit('rcon_cmd_rem', { command: command_1 });
111
- var index = this.CommandList.findIndex(function (a) { return a.command == command_1; });
112
- if (index - 1 >= 0)
113
- this.CommandList.splice(index, 1);
114
- }
115
- else {
116
- return false;
117
- }
118
- return true;
119
- };
120
- return Rcon;
121
- }(stream_1.EventEmitter));
122
- exports.Rcon = Rcon;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Rcon = void 0;
4
+ const stream_1 = require("stream");
5
+ const MsgPacker_1 = require("../MsgPacker");
6
+ const MsgUnpacker_1 = require("../MsgUnpacker");
7
+ class Rcon extends stream_1.EventEmitter {
8
+ on(event, listener) {
9
+ return super.on(event, listener);
10
+ }
11
+ emit(event, ...args) {
12
+ return super.emit(event, ...args);
13
+ }
14
+ constructor(_client) {
15
+ super();
16
+ this.CommandList = [];
17
+ this._client = _client;
18
+ }
19
+ // SendMsgEx: (Msgs: MsgPacker[] | MsgPacker) => void;
20
+ send(packer) {
21
+ var _a;
22
+ if (!((_a = this._client.options) === null || _a === void 0 ? void 0 : _a.lightweight))
23
+ this._client.QueueChunkEx(packer);
24
+ else
25
+ this._client.SendMsgEx(packer);
26
+ }
27
+ /** Rcon auth, set the `username` to empty string for authentication w/o username **/
28
+ auth(usernameOrPassword, password) {
29
+ const rconAuthMsg = new MsgPacker_1.MsgPacker(18 /* NETMSG.System.NETMSG_RCON_AUTH */, true, 1);
30
+ if (password == undefined) {
31
+ rconAuthMsg.AddString("");
32
+ rconAuthMsg.AddString(usernameOrPassword);
33
+ }
34
+ else {
35
+ rconAuthMsg.AddString(usernameOrPassword);
36
+ rconAuthMsg.AddString(password);
37
+ }
38
+ rconAuthMsg.AddInt(1);
39
+ this.send(rconAuthMsg);
40
+ }
41
+ /** Send rcon command **/
42
+ rcon(cmds) {
43
+ let _cmds;
44
+ if (cmds instanceof Array)
45
+ _cmds = cmds;
46
+ else
47
+ _cmds = [cmds];
48
+ const msgs = [];
49
+ _cmds.forEach((cmd) => {
50
+ const rconCmdMsg = new MsgPacker_1.MsgPacker(17 /* NETMSG.System.NETMSG_RCON_CMD */, true, 1);
51
+ rconCmdMsg.AddString(cmd);
52
+ msgs.push(rconCmdMsg);
53
+ });
54
+ this.send(msgs);
55
+ }
56
+ /** This method is called by the Client to handle the chunks. It should not be called directly. */
57
+ _checkChunks(chunk) {
58
+ if (chunk.msgid == 11 /* NETMSG.System.NETMSG_RCON_LINE */) {
59
+ const unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
60
+ const msg = unpacker.unpackString();
61
+ this.emit('rcon_line', msg);
62
+ }
63
+ else if (chunk.msgid == 10 /* NETMSG.System.NETMSG_RCON_AUTH_STATUS */) {
64
+ const unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
65
+ const AuthLevel = unpacker.unpackInt();
66
+ const ReceiveCommands = unpacker.unpackInt();
67
+ this.emit('rcon_auth_status', { AuthLevel, ReceiveCommands });
68
+ }
69
+ else if (chunk.msgid == 25 /* NETMSG.System.NETMSG_RCON_CMD_ADD */) {
70
+ const unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
71
+ const command = unpacker.unpackString();
72
+ const description = unpacker.unpackString();
73
+ const params = unpacker.unpackString();
74
+ this.CommandList.push({ command, description, params });
75
+ this.emit('rcon_cmd_add', { command, description, params });
76
+ }
77
+ else if (chunk.msgid == 26 /* NETMSG.System.NETMSG_RCON_CMD_REM */) {
78
+ const unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
79
+ const command = unpacker.unpackString();
80
+ this.emit('rcon_cmd_rem', { command });
81
+ let index = this.CommandList.findIndex(a => a.command == command);
82
+ if (index - 1 >= 0)
83
+ this.CommandList.splice(index, 1);
84
+ }
85
+ else {
86
+ return false;
87
+ }
88
+ return true;
89
+ }
90
+ }
91
+ exports.Rcon = Rcon;