teeworlds 2.3.3 → 2.3.8
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/MsgPacker.js +2 -1
- package/lib/MsgPacker.ts +3 -1
- package/lib/MsgUnpacker.js +12 -10
- package/lib/MsgUnpacker.ts +12 -10
- package/lib/client.js +110 -76
- package/lib/client.ts +98 -65
- package/lib/snapshot.js +6 -6
- package/lib/snapshot.ts +6 -6
- package/package.json +1 -1
package/lib/MsgPacker.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MsgPacker = void 0;
|
|
4
4
|
var MsgPacker = /** @class */ (function () {
|
|
5
|
-
function MsgPacker(msg, sys) {
|
|
5
|
+
function MsgPacker(msg, sys, flag) {
|
|
6
6
|
this.result = Buffer.from([2 * msg + (sys ? 1 : 0)]);
|
|
7
7
|
this.sys = sys;
|
|
8
|
+
this.flag = flag;
|
|
8
9
|
}
|
|
9
10
|
MsgPacker.prototype.AddString = function (str) {
|
|
10
11
|
this.result = Buffer.concat([this.result, Buffer.from(str), Buffer.from([0x00])]);
|
package/lib/MsgPacker.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export class MsgPacker {
|
|
2
2
|
result: Buffer;
|
|
3
3
|
sys: boolean;
|
|
4
|
-
|
|
4
|
+
flag: number;
|
|
5
|
+
constructor(msg: number, sys: boolean, flag: number) {
|
|
5
6
|
this.result = Buffer.from([2*msg + (sys ? 1 : 0)]);
|
|
6
7
|
this.sys = sys;
|
|
8
|
+
this.flag = flag;
|
|
7
9
|
}
|
|
8
10
|
AddString(str: string) {
|
|
9
11
|
this.result = Buffer.concat([this.result, Buffer.from(str), Buffer.from([0x00])])
|
package/lib/MsgUnpacker.js
CHANGED
|
@@ -4,20 +4,22 @@ exports.MsgUnpacker = exports.unpackString = exports.unpackInt = void 0;
|
|
|
4
4
|
var decoder = new TextDecoder('utf-8');
|
|
5
5
|
function unpackInt(pSrc) {
|
|
6
6
|
var result = 0;
|
|
7
|
-
var iter = pSrc[Symbol.iterator]()
|
|
8
|
-
var src = iter.next()
|
|
9
|
-
src = src.value
|
|
10
|
-
var
|
|
11
|
-
|
|
7
|
+
// var iter = pSrc[Symbol.iterator]()
|
|
8
|
+
// var src: any = iter.next()
|
|
9
|
+
// src = src.value
|
|
10
|
+
var srcIndex = 0;
|
|
11
|
+
var sign = ((pSrc[srcIndex] >> 6) & 1);
|
|
12
|
+
result |= (pSrc[srcIndex] & 63);
|
|
12
13
|
for (var i = 0; i < 4; i++) {
|
|
13
|
-
if ((
|
|
14
|
+
if ((pSrc[srcIndex] & 128) === 0)
|
|
14
15
|
break;
|
|
15
|
-
src = iter.next()
|
|
16
|
-
src = src.value;
|
|
17
|
-
|
|
16
|
+
// src = iter.next()
|
|
17
|
+
// src = src.value;
|
|
18
|
+
srcIndex++;
|
|
19
|
+
result |= ((pSrc[srcIndex] & 127)) << (6 + 7 * i);
|
|
18
20
|
}
|
|
19
21
|
result ^= -sign;
|
|
20
|
-
return { result: result, remaining:
|
|
22
|
+
return { result: result, remaining: pSrc.slice(srcIndex + 1) };
|
|
21
23
|
}
|
|
22
24
|
exports.unpackInt = unpackInt;
|
|
23
25
|
function unpackString(pSrc) {
|
package/lib/MsgUnpacker.ts
CHANGED
|
@@ -2,25 +2,27 @@ const decoder = new TextDecoder('utf-8');
|
|
|
2
2
|
export function unpackInt(pSrc: number[]): {result: number, remaining: number[]} {
|
|
3
3
|
var result = 0;
|
|
4
4
|
|
|
5
|
-
var iter = pSrc[Symbol.iterator]()
|
|
6
|
-
var src: any = iter.next()
|
|
7
|
-
src = src.value
|
|
8
|
-
|
|
5
|
+
// var iter = pSrc[Symbol.iterator]()
|
|
6
|
+
// var src: any = iter.next()
|
|
7
|
+
// src = src.value
|
|
8
|
+
let srcIndex = 0;
|
|
9
|
+
var sign = ((pSrc[srcIndex] >> 6) & 1)
|
|
9
10
|
|
|
10
|
-
result |= (
|
|
11
|
+
result |= (pSrc[srcIndex] & 0b0011_1111)
|
|
11
12
|
for (let i = 0; i < 4; i++) {
|
|
12
13
|
|
|
13
|
-
if ((
|
|
14
|
+
if ((pSrc[srcIndex] & 0b1000_0000) === 0)
|
|
14
15
|
break;
|
|
15
|
-
src = iter.next()
|
|
16
|
+
// src = iter.next()
|
|
16
17
|
|
|
17
|
-
src = src.value;
|
|
18
|
-
|
|
18
|
+
// src = src.value;
|
|
19
|
+
srcIndex++;
|
|
20
|
+
result |= ((pSrc[srcIndex] & 0b0111_1111)) << (6+7*i)
|
|
19
21
|
|
|
20
22
|
}
|
|
21
23
|
result ^= -sign;
|
|
22
24
|
|
|
23
|
-
return {result, remaining:
|
|
25
|
+
return {result, remaining: pSrc.slice(srcIndex+1)};
|
|
24
26
|
}
|
|
25
27
|
export function unpackString(pSrc: number[]): {result: string, remaining: number[]} {
|
|
26
28
|
var result = pSrc.slice(0, pSrc.indexOf(0))
|
package/lib/client.js
CHANGED
|
@@ -139,11 +139,12 @@ var Client = /** @class */ (function (_super) {
|
|
|
139
139
|
if (msg.ack > lastAck)
|
|
140
140
|
toResend.push(msg.msg);
|
|
141
141
|
});
|
|
142
|
-
|
|
142
|
+
toResend.forEach(function (a) { return a.flag = 1 | 2; });
|
|
143
|
+
this.SendMsgEx(toResend);
|
|
143
144
|
};
|
|
144
145
|
Client.prototype.Unpack = function (packet) {
|
|
145
146
|
var unpacked = { twprotocol: { flags: packet[0] >> 4, ack: ((packet[0] & 0xf) << 8) | packet[1], chunkAmount: packet[2], size: packet.byteLength - 3 }, chunks: [] };
|
|
146
|
-
if (packet.indexOf(Buffer.from([0xff, 0xff, 0xff, 0xff])) == 0
|
|
147
|
+
if (packet.indexOf(Buffer.from([0xff, 0xff, 0xff, 0xff])) == 0) // !(unpacked.twprotocol.flags & 8) || unpacked.twprotocol.flags == 255) // flags == 255 is connectionless (used for sending usernames)
|
|
147
148
|
return unpacked;
|
|
148
149
|
if (unpacked.twprotocol.flags & 4) { // resend flag
|
|
149
150
|
this.ResendAfter(unpacked.twprotocol.ack);
|
|
@@ -199,7 +200,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
199
200
|
*/
|
|
200
201
|
});
|
|
201
202
|
};
|
|
202
|
-
Client.prototype.SendMsgEx = function (Msgs
|
|
203
|
+
Client.prototype.SendMsgEx = function (Msgs) {
|
|
203
204
|
var _this = this;
|
|
204
205
|
if (this.State == States.STATE_OFFLINE)
|
|
205
206
|
return;
|
|
@@ -219,20 +220,20 @@ var Client = /** @class */ (function (_super) {
|
|
|
219
220
|
if (this.clientAck == 0)
|
|
220
221
|
this.lastSentMessages = [];
|
|
221
222
|
_Msgs.forEach(function (Msg, index) {
|
|
222
|
-
header[index] = Buffer.alloc((
|
|
223
|
-
header[index][0] = ((
|
|
223
|
+
header[index] = Buffer.alloc((Msg.flag & 1 ? 3 : 2));
|
|
224
|
+
header[index][0] = ((Msg.flag & 3) << 6) | ((Msg.size >> 4) & 0x3f);
|
|
224
225
|
header[index][1] = (Msg.size & 0xf);
|
|
225
|
-
if (
|
|
226
|
+
if (Msg.flag & 1) {
|
|
226
227
|
_this.clientAck = (_this.clientAck + 1) % (1 << 10);
|
|
227
228
|
if (_this.clientAck == 0)
|
|
228
229
|
_this.lastSentMessages = [];
|
|
229
230
|
header[index][1] |= (_this.clientAck >> 2) & 0xf0;
|
|
230
231
|
header[index][2] = _this.clientAck & 0xff;
|
|
231
|
-
header[index][0] = (((
|
|
232
|
-
if ((
|
|
232
|
+
header[index][0] = (((Msg.flag | 2) & 3) << 6) | ((Msg.size >> 4) & 0x3f); // 2 is resend flag (ugly hack for queue)
|
|
233
|
+
if ((Msg.flag & 2) == 0)
|
|
233
234
|
_this.sentChunkQueue.push(Buffer.concat([header[index], Msg.buffer]));
|
|
234
|
-
header[index][0] = (((
|
|
235
|
-
if ((
|
|
235
|
+
header[index][0] = (((Msg.flag) & 3) << 6) | ((Msg.size >> 4) & 0x3f);
|
|
236
|
+
if ((Msg.flag & 2) == 0)
|
|
236
237
|
_this.lastSentMessages.push({ msg: Msg, ack: _this.clientAck });
|
|
237
238
|
}
|
|
238
239
|
});
|
|
@@ -249,11 +250,12 @@ var Client = /** @class */ (function (_super) {
|
|
|
249
250
|
chunks = Buffer.concat([chunks, Buffer.from(header[index]), Msg.buffer]);
|
|
250
251
|
else {
|
|
251
252
|
skip = true;
|
|
252
|
-
_this.SendMsgEx(_Msgs.slice(index)
|
|
253
|
+
_this.SendMsgEx(_Msgs.slice(index));
|
|
253
254
|
}
|
|
254
255
|
});
|
|
255
256
|
var packet = Buffer.concat([(packetHeader), chunks, this.TKEN]);
|
|
256
|
-
|
|
257
|
+
if (chunks.length < 0)
|
|
258
|
+
return;
|
|
257
259
|
this.socket.send(packet, 0, packet.length, this.port, this.host);
|
|
258
260
|
};
|
|
259
261
|
Client.prototype.QueueChunkEx = function (Msg) {
|
|
@@ -267,6 +269,8 @@ var Client = /** @class */ (function (_super) {
|
|
|
267
269
|
this.lastSendTime = new Date().getTime();
|
|
268
270
|
var packetHeader = Buffer.from([0x0 + (((16 << 4) & 0xf0) | ((this.ack >> 8) & 0xf)), this.ack & 0xff, chunks.length]);
|
|
269
271
|
var packet = Buffer.concat([(packetHeader), Buffer.concat(chunks), this.TKEN]);
|
|
272
|
+
if (chunks.length < 0)
|
|
273
|
+
return;
|
|
270
274
|
this.socket.send(packet, 0, packet.length, this.port, this.host);
|
|
271
275
|
};
|
|
272
276
|
Client.prototype.MsgToChunk = function (packet) {
|
|
@@ -294,6 +298,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
294
298
|
};
|
|
295
299
|
Client.prototype.connect = function () {
|
|
296
300
|
var _this = this;
|
|
301
|
+
var _a;
|
|
297
302
|
this.State = States.STATE_CONNECTING;
|
|
298
303
|
var predTimer = setInterval(function () {
|
|
299
304
|
if (_this.State == States.STATE_ONLINE) {
|
|
@@ -310,14 +315,16 @@ var Client = /** @class */ (function (_super) {
|
|
|
310
315
|
else
|
|
311
316
|
clearInterval(connectInterval);
|
|
312
317
|
}, 500);
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
318
|
+
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight)) {
|
|
319
|
+
var inputInterval_1 = setInterval(function () {
|
|
320
|
+
if (_this.State == States.STATE_OFFLINE)
|
|
321
|
+
clearInterval(inputInterval_1);
|
|
322
|
+
if (_this.State != States.STATE_ONLINE)
|
|
323
|
+
return;
|
|
324
|
+
_this.time = new Date().getTime();
|
|
325
|
+
_this.sendInput();
|
|
326
|
+
}, 500);
|
|
327
|
+
}
|
|
321
328
|
var resendTimeout = setInterval(function () {
|
|
322
329
|
if (_this.State != States.STATE_OFFLINE) {
|
|
323
330
|
if (((new Date().getTime()) - _this.lastSendTime) > 900 && _this.sentChunkQueue.length > 0) {
|
|
@@ -340,7 +347,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
340
347
|
this.time = new Date().getTime() + 2000; // start sending keepalives after 2s
|
|
341
348
|
if (this.socket)
|
|
342
349
|
this.socket.on("message", function (a, rinfo) {
|
|
343
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
350
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
344
351
|
if (_this.State == 0 || rinfo.address != _this.host || rinfo.port != _this.port)
|
|
345
352
|
return;
|
|
346
353
|
clearInterval(connectInterval);
|
|
@@ -351,10 +358,10 @@ var Client = /** @class */ (function (_super) {
|
|
|
351
358
|
_this.SendControlMsg(3);
|
|
352
359
|
_this.State = States.STATE_LOADING; // loading state
|
|
353
360
|
_this.receivedSnaps = 0;
|
|
354
|
-
var info = new MsgPacker_1.MsgPacker(1, true);
|
|
361
|
+
var info = new MsgPacker_1.MsgPacker(1, true, 1);
|
|
355
362
|
info.AddString(((_a = _this.options) === null || _a === void 0 ? void 0 : _a.NET_VERSION) ? _this.options.NET_VERSION : "0.6 626fce9a778df4d4");
|
|
356
363
|
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
|
|
357
|
-
var client_version = new MsgPacker_1.MsgPacker(0, true);
|
|
364
|
+
var client_version = new MsgPacker_1.MsgPacker(0, true, 1);
|
|
358
365
|
client_version.AddBuffer(Buffer.from("8c00130484613e478787f672b3835bd4", 'hex'));
|
|
359
366
|
var randomUuid = Buffer.alloc(16);
|
|
360
367
|
crypto_1.randomBytes(16).copy(randomUuid);
|
|
@@ -367,7 +374,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
367
374
|
client_version.AddInt(16003);
|
|
368
375
|
client_version.AddString("DDNet 16.0.3");
|
|
369
376
|
}
|
|
370
|
-
_this.SendMsgEx([client_version, info]
|
|
377
|
+
_this.SendMsgEx([client_version, info]);
|
|
371
378
|
}
|
|
372
379
|
else if (a.toJSON().data[3] == 0x4) {
|
|
373
380
|
// disconnected
|
|
@@ -379,12 +386,13 @@ var Client = /** @class */ (function (_super) {
|
|
|
379
386
|
_this.lastRecvTime = new Date().getTime();
|
|
380
387
|
}
|
|
381
388
|
}
|
|
382
|
-
else
|
|
389
|
+
else {
|
|
383
390
|
_this.lastRecvTime = new Date().getTime();
|
|
391
|
+
}
|
|
384
392
|
var unpacked = _this.Unpack(a);
|
|
385
393
|
unpacked.chunks.forEach(function (a) {
|
|
386
|
-
if (a.flags & 1) { // vital
|
|
387
|
-
if (a.seq === (_this.ack + 1) % (1 << 10)) {
|
|
394
|
+
if (a.flags & 1 && (a.flags !== 15)) { // vital and not connless
|
|
395
|
+
if (a.seq === (_this.ack + 1) % (1 << 10)) { // https://github.com/nobody-mb/twchatonly/blob/master/chatonly.cpp#L237
|
|
388
396
|
_this.ack = a.seq;
|
|
389
397
|
_this.requestResend = false;
|
|
390
398
|
}
|
|
@@ -399,8 +407,6 @@ var Client = /** @class */ (function (_super) {
|
|
|
399
407
|
return;
|
|
400
408
|
}
|
|
401
409
|
_this.requestResend = true;
|
|
402
|
-
// c_flags |= 4; /* resend flag */
|
|
403
|
-
// continue; // take the next chunk in the packet
|
|
404
410
|
}
|
|
405
411
|
}
|
|
406
412
|
});
|
|
@@ -415,7 +421,9 @@ var Client = /** @class */ (function (_super) {
|
|
|
415
421
|
_this.sentChunkQueue.splice(i, 1);
|
|
416
422
|
}
|
|
417
423
|
});
|
|
418
|
-
var snapChunks =
|
|
424
|
+
var snapChunks = [];
|
|
425
|
+
if (((_g = _this.options) === null || _g === void 0 ? void 0 : _g.lightweight) !== true)
|
|
426
|
+
snapChunks = unpacked.chunks.filter(function (a) { return a.msg === "SNAP" || a.msg === "SNAP_SINGLE" || a.msg === "SNAP_EMPTY"; });
|
|
419
427
|
if (snapChunks.length > 0) {
|
|
420
428
|
var part = 0;
|
|
421
429
|
var num_parts = 1;
|
|
@@ -436,9 +444,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
436
444
|
var num_parts_1 = 1;
|
|
437
445
|
var part_1 = 0;
|
|
438
446
|
if (chunk.msg === "SNAP") {
|
|
439
|
-
// chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // delta tick
|
|
440
447
|
num_parts_1 = unpacker.unpackInt();
|
|
441
|
-
// chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // num parts
|
|
442
448
|
part_1 = unpacker.unpackInt();
|
|
443
449
|
}
|
|
444
450
|
var crc = 0;
|
|
@@ -456,6 +462,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
456
462
|
var mergedSnaps = Buffer.concat(_this.snaps);
|
|
457
463
|
var snapUnpacked = _this.SnapUnpacker.unpackSnapshot(mergedSnaps.toJSON().data, DeltaTick, AckGameTick);
|
|
458
464
|
_this.AckGameTick = snapUnpacked.recvTick;
|
|
465
|
+
_this.emit("snapshot");
|
|
459
466
|
_this.sendInput();
|
|
460
467
|
}
|
|
461
468
|
}
|
|
@@ -482,37 +489,40 @@ var Client = /** @class */ (function (_super) {
|
|
|
482
489
|
}
|
|
483
490
|
});
|
|
484
491
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
unpacked.victim = { ClientInfo: _this.client_info(unpacked.victim_id), PlayerInfo: _this.player_info(unpacked.victim_id) };
|
|
497
|
-
}
|
|
498
|
-
if (unpacked.killer_id != -1 && unpacked.killer_id < 64)
|
|
499
|
-
unpacked.killer = { ClientInfo: _this.client_info(unpacked.killer_id), PlayerInfo: _this.player_info(unpacked.killer_id) };
|
|
500
|
-
_this.emit("kill", unpacked);
|
|
492
|
+
var chat = unpacked.chunks.filter(function (a) { return a.msg == "SV_KILL_MSG" || a.msg == "SV_MOTD"; });
|
|
493
|
+
chat.forEach(function (a) {
|
|
494
|
+
if (a.msg == "SV_KILL_MSG") {
|
|
495
|
+
var unpacked = {};
|
|
496
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(a.raw.toJSON().data);
|
|
497
|
+
unpacked.killer_id = unpacker.unpackInt();
|
|
498
|
+
unpacked.victim_id = unpacker.unpackInt();
|
|
499
|
+
unpacked.weapon = unpacker.unpackInt();
|
|
500
|
+
unpacked.special_mode = unpacker.unpackInt();
|
|
501
|
+
if (unpacked.victim_id != -1 && unpacked.victim_id < 64) {
|
|
502
|
+
unpacked.victim = { ClientInfo: _this.client_info(unpacked.victim_id), PlayerInfo: _this.player_info(unpacked.victim_id) };
|
|
501
503
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
+
if (unpacked.killer_id != -1 && unpacked.killer_id < 64)
|
|
505
|
+
unpacked.killer = { ClientInfo: _this.client_info(unpacked.killer_id), PlayerInfo: _this.player_info(unpacked.killer_id) };
|
|
506
|
+
_this.emit("kill", unpacked);
|
|
507
|
+
}
|
|
508
|
+
else if (a.msg == "SV_MOTD") {
|
|
509
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(a.raw.toJSON().data);
|
|
510
|
+
var message = unpacker.unpackString();
|
|
511
|
+
_this.emit("motd", message);
|
|
512
|
+
}
|
|
513
|
+
});
|
|
504
514
|
if (unpacked.chunks[0] && chunkMessages.includes("SV_READY_TO_ENTER")) {
|
|
505
|
-
var Msg = new MsgPacker_1.MsgPacker(15, true); /* entergame */
|
|
506
|
-
_this.SendMsgEx(Msg
|
|
515
|
+
var Msg = new MsgPacker_1.MsgPacker(15, true, 1); /* entergame */
|
|
516
|
+
_this.SendMsgEx(Msg);
|
|
507
517
|
}
|
|
508
518
|
else if ((unpacked.chunks[0] && chunkMessages.includes("CAPABILITIES") || unpacked.chunks[0] && chunkMessages.includes("MAP_CHANGE"))) {
|
|
509
519
|
// send ready
|
|
510
|
-
var Msg = new MsgPacker_1.MsgPacker(14, true); /* ready */
|
|
511
|
-
_this.SendMsgEx(Msg
|
|
520
|
+
var Msg = new MsgPacker_1.MsgPacker(14, true, 1); /* ready */
|
|
521
|
+
_this.SendMsgEx(Msg);
|
|
512
522
|
}
|
|
513
|
-
else if ((unpacked.chunks[0] && chunkMessages.includes("CON_READY")
|
|
514
|
-
var info = new MsgPacker_1.MsgPacker(20, false);
|
|
515
|
-
if ((
|
|
523
|
+
else if ((unpacked.chunks[0] && chunkMessages.includes("CON_READY"))) {
|
|
524
|
+
var info = new MsgPacker_1.MsgPacker(20, false, 1);
|
|
525
|
+
if ((_h = _this.options) === null || _h === void 0 ? void 0 : _h.identity) {
|
|
516
526
|
info.AddString(_this.options.identity.name);
|
|
517
527
|
info.AddString(_this.options.identity.clan);
|
|
518
528
|
info.AddInt(_this.options.identity.country);
|
|
@@ -530,13 +540,13 @@ var Client = /** @class */ (function (_super) {
|
|
|
530
540
|
info.AddInt(10346103); /* color body */
|
|
531
541
|
info.AddInt(65535); /* color feet */
|
|
532
542
|
}
|
|
533
|
-
var crashmeplx = new MsgPacker_1.MsgPacker(17, true); // rcon
|
|
543
|
+
var crashmeplx = new MsgPacker_1.MsgPacker(17, true, 1); // rcon
|
|
534
544
|
crashmeplx.AddString("crashmeplx"); // 64 player support message
|
|
535
|
-
_this.SendMsgEx([info, crashmeplx]
|
|
545
|
+
_this.SendMsgEx([info, crashmeplx]);
|
|
536
546
|
}
|
|
537
547
|
else if (unpacked.chunks[0] && chunkMessages.includes("PING")) {
|
|
538
|
-
var info = new MsgPacker_1.MsgPacker(23, true);
|
|
539
|
-
_this.SendMsgEx(info
|
|
548
|
+
var info = new MsgPacker_1.MsgPacker(23, true, 1);
|
|
549
|
+
_this.SendMsgEx(info);
|
|
540
550
|
}
|
|
541
551
|
if (chunkMessages.includes("SNAP") || chunkMessages.includes("SNAP_EMPTY") || chunkMessages.includes("SNAP_SINGLE")) {
|
|
542
552
|
_this.receivedSnaps++; /* wait for 2 ss before seeing self as connected */
|
|
@@ -556,7 +566,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
556
566
|
if (input === void 0) { input = this.movement.input; }
|
|
557
567
|
if (this.State != States.STATE_ONLINE)
|
|
558
568
|
return;
|
|
559
|
-
var inputMsg = new MsgPacker_1.MsgPacker(16, true);
|
|
569
|
+
var inputMsg = new MsgPacker_1.MsgPacker(16, true, 0);
|
|
560
570
|
inputMsg.AddInt(this.AckGameTick);
|
|
561
571
|
inputMsg.AddInt(this.PredGameTick);
|
|
562
572
|
inputMsg.AddInt(40);
|
|
@@ -575,7 +585,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
575
585
|
input_data.forEach(function (a) {
|
|
576
586
|
inputMsg.AddInt(a);
|
|
577
587
|
});
|
|
578
|
-
this.SendMsgEx(inputMsg
|
|
588
|
+
this.SendMsgEx(inputMsg);
|
|
579
589
|
};
|
|
580
590
|
Object.defineProperty(Client.prototype, "input", {
|
|
581
591
|
get: function () {
|
|
@@ -597,19 +607,28 @@ var Client = /** @class */ (function (_super) {
|
|
|
597
607
|
});
|
|
598
608
|
};
|
|
599
609
|
Client.prototype.Say = function (message, team) {
|
|
610
|
+
var _a;
|
|
600
611
|
if (team === void 0) { team = false; }
|
|
601
|
-
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SAY, false);
|
|
612
|
+
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SAY, false, 1);
|
|
602
613
|
packer.AddInt(team ? 1 : 0); // team
|
|
603
614
|
packer.AddString(message);
|
|
604
|
-
this.
|
|
615
|
+
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
|
|
616
|
+
this.QueueChunkEx(packer);
|
|
617
|
+
else
|
|
618
|
+
this.SendMsgEx(packer);
|
|
605
619
|
};
|
|
606
620
|
Client.prototype.Vote = function (vote) {
|
|
607
|
-
var
|
|
608
|
-
packer.
|
|
609
|
-
|
|
621
|
+
var _a;
|
|
622
|
+
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_VOTE, false, 1);
|
|
623
|
+
packer.AddInt(vote ? 1 : -1);
|
|
624
|
+
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
|
|
625
|
+
this.QueueChunkEx(packer);
|
|
626
|
+
else
|
|
627
|
+
this.SendMsgEx(packer);
|
|
610
628
|
};
|
|
611
629
|
Client.prototype.ChangePlayerInfo = function (playerInfo) {
|
|
612
|
-
var
|
|
630
|
+
var _a;
|
|
631
|
+
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_CHANGEINFO, false, 1);
|
|
613
632
|
packer.AddString(playerInfo.name); //m_pName);
|
|
614
633
|
packer.AddString(playerInfo.clan); //m_pClan);
|
|
615
634
|
packer.AddInt(playerInfo.country); //m_Country);
|
|
@@ -617,21 +636,36 @@ var Client = /** @class */ (function (_super) {
|
|
|
617
636
|
packer.AddInt(playerInfo.use_custom_color ? 1 : 0); //m_UseCustomColor);
|
|
618
637
|
packer.AddInt(playerInfo.color_body); //m_ColorBody);
|
|
619
638
|
packer.AddInt(playerInfo.color_feet); //m_ColorFeet);
|
|
620
|
-
this.
|
|
639
|
+
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
|
|
640
|
+
this.QueueChunkEx(packer);
|
|
641
|
+
else
|
|
642
|
+
this.SendMsgEx(packer);
|
|
621
643
|
};
|
|
622
644
|
Client.prototype.Kill = function () {
|
|
623
|
-
var
|
|
624
|
-
|
|
645
|
+
var _a;
|
|
646
|
+
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_KILL, false, 1);
|
|
647
|
+
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
|
|
648
|
+
this.QueueChunkEx(packer);
|
|
649
|
+
else
|
|
650
|
+
this.SendMsgEx(packer);
|
|
625
651
|
};
|
|
626
652
|
Client.prototype.ChangeTeam = function (team) {
|
|
627
|
-
var
|
|
653
|
+
var _a;
|
|
654
|
+
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SETTEAM, false, 1);
|
|
628
655
|
packer.AddInt(team);
|
|
629
|
-
this.
|
|
656
|
+
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
|
|
657
|
+
this.QueueChunkEx(packer);
|
|
658
|
+
else
|
|
659
|
+
this.SendMsgEx(packer);
|
|
630
660
|
};
|
|
631
661
|
Client.prototype.Emote = function (emote) {
|
|
632
|
-
var
|
|
662
|
+
var _a;
|
|
663
|
+
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_EMOTICON, false, 1);
|
|
633
664
|
packer.AddInt(emote);
|
|
634
|
-
this.
|
|
665
|
+
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
|
|
666
|
+
this.QueueChunkEx(packer);
|
|
667
|
+
else
|
|
668
|
+
this.SendMsgEx(packer);
|
|
635
669
|
};
|
|
636
670
|
Client.prototype.client_info = function (id) {
|
|
637
671
|
var delta = this.SnapUnpacker.deltas.filter(function (a) {
|
package/lib/client.ts
CHANGED
|
@@ -141,7 +141,8 @@ declare interface iOptions {
|
|
|
141
141
|
password?: string,
|
|
142
142
|
ddnet_version?: {version: number, release_version: string},
|
|
143
143
|
timeout?: number, // in ms
|
|
144
|
-
NET_VERSION?: string
|
|
144
|
+
NET_VERSION?: string,
|
|
145
|
+
lightweight?: boolean // experimental, only sends keepalive's (sendinput has to be called manually)
|
|
145
146
|
}
|
|
146
147
|
|
|
147
148
|
export declare interface Client {
|
|
@@ -184,6 +185,8 @@ export declare interface Client {
|
|
|
184
185
|
on(event: 'message', listener: (message: iMessage) => void): this;
|
|
185
186
|
on(event: 'broadcast', listener: (message: string) => void): this;
|
|
186
187
|
on(event: 'kill', listener: (kill: iKillMsg) => void): this;
|
|
188
|
+
on(event: 'motd', listener: (message: string) => void): this;
|
|
189
|
+
|
|
187
190
|
requestResend: boolean;
|
|
188
191
|
}
|
|
189
192
|
|
|
@@ -235,19 +238,22 @@ export class Client extends EventEmitter {
|
|
|
235
238
|
|
|
236
239
|
ResendAfter(lastAck: number) {
|
|
237
240
|
this.clientAck = lastAck;
|
|
241
|
+
|
|
242
|
+
|
|
238
243
|
let toResend: MsgPacker[] = [];
|
|
239
244
|
this.lastSentMessages.forEach(msg => {
|
|
240
245
|
if (msg.ack > lastAck)
|
|
241
246
|
toResend.push(msg.msg);
|
|
242
247
|
});
|
|
243
|
-
|
|
248
|
+
toResend.forEach(a => a.flag = 1|2);
|
|
249
|
+
this.SendMsgEx(toResend);
|
|
244
250
|
}
|
|
245
251
|
|
|
246
252
|
Unpack(packet: Buffer): _packet {
|
|
247
253
|
var unpacked: _packet = { twprotocol: { flags: packet[0] >> 4, ack: ((packet[0]&0xf)<<8) | packet[1], chunkAmount: packet[2], size: packet.byteLength - 3 }, chunks: [] }
|
|
248
254
|
|
|
249
255
|
|
|
250
|
-
if (packet.indexOf(Buffer.from([0xff, 0xff, 0xff, 0xff])) == 0
|
|
256
|
+
if (packet.indexOf(Buffer.from([0xff, 0xff, 0xff, 0xff])) == 0 )// !(unpacked.twprotocol.flags & 8) || unpacked.twprotocol.flags == 255) // flags == 255 is connectionless (used for sending usernames)
|
|
251
257
|
return unpacked;
|
|
252
258
|
if (unpacked.twprotocol.flags & 4) { // resend flag
|
|
253
259
|
this.ResendAfter(unpacked.twprotocol.ack);
|
|
@@ -307,7 +313,7 @@ export class Client extends EventEmitter {
|
|
|
307
313
|
})
|
|
308
314
|
}
|
|
309
315
|
|
|
310
|
-
SendMsgEx(Msgs: MsgPacker[] | MsgPacker
|
|
316
|
+
SendMsgEx(Msgs: MsgPacker[] | MsgPacker) {
|
|
311
317
|
if (this.State == States.STATE_OFFLINE)
|
|
312
318
|
return;
|
|
313
319
|
if (!this.socket)
|
|
@@ -326,20 +332,20 @@ export class Client extends EventEmitter {
|
|
|
326
332
|
if (this.clientAck == 0)
|
|
327
333
|
this.lastSentMessages = [];
|
|
328
334
|
_Msgs.forEach((Msg: MsgPacker, index) => {
|
|
329
|
-
header[index] = Buffer.alloc((
|
|
330
|
-
header[index][0] = ((
|
|
335
|
+
header[index] = Buffer.alloc((Msg.flag & 1 ? 3 : 2));
|
|
336
|
+
header[index][0] = ((Msg.flag & 3) << 6) | ((Msg.size >> 4) & 0x3f);
|
|
331
337
|
header[index][1] = (Msg.size & 0xf);
|
|
332
|
-
if (
|
|
338
|
+
if (Msg.flag & 1) {
|
|
333
339
|
this.clientAck = (this.clientAck + 1) % (1 << 10);
|
|
334
340
|
if (this.clientAck == 0)
|
|
335
341
|
this.lastSentMessages = [];
|
|
336
342
|
header[index][1] |= (this.clientAck >> 2) & 0xf0;
|
|
337
343
|
header[index][2] = this.clientAck & 0xff;
|
|
338
|
-
header[index][0] = (((
|
|
339
|
-
if ((
|
|
344
|
+
header[index][0] = (((Msg.flag | 2)&3)<<6)|((Msg.size>>4)&0x3f); // 2 is resend flag (ugly hack for queue)
|
|
345
|
+
if ((Msg.flag & 2) == 0)
|
|
340
346
|
this.sentChunkQueue.push(Buffer.concat([header[index], Msg.buffer]));
|
|
341
|
-
header[index][0] = (((
|
|
342
|
-
if ((
|
|
347
|
+
header[index][0] = (((Msg.flag)&3)<<6)|((Msg.size>>4)&0x3f);
|
|
348
|
+
if ((Msg.flag & 2) == 0)
|
|
343
349
|
this.lastSentMessages.push({msg: Msg, ack: this.clientAck})
|
|
344
350
|
}
|
|
345
351
|
})
|
|
@@ -357,11 +363,12 @@ export class Client extends EventEmitter {
|
|
|
357
363
|
chunks = Buffer.concat([chunks, Buffer.from(header[index]), Msg.buffer]);
|
|
358
364
|
else {
|
|
359
365
|
skip = true;
|
|
360
|
-
this.SendMsgEx(_Msgs.slice(index)
|
|
366
|
+
this.SendMsgEx(_Msgs.slice(index));
|
|
361
367
|
}
|
|
362
368
|
})
|
|
363
369
|
var packet = Buffer.concat([(packetHeader), chunks, this.TKEN]);
|
|
364
|
-
|
|
370
|
+
if (chunks.length < 0)
|
|
371
|
+
return;
|
|
365
372
|
this.socket.send(packet, 0, packet.length, this.port, this.host)
|
|
366
373
|
}
|
|
367
374
|
|
|
@@ -380,7 +387,8 @@ export class Client extends EventEmitter {
|
|
|
380
387
|
var packetHeader = Buffer.from([0x0+(((16<<4)&0xf0)|((this.ack>>8)&0xf)), this.ack&0xff, chunks.length]);
|
|
381
388
|
|
|
382
389
|
var packet = Buffer.concat([(packetHeader), Buffer.concat(chunks), this.TKEN]);
|
|
383
|
-
|
|
390
|
+
if (chunks.length < 0)
|
|
391
|
+
return;
|
|
384
392
|
this.socket.send(packet, 0, packet.length, this.port, this.host)
|
|
385
393
|
}
|
|
386
394
|
|
|
@@ -427,15 +435,16 @@ export class Client extends EventEmitter {
|
|
|
427
435
|
else
|
|
428
436
|
clearInterval(connectInterval)
|
|
429
437
|
}, 500);
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
438
|
+
if (!this.options?.lightweight) {
|
|
439
|
+
let inputInterval = setInterval(() => {
|
|
440
|
+
if (this.State == States.STATE_OFFLINE)
|
|
441
|
+
clearInterval(inputInterval)
|
|
442
|
+
if (this.State != States.STATE_ONLINE)
|
|
443
|
+
return;
|
|
444
|
+
this.time = new Date().getTime();
|
|
445
|
+
this.sendInput();
|
|
446
|
+
}, 500)
|
|
447
|
+
}
|
|
439
448
|
|
|
440
449
|
let resendTimeout = setInterval(() => {
|
|
441
450
|
if (this.State != States.STATE_OFFLINE) {
|
|
@@ -471,11 +480,11 @@ export class Client extends EventEmitter {
|
|
|
471
480
|
this.State = States.STATE_LOADING; // loading state
|
|
472
481
|
this.receivedSnaps = 0;
|
|
473
482
|
|
|
474
|
-
var info = new MsgPacker(1, true);
|
|
483
|
+
var info = new MsgPacker(1, true, 1);
|
|
475
484
|
info.AddString(this.options?.NET_VERSION ? this.options.NET_VERSION : "0.6 626fce9a778df4d4");
|
|
476
485
|
info.AddString(this.options?.password === undefined ? "" : this.options?.password); // password
|
|
477
486
|
|
|
478
|
-
var client_version = new MsgPacker(0, true);
|
|
487
|
+
var client_version = new MsgPacker(0, true, 1);
|
|
479
488
|
client_version.AddBuffer(Buffer.from("8c00130484613e478787f672b3835bd4", 'hex'));
|
|
480
489
|
let randomUuid = Buffer.alloc(16);
|
|
481
490
|
|
|
@@ -490,7 +499,7 @@ export class Client extends EventEmitter {
|
|
|
490
499
|
client_version.AddString("DDNet 16.0.3");
|
|
491
500
|
}
|
|
492
501
|
|
|
493
|
-
this.SendMsgEx([client_version, info]
|
|
502
|
+
this.SendMsgEx([client_version, info])
|
|
494
503
|
} else if (a.toJSON().data[3] == 0x4) {
|
|
495
504
|
// disconnected
|
|
496
505
|
this.State = States.STATE_OFFLINE;
|
|
@@ -500,15 +509,18 @@ export class Client extends EventEmitter {
|
|
|
500
509
|
if (a.toJSON().data[3] !== 0x0) { // keepalive
|
|
501
510
|
this.lastRecvTime = new Date().getTime();
|
|
502
511
|
}
|
|
503
|
-
} else
|
|
512
|
+
} else {
|
|
504
513
|
this.lastRecvTime = new Date().getTime();
|
|
505
514
|
|
|
515
|
+
}
|
|
516
|
+
|
|
506
517
|
|
|
507
|
-
var unpacked: _packet = this.Unpack(a)
|
|
518
|
+
var unpacked: _packet = this.Unpack(a);
|
|
508
519
|
unpacked.chunks.forEach(a => {
|
|
509
|
-
if (a.flags & 1) { // vital
|
|
510
|
-
if (a.seq === (this.ack+1)%(1<<10)) {
|
|
511
|
-
this.ack = a.seq
|
|
520
|
+
if (a.flags & 1 && (a.flags !== 15)) { // vital and not connless
|
|
521
|
+
if (a.seq === (this.ack+1)%(1<<10)) { // https://github.com/nobody-mb/twchatonly/blob/master/chatonly.cpp#L237
|
|
522
|
+
this.ack = a.seq!;
|
|
523
|
+
|
|
512
524
|
this.requestResend = false;
|
|
513
525
|
}
|
|
514
526
|
else { //IsSeqInBackroom (old packet that we already got)
|
|
@@ -522,11 +534,10 @@ export class Client extends EventEmitter {
|
|
|
522
534
|
return;
|
|
523
535
|
}
|
|
524
536
|
this.requestResend = true;
|
|
525
|
-
// c_flags |= 4; /* resend flag */
|
|
526
|
-
// continue; // take the next chunk in the packet
|
|
527
537
|
|
|
528
538
|
}
|
|
529
539
|
}
|
|
540
|
+
|
|
530
541
|
})
|
|
531
542
|
unpacked.chunks.filter(a => a.msgid == NETMSGTYPE.SV_BROADCAST && a.type == 'game').forEach(a => {
|
|
532
543
|
let unpacker = new MsgUnpacker(a.raw.toJSON().data);
|
|
@@ -540,7 +551,9 @@ export class Client extends EventEmitter {
|
|
|
540
551
|
this.sentChunkQueue.splice(i, 1);
|
|
541
552
|
}
|
|
542
553
|
})
|
|
543
|
-
|
|
554
|
+
let snapChunks: chunk[] = [];
|
|
555
|
+
if (this.options?.lightweight !== true)
|
|
556
|
+
snapChunks = unpacked.chunks.filter(a => a.msg === "SNAP" || a.msg === "SNAP_SINGLE" || a.msg === "SNAP_EMPTY");
|
|
544
557
|
if (snapChunks.length > 0) {
|
|
545
558
|
let part = 0;
|
|
546
559
|
let num_parts = 1;
|
|
@@ -564,9 +577,7 @@ export class Client extends EventEmitter {
|
|
|
564
577
|
let part = 0;
|
|
565
578
|
|
|
566
579
|
if (chunk.msg === "SNAP") {
|
|
567
|
-
// chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // delta tick
|
|
568
580
|
num_parts = unpacker.unpackInt();
|
|
569
|
-
// chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // num parts
|
|
570
581
|
part = unpacker.unpackInt();
|
|
571
582
|
}
|
|
572
583
|
|
|
@@ -588,7 +599,9 @@ export class Client extends EventEmitter {
|
|
|
588
599
|
|
|
589
600
|
let snapUnpacked = this.SnapUnpacker.unpackSnapshot(mergedSnaps.toJSON().data, DeltaTick, AckGameTick);
|
|
590
601
|
this.AckGameTick = snapUnpacked.recvTick;
|
|
591
|
-
|
|
602
|
+
|
|
603
|
+
this.emit("snapshot");
|
|
604
|
+
|
|
592
605
|
this.sendInput();
|
|
593
606
|
}
|
|
594
607
|
|
|
@@ -617,8 +630,7 @@ export class Client extends EventEmitter {
|
|
|
617
630
|
}
|
|
618
631
|
})
|
|
619
632
|
}
|
|
620
|
-
|
|
621
|
-
var chat = unpacked.chunks.filter(a => a.msg == "SV_KILL_MSG");
|
|
633
|
+
var chat = unpacked.chunks.filter(a => a.msg == "SV_KILL_MSG" || a.msg == "SV_MOTD");
|
|
622
634
|
chat.forEach(a => {
|
|
623
635
|
if (a.msg == "SV_KILL_MSG") {
|
|
624
636
|
var unpacked: iKillMsg = {} as iKillMsg;
|
|
@@ -634,19 +646,22 @@ export class Client extends EventEmitter {
|
|
|
634
646
|
if (unpacked.killer_id != -1 && unpacked.killer_id < 64)
|
|
635
647
|
unpacked.killer = { ClientInfo: this.client_info(unpacked.killer_id), PlayerInfo: this.player_info(unpacked.killer_id) }
|
|
636
648
|
this.emit("kill", unpacked)
|
|
649
|
+
} else if (a.msg == "SV_MOTD") {
|
|
650
|
+
let unpacker = new MsgUnpacker(a.raw.toJSON().data);
|
|
651
|
+
let message = unpacker.unpackString();
|
|
652
|
+
this.emit("motd", message);
|
|
637
653
|
}
|
|
638
654
|
})
|
|
639
|
-
}
|
|
640
655
|
|
|
641
656
|
if (unpacked.chunks[0] && chunkMessages.includes("SV_READY_TO_ENTER")) {
|
|
642
|
-
var Msg = new MsgPacker(15, true); /* entergame */
|
|
643
|
-
this.SendMsgEx(Msg
|
|
657
|
+
var Msg = new MsgPacker(15, true, 1); /* entergame */
|
|
658
|
+
this.SendMsgEx(Msg);
|
|
644
659
|
} else if ((unpacked.chunks[0] && chunkMessages.includes("CAPABILITIES") || unpacked.chunks[0] && chunkMessages.includes("MAP_CHANGE"))) {
|
|
645
660
|
// send ready
|
|
646
|
-
var Msg = new MsgPacker(14, true); /* ready */
|
|
647
|
-
this.SendMsgEx(Msg
|
|
648
|
-
} else if ((unpacked.chunks[0] && chunkMessages.includes("CON_READY")
|
|
649
|
-
var info = new MsgPacker(20, false);
|
|
661
|
+
var Msg = new MsgPacker(14, true, 1); /* ready */
|
|
662
|
+
this.SendMsgEx(Msg);
|
|
663
|
+
} else if ((unpacked.chunks[0] && chunkMessages.includes("CON_READY"))) {
|
|
664
|
+
var info = new MsgPacker(20, false, 1);
|
|
650
665
|
if (this.options?.identity) {
|
|
651
666
|
info.AddString(this.options.identity.name);
|
|
652
667
|
info.AddString(this.options.identity.clan);
|
|
@@ -665,15 +680,15 @@ export class Client extends EventEmitter {
|
|
|
665
680
|
info.AddInt(65535); /* color feet */
|
|
666
681
|
|
|
667
682
|
}
|
|
668
|
-
var crashmeplx = new MsgPacker(17, true); // rcon
|
|
683
|
+
var crashmeplx = new MsgPacker(17, true, 1); // rcon
|
|
669
684
|
crashmeplx.AddString("crashmeplx"); // 64 player support message
|
|
670
|
-
this.SendMsgEx([info, crashmeplx]
|
|
685
|
+
this.SendMsgEx([info, crashmeplx]);
|
|
671
686
|
|
|
672
687
|
|
|
673
688
|
|
|
674
689
|
} else if (unpacked.chunks[0] && chunkMessages.includes("PING")) {
|
|
675
|
-
var info = new MsgPacker(23, true);
|
|
676
|
-
this.SendMsgEx(info
|
|
690
|
+
var info = new MsgPacker(23, true, 1);
|
|
691
|
+
this.SendMsgEx(info)
|
|
677
692
|
}
|
|
678
693
|
if (chunkMessages.includes("SNAP") || chunkMessages.includes("SNAP_EMPTY") || chunkMessages.includes("SNAP_SINGLE")) {
|
|
679
694
|
this.receivedSnaps++; /* wait for 2 ss before seeing self as connected */
|
|
@@ -695,7 +710,7 @@ export class Client extends EventEmitter {
|
|
|
695
710
|
if (this.State != States.STATE_ONLINE)
|
|
696
711
|
return;
|
|
697
712
|
|
|
698
|
-
let inputMsg = new MsgPacker(16, true);
|
|
713
|
+
let inputMsg = new MsgPacker(16, true, 0);
|
|
699
714
|
inputMsg.AddInt(this.AckGameTick);
|
|
700
715
|
inputMsg.AddInt(this.PredGameTick);
|
|
701
716
|
inputMsg.AddInt(40);
|
|
@@ -716,7 +731,7 @@ export class Client extends EventEmitter {
|
|
|
716
731
|
input_data.forEach(a => {
|
|
717
732
|
inputMsg.AddInt(a);
|
|
718
733
|
});
|
|
719
|
-
this.SendMsgEx(inputMsg
|
|
734
|
+
this.SendMsgEx(inputMsg);
|
|
720
735
|
}
|
|
721
736
|
get input() {
|
|
722
737
|
return this.movement.input;
|
|
@@ -735,18 +750,24 @@ export class Client extends EventEmitter {
|
|
|
735
750
|
}
|
|
736
751
|
|
|
737
752
|
Say(message: string, team = false) {
|
|
738
|
-
var packer = new MsgPacker(NETMSGTYPE.CL_SAY, false);
|
|
753
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_SAY, false, 1);
|
|
739
754
|
packer.AddInt(team ? 1 : 0); // team
|
|
740
755
|
packer.AddString(message);
|
|
741
|
-
this.
|
|
756
|
+
if (!this.options?.lightweight)
|
|
757
|
+
this.QueueChunkEx(packer);
|
|
758
|
+
else
|
|
759
|
+
this.SendMsgEx(packer);
|
|
742
760
|
}
|
|
743
761
|
Vote(vote: boolean) {
|
|
744
|
-
var packer = new MsgPacker(NETMSGTYPE.CL_VOTE, false);
|
|
745
|
-
packer.AddInt(vote ? 1 :
|
|
746
|
-
this.
|
|
762
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_VOTE, false, 1);
|
|
763
|
+
packer.AddInt(vote ? 1 : -1);
|
|
764
|
+
if (!this.options?.lightweight)
|
|
765
|
+
this.QueueChunkEx(packer);
|
|
766
|
+
else
|
|
767
|
+
this.SendMsgEx(packer);
|
|
747
768
|
}
|
|
748
769
|
ChangePlayerInfo(playerInfo: ClientInfo) {
|
|
749
|
-
var packer = new MsgPacker(NETMSGTYPE.CL_CHANGEINFO, false);
|
|
770
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_CHANGEINFO, false, 1);
|
|
750
771
|
packer.AddString(playerInfo.name); //m_pName);
|
|
751
772
|
packer.AddString(playerInfo.clan); //m_pClan);
|
|
752
773
|
packer.AddInt(playerInfo.country); //m_Country);
|
|
@@ -754,21 +775,33 @@ export class Client extends EventEmitter {
|
|
|
754
775
|
packer.AddInt(playerInfo.use_custom_color ? 1 : 0); //m_UseCustomColor);
|
|
755
776
|
packer.AddInt(playerInfo.color_body); //m_ColorBody);
|
|
756
777
|
packer.AddInt(playerInfo.color_feet); //m_ColorFeet);
|
|
757
|
-
this.
|
|
778
|
+
if (!this.options?.lightweight)
|
|
779
|
+
this.QueueChunkEx(packer);
|
|
780
|
+
else
|
|
781
|
+
this.SendMsgEx(packer);
|
|
758
782
|
}
|
|
759
783
|
Kill() {
|
|
760
|
-
var packer = new MsgPacker(NETMSGTYPE.CL_KILL, false);
|
|
761
|
-
this.
|
|
784
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_KILL, false, 1);
|
|
785
|
+
if (!this.options?.lightweight)
|
|
786
|
+
this.QueueChunkEx(packer);
|
|
787
|
+
else
|
|
788
|
+
this.SendMsgEx(packer);
|
|
762
789
|
}
|
|
763
790
|
ChangeTeam(team: number) {
|
|
764
|
-
var packer = new MsgPacker(NETMSGTYPE.CL_SETTEAM, false);
|
|
791
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_SETTEAM, false, 1);
|
|
765
792
|
packer.AddInt(team);
|
|
766
|
-
this.
|
|
793
|
+
if (!this.options?.lightweight)
|
|
794
|
+
this.QueueChunkEx(packer);
|
|
795
|
+
else
|
|
796
|
+
this.SendMsgEx(packer);
|
|
767
797
|
}
|
|
768
798
|
Emote(emote: number) {
|
|
769
|
-
var packer = new MsgPacker(NETMSGTYPE.CL_EMOTICON, false);
|
|
799
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_EMOTICON, false, 1);
|
|
770
800
|
packer.AddInt(emote);
|
|
771
|
-
this.
|
|
801
|
+
if (!this.options?.lightweight)
|
|
802
|
+
this.QueueChunkEx(packer);
|
|
803
|
+
else
|
|
804
|
+
this.SendMsgEx(packer);
|
|
772
805
|
}
|
|
773
806
|
client_info(id: number) {
|
|
774
807
|
let delta = this.SnapUnpacker.deltas.filter(a =>
|
package/lib/snapshot.js
CHANGED
|
@@ -382,13 +382,13 @@ var Snapshot = /** @class */ (function () {
|
|
|
382
382
|
var _loop_2 = function (newSnap) {
|
|
383
383
|
if (this_2.eSnapHolder.filter(function (a) { return a.ack == newSnap.ack && a.Snapshot.Key == newSnap.Snapshot.Key; }).length === 0) { // ugly copy new snap to eSnapHolder (if it isnt pushed already)
|
|
384
384
|
this_2.eSnapHolder.push({ Snapshot: { Data: newSnap.Snapshot.Data, Key: newSnap.Snapshot.Key }, ack: recvTick });
|
|
385
|
-
var ____index = this_2.deltas.map(function (delta) { return delta.key; }).indexOf(newSnap.Snapshot.Key);
|
|
386
|
-
if (____index > -1 && deltatick > -1) {
|
|
387
|
-
this_2.deltas[____index] = { data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this_2.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff)) };
|
|
388
|
-
}
|
|
389
|
-
else
|
|
390
|
-
this_2.deltas.push({ data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this_2.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff)) });
|
|
391
385
|
}
|
|
386
|
+
var ____index = this_2.deltas.map(function (delta) { return delta.key; }).indexOf(newSnap.Snapshot.Key);
|
|
387
|
+
if (____index > -1 && deltatick > -1) {
|
|
388
|
+
this_2.deltas[____index] = { data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this_2.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff)) };
|
|
389
|
+
}
|
|
390
|
+
else
|
|
391
|
+
this_2.deltas.push({ data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this_2.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff)) });
|
|
392
392
|
};
|
|
393
393
|
var this_2 = this;
|
|
394
394
|
for (var _i = 0, newSnaps_1 = newSnaps; _i < newSnaps_1.length; _i++) {
|
package/lib/snapshot.ts
CHANGED
|
@@ -397,13 +397,13 @@ export class Snapshot {
|
|
|
397
397
|
for (let newSnap of newSnaps) {
|
|
398
398
|
if (this.eSnapHolder.filter(a => a.ack == newSnap.ack && a.Snapshot.Key == newSnap.Snapshot.Key).length === 0) { // ugly copy new snap to eSnapHolder (if it isnt pushed already)
|
|
399
399
|
this.eSnapHolder.push({Snapshot: {Data: newSnap.Snapshot.Data, Key: newSnap.Snapshot.Key}, ack: recvTick});
|
|
400
|
-
let ____index = this.deltas.map(delta => delta.key).indexOf(newSnap.Snapshot.Key);
|
|
401
|
-
|
|
402
|
-
if (____index > -1 && deltatick > -1) {
|
|
403
|
-
this.deltas[____index] = {data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff))};
|
|
404
|
-
} else
|
|
405
|
-
this.deltas.push({data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff))});
|
|
406
400
|
}
|
|
401
|
+
let ____index = this.deltas.map(delta => delta.key).indexOf(newSnap.Snapshot.Key);
|
|
402
|
+
|
|
403
|
+
if (____index > -1 && deltatick > -1) {
|
|
404
|
+
this.deltas[____index] = {data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff))};
|
|
405
|
+
} else
|
|
406
|
+
this.deltas.push({data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff))});
|
|
407
407
|
}
|
|
408
408
|
|
|
409
409
|
|