teeworlds 2.4.4 → 2.4.7
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 +7 -7
- package/docs/events.md +367 -0
- package/docs/examples/chat_bot.js +25 -0
- package/docs/examples/kill_on_freeze.js +20 -0
- package/index.js +0 -1
- package/index.ts +1 -2
- package/lib/MsgUnpacker.js +6 -0
- package/lib/MsgUnpacker.ts +7 -0
- package/lib/UUIDManager.js +50 -0
- package/lib/UUIDManager.ts +45 -0
- package/lib/client.js +149 -99
- package/lib/client.ts +197 -126
- package/lib/components/game.js +11 -11
- package/lib/components/game.ts +33 -21
- package/lib/{movement.js → components/movement.js} +28 -0
- package/lib/{movement.ts → components/movement.ts} +25 -0
- package/lib/components/snapshot.js +258 -0
- package/lib/components/snapshot.ts +219 -0
- package/lib/snapshot.js +143 -90
- package/lib/snapshot.ts +166 -106
- package/lib/snapshots.d.ts +81 -29
- package/package.json +1 -1
- package/test.js +57 -0
package/lib/client.js
CHANGED
|
@@ -23,11 +23,13 @@ var crypto_1 = require("crypto");
|
|
|
23
23
|
var dgram_1 = __importDefault(require("dgram"));
|
|
24
24
|
var stream_1 = require("stream");
|
|
25
25
|
var MsgUnpacker_1 = require("./MsgUnpacker");
|
|
26
|
-
var movement_1 = __importDefault(require("./movement"));
|
|
26
|
+
var movement_1 = __importDefault(require("./components/movement"));
|
|
27
27
|
var MsgPacker_1 = require("./MsgPacker");
|
|
28
28
|
var snapshot_1 = require("./snapshot");
|
|
29
29
|
var huffman_1 = __importDefault(require("./huffman"));
|
|
30
30
|
var game_1 = require("./components/game");
|
|
31
|
+
var snapshot_2 = require("./components/snapshot");
|
|
32
|
+
var UUIDManager_1 = require("./UUIDManager");
|
|
31
33
|
var huff = new huffman_1.default();
|
|
32
34
|
var States;
|
|
33
35
|
(function (States) {
|
|
@@ -111,34 +113,23 @@ var NETMSG_Sys;
|
|
|
111
113
|
NETMSG_Sys[NETMSG_Sys["NETMSG_RCON_CMD_ADD"] = 25] = "NETMSG_RCON_CMD_ADD";
|
|
112
114
|
NETMSG_Sys[NETMSG_Sys["NETMSG_RCON_CMD_REM"] = 26] = "NETMSG_RCON_CMD_REM";
|
|
113
115
|
NETMSG_Sys[NETMSG_Sys["NUM_NETMSGS"] = 27] = "NUM_NETMSGS";
|
|
116
|
+
NETMSG_Sys[NETMSG_Sys["NETMSG_WHATIS"] = 65536] = "NETMSG_WHATIS";
|
|
117
|
+
NETMSG_Sys[NETMSG_Sys["NETMSG_ITIS"] = 65537] = "NETMSG_ITIS";
|
|
118
|
+
NETMSG_Sys[NETMSG_Sys["NETMSG_IDONTKNOW"] = 65538] = "NETMSG_IDONTKNOW";
|
|
119
|
+
NETMSG_Sys[NETMSG_Sys["NETMSG_RCONTYPE"] = 65539] = "NETMSG_RCONTYPE";
|
|
120
|
+
NETMSG_Sys[NETMSG_Sys["NETMSG_MAP_DETAILS"] = 65540] = "NETMSG_MAP_DETAILS";
|
|
121
|
+
NETMSG_Sys[NETMSG_Sys["NETMSG_CAPABILITIES"] = 65541] = "NETMSG_CAPABILITIES";
|
|
122
|
+
NETMSG_Sys[NETMSG_Sys["NETMSG_CLIENTVER"] = 65542] = "NETMSG_CLIENTVER";
|
|
123
|
+
NETMSG_Sys[NETMSG_Sys["NETMSG_PINGEX"] = 65543] = "NETMSG_PINGEX";
|
|
124
|
+
NETMSG_Sys[NETMSG_Sys["NETMSG_PONGEX"] = 65544] = "NETMSG_PONGEX";
|
|
125
|
+
NETMSG_Sys[NETMSG_Sys["NETMSG_CHECKSUM_REQUEST"] = 65545] = "NETMSG_CHECKSUM_REQUEST";
|
|
126
|
+
NETMSG_Sys[NETMSG_Sys["NETMSG_CHECKSUM_RESPONSE"] = 65546] = "NETMSG_CHECKSUM_RESPONSE";
|
|
127
|
+
NETMSG_Sys[NETMSG_Sys["NETMSG_CHECKSUM_ERROR"] = 65547] = "NETMSG_CHECKSUM_ERROR";
|
|
114
128
|
})(NETMSG_Sys || (NETMSG_Sys = {}));
|
|
115
|
-
function toHexStream(buff) {
|
|
116
|
-
return buff.toJSON().data.map(function (a) { return ('0' + (a & 0xff).toString(16)).slice(-2); }).join("");
|
|
117
|
-
}
|
|
118
129
|
var messageTypes = [
|
|
119
130
|
["none, starts at 1", "SV_MOTD", "SV_BROADCAST", "SV_CHAT", "SV_KILL_MSG", "SV_SOUND_GLOBAL", "SV_TUNE_PARAMS", "SV_EXTRA_PROJECTILE", "SV_READY_TO_ENTER", "SV_WEAPON_PICKUP", "SV_EMOTICON", "SV_VOTE_CLEAR_OPTIONS", "SV_VOTE_OPTION_LIST_ADD", "SV_VOTE_OPTION_ADD", "SV_VOTE_OPTION_REMOVE", "SV_VOTE_SET", "SV_VOTE_STATUS", "CL_SAY", "CL_SET_TEAM", "CL_SET_SPECTATOR_MODE", "CL_START_INFO", "CL_CHANGE_INFO", "CL_KILL", "CL_EMOTICON", "CL_VOTE", "CL_CALL_VOTE", "CL_IS_DDNET", "SV_DDRACE_TIME", "SV_RECORD", "UNUSED", "SV_TEAMS_STATE", "CL_SHOW_OTHERS_LEGACY"],
|
|
120
131
|
["none, starts at 1", "INFO", "MAP_CHANGE", "MAP_DATA", "CON_READY", "SNAP", "SNAP_EMPTY", "SNAP_SINGLE", "INPUT_TIMING", "RCON_AUTH_STATUS", "RCON_LINE", "READY", "ENTER_GAME", "INPUT", "RCON_CMD", "RCON_AUTH", "REQUEST_MAP_DATA", "PING", "PING_REPLY", "RCON_CMD_ADD", "RCON_CMD_REMOVE"]
|
|
121
132
|
];
|
|
122
|
-
var messageUUIDs = {
|
|
123
|
-
"WHAT_IS": Buffer.from([0x24, 0x5e, 0x50, 0x97, 0x9f, 0xe0, 0x39, 0xd6, 0xbf, 0x7d, 0x9a, 0x29, 0xe1, 0x69, 0x1e, 0x4c]),
|
|
124
|
-
"IT_IS": Buffer.from([0x69, 0x54, 0x84, 0x7e, 0x2e, 0x87, 0x36, 0x03, 0xb5, 0x62, 0x36, 0xda, 0x29, 0xed, 0x1a, 0xca]),
|
|
125
|
-
"I_DONT_KNOW": Buffer.from([0x41, 0x69, 0x11, 0xb5, 0x79, 0x73, 0x33, 0xbf, 0x8d, 0x52, 0x7b, 0xf0, 0x1e, 0x51, 0x9c, 0xf0]),
|
|
126
|
-
"RCON_TYPE": Buffer.from([0x12, 0x81, 0x0e, 0x1f, 0xa1, 0xdb, 0x33, 0x78, 0xb4, 0xfb, 0x16, 0x4e, 0xd6, 0x50, 0x59, 0x26]),
|
|
127
|
-
"MAP_DETAILS": Buffer.from([0xf9, 0x11, 0x7b, 0x3c, 0x80, 0x39, 0x34, 0x16, 0x9f, 0xc0, 0xae, 0xf2, 0xbc, 0xb7, 0x5c, 0x03]),
|
|
128
|
-
"CLIENT_VERSION": Buffer.from([0x8c, 0x00, 0x13, 0x04, 0x84, 0x61, 0x3e, 0x47, 0x87, 0x87, 0xf6, 0x72, 0xb3, 0x83, 0x5b, 0xd4]),
|
|
129
|
-
"CAPABILITIES": Buffer.from([0xf6, 0x21, 0xa5, 0xa1, 0xf5, 0x85, 0x37, 0x75, 0x8e, 0x73, 0x41, 0xbe, 0xee, 0x79, 0xf2, 0xb2]),
|
|
130
|
-
};
|
|
131
|
-
function arrStartsWith(arr, arrStart, start) {
|
|
132
|
-
if (start === void 0) { start = 0; }
|
|
133
|
-
arr.splice(0, start);
|
|
134
|
-
for (var i = 0; i < arrStart.length; i++) {
|
|
135
|
-
if (arr[i] == arrStart[i])
|
|
136
|
-
continue;
|
|
137
|
-
else
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
133
|
var Client = /** @class */ (function (_super) {
|
|
143
134
|
__extends(Client, _super);
|
|
144
135
|
function Client(ip, port, nickname, options) {
|
|
@@ -150,7 +141,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
150
141
|
_this.PredGameTick = 0;
|
|
151
142
|
_this.currentSnapshotGameTick = 0;
|
|
152
143
|
_this.SnapshotParts = 0;
|
|
153
|
-
_this.SnapUnpacker = new snapshot_1.Snapshot();
|
|
144
|
+
_this.SnapUnpacker = new snapshot_1.Snapshot(_this);
|
|
154
145
|
// this.eSnapHolder = [];
|
|
155
146
|
_this.requestResend = false;
|
|
156
147
|
_this.VoteList = [];
|
|
@@ -172,6 +163,20 @@ var Client = /** @class */ (function (_super) {
|
|
|
172
163
|
_this.lastSentMessages = [];
|
|
173
164
|
_this.movement = new movement_1.default();
|
|
174
165
|
_this.game = new game_1.Game(_this);
|
|
166
|
+
_this.SnapshotUnpacker = new snapshot_2.SnapshotWrapper(_this);
|
|
167
|
+
_this.UUIDManager = new UUIDManager_1.UUIDManager();
|
|
168
|
+
_this.UUIDManager.RegisterName("what-is@ddnet.tw", NETMSG_Sys.NETMSG_WHATIS);
|
|
169
|
+
_this.UUIDManager.RegisterName("it-is@ddnet.tw", NETMSG_Sys.NETMSG_ITIS);
|
|
170
|
+
_this.UUIDManager.RegisterName("i-dont-know@ddnet.tw", NETMSG_Sys.NETMSG_IDONTKNOW);
|
|
171
|
+
_this.UUIDManager.RegisterName("rcon-type@ddnet.tw", NETMSG_Sys.NETMSG_RCONTYPE);
|
|
172
|
+
_this.UUIDManager.RegisterName("map-details@ddnet.tw", NETMSG_Sys.NETMSG_MAP_DETAILS);
|
|
173
|
+
_this.UUIDManager.RegisterName("capabilities@ddnet.tw", NETMSG_Sys.NETMSG_CAPABILITIES);
|
|
174
|
+
_this.UUIDManager.RegisterName("clientver@ddnet.tw", NETMSG_Sys.NETMSG_CLIENTVER);
|
|
175
|
+
_this.UUIDManager.RegisterName("ping@ddnet.tw", NETMSG_Sys.NETMSG_PING);
|
|
176
|
+
_this.UUIDManager.RegisterName("pong@ddnet.tw", NETMSG_Sys.NETMSG_PONGEX);
|
|
177
|
+
_this.UUIDManager.RegisterName("checksum-request@ddnet.tw", NETMSG_Sys.NETMSG_CHECKSUM_REQUEST);
|
|
178
|
+
_this.UUIDManager.RegisterName("checksum-response@ddnet.tw", NETMSG_Sys.NETMSG_CHECKSUM_RESPONSE);
|
|
179
|
+
_this.UUIDManager.RegisterName("checksum-error@ddnet.tw", NETMSG_Sys.NETMSG_CHECKSUM_ERROR);
|
|
175
180
|
return _this;
|
|
176
181
|
}
|
|
177
182
|
Client.prototype.ResendAfter = function (lastAck) {
|
|
@@ -213,18 +218,21 @@ var Client = /** @class */ (function (_super) {
|
|
|
213
218
|
chunk.msgid = (packet[0] - (packet[0] & 1)) / 2;
|
|
214
219
|
chunk.msg = messageTypes[packet[0] & 1][chunk.msgid];
|
|
215
220
|
chunk.raw = packet.slice(1, chunk.bytes);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
chunk.
|
|
221
|
+
if (chunk.msgid == 0 && chunk.raw.byteLength >= 16) {
|
|
222
|
+
var uuid = this.UUIDManager.LookupUUID(chunk.raw.slice(0, 16));
|
|
223
|
+
if (uuid !== undefined) {
|
|
224
|
+
chunk.extended_msgid = uuid.hash;
|
|
225
|
+
chunk.msg = uuid.name;
|
|
226
|
+
chunk.raw = chunk.raw.slice(16);
|
|
227
|
+
chunk.msgid = uuid.type_id;
|
|
220
228
|
}
|
|
221
|
-
}
|
|
229
|
+
}
|
|
222
230
|
packet = packet.slice(chunk.bytes);
|
|
223
231
|
unpacked.chunks.push(chunk);
|
|
224
232
|
}
|
|
225
233
|
return unpacked;
|
|
226
234
|
};
|
|
227
|
-
|
|
235
|
+
/** Send a Control Msg to the server. (used for disconnect)*/
|
|
228
236
|
Client.prototype.SendControlMsg = function (msg, ExtraMsg) {
|
|
229
237
|
var _this = this;
|
|
230
238
|
if (ExtraMsg === void 0) { ExtraMsg = ""; }
|
|
@@ -244,9 +252,10 @@ var Client = /** @class */ (function (_super) {
|
|
|
244
252
|
*/
|
|
245
253
|
});
|
|
246
254
|
};
|
|
247
|
-
|
|
248
|
-
Client.prototype.SendMsgEx = function (Msgs) {
|
|
255
|
+
/** Send a Msg (or Msg[]) to the server.*/
|
|
256
|
+
Client.prototype.SendMsgEx = function (Msgs, flags) {
|
|
249
257
|
var _this = this;
|
|
258
|
+
if (flags === void 0) { flags = 0; }
|
|
250
259
|
if (this.State == States.STATE_OFFLINE)
|
|
251
260
|
return;
|
|
252
261
|
if (!this.socket)
|
|
@@ -282,7 +291,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
282
291
|
_this.lastSentMessages.push({ msg: Msg, ack: _this.clientAck });
|
|
283
292
|
}
|
|
284
293
|
});
|
|
285
|
-
|
|
294
|
+
// let flags = 0;
|
|
286
295
|
if (this.requestResend)
|
|
287
296
|
flags |= 4;
|
|
288
297
|
var packetHeader = Buffer.from([((flags << 4) & 0xf0) | ((this.ack >> 8) & 0xf), this.ack & 0xff, _Msgs.length]);
|
|
@@ -303,11 +312,11 @@ var Client = /** @class */ (function (_super) {
|
|
|
303
312
|
return;
|
|
304
313
|
this.socket.send(packet, 0, packet.length, this.port, this.host);
|
|
305
314
|
};
|
|
306
|
-
|
|
315
|
+
/** Queue a chunk (It will get sent in the next packet). */
|
|
307
316
|
Client.prototype.QueueChunkEx = function (Msg) {
|
|
308
317
|
this.queueChunkEx.push(Msg);
|
|
309
318
|
};
|
|
310
|
-
|
|
319
|
+
/** Send a Raw Buffer (as chunk) to the server. */
|
|
311
320
|
Client.prototype.SendMsgRaw = function (chunks) {
|
|
312
321
|
if (this.State == States.STATE_OFFLINE)
|
|
313
322
|
return;
|
|
@@ -336,15 +345,18 @@ var Client = /** @class */ (function (_super) {
|
|
|
336
345
|
chunk.msgid = (packet[0] - (packet[0] & 1)) / 2;
|
|
337
346
|
chunk.msg = messageTypes[packet[0] & 1][chunk.msgid];
|
|
338
347
|
chunk.raw = packet.slice(1, chunk.bytes);
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
chunk.
|
|
348
|
+
if (chunk.msgid == 0) {
|
|
349
|
+
var uuid = this.UUIDManager.LookupUUID(chunk.raw.slice(0, 16));
|
|
350
|
+
if (uuid !== undefined) {
|
|
351
|
+
chunk.extended_msgid = uuid.hash;
|
|
352
|
+
chunk.msgid = uuid.type_id;
|
|
353
|
+
chunk.msg = uuid.name;
|
|
354
|
+
chunk.raw = chunk.raw.slice(16);
|
|
343
355
|
}
|
|
344
|
-
}
|
|
356
|
+
}
|
|
345
357
|
return chunk;
|
|
346
358
|
};
|
|
347
|
-
|
|
359
|
+
/** Connect the client to the server. */
|
|
348
360
|
Client.prototype.connect = function () {
|
|
349
361
|
var _this = this;
|
|
350
362
|
var _a;
|
|
@@ -356,7 +368,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
356
368
|
}
|
|
357
369
|
else if (_this.State == States.STATE_OFFLINE)
|
|
358
370
|
clearInterval(predTimer);
|
|
359
|
-
},
|
|
371
|
+
}, 1000 / 50); // 50 ticks per second
|
|
360
372
|
this.SendControlMsg(1, "TKEN");
|
|
361
373
|
var connectInterval = setInterval(function () {
|
|
362
374
|
if (_this.State == States.STATE_CONNECTING)
|
|
@@ -372,7 +384,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
372
384
|
return;
|
|
373
385
|
_this.time = new Date().getTime();
|
|
374
386
|
_this.sendInput();
|
|
375
|
-
},
|
|
387
|
+
}, 50);
|
|
376
388
|
}
|
|
377
389
|
var resendTimeout = setInterval(function () {
|
|
378
390
|
if (_this.State != States.STATE_OFFLINE) {
|
|
@@ -412,16 +424,15 @@ var Client = /** @class */ (function (_super) {
|
|
|
412
424
|
info.AddString(((_b = _this.options) === null || _b === void 0 ? void 0 : _b.password) === undefined ? "" : (_c = _this.options) === null || _c === void 0 ? void 0 : _c.password); // password
|
|
413
425
|
var client_version = new MsgPacker_1.MsgPacker(0, true, 1);
|
|
414
426
|
client_version.AddBuffer(Buffer.from("8c00130484613e478787f672b3835bd4", 'hex'));
|
|
415
|
-
var randomUuid =
|
|
416
|
-
(0, crypto_1.randomBytes)(16).copy(randomUuid);
|
|
427
|
+
var randomUuid = (0, crypto_1.randomBytes)(16);
|
|
417
428
|
client_version.AddBuffer(randomUuid);
|
|
418
429
|
if (((_d = _this.options) === null || _d === void 0 ? void 0 : _d.ddnet_version) !== undefined) {
|
|
419
430
|
client_version.AddInt((_e = _this.options) === null || _e === void 0 ? void 0 : _e.ddnet_version.version);
|
|
420
431
|
client_version.AddString("DDNet " + ((_f = _this.options) === null || _f === void 0 ? void 0 : _f.ddnet_version.release_version));
|
|
421
432
|
}
|
|
422
433
|
else {
|
|
423
|
-
client_version.AddInt(
|
|
424
|
-
client_version.AddString("DDNet 16.0
|
|
434
|
+
client_version.AddInt(16050);
|
|
435
|
+
client_version.AddString("DDNet 16.5.0");
|
|
425
436
|
}
|
|
426
437
|
_this.SendMsgEx([client_version, info]);
|
|
427
438
|
}
|
|
@@ -551,15 +562,87 @@ var Client = /** @class */ (function (_super) {
|
|
|
551
562
|
var mergedSnaps = Buffer.concat(_this.snaps);
|
|
552
563
|
_this.SnapshotParts = 0;
|
|
553
564
|
var snapUnpacked = _this.SnapUnpacker.unpackSnapshot(mergedSnaps, DeltaTick, GameTick, Crc);
|
|
554
|
-
_this.emit("snapshot");
|
|
565
|
+
_this.emit("snapshot", snapUnpacked.items);
|
|
555
566
|
_this.AckGameTick = snapUnpacked.recvTick;
|
|
556
|
-
if (Math.abs(_this.PredGameTick - _this.AckGameTick) > 10)
|
|
567
|
+
if (Math.abs(_this.PredGameTick - _this.AckGameTick) > 10) {
|
|
557
568
|
_this.PredGameTick = _this.AckGameTick + 1;
|
|
558
|
-
|
|
569
|
+
_this.sendInput();
|
|
570
|
+
}
|
|
559
571
|
}
|
|
560
572
|
}
|
|
561
573
|
// })
|
|
562
574
|
}
|
|
575
|
+
if (chunk.msgid >= NETMSG_Sys.NETMSG_WHATIS && chunk.msgid <= NETMSG_Sys.NETMSG_CHECKSUM_ERROR) {
|
|
576
|
+
if (chunk.msgid == NETMSG_Sys.NETMSG_WHATIS) {
|
|
577
|
+
var Uuid = chunk.raw.slice(0, 16);
|
|
578
|
+
var uuid = _this.UUIDManager.LookupUUID(Uuid);
|
|
579
|
+
var packer = new MsgPacker_1.MsgPacker(0, true, 1);
|
|
580
|
+
if (uuid !== undefined) {
|
|
581
|
+
// IT_IS msg
|
|
582
|
+
packer.AddBuffer(_this.UUIDManager.LookupType(NETMSG_Sys.NETMSG_ITIS).hash);
|
|
583
|
+
packer.AddBuffer(Uuid);
|
|
584
|
+
packer.AddString(uuid.name);
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
// dont_know msg
|
|
588
|
+
packer.AddBuffer(_this.UUIDManager.LookupType(NETMSG_Sys.NETMSG_IDONTKNOW).hash);
|
|
589
|
+
packer.AddBuffer(Uuid);
|
|
590
|
+
}
|
|
591
|
+
_this.QueueChunkEx(packer);
|
|
592
|
+
}
|
|
593
|
+
if (chunk.msgid == NETMSG_Sys.NETMSG_MAP_DETAILS) { // TODO: option for downloading maps
|
|
594
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
|
|
595
|
+
var map_name = unpacker.unpackString();
|
|
596
|
+
var map_sha256 = Buffer.alloc(32);
|
|
597
|
+
if (unpacker.remaining.length >= 32)
|
|
598
|
+
map_sha256 = unpacker.unpackRaw(32);
|
|
599
|
+
var map_crc = unpacker.unpackInt();
|
|
600
|
+
var map_size = unpacker.unpackInt();
|
|
601
|
+
var map_url = "";
|
|
602
|
+
if (unpacker.remaining.length)
|
|
603
|
+
map_url = unpacker.unpackString();
|
|
604
|
+
_this.emit("map_details", { map_name: map_name, map_sha256: map_sha256, map_crc: map_crc, map_size: map_size, map_url: map_url });
|
|
605
|
+
// unpacker.unpack
|
|
606
|
+
}
|
|
607
|
+
else if (chunk.msgid == NETMSG_Sys.NETMSG_CAPABILITIES) {
|
|
608
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
|
|
609
|
+
var Version = unpacker.unpackInt();
|
|
610
|
+
var Flags = unpacker.unpackInt();
|
|
611
|
+
if (Version <= 0)
|
|
612
|
+
return;
|
|
613
|
+
var DDNet = false;
|
|
614
|
+
if (Version >= 1) {
|
|
615
|
+
DDNet = Boolean(Flags & 1);
|
|
616
|
+
}
|
|
617
|
+
var ChatTimeoutCode = DDNet;
|
|
618
|
+
var AnyPlayerFlag = DDNet;
|
|
619
|
+
var PingEx = false;
|
|
620
|
+
var AllowDummy = true;
|
|
621
|
+
var SyncWeaponInput = false;
|
|
622
|
+
if (Version >= 1) {
|
|
623
|
+
ChatTimeoutCode = Boolean(Flags & 2);
|
|
624
|
+
}
|
|
625
|
+
if (Version >= 2) {
|
|
626
|
+
AnyPlayerFlag = Boolean(Flags & 4);
|
|
627
|
+
}
|
|
628
|
+
if (Version >= 3) {
|
|
629
|
+
PingEx = Boolean(Flags & 8);
|
|
630
|
+
}
|
|
631
|
+
if (Version >= 4) {
|
|
632
|
+
AllowDummy = Boolean(Flags & 16);
|
|
633
|
+
}
|
|
634
|
+
if (Version >= 5) {
|
|
635
|
+
SyncWeaponInput = Boolean(Flags & 32);
|
|
636
|
+
}
|
|
637
|
+
_this.emit("capabilities", { ChatTimeoutCode: ChatTimeoutCode, AnyPlayerFlag: AnyPlayerFlag, PingEx: PingEx, AllowDummy: AllowDummy, SyncWeaponInput: SyncWeaponInput });
|
|
638
|
+
// https://github.com/ddnet/ddnet/blob/06e3eb564150e9ab81b3a5595c48e9fe5952ed32/src/engine/client/client.cpp#L1565
|
|
639
|
+
}
|
|
640
|
+
else if (chunk.msgid == NETMSG_Sys.NETMSG_PINGEX) {
|
|
641
|
+
var packer = new MsgPacker_1.MsgPacker(0, true, 2);
|
|
642
|
+
packer.AddBuffer(_this.UUIDManager.LookupType(NETMSG_Sys.NETMSG_PONGEX).hash);
|
|
643
|
+
_this.SendMsgEx(packer, 2);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
563
646
|
}
|
|
564
647
|
else {
|
|
565
648
|
// game messages
|
|
@@ -574,7 +657,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
574
657
|
for (var i = 0; i < 15; i++) {
|
|
575
658
|
list.push(unpacker.unpackString());
|
|
576
659
|
}
|
|
577
|
-
list = list.slice(NumOptions);
|
|
660
|
+
list = list.slice(0, NumOptions);
|
|
578
661
|
(_a = _this.VoteList).push.apply(_a, list);
|
|
579
662
|
}
|
|
580
663
|
else if (chunk.msgid == NETMSG_Game.SV_VOTEOPTIONADD) {
|
|
@@ -596,8 +679,8 @@ var Client = /** @class */ (function (_super) {
|
|
|
596
679
|
};
|
|
597
680
|
if (unpacked_1.client_id != -1) {
|
|
598
681
|
unpacked_1.author = {
|
|
599
|
-
ClientInfo: _this.
|
|
600
|
-
PlayerInfo: _this.
|
|
682
|
+
ClientInfo: _this.SnapshotUnpacker.getObjClientInfo(unpacked_1.client_id),
|
|
683
|
+
PlayerInfo: _this.SnapshotUnpacker.getObjPlayerInfo(unpacked_1.client_id)
|
|
601
684
|
};
|
|
602
685
|
}
|
|
603
686
|
_this.emit("emote", unpacked_1);
|
|
@@ -615,8 +698,8 @@ var Client = /** @class */ (function (_super) {
|
|
|
615
698
|
};
|
|
616
699
|
if (unpacked_2.client_id != -1) {
|
|
617
700
|
unpacked_2.author = {
|
|
618
|
-
ClientInfo: _this.
|
|
619
|
-
PlayerInfo: _this.
|
|
701
|
+
ClientInfo: _this.SnapshotUnpacker.getObjClientInfo(unpacked_2.client_id),
|
|
702
|
+
PlayerInfo: _this.SnapshotUnpacker.getObjPlayerInfo(unpacked_2.client_id)
|
|
620
703
|
};
|
|
621
704
|
}
|
|
622
705
|
_this.emit("message", unpacked_2);
|
|
@@ -629,10 +712,10 @@ var Client = /** @class */ (function (_super) {
|
|
|
629
712
|
unpacked_3.weapon = unpacker.unpackInt();
|
|
630
713
|
unpacked_3.special_mode = unpacker.unpackInt();
|
|
631
714
|
if (unpacked_3.victim_id != -1 && unpacked_3.victim_id < 64) {
|
|
632
|
-
unpacked_3.victim = { ClientInfo: _this.
|
|
715
|
+
unpacked_3.victim = { ClientInfo: _this.SnapshotUnpacker.getObjClientInfo(unpacked_3.victim_id), PlayerInfo: _this.SnapshotUnpacker.getObjPlayerInfo(unpacked_3.victim_id) };
|
|
633
716
|
}
|
|
634
717
|
if (unpacked_3.killer_id != -1 && unpacked_3.killer_id < 64)
|
|
635
|
-
unpacked_3.killer = { ClientInfo: _this.
|
|
718
|
+
unpacked_3.killer = { ClientInfo: _this.SnapshotUnpacker.getObjClientInfo(unpacked_3.killer_id), PlayerInfo: _this.SnapshotUnpacker.getObjPlayerInfo(unpacked_3.killer_id) };
|
|
636
719
|
_this.emit("kill", unpacked_3);
|
|
637
720
|
}
|
|
638
721
|
else if (chunk.msgid == NETMSG_Game.SV_MOTD) {
|
|
@@ -654,7 +737,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
654
737
|
}
|
|
655
738
|
});
|
|
656
739
|
};
|
|
657
|
-
|
|
740
|
+
/** Sending the input. (automatically done unless options.lightweight is on) */
|
|
658
741
|
Client.prototype.sendInput = function (input) {
|
|
659
742
|
if (input === void 0) { input = this.movement.input; }
|
|
660
743
|
if (this.State != States.STATE_ONLINE)
|
|
@@ -676,13 +759,14 @@ var Client = /** @class */ (function (_super) {
|
|
|
676
759
|
this.SendMsgEx(inputMsg);
|
|
677
760
|
};
|
|
678
761
|
Object.defineProperty(Client.prototype, "input", {
|
|
762
|
+
/** returns the movement object of the client */
|
|
679
763
|
get: function () {
|
|
680
764
|
return this.movement.input;
|
|
681
765
|
},
|
|
682
766
|
enumerable: false,
|
|
683
767
|
configurable: true
|
|
684
768
|
});
|
|
685
|
-
|
|
769
|
+
/** Disconnect the client. */
|
|
686
770
|
Client.prototype.Disconnect = function () {
|
|
687
771
|
var _this = this;
|
|
688
772
|
return new Promise(function (resolve) {
|
|
@@ -695,51 +779,17 @@ var Client = /** @class */ (function (_super) {
|
|
|
695
779
|
});
|
|
696
780
|
});
|
|
697
781
|
};
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
var delta = this.SnapUnpacker.deltas.filter(function (_delta) {
|
|
701
|
-
return _delta.type_id == 11
|
|
702
|
-
&& _delta.id == id;
|
|
703
|
-
});
|
|
704
|
-
if (delta.length == 0)
|
|
705
|
-
return undefined;
|
|
706
|
-
return delta[0].parsed;
|
|
707
|
-
// .sort((a, b) => a.id - b.id)
|
|
708
|
-
// .map(a => a.parsed as ClientInfo);
|
|
709
|
-
};
|
|
710
|
-
Object.defineProperty(Client.prototype, "client_infos", {
|
|
711
|
-
/* Get all client infos. */
|
|
712
|
-
get: function () {
|
|
713
|
-
return this.SnapUnpacker.deltas.filter(function (_delta) { return _delta.type_id == 11; })
|
|
714
|
-
.sort(function (a, b) { return a.id - b.id; })
|
|
715
|
-
.map(function (a) { return a.parsed; });
|
|
716
|
-
},
|
|
717
|
-
enumerable: false,
|
|
718
|
-
configurable: true
|
|
719
|
-
});
|
|
720
|
-
/* Get the player info from a specific player id. */
|
|
721
|
-
Client.prototype.player_info = function (id) {
|
|
722
|
-
var delta = this.SnapUnpacker.deltas.filter(function (_delta) {
|
|
723
|
-
return _delta.type_id == 10
|
|
724
|
-
&& _delta.id == id;
|
|
725
|
-
});
|
|
726
|
-
if (delta.length == 0)
|
|
727
|
-
return undefined;
|
|
728
|
-
return delta[0].parsed;
|
|
729
|
-
};
|
|
730
|
-
Object.defineProperty(Client.prototype, "player_infos", {
|
|
731
|
-
/* Get all player infos. */
|
|
782
|
+
Object.defineProperty(Client.prototype, "VoteOptionList", {
|
|
783
|
+
/** Get all available vote options (for example for map voting) */
|
|
732
784
|
get: function () {
|
|
733
|
-
return this.
|
|
734
|
-
.sort(function (a, b) { return a.id - b.id; })
|
|
735
|
-
.map(function (player) { return player.parsed; });
|
|
785
|
+
return this.VoteList;
|
|
736
786
|
},
|
|
737
787
|
enumerable: false,
|
|
738
788
|
configurable: true
|
|
739
789
|
});
|
|
740
|
-
Object.defineProperty(Client.prototype, "
|
|
790
|
+
Object.defineProperty(Client.prototype, "rawSnapUnpacker", {
|
|
741
791
|
get: function () {
|
|
742
|
-
return this.
|
|
792
|
+
return this.SnapUnpacker;
|
|
743
793
|
},
|
|
744
794
|
enumerable: false,
|
|
745
795
|
configurable: true
|