teeworlds 2.4.3 → 2.4.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/index.js +0 -1
- package/index.ts +1 -2
- package/lib/MsgUnpacker.js +9 -11
- package/lib/MsgUnpacker.ts +13 -13
- package/lib/client.js +59 -108
- package/lib/client.ts +80 -133
- package/lib/components/game.js +11 -11
- package/lib/components/game.ts +33 -21
- package/lib/{movement.js → components/movement.js} +0 -0
- package/lib/{movement.ts → components/movement.ts} +0 -0
- package/lib/components/snapshot.js +200 -0
- package/lib/components/snapshot.ts +174 -0
- package/lib/snapshot.js +129 -56
- package/lib/snapshot.ts +134 -50
- package/lib/snapshots.d.ts +26 -22
- package/package.json +1 -1
- package/test.js +0 -32
package/index.js
CHANGED
|
@@ -20,4 +20,3 @@ Object.defineProperty(exports, "Client", { enumerable: true, get: function () {
|
|
|
20
20
|
__exportStar(require("./lib/MsgPacker"), exports);
|
|
21
21
|
__exportStar(require("./lib/MsgUnpacker"), exports);
|
|
22
22
|
__exportStar(require("./lib/snapshot"), exports);
|
|
23
|
-
__exportStar(require("./lib/movement"), exports);
|
package/index.ts
CHANGED
package/lib/MsgUnpacker.js
CHANGED
|
@@ -26,17 +26,15 @@ var MsgUnpacker = /** @class */ (function () {
|
|
|
26
26
|
function MsgUnpacker(pSrc) {
|
|
27
27
|
this.remaining = pSrc;
|
|
28
28
|
}
|
|
29
|
-
MsgUnpacker.prototype.unpackInt = function (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.remaining = this.remaining.slice(1);
|
|
39
|
-
}
|
|
29
|
+
MsgUnpacker.prototype.unpackInt = function () {
|
|
30
|
+
// let unpacked;
|
|
31
|
+
// if (!_unpacked) {
|
|
32
|
+
var unpacked = unpackInt(this.remaining);
|
|
33
|
+
this.remaining = unpacked.remaining;
|
|
34
|
+
// } else {
|
|
35
|
+
// unpacked = {result: this.remaining[0]};
|
|
36
|
+
// this.remaining = this.remaining.slice(1);
|
|
37
|
+
// }
|
|
40
38
|
return unpacked.result;
|
|
41
39
|
};
|
|
42
40
|
MsgUnpacker.prototype.unpackString = function () {
|
package/lib/MsgUnpacker.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const decoder = new TextDecoder('utf-8');
|
|
2
|
-
export function unpackInt(pSrc:
|
|
2
|
+
export function unpackInt(pSrc: Buffer): {result: number, remaining: Buffer} {
|
|
3
3
|
|
|
4
4
|
var srcIndex = 0;
|
|
5
5
|
const sign = ((pSrc[srcIndex] >> 6) & 1)
|
|
@@ -18,28 +18,28 @@ export function unpackInt(pSrc: number[]): {result: number, remaining: number[]}
|
|
|
18
18
|
|
|
19
19
|
return {result, remaining: pSrc.slice(srcIndex+1)};
|
|
20
20
|
}
|
|
21
|
-
export function unpackString(pSrc:
|
|
21
|
+
export function unpackString(pSrc: Buffer): {result: string, remaining: Buffer} {
|
|
22
22
|
var result = pSrc.slice(0, pSrc.indexOf(0))
|
|
23
23
|
pSrc = pSrc.slice(pSrc.indexOf(0) + 1, pSrc.length)
|
|
24
24
|
return {result: decoder.decode(new Uint8Array(result)), remaining: pSrc}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export class MsgUnpacker {
|
|
28
|
-
remaining:
|
|
29
|
-
constructor(pSrc:
|
|
28
|
+
remaining: Buffer;
|
|
29
|
+
constructor(pSrc: Buffer) {
|
|
30
30
|
this.remaining = pSrc;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
unpackInt(
|
|
34
|
-
let unpacked;
|
|
35
|
-
if (!_unpacked) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} else {
|
|
39
|
-
unpacked = {result: this.remaining[0]};
|
|
40
|
-
this.remaining = this.remaining.slice(1);
|
|
33
|
+
unpackInt(): number {
|
|
34
|
+
// let unpacked;
|
|
35
|
+
// if (!_unpacked) {
|
|
36
|
+
let unpacked = unpackInt(this.remaining);
|
|
37
|
+
this.remaining = unpacked.remaining;
|
|
38
|
+
// } else {
|
|
39
|
+
// unpacked = {result: this.remaining[0]};
|
|
40
|
+
// this.remaining = this.remaining.slice(1);
|
|
41
41
|
|
|
42
|
-
}
|
|
42
|
+
// }
|
|
43
43
|
return unpacked.result;
|
|
44
44
|
}
|
|
45
45
|
|
package/lib/client.js
CHANGED
|
@@ -23,11 +23,12 @@ 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");
|
|
31
32
|
var huff = new huffman_1.default();
|
|
32
33
|
var States;
|
|
33
34
|
(function (States) {
|
|
@@ -112,9 +113,6 @@ var NETMSG_Sys;
|
|
|
112
113
|
NETMSG_Sys[NETMSG_Sys["NETMSG_RCON_CMD_REM"] = 26] = "NETMSG_RCON_CMD_REM";
|
|
113
114
|
NETMSG_Sys[NETMSG_Sys["NUM_NETMSGS"] = 27] = "NUM_NETMSGS";
|
|
114
115
|
})(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
116
|
var messageTypes = [
|
|
119
117
|
["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
118
|
["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"]
|
|
@@ -128,17 +126,6 @@ var messageUUIDs = {
|
|
|
128
126
|
"CLIENT_VERSION": Buffer.from([0x8c, 0x00, 0x13, 0x04, 0x84, 0x61, 0x3e, 0x47, 0x87, 0x87, 0xf6, 0x72, 0xb3, 0x83, 0x5b, 0xd4]),
|
|
129
127
|
"CAPABILITIES": Buffer.from([0xf6, 0x21, 0xa5, 0xa1, 0xf5, 0x85, 0x37, 0x75, 0x8e, 0x73, 0x41, 0xbe, 0xee, 0x79, 0xf2, 0xb2]),
|
|
130
128
|
};
|
|
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
129
|
var Client = /** @class */ (function (_super) {
|
|
143
130
|
__extends(Client, _super);
|
|
144
131
|
function Client(ip, port, nickname, options) {
|
|
@@ -150,7 +137,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
150
137
|
_this.PredGameTick = 0;
|
|
151
138
|
_this.currentSnapshotGameTick = 0;
|
|
152
139
|
_this.SnapshotParts = 0;
|
|
153
|
-
_this.SnapUnpacker = new snapshot_1.Snapshot();
|
|
140
|
+
_this.SnapUnpacker = new snapshot_1.Snapshot(_this);
|
|
154
141
|
// this.eSnapHolder = [];
|
|
155
142
|
_this.requestResend = false;
|
|
156
143
|
_this.VoteList = [];
|
|
@@ -172,6 +159,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
172
159
|
_this.lastSentMessages = [];
|
|
173
160
|
_this.movement = new movement_1.default();
|
|
174
161
|
_this.game = new game_1.Game(_this);
|
|
162
|
+
_this.SnapshotUnpacker = new snapshot_2.SnapshotWrapper(_this);
|
|
175
163
|
return _this;
|
|
176
164
|
}
|
|
177
165
|
Client.prototype.ResendAfter = function (lastAck) {
|
|
@@ -214,7 +202,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
214
202
|
chunk.msg = messageTypes[packet[0] & 1][chunk.msgid];
|
|
215
203
|
chunk.raw = packet.slice(1, chunk.bytes);
|
|
216
204
|
Object.values(messageUUIDs).forEach(function (a, i) {
|
|
217
|
-
if (a.compare(packet.slice(0, 16)) == 0) {
|
|
205
|
+
if (a.byteLength >= 16 && a.compare(packet.slice(0, 16)) == 0) {
|
|
218
206
|
chunk.extended_msgid = a;
|
|
219
207
|
chunk.msg = Object.keys(messageUUIDs)[i];
|
|
220
208
|
}
|
|
@@ -224,7 +212,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
224
212
|
}
|
|
225
213
|
return unpacked;
|
|
226
214
|
};
|
|
227
|
-
|
|
215
|
+
/** Send a Control Msg to the server. (used for disconnect)*/
|
|
228
216
|
Client.prototype.SendControlMsg = function (msg, ExtraMsg) {
|
|
229
217
|
var _this = this;
|
|
230
218
|
if (ExtraMsg === void 0) { ExtraMsg = ""; }
|
|
@@ -244,7 +232,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
244
232
|
*/
|
|
245
233
|
});
|
|
246
234
|
};
|
|
247
|
-
|
|
235
|
+
/** Send a Msg (or Msg[]) to the server.*/
|
|
248
236
|
Client.prototype.SendMsgEx = function (Msgs) {
|
|
249
237
|
var _this = this;
|
|
250
238
|
if (this.State == States.STATE_OFFLINE)
|
|
@@ -303,11 +291,11 @@ var Client = /** @class */ (function (_super) {
|
|
|
303
291
|
return;
|
|
304
292
|
this.socket.send(packet, 0, packet.length, this.port, this.host);
|
|
305
293
|
};
|
|
306
|
-
|
|
294
|
+
/** Queue a chunk (It will get sent in the next packet). */
|
|
307
295
|
Client.prototype.QueueChunkEx = function (Msg) {
|
|
308
296
|
this.queueChunkEx.push(Msg);
|
|
309
297
|
};
|
|
310
|
-
|
|
298
|
+
/** Send a Raw Buffer (as chunk) to the server. */
|
|
311
299
|
Client.prototype.SendMsgRaw = function (chunks) {
|
|
312
300
|
if (this.State == States.STATE_OFFLINE)
|
|
313
301
|
return;
|
|
@@ -337,14 +325,14 @@ var Client = /** @class */ (function (_super) {
|
|
|
337
325
|
chunk.msg = messageTypes[packet[0] & 1][chunk.msgid];
|
|
338
326
|
chunk.raw = packet.slice(1, chunk.bytes);
|
|
339
327
|
Object.values(messageUUIDs).forEach(function (a, i) {
|
|
340
|
-
if (a.compare(packet.slice(0, 16)) === 0) {
|
|
328
|
+
if (a.byteLength >= 16 && a.compare(packet.slice(0, 16)) === 0) {
|
|
341
329
|
chunk.extended_msgid = a;
|
|
342
330
|
chunk.msg = Object.keys(messageUUIDs)[i];
|
|
343
331
|
}
|
|
344
332
|
});
|
|
345
333
|
return chunk;
|
|
346
334
|
};
|
|
347
|
-
|
|
335
|
+
/** Connect the client to the server. */
|
|
348
336
|
Client.prototype.connect = function () {
|
|
349
337
|
var _this = this;
|
|
350
338
|
var _a;
|
|
@@ -400,10 +388,10 @@ var Client = /** @class */ (function (_super) {
|
|
|
400
388
|
if (_this.State == 0 || rinfo.address != _this.host || rinfo.port != _this.port)
|
|
401
389
|
return;
|
|
402
390
|
clearInterval(connectInterval);
|
|
403
|
-
if (packet
|
|
404
|
-
if (packet.toString().includes("TKEN") || packet
|
|
391
|
+
if (packet[0] == 0x10) {
|
|
392
|
+
if (packet.toString().includes("TKEN") || packet[3] == 0x2) {
|
|
405
393
|
clearInterval(connectInterval);
|
|
406
|
-
_this.TKEN =
|
|
394
|
+
_this.TKEN = packet.slice(-4);
|
|
407
395
|
_this.SendControlMsg(3);
|
|
408
396
|
_this.State = States.STATE_LOADING; // loading state
|
|
409
397
|
_this.receivedSnaps = 0;
|
|
@@ -412,7 +400,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
412
400
|
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
401
|
var client_version = new MsgPacker_1.MsgPacker(0, true, 1);
|
|
414
402
|
client_version.AddBuffer(Buffer.from("8c00130484613e478787f672b3835bd4", 'hex'));
|
|
415
|
-
var randomUuid = Buffer.
|
|
403
|
+
var randomUuid = Buffer.allocUnsafe(16);
|
|
416
404
|
(0, crypto_1.randomBytes)(16).copy(randomUuid);
|
|
417
405
|
client_version.AddBuffer(randomUuid);
|
|
418
406
|
if (((_d = _this.options) === null || _d === void 0 ? void 0 : _d.ddnet_version) !== undefined) {
|
|
@@ -425,13 +413,13 @@ var Client = /** @class */ (function (_super) {
|
|
|
425
413
|
}
|
|
426
414
|
_this.SendMsgEx([client_version, info]);
|
|
427
415
|
}
|
|
428
|
-
else if (packet
|
|
416
|
+
else if (packet[3] == 0x4) {
|
|
429
417
|
// disconnected
|
|
430
418
|
_this.State = States.STATE_OFFLINE;
|
|
431
|
-
var reason = ((0, MsgUnpacker_1.unpackString)(packet.
|
|
419
|
+
var reason = ((0, MsgUnpacker_1.unpackString)(packet.slice(4)).result);
|
|
432
420
|
_this.emit("disconnect", reason);
|
|
433
421
|
}
|
|
434
|
-
if (packet
|
|
422
|
+
if (packet[3] !== 0x0) { // keepalive
|
|
435
423
|
_this.lastRecvTime = new Date().getTime();
|
|
436
424
|
}
|
|
437
425
|
}
|
|
@@ -461,8 +449,9 @@ var Client = /** @class */ (function (_super) {
|
|
|
461
449
|
}
|
|
462
450
|
});
|
|
463
451
|
_this.sentChunkQueue.forEach(function (buff, i) {
|
|
464
|
-
var
|
|
465
|
-
if (
|
|
452
|
+
var chunkFlags = (buff[0] >> 6) & 3;
|
|
453
|
+
if (chunkFlags & 1) {
|
|
454
|
+
var chunk = _this.MsgToChunk(buff);
|
|
466
455
|
if (chunk.seq && chunk.seq >= _this.ack)
|
|
467
456
|
_this.sentChunkQueue.splice(i, 1);
|
|
468
457
|
}
|
|
@@ -519,7 +508,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
519
508
|
if (Math.abs(_this.PredGameTick - _this.AckGameTick) > 10)
|
|
520
509
|
_this.PredGameTick = _this.AckGameTick + 1;
|
|
521
510
|
// snapChunks.forEach(chunk => {
|
|
522
|
-
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw
|
|
511
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
|
|
523
512
|
var NumParts = 1;
|
|
524
513
|
var Part = 0;
|
|
525
514
|
var GameTick = unpacker.unpackInt();
|
|
@@ -527,11 +516,11 @@ var Client = /** @class */ (function (_super) {
|
|
|
527
516
|
var PartSize = 0;
|
|
528
517
|
var Crc = 0;
|
|
529
518
|
var CompleteSize = 0;
|
|
530
|
-
if (chunk.
|
|
519
|
+
if (chunk.msgid == NETMSG_Sys.NETMSG_SNAP) {
|
|
531
520
|
NumParts = unpacker.unpackInt();
|
|
532
521
|
Part = unpacker.unpackInt();
|
|
533
522
|
}
|
|
534
|
-
if (chunk.
|
|
523
|
+
if (chunk.msgid != NETMSG_Sys.NETMSG_SNAPEMPTY) {
|
|
535
524
|
Crc = unpacker.unpackInt();
|
|
536
525
|
PartSize = unpacker.unpackInt();
|
|
537
526
|
}
|
|
@@ -544,13 +533,13 @@ var Client = /** @class */ (function (_super) {
|
|
|
544
533
|
_this.currentSnapshotGameTick = GameTick;
|
|
545
534
|
}
|
|
546
535
|
// chunk.raw = Buffer.from(unpacker.remaining);
|
|
547
|
-
_this.snaps[Part] =
|
|
536
|
+
_this.snaps[Part] = unpacker.remaining;
|
|
548
537
|
_this.SnapshotParts |= 1 << Part;
|
|
549
538
|
if (_this.SnapshotParts == ((1 << NumParts) - 1)) {
|
|
550
539
|
var mergedSnaps = Buffer.concat(_this.snaps);
|
|
551
540
|
_this.SnapshotParts = 0;
|
|
552
|
-
var snapUnpacked = _this.SnapUnpacker.unpackSnapshot(mergedSnaps
|
|
553
|
-
_this.emit("snapshot");
|
|
541
|
+
var snapUnpacked = _this.SnapUnpacker.unpackSnapshot(mergedSnaps, DeltaTick, GameTick, Crc);
|
|
542
|
+
_this.emit("snapshot", snapUnpacked.items);
|
|
554
543
|
_this.AckGameTick = snapUnpacked.recvTick;
|
|
555
544
|
if (Math.abs(_this.PredGameTick - _this.AckGameTick) > 10)
|
|
556
545
|
_this.PredGameTick = _this.AckGameTick + 1;
|
|
@@ -567,7 +556,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
567
556
|
_this.VoteList = [];
|
|
568
557
|
}
|
|
569
558
|
else if (chunk.msgid == NETMSG_Game.SV_VOTEOPTIONLISTADD) {
|
|
570
|
-
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw
|
|
559
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
|
|
571
560
|
var NumOptions = unpacker.unpackInt();
|
|
572
561
|
var list = [];
|
|
573
562
|
for (var i = 0; i < 15; i++) {
|
|
@@ -577,36 +566,36 @@ var Client = /** @class */ (function (_super) {
|
|
|
577
566
|
(_a = _this.VoteList).push.apply(_a, list);
|
|
578
567
|
}
|
|
579
568
|
else if (chunk.msgid == NETMSG_Game.SV_VOTEOPTIONADD) {
|
|
580
|
-
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw
|
|
569
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
|
|
581
570
|
_this.VoteList.push(unpacker.unpackString());
|
|
582
571
|
}
|
|
583
572
|
else if (chunk.msgid == NETMSG_Game.SV_VOTEOPTIONREMOVE) {
|
|
584
|
-
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw
|
|
573
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
|
|
585
574
|
var index_1 = _this.VoteList.indexOf(unpacker.unpackString());
|
|
586
575
|
if (index_1 > -1)
|
|
587
576
|
_this.VoteList = _this.VoteList.splice(index_1, 1);
|
|
588
577
|
}
|
|
589
578
|
// events
|
|
590
579
|
if (chunk.msgid == NETMSG_Game.SV_EMOTICON) {
|
|
591
|
-
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw
|
|
580
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
|
|
592
581
|
var unpacked_1 = {
|
|
593
582
|
client_id: unpacker.unpackInt(),
|
|
594
583
|
emoticon: unpacker.unpackInt()
|
|
595
584
|
};
|
|
596
585
|
if (unpacked_1.client_id != -1) {
|
|
597
586
|
unpacked_1.author = {
|
|
598
|
-
ClientInfo: _this.
|
|
599
|
-
PlayerInfo: _this.
|
|
587
|
+
ClientInfo: _this.SnapshotUnpacker.getObjClientInfo(unpacked_1.client_id),
|
|
588
|
+
PlayerInfo: _this.SnapshotUnpacker.getObjPlayerInfo(unpacked_1.client_id)
|
|
600
589
|
};
|
|
601
590
|
}
|
|
602
591
|
_this.emit("emote", unpacked_1);
|
|
603
592
|
}
|
|
604
593
|
else if (chunk.msgid == NETMSG_Game.SV_BROADCAST) {
|
|
605
|
-
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw
|
|
594
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
|
|
606
595
|
_this.emit("broadcast", unpacker.unpackString());
|
|
607
596
|
}
|
|
608
597
|
if (chunk.msgid == NETMSG_Game.SV_CHAT) {
|
|
609
|
-
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw
|
|
598
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
|
|
610
599
|
var unpacked_2 = {
|
|
611
600
|
team: unpacker.unpackInt(),
|
|
612
601
|
client_id: unpacker.unpackInt(),
|
|
@@ -614,28 +603,28 @@ var Client = /** @class */ (function (_super) {
|
|
|
614
603
|
};
|
|
615
604
|
if (unpacked_2.client_id != -1) {
|
|
616
605
|
unpacked_2.author = {
|
|
617
|
-
ClientInfo: _this.
|
|
618
|
-
PlayerInfo: _this.
|
|
606
|
+
ClientInfo: _this.SnapshotUnpacker.getObjClientInfo(unpacked_2.client_id),
|
|
607
|
+
PlayerInfo: _this.SnapshotUnpacker.getObjPlayerInfo(unpacked_2.client_id)
|
|
619
608
|
};
|
|
620
609
|
}
|
|
621
610
|
_this.emit("message", unpacked_2);
|
|
622
611
|
}
|
|
623
612
|
else if (chunk.msgid == NETMSG_Game.SV_KILLMSG) {
|
|
624
613
|
var unpacked_3 = {};
|
|
625
|
-
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw
|
|
614
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
|
|
626
615
|
unpacked_3.killer_id = unpacker.unpackInt();
|
|
627
616
|
unpacked_3.victim_id = unpacker.unpackInt();
|
|
628
617
|
unpacked_3.weapon = unpacker.unpackInt();
|
|
629
618
|
unpacked_3.special_mode = unpacker.unpackInt();
|
|
630
619
|
if (unpacked_3.victim_id != -1 && unpacked_3.victim_id < 64) {
|
|
631
|
-
unpacked_3.victim = { ClientInfo: _this.
|
|
620
|
+
unpacked_3.victim = { ClientInfo: _this.SnapshotUnpacker.getObjClientInfo(unpacked_3.victim_id), PlayerInfo: _this.SnapshotUnpacker.getObjPlayerInfo(unpacked_3.victim_id) };
|
|
632
621
|
}
|
|
633
622
|
if (unpacked_3.killer_id != -1 && unpacked_3.killer_id < 64)
|
|
634
|
-
unpacked_3.killer = { ClientInfo: _this.
|
|
623
|
+
unpacked_3.killer = { ClientInfo: _this.SnapshotUnpacker.getObjClientInfo(unpacked_3.killer_id), PlayerInfo: _this.SnapshotUnpacker.getObjPlayerInfo(unpacked_3.killer_id) };
|
|
635
624
|
_this.emit("kill", unpacked_3);
|
|
636
625
|
}
|
|
637
626
|
else if (chunk.msgid == NETMSG_Game.SV_MOTD) {
|
|
638
|
-
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw
|
|
627
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw);
|
|
639
628
|
var message = unpacker.unpackString();
|
|
640
629
|
_this.emit("motd", message);
|
|
641
630
|
}
|
|
@@ -653,7 +642,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
653
642
|
}
|
|
654
643
|
});
|
|
655
644
|
};
|
|
656
|
-
|
|
645
|
+
/** Sending the input. (automatically done unless options.lightweight is on) */
|
|
657
646
|
Client.prototype.sendInput = function (input) {
|
|
658
647
|
if (input === void 0) { input = this.movement.input; }
|
|
659
648
|
if (this.State != States.STATE_ONLINE)
|
|
@@ -662,31 +651,27 @@ var Client = /** @class */ (function (_super) {
|
|
|
662
651
|
inputMsg.AddInt(this.AckGameTick);
|
|
663
652
|
inputMsg.AddInt(this.PredGameTick);
|
|
664
653
|
inputMsg.AddInt(40);
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
input.m_PrevWeapon
|
|
676
|
-
];
|
|
677
|
-
input_data.forEach(function (a) {
|
|
678
|
-
inputMsg.AddInt(a);
|
|
679
|
-
});
|
|
654
|
+
inputMsg.AddInt(input.m_Direction);
|
|
655
|
+
inputMsg.AddInt(input.m_TargetX);
|
|
656
|
+
inputMsg.AddInt(input.m_TargetY);
|
|
657
|
+
inputMsg.AddInt(input.m_Jump);
|
|
658
|
+
inputMsg.AddInt(input.m_Fire);
|
|
659
|
+
inputMsg.AddInt(input.m_Hook);
|
|
660
|
+
inputMsg.AddInt(input.m_PlayerFlags);
|
|
661
|
+
inputMsg.AddInt(input.m_WantedWeapon);
|
|
662
|
+
inputMsg.AddInt(input.m_NextWeapon);
|
|
663
|
+
inputMsg.AddInt(input.m_PrevWeapon);
|
|
680
664
|
this.SendMsgEx(inputMsg);
|
|
681
665
|
};
|
|
682
666
|
Object.defineProperty(Client.prototype, "input", {
|
|
667
|
+
/** returns the movement object of the client */
|
|
683
668
|
get: function () {
|
|
684
669
|
return this.movement.input;
|
|
685
670
|
},
|
|
686
671
|
enumerable: false,
|
|
687
672
|
configurable: true
|
|
688
673
|
});
|
|
689
|
-
|
|
674
|
+
/** Disconnect the client. */
|
|
690
675
|
Client.prototype.Disconnect = function () {
|
|
691
676
|
var _this = this;
|
|
692
677
|
return new Promise(function (resolve) {
|
|
@@ -699,51 +684,17 @@ var Client = /** @class */ (function (_super) {
|
|
|
699
684
|
});
|
|
700
685
|
});
|
|
701
686
|
};
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
var delta = this.SnapUnpacker.deltas.filter(function (_delta) {
|
|
705
|
-
return _delta.type_id == 11
|
|
706
|
-
&& _delta.id == id;
|
|
707
|
-
});
|
|
708
|
-
if (delta.length == 0)
|
|
709
|
-
return undefined;
|
|
710
|
-
return delta[0].parsed;
|
|
711
|
-
// .sort((a, b) => a.id - b.id)
|
|
712
|
-
// .map(a => a.parsed as ClientInfo);
|
|
713
|
-
};
|
|
714
|
-
Object.defineProperty(Client.prototype, "client_infos", {
|
|
715
|
-
/* Get all client infos. */
|
|
716
|
-
get: function () {
|
|
717
|
-
return this.SnapUnpacker.deltas.filter(function (_delta) { return _delta.type_id == 11; })
|
|
718
|
-
.sort(function (a, b) { return a.id - b.id; })
|
|
719
|
-
.map(function (a) { return a.parsed; });
|
|
720
|
-
},
|
|
721
|
-
enumerable: false,
|
|
722
|
-
configurable: true
|
|
723
|
-
});
|
|
724
|
-
/* Get the player info from a specific player id. */
|
|
725
|
-
Client.prototype.player_info = function (id) {
|
|
726
|
-
var delta = this.SnapUnpacker.deltas.filter(function (_delta) {
|
|
727
|
-
return _delta.type_id == 10
|
|
728
|
-
&& _delta.id == id;
|
|
729
|
-
});
|
|
730
|
-
if (delta.length == 0)
|
|
731
|
-
return undefined;
|
|
732
|
-
return delta[0].parsed;
|
|
733
|
-
};
|
|
734
|
-
Object.defineProperty(Client.prototype, "player_infos", {
|
|
735
|
-
/* Get all player infos. */
|
|
687
|
+
Object.defineProperty(Client.prototype, "VoteOptionList", {
|
|
688
|
+
/** Get all available vote options (for example for map voting) */
|
|
736
689
|
get: function () {
|
|
737
|
-
return this.
|
|
738
|
-
.sort(function (a, b) { return a.id - b.id; })
|
|
739
|
-
.map(function (player) { return player.parsed; });
|
|
690
|
+
return this.VoteList;
|
|
740
691
|
},
|
|
741
692
|
enumerable: false,
|
|
742
693
|
configurable: true
|
|
743
694
|
});
|
|
744
|
-
Object.defineProperty(Client.prototype, "
|
|
695
|
+
Object.defineProperty(Client.prototype, "rawSnapUnpacker", {
|
|
745
696
|
get: function () {
|
|
746
|
-
return this.
|
|
697
|
+
return this.SnapUnpacker;
|
|
747
698
|
},
|
|
748
699
|
enumerable: false,
|
|
749
700
|
configurable: true
|