teeworlds 2.5.3 → 2.5.4
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.js +464 -479
- package/lib/client.ts +102 -213
- package/lib/components/game.js +9 -46
- package/lib/components/game.ts +12 -13
- package/lib/components/rcon.js +122 -0
- package/lib/components/rcon.ts +114 -0
- package/lib/components/snapshot.js +24 -48
- package/lib/components/snapshot.ts +68 -100
- package/lib/enums_types/protocol.js +13 -0
- package/lib/enums_types/protocol.ts +137 -0
- package/lib/enums_types/types.d.ts +236 -0
- package/lib/snapshot.ts +36 -38
- package/package.json +1 -1
- package/lib/snapshots.d.ts +0 -233
package/lib/components/game.js
CHANGED
|
@@ -2,43 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Game = void 0;
|
|
4
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
5
|
var Game = /** @class */ (function () {
|
|
43
6
|
function Game(_client) {
|
|
44
7
|
// this.SendMsgEx = callback;
|
|
@@ -54,26 +17,26 @@ var Game = /** @class */ (function () {
|
|
|
54
17
|
};
|
|
55
18
|
Game.prototype.Say = function (message, team) {
|
|
56
19
|
if (team === void 0) { team = false; }
|
|
57
|
-
var packer = new MsgPacker_1.MsgPacker(
|
|
20
|
+
var packer = new MsgPacker_1.MsgPacker(17 /* NETMSG.Game.CL_SAY */, false, 1);
|
|
58
21
|
packer.AddInt(team ? 1 : 0); // team
|
|
59
22
|
packer.AddString(message);
|
|
60
23
|
this.send(packer);
|
|
61
24
|
};
|
|
62
25
|
/** Set the team of an bot. (-1 spectator team, 0 team red/normal team, 1 team blue) */
|
|
63
26
|
Game.prototype.SetTeam = function (team) {
|
|
64
|
-
var packer = new MsgPacker_1.MsgPacker(
|
|
27
|
+
var packer = new MsgPacker_1.MsgPacker(18 /* NETMSG.Game.CL_SETTEAM */, false, 1);
|
|
65
28
|
packer.AddInt(team);
|
|
66
29
|
this.send(packer);
|
|
67
30
|
};
|
|
68
31
|
/** Spectate an player, taking their id as parameter. pretty useless */
|
|
69
32
|
Game.prototype.SpectatorMode = function (SpectatorID) {
|
|
70
|
-
var packer = new MsgPacker_1.MsgPacker(
|
|
33
|
+
var packer = new MsgPacker_1.MsgPacker(19 /* NETMSG.Game.CL_SETSPECTATORMODE */, false, 1);
|
|
71
34
|
packer.AddInt(SpectatorID);
|
|
72
35
|
this.send(packer);
|
|
73
36
|
};
|
|
74
37
|
/** Change the player info */
|
|
75
38
|
Game.prototype.ChangePlayerInfo = function (playerInfo) {
|
|
76
|
-
var packer = new MsgPacker_1.MsgPacker(
|
|
39
|
+
var packer = new MsgPacker_1.MsgPacker(21 /* NETMSG.Game.CL_CHANGEINFO */, false, 1);
|
|
77
40
|
packer.AddString(playerInfo.name);
|
|
78
41
|
packer.AddString(playerInfo.clan);
|
|
79
42
|
packer.AddInt(playerInfo.country);
|
|
@@ -85,23 +48,23 @@ var Game = /** @class */ (function () {
|
|
|
85
48
|
};
|
|
86
49
|
/** Kill */
|
|
87
50
|
Game.prototype.Kill = function () {
|
|
88
|
-
var packer = new MsgPacker_1.MsgPacker(
|
|
51
|
+
var packer = new MsgPacker_1.MsgPacker(22 /* NETMSG.Game.CL_KILL */, false, 1);
|
|
89
52
|
this.send(packer);
|
|
90
53
|
};
|
|
91
54
|
/** Send emote */
|
|
92
55
|
Game.prototype.Emote = function (emote) {
|
|
93
|
-
var packer = new MsgPacker_1.MsgPacker(
|
|
56
|
+
var packer = new MsgPacker_1.MsgPacker(23 /* NETMSG.Game.CL_EMOTICON */, false, 1);
|
|
94
57
|
packer.AddInt(emote);
|
|
95
58
|
this.send(packer);
|
|
96
59
|
};
|
|
97
60
|
/** Vote for an already running vote (true = f3 / false = f4) */
|
|
98
61
|
Game.prototype.Vote = function (vote) {
|
|
99
|
-
var packer = new MsgPacker_1.MsgPacker(
|
|
62
|
+
var packer = new MsgPacker_1.MsgPacker(24 /* NETMSG.Game.CL_VOTE */, false, 1);
|
|
100
63
|
packer.AddInt(vote ? 1 : -1);
|
|
101
64
|
this.send(packer);
|
|
102
65
|
};
|
|
103
66
|
Game.prototype.CallVote = function (Type, Value, Reason) {
|
|
104
|
-
var packer = new MsgPacker_1.MsgPacker(
|
|
67
|
+
var packer = new MsgPacker_1.MsgPacker(25 /* NETMSG.Game.CL_CALLVOTE */, false, 1);
|
|
105
68
|
packer.AddString(Type);
|
|
106
69
|
packer.AddString(String(Value));
|
|
107
70
|
packer.AddString(Reason);
|
|
@@ -121,7 +84,7 @@ var Game = /** @class */ (function () {
|
|
|
121
84
|
};
|
|
122
85
|
/** probably some verification of using ddnet client. */
|
|
123
86
|
Game.prototype.IsDDNetLegacy = function () {
|
|
124
|
-
var packer = new MsgPacker_1.MsgPacker(
|
|
87
|
+
var packer = new MsgPacker_1.MsgPacker(26 /* NETMSG.Game.CL_ISDDNETLEGACY */, false, 1);
|
|
125
88
|
this.send(packer);
|
|
126
89
|
};
|
|
127
90
|
/** returns the ping in ms (as a promise) */
|
package/lib/components/game.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
import { MsgPacker } from "../MsgPacker";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { SnapshotItemTypes } from "../enums_types/types";
|
|
5
4
|
import { Client } from "../client";
|
|
6
|
-
|
|
5
|
+
import { NETMSG } from "../enums_types/protocol";
|
|
7
6
|
|
|
8
7
|
export class Game {
|
|
9
8
|
// SendMsgEx: (Msgs: MsgPacker[] | MsgPacker) => void;
|
|
@@ -24,7 +23,7 @@ export class Game {
|
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
Say(message: string, team = false) {
|
|
27
|
-
var packer = new MsgPacker(
|
|
26
|
+
var packer = new MsgPacker(NETMSG.Game.CL_SAY, false, 1);
|
|
28
27
|
packer.AddInt(team ? 1 : 0); // team
|
|
29
28
|
packer.AddString(message);
|
|
30
29
|
this.send(packer);
|
|
@@ -33,7 +32,7 @@ export class Game {
|
|
|
33
32
|
|
|
34
33
|
/** Set the team of an bot. (-1 spectator team, 0 team red/normal team, 1 team blue) */
|
|
35
34
|
SetTeam(team: number) {
|
|
36
|
-
var packer = new MsgPacker(
|
|
35
|
+
var packer = new MsgPacker(NETMSG.Game.CL_SETTEAM, false, 1);
|
|
37
36
|
packer.AddInt(team);
|
|
38
37
|
this.send(packer);
|
|
39
38
|
}
|
|
@@ -41,7 +40,7 @@ export class Game {
|
|
|
41
40
|
|
|
42
41
|
/** Spectate an player, taking their id as parameter. pretty useless */
|
|
43
42
|
SpectatorMode(SpectatorID: number) {
|
|
44
|
-
var packer = new MsgPacker(
|
|
43
|
+
var packer = new MsgPacker(NETMSG.Game.CL_SETSPECTATORMODE, false, 1);
|
|
45
44
|
packer.AddInt(SpectatorID);
|
|
46
45
|
this.send(packer);
|
|
47
46
|
}
|
|
@@ -49,8 +48,8 @@ export class Game {
|
|
|
49
48
|
|
|
50
49
|
|
|
51
50
|
/** Change the player info */
|
|
52
|
-
ChangePlayerInfo(playerInfo: ClientInfo) {
|
|
53
|
-
var packer = new MsgPacker(
|
|
51
|
+
ChangePlayerInfo(playerInfo: SnapshotItemTypes.ClientInfo) {
|
|
52
|
+
var packer = new MsgPacker(NETMSG.Game.CL_CHANGEINFO, false, 1);
|
|
54
53
|
packer.AddString(playerInfo.name);
|
|
55
54
|
packer.AddString(playerInfo.clan);
|
|
56
55
|
packer.AddInt(playerInfo.country);
|
|
@@ -64,14 +63,14 @@ export class Game {
|
|
|
64
63
|
|
|
65
64
|
/** Kill */
|
|
66
65
|
Kill() {
|
|
67
|
-
var packer = new MsgPacker(
|
|
66
|
+
var packer = new MsgPacker(NETMSG.Game.CL_KILL, false, 1);
|
|
68
67
|
this.send(packer);
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
|
|
72
71
|
/** Send emote */
|
|
73
72
|
Emote(emote: number) {
|
|
74
|
-
var packer = new MsgPacker(
|
|
73
|
+
var packer = new MsgPacker(NETMSG.Game.CL_EMOTICON, false, 1);
|
|
75
74
|
packer.AddInt(emote);
|
|
76
75
|
this.send(packer);
|
|
77
76
|
}
|
|
@@ -79,13 +78,13 @@ export class Game {
|
|
|
79
78
|
|
|
80
79
|
/** Vote for an already running vote (true = f3 / false = f4) */
|
|
81
80
|
Vote(vote: boolean) {
|
|
82
|
-
var packer = new MsgPacker(
|
|
81
|
+
var packer = new MsgPacker(NETMSG.Game.CL_VOTE, false, 1);
|
|
83
82
|
packer.AddInt(vote ? 1 : -1);
|
|
84
83
|
this.send(packer);
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
private CallVote(Type: "option" | "kick" | "spectate", Value: string|number, Reason: string) {
|
|
88
|
-
var packer = new MsgPacker(
|
|
87
|
+
var packer = new MsgPacker(NETMSG.Game.CL_CALLVOTE, false, 1);
|
|
89
88
|
packer.AddString(Type);
|
|
90
89
|
packer.AddString(String(Value));
|
|
91
90
|
packer.AddString(Reason);
|
|
@@ -111,7 +110,7 @@ export class Game {
|
|
|
111
110
|
|
|
112
111
|
/** probably some verification of using ddnet client. */
|
|
113
112
|
IsDDNetLegacy() {
|
|
114
|
-
var packer = new MsgPacker(
|
|
113
|
+
var packer = new MsgPacker(NETMSG.Game.CL_ISDDNETLEGACY, false, 1);
|
|
115
114
|
this.send(packer);
|
|
116
115
|
}
|
|
117
116
|
|
|
@@ -0,0 +1,122 @@
|
|
|
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;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
|
|
2
|
+
import { EventEmitter } from "stream";
|
|
3
|
+
import { MsgPacker } from "../MsgPacker";
|
|
4
|
+
import { MsgUnpacker } from "../MsgUnpacker";
|
|
5
|
+
import { Client } from "../client";
|
|
6
|
+
import { NETMSG } from "../enums_types/protocol";
|
|
7
|
+
import { Chunk, RconCommand } from "../enums_types/types";
|
|
8
|
+
|
|
9
|
+
interface RconEvents {
|
|
10
|
+
rcon_line: (line: string) => void;
|
|
11
|
+
rcon_auth_status: (info: {AuthLevel: number, ReceiveCommands: number}) => void;
|
|
12
|
+
rcon_cmd_add: (info: {command: string, description: string, params: string}) => void;
|
|
13
|
+
rcon_cmd_rem: (info: {command: string}) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export class Rcon extends EventEmitter {
|
|
18
|
+
on<K extends keyof RconEvents>(event: K, listener: RconEvents[K]): this {
|
|
19
|
+
return super.on(event, listener);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
emit<K extends keyof RconEvents>(event: K, ...args: Parameters<RconEvents[K]>): boolean {
|
|
23
|
+
return super.emit(event, ...args);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
CommandList: RconCommand[] = [];
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
private _client: Client;
|
|
30
|
+
constructor(_client: Client) {
|
|
31
|
+
super();
|
|
32
|
+
this._client = _client;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// SendMsgEx: (Msgs: MsgPacker[] | MsgPacker) => void;
|
|
36
|
+
private send(packer: MsgPacker | MsgPacker[]) {
|
|
37
|
+
if (!this._client.options?.lightweight)
|
|
38
|
+
this._client.QueueChunkEx(packer);
|
|
39
|
+
else
|
|
40
|
+
this._client.SendMsgEx(packer);
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
public auth(username: string, password: string): void;
|
|
44
|
+
public auth(password: string): void;
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
/** Rcon auth, set the `username` to empty string for authentication w/o username **/
|
|
48
|
+
auth(usernameOrPassword: string, password?: string) {
|
|
49
|
+
const rconAuthMsg = new MsgPacker(NETMSG.System.NETMSG_RCON_AUTH, true, 1);
|
|
50
|
+
if (password == undefined) {
|
|
51
|
+
rconAuthMsg.AddString("");
|
|
52
|
+
rconAuthMsg.AddString(usernameOrPassword);
|
|
53
|
+
|
|
54
|
+
} else {
|
|
55
|
+
rconAuthMsg.AddString(usernameOrPassword);
|
|
56
|
+
rconAuthMsg.AddString(password);
|
|
57
|
+
}
|
|
58
|
+
rconAuthMsg.AddInt(1);
|
|
59
|
+
this.send(rconAuthMsg);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Send rcon command **/
|
|
63
|
+
rcon(cmds: string[] | string) {
|
|
64
|
+
let _cmds: string[];
|
|
65
|
+
if (cmds instanceof Array) _cmds = cmds
|
|
66
|
+
else _cmds = [cmds];
|
|
67
|
+
const msgs: MsgPacker[] = [];
|
|
68
|
+
_cmds.forEach((cmd) => {
|
|
69
|
+
const rconCmdMsg = new MsgPacker(NETMSG.System.NETMSG_RCON_CMD, true, 1);
|
|
70
|
+
rconCmdMsg.AddString(cmd);
|
|
71
|
+
msgs.push(rconCmdMsg);
|
|
72
|
+
})
|
|
73
|
+
this.send(msgs);
|
|
74
|
+
}
|
|
75
|
+
/** This method is called by the Client to handle the chunks. It should not be called directly. */
|
|
76
|
+
_checkChunks(chunk: Chunk): boolean {
|
|
77
|
+
if (chunk.msgid == NETMSG.System.NETMSG_RCON_LINE) {
|
|
78
|
+
const unpacker = new MsgUnpacker(chunk.raw);
|
|
79
|
+
const msg = unpacker.unpackString();
|
|
80
|
+
this.emit('rcon_line', msg);
|
|
81
|
+
|
|
82
|
+
} else if (chunk.msgid == NETMSG.System.NETMSG_RCON_AUTH_STATUS) {
|
|
83
|
+
const unpacker = new MsgUnpacker(chunk.raw);
|
|
84
|
+
const AuthLevel = unpacker.unpackInt();
|
|
85
|
+
const ReceiveCommands = unpacker.unpackInt();
|
|
86
|
+
this.emit('rcon_auth_status', {AuthLevel, ReceiveCommands});
|
|
87
|
+
} else if (chunk.msgid == NETMSG.System.NETMSG_RCON_CMD_ADD) {
|
|
88
|
+
const unpacker = new MsgUnpacker(chunk.raw);
|
|
89
|
+
const command = unpacker.unpackString();
|
|
90
|
+
const description = unpacker.unpackString();
|
|
91
|
+
const params = unpacker.unpackString();
|
|
92
|
+
|
|
93
|
+
this.CommandList.push({command, description, params});
|
|
94
|
+
|
|
95
|
+
this.emit('rcon_cmd_add', {command, description, params});
|
|
96
|
+
} else if (chunk.msgid == NETMSG.System.NETMSG_RCON_CMD_REM) {
|
|
97
|
+
const unpacker = new MsgUnpacker(chunk.raw);
|
|
98
|
+
const command = unpacker.unpackString();
|
|
99
|
+
this.emit('rcon_cmd_rem', {command});
|
|
100
|
+
|
|
101
|
+
let index = this.CommandList.findIndex(a => a.command == command);
|
|
102
|
+
if (index -1 >= 0)
|
|
103
|
+
this.CommandList.splice(index, 1);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
}
|
|
@@ -17,30 +17,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.SnapshotWrapper = void 0;
|
|
19
19
|
var stream_1 = require("stream");
|
|
20
|
-
var items;
|
|
21
|
-
(function (items) {
|
|
22
|
-
items[items["OBJ_EX"] = 0] = "OBJ_EX";
|
|
23
|
-
items[items["OBJ_PLAYER_INPUT"] = 1] = "OBJ_PLAYER_INPUT";
|
|
24
|
-
items[items["OBJ_PROJECTILE"] = 2] = "OBJ_PROJECTILE";
|
|
25
|
-
items[items["OBJ_LASER"] = 3] = "OBJ_LASER";
|
|
26
|
-
items[items["OBJ_PICKUP"] = 4] = "OBJ_PICKUP";
|
|
27
|
-
items[items["OBJ_FLAG"] = 5] = "OBJ_FLAG";
|
|
28
|
-
items[items["OBJ_GAME_INFO"] = 6] = "OBJ_GAME_INFO";
|
|
29
|
-
items[items["OBJ_GAME_DATA"] = 7] = "OBJ_GAME_DATA";
|
|
30
|
-
items[items["OBJ_CHARACTER_CORE"] = 8] = "OBJ_CHARACTER_CORE";
|
|
31
|
-
items[items["OBJ_CHARACTER"] = 9] = "OBJ_CHARACTER";
|
|
32
|
-
items[items["OBJ_PLAYER_INFO"] = 10] = "OBJ_PLAYER_INFO";
|
|
33
|
-
items[items["OBJ_CLIENT_INFO"] = 11] = "OBJ_CLIENT_INFO";
|
|
34
|
-
items[items["OBJ_SPECTATOR_INFO"] = 12] = "OBJ_SPECTATOR_INFO";
|
|
35
|
-
items[items["EVENT_COMMON"] = 13] = "EVENT_COMMON";
|
|
36
|
-
items[items["EVENT_EXPLOSION"] = 14] = "EVENT_EXPLOSION";
|
|
37
|
-
items[items["EVENT_SPAWN"] = 15] = "EVENT_SPAWN";
|
|
38
|
-
items[items["EVENT_HAMMERHIT"] = 16] = "EVENT_HAMMERHIT";
|
|
39
|
-
items[items["EVENT_DEATH"] = 17] = "EVENT_DEATH";
|
|
40
|
-
items[items["EVENT_SOUND_GLOBAL"] = 18] = "EVENT_SOUND_GLOBAL";
|
|
41
|
-
items[items["EVENT_SOUND_WORLD"] = 19] = "EVENT_SOUND_WORLD";
|
|
42
|
-
items[items["EVENT_DAMAGE_INDICATOR"] = 20] = "EVENT_DAMAGE_INDICATOR";
|
|
43
|
-
})(items || (items = {}));
|
|
44
20
|
var SnapshotWrapper = /** @class */ (function (_super) {
|
|
45
21
|
__extends(SnapshotWrapper, _super);
|
|
46
22
|
function SnapshotWrapper(_client) {
|
|
@@ -68,125 +44,125 @@ var SnapshotWrapper = /** @class */ (function (_super) {
|
|
|
68
44
|
// return this._client.rawSnapUnpacker.deltas.filter(delta => delta.type_id == type_id && delta.id == id).map(a => a.parsed);
|
|
69
45
|
};
|
|
70
46
|
SnapshotWrapper.prototype.getObjPlayerInput = function (player_id) {
|
|
71
|
-
return this.getParsed(
|
|
47
|
+
return this.getParsed(1 /* SnapshotItemIDs.OBJ_PLAYER_INPUT */, player_id);
|
|
72
48
|
};
|
|
73
49
|
Object.defineProperty(SnapshotWrapper.prototype, "AllObjPlayerInput", {
|
|
74
50
|
get: function () {
|
|
75
|
-
return this.getAll(
|
|
51
|
+
return this.getAll(1 /* SnapshotItemIDs.OBJ_PLAYER_INPUT */);
|
|
76
52
|
},
|
|
77
53
|
enumerable: false,
|
|
78
54
|
configurable: true
|
|
79
55
|
});
|
|
80
56
|
SnapshotWrapper.prototype.getObjProjectile = function (id) {
|
|
81
|
-
return this.getParsed(
|
|
57
|
+
return this.getParsed(2 /* SnapshotItemIDs.OBJ_PROJECTILE */, id);
|
|
82
58
|
};
|
|
83
59
|
Object.defineProperty(SnapshotWrapper.prototype, "AllProjectiles", {
|
|
84
60
|
get: function () {
|
|
85
|
-
return this.getAll(
|
|
61
|
+
return this.getAll(2 /* SnapshotItemIDs.OBJ_PROJECTILE */);
|
|
86
62
|
},
|
|
87
63
|
enumerable: false,
|
|
88
64
|
configurable: true
|
|
89
65
|
});
|
|
90
66
|
SnapshotWrapper.prototype.getObjLaser = function (id) {
|
|
91
|
-
return this.getParsed(
|
|
67
|
+
return this.getParsed(3 /* SnapshotItemIDs.OBJ_LASER */, id);
|
|
92
68
|
};
|
|
93
69
|
Object.defineProperty(SnapshotWrapper.prototype, "AllObjLaser", {
|
|
94
70
|
get: function () {
|
|
95
|
-
return this.getAll(
|
|
71
|
+
return this.getAll(3 /* SnapshotItemIDs.OBJ_LASER */);
|
|
96
72
|
},
|
|
97
73
|
enumerable: false,
|
|
98
74
|
configurable: true
|
|
99
75
|
});
|
|
100
76
|
SnapshotWrapper.prototype.getObjPickup = function (id) {
|
|
101
|
-
return this.getParsed(
|
|
77
|
+
return this.getParsed(4 /* SnapshotItemIDs.OBJ_PICKUP */, id);
|
|
102
78
|
};
|
|
103
79
|
Object.defineProperty(SnapshotWrapper.prototype, "AllObjPickup", {
|
|
104
80
|
get: function () {
|
|
105
|
-
return this.getAll(
|
|
81
|
+
return this.getAll(4 /* SnapshotItemIDs.OBJ_PICKUP */);
|
|
106
82
|
},
|
|
107
83
|
enumerable: false,
|
|
108
84
|
configurable: true
|
|
109
85
|
});
|
|
110
86
|
SnapshotWrapper.prototype.getObjFlag = function (id) {
|
|
111
|
-
return this.getParsed(
|
|
87
|
+
return this.getParsed(5 /* SnapshotItemIDs.OBJ_FLAG */, id);
|
|
112
88
|
};
|
|
113
89
|
Object.defineProperty(SnapshotWrapper.prototype, "AllObjFlag", {
|
|
114
90
|
get: function () {
|
|
115
|
-
return this.getAll(
|
|
91
|
+
return this.getAll(5 /* SnapshotItemIDs.OBJ_FLAG */);
|
|
116
92
|
},
|
|
117
93
|
enumerable: false,
|
|
118
94
|
configurable: true
|
|
119
95
|
});
|
|
120
96
|
SnapshotWrapper.prototype.getObjGameInfo = function (id) {
|
|
121
|
-
return this.getParsed(
|
|
97
|
+
return this.getParsed(6 /* SnapshotItemIDs.OBJ_GAME_INFO */, id);
|
|
122
98
|
};
|
|
123
99
|
Object.defineProperty(SnapshotWrapper.prototype, "AllObjGameInfo", {
|
|
124
100
|
get: function () {
|
|
125
|
-
return this.getAll(
|
|
101
|
+
return this.getAll(6 /* SnapshotItemIDs.OBJ_GAME_INFO */);
|
|
126
102
|
},
|
|
127
103
|
enumerable: false,
|
|
128
104
|
configurable: true
|
|
129
105
|
});
|
|
130
106
|
SnapshotWrapper.prototype.getObjGameData = function (id) {
|
|
131
|
-
return this.getParsed(
|
|
107
|
+
return this.getParsed(7 /* SnapshotItemIDs.OBJ_GAME_DATA */, id);
|
|
132
108
|
};
|
|
133
109
|
Object.defineProperty(SnapshotWrapper.prototype, "AllObjGameData", {
|
|
134
110
|
get: function () {
|
|
135
|
-
return this.getAll(
|
|
111
|
+
return this.getAll(7 /* SnapshotItemIDs.OBJ_GAME_DATA */);
|
|
136
112
|
},
|
|
137
113
|
enumerable: false,
|
|
138
114
|
configurable: true
|
|
139
115
|
});
|
|
140
116
|
/** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
|
|
141
117
|
SnapshotWrapper.prototype.getObjCharacterCore = function (player_id) {
|
|
142
|
-
return this.getParsed(
|
|
118
|
+
return this.getParsed(8 /* SnapshotItemIDs.OBJ_CHARACTER_CORE */, player_id);
|
|
143
119
|
};
|
|
144
120
|
Object.defineProperty(SnapshotWrapper.prototype, "AllObjCharacterCore", {
|
|
145
121
|
/** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
|
|
146
122
|
get: function () {
|
|
147
|
-
return this.getAll(
|
|
123
|
+
return this.getAll(8 /* SnapshotItemIDs.OBJ_CHARACTER_CORE */);
|
|
148
124
|
},
|
|
149
125
|
enumerable: false,
|
|
150
126
|
configurable: true
|
|
151
127
|
});
|
|
152
128
|
/** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
|
|
153
129
|
SnapshotWrapper.prototype.getObjCharacter = function (player_id) {
|
|
154
|
-
return this.getParsed(
|
|
130
|
+
return this.getParsed(9 /* SnapshotItemIDs.OBJ_CHARACTER */, player_id);
|
|
155
131
|
};
|
|
156
132
|
Object.defineProperty(SnapshotWrapper.prototype, "AllObjCharacter", {
|
|
157
133
|
/** NOTICE: x & y positions always differ from the positions in the ingame debug menu. If you want the debug menu positions, you can calculate them like this: Math.round((myChar.character_core.x / 32) * 100)/100 */
|
|
158
134
|
get: function () {
|
|
159
|
-
return this.getAll(
|
|
135
|
+
return this.getAll(9 /* SnapshotItemIDs.OBJ_CHARACTER */);
|
|
160
136
|
},
|
|
161
137
|
enumerable: false,
|
|
162
138
|
configurable: true
|
|
163
139
|
});
|
|
164
140
|
SnapshotWrapper.prototype.getObjPlayerInfo = function (player_id) {
|
|
165
|
-
return this.getParsed(
|
|
141
|
+
return this.getParsed(10 /* SnapshotItemIDs.OBJ_PLAYER_INFO */, player_id);
|
|
166
142
|
};
|
|
167
143
|
Object.defineProperty(SnapshotWrapper.prototype, "AllObjPlayerInfo", {
|
|
168
144
|
get: function () {
|
|
169
|
-
return this.getAll(
|
|
145
|
+
return this.getAll(10 /* SnapshotItemIDs.OBJ_PLAYER_INFO */);
|
|
170
146
|
},
|
|
171
147
|
enumerable: false,
|
|
172
148
|
configurable: true
|
|
173
149
|
});
|
|
174
150
|
SnapshotWrapper.prototype.getObjClientInfo = function (player_id) {
|
|
175
|
-
return this.getParsed(
|
|
151
|
+
return this.getParsed(11 /* SnapshotItemIDs.OBJ_CLIENT_INFO */, player_id);
|
|
176
152
|
};
|
|
177
153
|
Object.defineProperty(SnapshotWrapper.prototype, "AllObjClientInfo", {
|
|
178
154
|
get: function () {
|
|
179
|
-
return this.getAll(
|
|
155
|
+
return this.getAll(11 /* SnapshotItemIDs.OBJ_CLIENT_INFO */);
|
|
180
156
|
},
|
|
181
157
|
enumerable: false,
|
|
182
158
|
configurable: true
|
|
183
159
|
});
|
|
184
160
|
SnapshotWrapper.prototype.getObjSpectatorInfo = function (player_id) {
|
|
185
|
-
return this.getParsed(
|
|
161
|
+
return this.getParsed(12 /* SnapshotItemIDs.OBJ_SPECTATOR_INFO */, player_id);
|
|
186
162
|
};
|
|
187
163
|
Object.defineProperty(SnapshotWrapper.prototype, "AllObjSpectatorInfo", {
|
|
188
164
|
get: function () {
|
|
189
|
-
return this.getAll(
|
|
165
|
+
return this.getAll(12 /* SnapshotItemIDs.OBJ_SPECTATOR_INFO */);
|
|
190
166
|
},
|
|
191
167
|
enumerable: false,
|
|
192
168
|
configurable: true
|