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/README.md +4 -3
- package/docs/documentation.md +3 -0
- package/index.js +24 -24
- package/lib/MsgPacker.js +46 -55
- package/lib/MsgUnpacker.js +52 -53
- package/lib/UUIDManager.js +44 -50
- package/lib/client.js +761 -830
- package/lib/client.ts +24 -3
- package/lib/components/game.js +103 -106
- package/lib/components/movement.js +74 -82
- package/lib/components/rcon.js +91 -122
- package/lib/components/snapshot.js +143 -234
- package/lib/enums_types/protocol.js +13 -13
- package/lib/enums_types/protocol.ts +8 -0
- package/lib/huffman.js +186 -192
- package/lib/snapshot.js +598 -610
- package/package.json +4 -3
- package/tsconfig.json +1 -1
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
|
-
|
|
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
|
}
|
package/lib/components/game.js
CHANGED
|
@@ -1,106 +1,103 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Game = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// this.SendMsgEx = callback;
|
|
8
|
-
this._client = _client;
|
|
9
|
-
this._ping_resolve =
|
|
10
|
-
}
|
|
11
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
packer.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
packer.AddString(playerInfo.
|
|
41
|
-
packer.
|
|
42
|
-
packer.
|
|
43
|
-
packer.
|
|
44
|
-
packer.AddInt(playerInfo.
|
|
45
|
-
packer.AddInt(playerInfo.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
packer.AddString(
|
|
69
|
-
packer.AddString(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
5
|
-
|
|
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
|
-
|
|
9
|
-
this.input.m_Direction = -1;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
this.input.m_Direction = 1;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
this.input.m_Direction = 0;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.Flag(toggle,
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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;
|
package/lib/components/rcon.js
CHANGED
|
@@ -1,122 +1,91 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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;
|