teeworlds 2.1.7 → 2.1.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 CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MsgPacker = void 0;
4
4
  var MsgPacker = /** @class */ (function () {
5
5
  function MsgPacker(msg, sys) {
6
- this.result = Buffer.from([2 * msg + (sys ? 1 : 0)]); // booleans turn into int automatically.
6
+ this.result = Buffer.from([2 * msg + (sys ? 1 : 0)]);
7
7
  this.sys = sys;
8
8
  }
9
9
  MsgPacker.prototype.AddString = function (str) {
@@ -33,7 +33,6 @@ var MsgPacker = /** @class */ (function () {
33
33
  }
34
34
  else
35
35
  result.push(pDst);
36
- // ... i'll just stop trying to understand.
37
36
  this.result = Buffer.concat([this.result, Buffer.from(result)]);
38
37
  };
39
38
  Object.defineProperty(MsgPacker.prototype, "size", {
@@ -53,5 +52,3 @@ var MsgPacker = /** @class */ (function () {
53
52
  return MsgPacker;
54
53
  }());
55
54
  exports.MsgPacker = MsgPacker;
56
- // module.exports = MsgPacker;
57
- // export = MsgPacker;
package/lib/MsgPacker.ts CHANGED
@@ -2,7 +2,7 @@ export class MsgPacker {
2
2
  result: Buffer;
3
3
  sys: boolean;
4
4
  constructor(msg: number, sys: boolean) {
5
- this.result = Buffer.from([2*msg + (sys ? 1 : 0)]) // booleans turn into int automatically.
5
+ this.result = Buffer.from([2*msg + (sys ? 1 : 0)]);
6
6
  this.sys = sys;
7
7
  }
8
8
  AddString(str: string) {
@@ -32,8 +32,6 @@ export class MsgPacker {
32
32
  } else
33
33
  result.push(pDst)
34
34
 
35
- // ... i'll just stop trying to understand.
36
-
37
35
  this.result = Buffer.concat([this.result, Buffer.from(result)])
38
36
  }
39
37
  get size() {
@@ -43,5 +41,3 @@ export class MsgPacker {
43
41
  return this.result
44
42
  }
45
43
  }
46
- // module.exports = MsgPacker;
47
- // export = MsgPacker;
@@ -4,7 +4,6 @@ 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 len = 1;
8
7
  var iter = pSrc[Symbol.iterator]();
9
8
  var src = iter.next();
10
9
  src = src.value;
@@ -15,7 +14,6 @@ function unpackInt(pSrc) {
15
14
  break;
16
15
  src = iter.next();
17
16
  src = src.value;
18
- // len++;
19
17
  result |= ((src & 127)) << (6 + 7 * i);
20
18
  }
21
19
  result ^= -sign;
@@ -53,4 +51,3 @@ var MsgUnpacker = /** @class */ (function () {
53
51
  return MsgUnpacker;
54
52
  }());
55
53
  exports.MsgUnpacker = MsgUnpacker;
56
- // export = {MsgUnpacker, unpackInt, unpackString}
@@ -1,7 +1,6 @@
1
1
  const decoder = new TextDecoder('utf-8');
2
2
  export function unpackInt(pSrc: number[]): {result: number, remaining: number[]} {
3
3
  var result = 0;
4
- // var len = 1;
5
4
 
6
5
  var iter = pSrc[Symbol.iterator]()
7
6
  var src: any = iter.next()
@@ -16,7 +15,6 @@ export function unpackInt(pSrc: number[]): {result: number, remaining: number[]}
16
15
  src = iter.next()
17
16
 
18
17
  src = src.value;
19
- // len++;
20
18
  result |= ((src & 0b0111_1111)) << (6+7*i)
21
19
 
22
20
  }
@@ -55,6 +53,3 @@ export class MsgUnpacker {
55
53
  return unpacked.result;
56
54
  }
57
55
  }
58
-
59
-
60
- // export = {MsgUnpacker, unpackInt, unpackString}
package/lib/client.js CHANGED
@@ -164,10 +164,9 @@ var Client = /** @class */ (function (_super) {
164
164
  if (packet.length == 1 && packet[0] == -1)
165
165
  return unpacked;
166
166
  }
167
- // return unpacked;
168
167
  for (var i = 0; i < unpacked.twprotocol.chunkAmount; i++) {
169
168
  var chunk = {};
170
- chunk.bytes = ((packet[0] & 0x3f) << 4) | (packet[1] & ((1 << 4) - 1)); // idk what this shit is but it works
169
+ chunk.bytes = ((packet[0] & 0x3f) << 4) | (packet[1] & ((1 << 4) - 1));
171
170
  chunk.flags = (packet[0] >> 6) & 3;
172
171
  chunk.sequence = -1;
173
172
  if (chunk.flags & 1) {
@@ -183,11 +182,10 @@ var Client = /** @class */ (function (_super) {
183
182
  Object.values(messageUUIDs).forEach(function (a, i) {
184
183
  if (a.compare(packet.slice(0, 16)) == 0) {
185
184
  chunk.extended_msgid = a;
186
- // chunk.type = 'sys';
187
185
  chunk.msg = Object.keys(messageUUIDs)[i];
188
186
  }
189
187
  });
190
- packet = packet.slice(chunk.bytes); // +1 cuz it adds an extra \x00 for easier parsing i guess
188
+ packet = packet.slice(chunk.bytes);
191
189
  unpacked.chunks.push(chunk);
192
190
  }
193
191
  return unpacked;
@@ -211,31 +209,10 @@ var Client = /** @class */ (function (_super) {
211
209
  */
212
210
  });
213
211
  };
214
- // SendMsgEx(Msg: MsgPacker, Flags: number) {
215
- // if (this.State == States.STATE_OFFLINE)
216
- // throw new Error("Client is not connected");
217
- // if (!this.socket)
218
- // return;
219
- // this.lastSendTime = new Date().getTime();
220
- // var header = []
221
- // header[0] = ((Flags & 3) << 6) | ((Msg.size >> 4) & 0x3f);
222
- // header[1] = (Msg.size & 0xf);
223
- // if (Flags & 1) {
224
- // this.clientAck = (this.clientAck + 1) % (1 << 10);
225
- // header[1] |= (this.clientAck >> 2) & 0xf0;
226
- // header[2] = this.clientAck & 0xff;
227
- // this.sentChunkQueue.push(Buffer.concat([Buffer.from(header), Msg.buffer]));
228
- // }
229
- // let latestBuf = Buffer.from([0x0 + (((16 << 4) & 0xf0) | ((this.ack >> 8) & 0xf)), this.ack & 0xff, 0x1, header[0], header[1]]);
230
- // if (Flags & 1)
231
- // latestBuf = Buffer.concat([latestBuf, Buffer.from([this.clientAck])]);
232
- // latestBuf = Buffer.concat([latestBuf, Msg.buffer, this.TKEN]);
233
- // this.socket.send(latestBuf, 0, latestBuf.length, this.port, this.host);
234
- // }
235
212
  Client.prototype.SendMsgEx = function (Msgs, Flags) {
236
213
  var _this = this;
237
214
  if (this.State == States.STATE_OFFLINE)
238
- return; //throw new Error("Client is not connected");
215
+ return;
239
216
  if (!this.socket)
240
217
  return;
241
218
  var _Msgs;
@@ -268,7 +245,7 @@ var Client = /** @class */ (function (_super) {
268
245
  };
269
246
  Client.prototype.SendMsgRaw = function (chunks) {
270
247
  if (this.State == States.STATE_OFFLINE)
271
- return console.log(chunks, "client not connected"); //throw new Error("Client is not connected");
248
+ return;
272
249
  if (!this.socket)
273
250
  return;
274
251
  this.lastSendTime = new Date().getTime();
@@ -278,7 +255,6 @@ var Client = /** @class */ (function (_super) {
278
255
  };
279
256
  Client.prototype.MsgToChunk = function (packet) {
280
257
  var chunk = {};
281
- // let packet = Msg.buffer;
282
258
  chunk.bytes = ((packet[0] & 0x3f) << 4) | (packet[1] & ((1 << 4) - 1));
283
259
  chunk.flags = (packet[0] >> 6) & 3;
284
260
  chunk.sequence = -1;
@@ -291,13 +267,10 @@ var Client = /** @class */ (function (_super) {
291
267
  chunk.type = packet[0] & 1 ? "sys" : "game"; // & 1 = binary, ****_***1. e.g 0001_0111 sys, 0001_0110 game
292
268
  chunk.msgid = (packet[0] - (packet[0] & 1)) / 2;
293
269
  chunk.msg = messageTypes[packet[0] & 1][chunk.msgid];
294
- // if (chunk.msg == undefined)
295
- // console.log(packet)
296
270
  chunk.raw = packet.slice(1, chunk.bytes);
297
271
  Object.values(messageUUIDs).forEach(function (a, i) {
298
272
  if (a.compare(packet.slice(0, 16)) === 0) {
299
273
  chunk.extended_msgid = a;
300
- // chunk.type = 'sys';
301
274
  chunk.msg = Object.keys(messageUUIDs)[i];
302
275
  }
303
276
  });
@@ -310,7 +283,6 @@ var Client = /** @class */ (function (_super) {
310
283
  if (_this.State == States.STATE_ONLINE) {
311
284
  if (_this.AckGameTick > 0)
312
285
  _this.PredGameTick++;
313
- // console.log(this.PredGameTick, this.AckGameTick)
314
286
  }
315
287
  else if (_this.State == States.STATE_OFFLINE)
316
288
  clearInterval(predTimer);
@@ -323,30 +295,21 @@ var Client = /** @class */ (function (_super) {
323
295
  clearInterval(connectInterval);
324
296
  }, 500);
325
297
  var inputInterval = setInterval(function () {
326
- // if (new Date().getTime() - this.time >= 1000) {
327
298
  if (_this.State == States.STATE_OFFLINE)
328
299
  clearInterval(inputInterval);
329
300
  if (_this.State != States.STATE_ONLINE)
330
301
  return;
331
302
  _this.time = new Date().getTime();
332
- // this.SendControlMsg(0);
333
- // console.log("sending with " + this.AckGameTick)
334
303
  _this.sendInput();
335
- // }
336
304
  }, 500);
337
305
  var resendTimeout = setInterval(function () {
338
- // this.sentChunkQueue.forEach((chunk) => {
339
- // if (this.State == 0) // disconnected
340
- // return;
341
306
  if (_this.State != States.STATE_OFFLINE) {
342
307
  if (((new Date().getTime()) - _this.lastSendTime) > 900 && _this.sentChunkQueue.length > 0) {
343
308
  _this.SendMsgRaw([_this.sentChunkQueue[0]]);
344
- console.log(_this.sentChunkQueue, _this.State);
345
309
  }
346
310
  }
347
311
  else
348
312
  clearInterval(resendTimeout);
349
- // })
350
313
  }, 1000);
351
314
  this.time = new Date().getTime() + 2000; // start sending keepalives after 2s
352
315
  if (this.socket)
@@ -384,7 +347,6 @@ var Client = /** @class */ (function (_super) {
384
347
  // disconnected
385
348
  _this.State = States.STATE_OFFLINE;
386
349
  var reason = (MsgUnpacker_1.unpackString(a.toJSON().data.slice(4)).result);
387
- // this.State = -1;
388
350
  _this.emit("disconnect", reason);
389
351
  }
390
352
  }
@@ -393,8 +355,6 @@ var Client = /** @class */ (function (_super) {
393
355
  if (a.flags & 1) { // vital
394
356
  if (a.seq != undefined && a.seq != -1)
395
357
  _this.ack = a.seq;
396
- else
397
- console.log("no seq", a);
398
358
  }
399
359
  });
400
360
  _this.sentChunkQueue.forEach(function (buff, i) {
@@ -402,61 +362,55 @@ var Client = /** @class */ (function (_super) {
402
362
  if (chunk.flags & 1) {
403
363
  if (chunk.seq && chunk.seq < _this.ack) {
404
364
  _this.sentChunkQueue.splice(i, 1);
405
- // this.ack = (this.ack + 1) % (1 << 10);
406
365
  }
407
366
  }
408
367
  });
409
368
  var snapChunks = unpacked.chunks.filter(function (a) { return a.msg === "SNAP" || a.msg === "SNAP_SINGLE" || a.msg === "SNAP_EMPTY"; });
410
- // console.log(unpacked.chunks.length, unpacked)
411
369
  if (snapChunks.length > 0) {
412
- var part_1 = 0;
413
- var num_parts_1 = 1;
370
+ var part = 0;
371
+ var num_parts = 1;
414
372
  snapChunks.forEach(function (chunk) {
415
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
416
- var AckGameTick = (MsgUnpacker_1.unpackInt(chunk.raw.toJSON().data).result);
417
- // setImmediate(() => {
418
- // console.log(AckGameTick, this.AckGameTick, chunk.msg)
373
+ var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw.toJSON().data);
374
+ var AckGameTick = unpacker.unpackInt();
419
375
  if (AckGameTick > _this.AckGameTick) {
420
376
  _this.AckGameTick = AckGameTick;
421
377
  if (Math.abs(_this.PredGameTick - _this.AckGameTick) > 10)
422
378
  _this.PredGameTick = AckGameTick + 1;
423
- // console.log(this.AckGameTick)
424
379
  }
425
- // })
426
- chunk.raw = Buffer.from(MsgUnpacker_1.unpackInt((_a = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _a === void 0 ? void 0 : _a.toJSON().data).remaining);
427
- var DeltaTick = MsgUnpacker_1.unpackInt((_b = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _b === void 0 ? void 0 : _b.toJSON().data).result;
380
+ // chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining);
381
+ var DeltaTick = AckGameTick - unpacker.unpackInt();
382
+ var num_parts = 1;
383
+ var part = 0;
428
384
  if (chunk.msg === "SNAP") {
429
- chunk.raw = Buffer.from(MsgUnpacker_1.unpackInt((_c = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _c === void 0 ? void 0 : _c.toJSON().data).remaining); // delta tick
430
- num_parts_1 = (MsgUnpacker_1.unpackInt((_d = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _d === void 0 ? void 0 : _d.toJSON().data).result);
431
- chunk.raw = Buffer.from(MsgUnpacker_1.unpackInt((_e = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _e === void 0 ? void 0 : _e.toJSON().data).remaining); // num parts
432
- part_1 = (MsgUnpacker_1.unpackInt((_f = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _f === void 0 ? void 0 : _f.toJSON().data).result);
385
+ // chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // delta tick
386
+ num_parts = unpacker.unpackInt();
387
+ // chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // num parts
388
+ part = unpacker.unpackInt();
389
+ }
390
+ var crc = 0;
391
+ var part_size = 0;
392
+ if (chunk.msg != "SNAP_EMPTY") {
393
+ crc = unpacker.unpackInt(); // crc
394
+ part_size = unpacker.unpackInt();
433
395
  }
434
- chunk.raw = Buffer.from(MsgUnpacker_1.unpackInt((_g = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _g === void 0 ? void 0 : _g.toJSON().data).remaining); // part
435
- if (chunk.msg != "SNAP_EMPTY")
436
- chunk.raw = Buffer.from(MsgUnpacker_1.unpackInt((_h = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _h === void 0 ? void 0 : _h.toJSON().data).remaining); // crc
437
- chunk.raw = Buffer.from(MsgUnpacker_1.unpackInt((_j = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _j === void 0 ? void 0 : _j.toJSON().data).remaining); // crc
438
- if (part_1 === 0 || _this.snaps.length > 30) {
396
+ if (part === 0 || _this.snaps.length > 30) {
439
397
  _this.snaps = [];
440
398
  }
441
- chunk.raw = Buffer.from(MsgUnpacker_1.unpackInt((_k = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _k === void 0 ? void 0 : _k.toJSON().data).remaining); // crc
399
+ chunk.raw = Buffer.from(unpacker.remaining);
442
400
  _this.snaps.push(chunk.raw);
443
- // console.log(this.PredGameTick - this.AckGameTick, this.PredGameTick, this.AckGameTick)
444
- if ((num_parts_1 - 1) === part_1 && _this.snaps.length === num_parts_1) {
401
+ if ((num_parts - 1) === part && _this.snaps.length === num_parts) {
445
402
  var mergedSnaps_1 = Buffer.concat(_this.snaps);
403
+ // mergedSnaps = Buffer.from(unpackInt(mergedSnaps.toJSON().data).remaining);
446
404
  var snapUnpacked = SnapUnpacker.unpackSnapshot(mergedSnaps_1.toJSON().data, 1);
447
- // console.log(snapUnpacked)
405
+ // console.log(snapUnpacked.items, toHexStream(mergedSnaps));
448
406
  snapUnpacked.items.forEach(function (a, i) {
449
407
  if (a.type_id === items.OBJ_CLIENT_INFO) {
450
- // console.log(a.parsed, i)
451
408
  _this.client_infos[a.id] = a.parsed;
452
- if (a.parsed.name.includes("������")) {
453
- console.log(_this.PredGameTick, _this.AckGameTick, mergedSnaps_1.toJSON().data.toString());
409
+ if (_this.client_infos[a.id].name.includes("") || _this.client_infos[a.id].clan.includes("�")) {
410
+ console.log("bad name", _this.client_infos[a.id], toHexStream(mergedSnaps_1), chunk, AckGameTick, DeltaTick, crc, part_size);
454
411
  }
455
- console.log(_this.client_infos[a.id].name, _this.client_infos[a.id].clan, [a.id]);
412
+ console.log(_this.client_infos[a.id]);
456
413
  }
457
- // else if (a.type_id === items.OBJ_PLAYER_INFO) {
458
- // this.player_infos[a.id] = a.parsed as PlayerInfo;
459
- // }
460
414
  });
461
415
  }
462
416
  });
@@ -466,15 +420,17 @@ var Client = /** @class */ (function (_super) {
466
420
  var chat = unpacked.chunks.filter(function (a) { return a.msg == "SV_CHAT"; });
467
421
  chat.forEach(function (a) {
468
422
  if (a.msg == "SV_CHAT") {
469
- var unpacked = {};
470
- unpacked.team = MsgUnpacker_1.unpackInt(a.raw.toJSON().data).result;
471
- var remaining = MsgUnpacker_1.unpackInt(a.raw.toJSON().data).remaining;
472
- unpacked.client_id = MsgUnpacker_1.unpackInt(remaining).result;
473
- remaining = MsgUnpacker_1.unpackInt(remaining).remaining;
474
- unpacked.message = MsgUnpacker_1.unpackString(remaining).result;
423
+ var unpacker = new MsgUnpacker_1.MsgUnpacker(a.raw.toJSON().data);
424
+ var unpacked = {
425
+ team: unpacker.unpackInt(),
426
+ client_id: unpacker.unpackInt(),
427
+ message: unpacker.unpackString()
428
+ };
475
429
  if (unpacked.client_id != -1)
476
- unpacked.author = { ClientInfo: _this.client_infos[unpacked.client_id], PlayerInfo: _this.player_infos[unpacked.client_id] };
477
- // console.log(unpacked)
430
+ unpacked.author = {
431
+ ClientInfo: _this.client_infos[unpacked.client_id],
432
+ PlayerInfo: _this.player_infos[unpacked.client_id]
433
+ };
478
434
  _this.emit("message", unpacked);
479
435
  }
480
436
  });
@@ -493,7 +449,6 @@ var Client = /** @class */ (function (_super) {
493
449
  unpacked.victim = { ClientInfo: _this.client_infos[unpacked.victim_id], PlayerInfo: _this.player_infos[unpacked.victim_id] };
494
450
  if (unpacked.killer_id != -1)
495
451
  unpacked.killer = { ClientInfo: _this.client_infos[unpacked.killer_id], PlayerInfo: _this.player_infos[unpacked.killer_id] };
496
- // console.log(unpacked)
497
452
  _this.emit("kill", unpacked);
498
453
  }
499
454
  });
@@ -540,51 +495,6 @@ var Client = /** @class */ (function (_super) {
540
495
  _this.emit('connected');
541
496
  _this.State = States.STATE_ONLINE;
542
497
  }
543
- var chunks = unpacked.chunks.filter(function (a) { return a.msg == "SNAP" || a.msg == "SNAP_SINGLE" || a.msg == "SNAP_EMPTY"; });
544
- if (chunks.length > 0) {
545
- var part_2 = 0;
546
- var num_parts_2 = 1;
547
- chunks.forEach(function (chunk) {
548
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
549
- var AckGameTick = (MsgUnpacker_1.unpackInt(chunk.raw.toJSON().data).result);
550
- chunk.raw = Buffer.from(MsgUnpacker_1.unpackInt((_a = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _a === void 0 ? void 0 : _a.toJSON().data).remaining);
551
- var DeltaTick = MsgUnpacker_1.unpackInt((_b = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _b === void 0 ? void 0 : _b.toJSON().data).result;
552
- if (chunk.msg == "SNAP") {
553
- chunk.raw = Buffer.from(MsgUnpacker_1.unpackInt((_c = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _c === void 0 ? void 0 : _c.toJSON().data).remaining); // delta tick
554
- num_parts_2 = (MsgUnpacker_1.unpackInt((_d = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _d === void 0 ? void 0 : _d.toJSON().data).result);
555
- chunk.raw = Buffer.from(MsgUnpacker_1.unpackInt((_e = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _e === void 0 ? void 0 : _e.toJSON().data).remaining); // num parts
556
- part_2 = (MsgUnpacker_1.unpackInt((_f = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _f === void 0 ? void 0 : _f.toJSON().data).result);
557
- }
558
- chunk.raw = Buffer.from(MsgUnpacker_1.unpackInt((_g = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _g === void 0 ? void 0 : _g.toJSON().data).remaining); // part
559
- if (chunk.msg != "SNAP_EMPTY")
560
- chunk.raw = Buffer.from(MsgUnpacker_1.unpackInt((_h = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _h === void 0 ? void 0 : _h.toJSON().data).remaining); // crc
561
- chunk.raw = Buffer.from(MsgUnpacker_1.unpackInt((_j = chunk === null || chunk === void 0 ? void 0 : chunk.raw) === null || _j === void 0 ? void 0 : _j.toJSON().data).remaining); // crc
562
- if (part_2 == 0 || _this.snaps.length > 30) {
563
- _this.snaps = [];
564
- }
565
- _this.snaps.push(chunk.raw);
566
- if ((num_parts_2 - 1) == part_2 && _this.snaps.length == num_parts_2) {
567
- var mergedSnaps = Buffer.concat(_this.snaps);
568
- var snapUnpacked = SnapUnpacker.unpackSnapshot(mergedSnaps.toJSON().data, 1);
569
- snapUnpacked.items.forEach(function (a, i) {
570
- if (a.type_id == items.OBJ_CLIENT_INFO) {
571
- _this.client_infos[a.id] = a.parsed;
572
- // console.log(a.parsed, i)
573
- // console.log(this.client_infos[a.id])
574
- }
575
- else if (a.type_id == items.OBJ_PLAYER_INFO) {
576
- _this.player_infos[i] = a.parsed;
577
- }
578
- else if (a.type_id == items.OBJ_EX || a.type_id > 0x4000) {
579
- if (a.data.length == 5 && (a.parsed.freeze_end > 0 || a.parsed.freeze_end == -1)) {
580
- // var packer = new MsgPacker(22, false)
581
- // this.SendMsgEx(packer, 1)
582
- }
583
- }
584
- });
585
- }
586
- });
587
- }
588
498
  }
589
499
  if (new Date().getTime() - _this.time >= 1000 && _this.State == States.STATE_ONLINE) {
590
500
  _this.time = new Date().getTime();
@@ -600,9 +510,6 @@ var Client = /** @class */ (function (_super) {
600
510
  inputMsg.AddInt(this.AckGameTick);
601
511
  inputMsg.AddInt(this.PredGameTick);
602
512
  inputMsg.AddInt(40);
603
- // let playerflags = 2;
604
- // playerflags |= 8; // scoreboard
605
- // playerflags |= 16; // aimline
606
513
  var input_data = [
607
514
  input.m_Direction,
608
515
  input.m_TargetX,
@@ -615,7 +522,6 @@ var Client = /** @class */ (function (_super) {
615
522
  input.m_NextWeapon,
616
523
  input.m_PrevWeapon
617
524
  ];
618
- // console.log(this.player_infos, this.client_infos)
619
525
  input_data.forEach(function (a) {
620
526
  inputMsg.AddInt(a);
621
527
  });
@@ -680,5 +586,3 @@ var Client = /** @class */ (function (_super) {
680
586
  return Client;
681
587
  }(stream_1.EventEmitter));
682
588
  exports.Client = Client;
683
- // export = Client;
684
- // module.exports = Client;
package/lib/client.ts CHANGED
@@ -3,7 +3,7 @@ import { randomBytes } from "crypto";
3
3
  import net from 'dgram';
4
4
  import { EventEmitter } from 'stream';
5
5
 
6
- import { unpackInt, unpackString, MsgUnpacker } from "./MsgUnpacker";
6
+ import { unpackString, MsgUnpacker } from "./MsgUnpacker";
7
7
 
8
8
  import Movement from './movement';
9
9
 
@@ -268,10 +268,10 @@ export class Client extends EventEmitter {
268
268
  if (packet.length == 1 && packet[0] == -1)
269
269
  return unpacked
270
270
  }
271
- // return unpacked;
271
+
272
272
  for (let i = 0; i < unpacked.twprotocol.chunkAmount; i++) {
273
273
  var chunk: chunk = {} as chunk;
274
- chunk.bytes = ((packet[0] & 0x3f) << 4) | (packet[1] & ((1 << 4) - 1)); // idk what this shit is but it works
274
+ chunk.bytes = ((packet[0] & 0x3f) << 4) | (packet[1] & ((1 << 4) - 1));
275
275
  chunk.flags = (packet[0] >> 6) & 3;
276
276
  chunk.sequence = -1;
277
277
 
@@ -287,12 +287,11 @@ export class Client extends EventEmitter {
287
287
  Object.values(messageUUIDs).forEach((a, i) => {
288
288
  if (a.compare(packet.slice(0, 16)) == 0) {
289
289
  chunk.extended_msgid = a;
290
- // chunk.type = 'sys';
291
290
  chunk.msg = Object.keys(messageUUIDs)[i];
292
291
  }
293
292
  })
294
293
 
295
- packet = packet.slice(chunk.bytes) // +1 cuz it adds an extra \x00 for easier parsing i guess
294
+ packet = packet.slice(chunk.bytes)
296
295
  unpacked.chunks.push(chunk)
297
296
  }
298
297
  return unpacked
@@ -315,33 +314,10 @@ export class Client extends EventEmitter {
315
314
  */
316
315
  })
317
316
  }
318
- // SendMsgEx(Msg: MsgPacker, Flags: number) {
319
- // if (this.State == States.STATE_OFFLINE)
320
- // throw new Error("Client is not connected");
321
- // if (!this.socket)
322
- // return;
323
- // this.lastSendTime = new Date().getTime();
324
- // var header = []
325
- // header[0] = ((Flags & 3) << 6) | ((Msg.size >> 4) & 0x3f);
326
- // header[1] = (Msg.size & 0xf);
327
- // if (Flags & 1) {
328
- // this.clientAck = (this.clientAck + 1) % (1 << 10);
329
- // header[1] |= (this.clientAck >> 2) & 0xf0;
330
- // header[2] = this.clientAck & 0xff;
331
-
332
- // this.sentChunkQueue.push(Buffer.concat([Buffer.from(header), Msg.buffer]));
333
- // }
334
-
335
- // let latestBuf = Buffer.from([0x0 + (((16 << 4) & 0xf0) | ((this.ack >> 8) & 0xf)), this.ack & 0xff, 0x1, header[0], header[1]]);
336
- // if (Flags & 1)
337
- // latestBuf = Buffer.concat([latestBuf, Buffer.from([this.clientAck])]);
338
- // latestBuf = Buffer.concat([latestBuf, Msg.buffer, this.TKEN]);
339
- // this.socket.send(latestBuf, 0, latestBuf.length, this.port, this.host);
340
-
341
- // }
317
+
342
318
  SendMsgEx(Msgs: MsgPacker[] | MsgPacker, Flags: number) {
343
319
  if (this.State == States.STATE_OFFLINE)
344
- return; //throw new Error("Client is not connected");
320
+ return;
345
321
  if (!this.socket)
346
322
  return;
347
323
  let _Msgs: MsgPacker[];
@@ -376,7 +352,7 @@ export class Client extends EventEmitter {
376
352
  }
377
353
  SendMsgRaw(chunks: Buffer[]) {
378
354
  if (this.State == States.STATE_OFFLINE)
379
- return console.log(chunks, "client not connected"); //throw new Error("Client is not connected");
355
+ return;
380
356
  if (!this.socket)
381
357
  return;
382
358
 
@@ -391,7 +367,6 @@ export class Client extends EventEmitter {
391
367
 
392
368
  MsgToChunk(packet: Buffer) {
393
369
  var chunk: chunk = {} as chunk;
394
- // let packet = Msg.buffer;
395
370
  chunk.bytes = ((packet[0] & 0x3f) << 4) | (packet[1] & ((1 << 4) - 1));
396
371
  chunk.flags = (packet[0] >> 6) & 3;
397
372
  chunk.sequence = -1;
@@ -404,13 +379,10 @@ export class Client extends EventEmitter {
404
379
  chunk.type = packet[0] & 1 ? "sys" : "game"; // & 1 = binary, ****_***1. e.g 0001_0111 sys, 0001_0110 game
405
380
  chunk.msgid = (packet[0]-(packet[0]&1))/2;
406
381
  chunk.msg = messageTypes[packet[0]&1][chunk.msgid];
407
- // if (chunk.msg == undefined)
408
- // console.log(packet)
409
382
  chunk.raw = packet.slice(1, chunk.bytes)
410
383
  Object.values(messageUUIDs).forEach((a, i) => {
411
384
  if (a.compare(packet.slice(0, 16)) === 0) {
412
385
  chunk.extended_msgid = a;
413
- // chunk.type = 'sys';
414
386
  chunk.msg = Object.keys(messageUUIDs)[i];
415
387
  }
416
388
  })
@@ -425,7 +397,6 @@ export class Client extends EventEmitter {
425
397
  if (this.State == States.STATE_ONLINE) {
426
398
  if (this.AckGameTick > 0)
427
399
  this.PredGameTick++;
428
- // console.log(this.PredGameTick, this.AckGameTick)
429
400
  } else if (this.State == States.STATE_OFFLINE)
430
401
  clearInterval(predTimer);
431
402
 
@@ -440,30 +411,21 @@ export class Client extends EventEmitter {
440
411
  }, 500);
441
412
 
442
413
  let inputInterval = setInterval(() => {
443
- // if (new Date().getTime() - this.time >= 1000) {
444
414
  if (this.State == States.STATE_OFFLINE)
445
415
  clearInterval(inputInterval)
446
416
  if (this.State != States.STATE_ONLINE)
447
417
  return;
448
418
  this.time = new Date().getTime();
449
- // this.SendControlMsg(0);
450
- // console.log("sending with " + this.AckGameTick)
451
419
  this.sendInput();
452
- // }
453
420
  }, 500)
454
421
 
455
422
  let resendTimeout = setInterval(() => {
456
- // this.sentChunkQueue.forEach((chunk) => {
457
- // if (this.State == 0) // disconnected
458
- // return;
459
423
  if (this.State != States.STATE_OFFLINE) {
460
424
  if (((new Date().getTime()) - this.lastSendTime) > 900 && this.sentChunkQueue.length > 0) {
461
425
  this.SendMsgRaw([this.sentChunkQueue[0]]);
462
- console.log(this.sentChunkQueue, this.State);
463
426
  }
464
427
  } else
465
428
  clearInterval(resendTimeout)
466
- // })
467
429
  }, 1000)
468
430
 
469
431
 
@@ -506,7 +468,6 @@ export class Client extends EventEmitter {
506
468
  // disconnected
507
469
  this.State = States.STATE_OFFLINE;
508
470
  let reason: string = (unpackString(a.toJSON().data.slice(4)).result);
509
- // this.State = -1;
510
471
  this.emit("disconnect", reason);
511
472
  }
512
473
 
@@ -517,8 +478,6 @@ export class Client extends EventEmitter {
517
478
  if (a.flags & 1) { // vital
518
479
  if (a.seq != undefined && a.seq != -1)
519
480
  this.ack = a.seq
520
- else
521
- console.log("no seq", a)
522
481
  }
523
482
  })
524
483
  this.sentChunkQueue.forEach((buff, i) => {
@@ -526,63 +485,60 @@ export class Client extends EventEmitter {
526
485
  if (chunk.flags & 1) {
527
486
  if (chunk.seq && chunk.seq < this.ack) {
528
487
  this.sentChunkQueue.splice(i, 1);
529
- // this.ack = (this.ack + 1) % (1 << 10);
530
488
  }
531
489
  }
532
490
  })
533
491
  var snapChunks = unpacked.chunks.filter(a => a.msg === "SNAP" || a.msg === "SNAP_SINGLE" || a.msg === "SNAP_EMPTY");
534
- // console.log(unpacked.chunks.length, unpacked)
535
492
  if (snapChunks.length > 0) {
536
493
  let part = 0;
537
494
  let num_parts = 1;
538
495
  snapChunks.forEach(chunk => {
539
- let AckGameTick = (unpackInt(chunk.raw.toJSON().data).result);
540
- // setImmediate(() => {
541
- // console.log(AckGameTick, this.AckGameTick, chunk.msg)
496
+ let unpacker = new MsgUnpacker(chunk.raw.toJSON().data);
497
+
498
+ let AckGameTick = unpacker.unpackInt();
542
499
  if (AckGameTick > this.AckGameTick) {
543
500
  this.AckGameTick = AckGameTick;
544
501
  if (Math.abs(this.PredGameTick - this.AckGameTick) > 10)
545
502
  this.PredGameTick = AckGameTick + 1;
546
- // console.log(this.AckGameTick)
547
503
  }
548
- // })
549
504
 
550
- chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining);
551
- let DeltaTick = unpackInt(chunk?.raw?.toJSON().data).result
505
+ // chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining);
506
+ let DeltaTick = AckGameTick - unpacker.unpackInt();
507
+ let num_parts = 1;
508
+ let part = 0;
509
+
552
510
  if (chunk.msg === "SNAP") {
553
- chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // delta tick
554
- num_parts = (unpackInt(chunk?.raw?.toJSON().data).result)
555
- chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // num parts
556
- part = (unpackInt(chunk?.raw?.toJSON().data).result)
511
+ // chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // delta tick
512
+ num_parts = unpacker.unpackInt();
513
+ // chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // num parts
514
+ part = unpacker.unpackInt();
515
+ }
516
+
517
+ let crc = 0;
518
+ let part_size = 0;
519
+ if (chunk.msg != "SNAP_EMPTY") {
520
+ crc = unpacker.unpackInt(); // crc
521
+ part_size = unpacker.unpackInt();
557
522
  }
558
- chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // part
559
- if (chunk.msg != "SNAP_EMPTY")
560
- chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // crc
561
- chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // crc
562
523
  if (part === 0 || this.snaps.length > 30) {
563
524
  this.snaps = [];
564
525
  }
565
- chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // crc
526
+ chunk.raw = Buffer.from(unpacker.remaining);
566
527
  this.snaps.push(chunk.raw)
567
- // console.log(this.PredGameTick - this.AckGameTick, this.PredGameTick, this.AckGameTick)
568
528
 
569
529
  if ((num_parts - 1) === part && this.snaps.length === num_parts) {
570
530
  let mergedSnaps = Buffer.concat(this.snaps);
531
+ // mergedSnaps = Buffer.from(unpackInt(mergedSnaps.toJSON().data).remaining);
571
532
  let snapUnpacked = SnapUnpacker.unpackSnapshot(mergedSnaps.toJSON().data, 1)
572
- // console.log(snapUnpacked)
573
-
533
+ // console.log(snapUnpacked.items, toHexStream(mergedSnaps));
574
534
  snapUnpacked.items.forEach((a, i) => {
575
535
  if (a.type_id === items.OBJ_CLIENT_INFO) {
576
- // console.log(a.parsed, i)
577
536
  this.client_infos[a.id] = a.parsed as ClientInfo;
578
- if ((a.parsed as ClientInfo).name.includes("������")) {
579
- console.log(this.PredGameTick, this.AckGameTick, mergedSnaps.toJSON().data.toString())
537
+ if (this.client_infos[a.id].name.includes("�") || this.client_infos[a.id].clan.includes("")) {
538
+ console.log("bad name", this.client_infos[a.id], toHexStream(mergedSnaps), chunk, AckGameTick, DeltaTick, crc, part_size);
580
539
  }
581
- console.log(this.client_infos[a.id].name, this.client_infos[a.id].clan, [a.id])
540
+ console.log(this.client_infos[a.id])
582
541
  }
583
- // else if (a.type_id === items.OBJ_PLAYER_INFO) {
584
- // this.player_infos[a.id] = a.parsed as PlayerInfo;
585
- // }
586
542
  })
587
543
  }
588
544
 
@@ -594,15 +550,18 @@ export class Client extends EventEmitter {
594
550
  var chat = unpacked.chunks.filter(a => a.msg == "SV_CHAT");
595
551
  chat.forEach(a => {
596
552
  if (a.msg == "SV_CHAT") {
597
- var unpacked: iMessage = {} as iMessage;
598
- unpacked.team = unpackInt(a.raw.toJSON().data).result;
599
- var remaining: number[] = unpackInt(a.raw.toJSON().data).remaining;
600
- unpacked.client_id = unpackInt(remaining).result;
601
- remaining = unpackInt(remaining).remaining;
602
- unpacked.message = unpackString(remaining).result;
553
+ let unpacker = new MsgUnpacker(a.raw.toJSON().data);
554
+ var unpacked: iMessage = {
555
+ team: unpacker.unpackInt(),
556
+ client_id: unpacker.unpackInt(),
557
+ message: unpacker.unpackString()
558
+ } as iMessage;
559
+
603
560
  if (unpacked.client_id != -1)
604
- unpacked.author = { ClientInfo: this.client_infos[unpacked.client_id], PlayerInfo: this.player_infos[unpacked.client_id] }
605
- // console.log(unpacked)
561
+ unpacked.author = {
562
+ ClientInfo: this.client_infos[unpacked.client_id],
563
+ PlayerInfo: this.player_infos[unpacked.client_id]
564
+ }
606
565
  this.emit("message", unpacked)
607
566
  }
608
567
  })
@@ -621,7 +580,6 @@ export class Client extends EventEmitter {
621
580
  unpacked.victim = { ClientInfo: this.client_infos[unpacked.victim_id], PlayerInfo: this.player_infos[unpacked.victim_id] }
622
581
  if (unpacked.killer_id != -1)
623
582
  unpacked.killer = { ClientInfo: this.client_infos[unpacked.killer_id], PlayerInfo: this.player_infos[unpacked.killer_id] }
624
- // console.log(unpacked)
625
583
  this.emit("kill", unpacked)
626
584
  }
627
585
  })
@@ -669,52 +627,6 @@ export class Client extends EventEmitter {
669
627
  this.State = States.STATE_ONLINE;
670
628
  }
671
629
 
672
- var chunks = unpacked.chunks.filter(a => a.msg == "SNAP" || a.msg == "SNAP_SINGLE" || a.msg == "SNAP_EMPTY");
673
- if (chunks.length > 0) {
674
- let part = 0;
675
- let num_parts = 1;
676
- chunks.forEach(chunk => {
677
- let AckGameTick = (unpackInt(chunk.raw.toJSON().data).result);
678
- chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining);
679
- let DeltaTick = unpackInt(chunk?.raw?.toJSON().data).result
680
- if (chunk.msg == "SNAP") {
681
- chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // delta tick
682
- num_parts = (unpackInt(chunk?.raw?.toJSON().data).result)
683
- chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // num parts
684
- part = (unpackInt(chunk?.raw?.toJSON().data).result)
685
- }
686
- chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // part
687
- if (chunk.msg != "SNAP_EMPTY")
688
- chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // crc
689
- chunk.raw = Buffer.from(unpackInt(chunk?.raw?.toJSON().data).remaining); // crc
690
- if (part == 0 || this.snaps.length > 30) {
691
- this.snaps = [];
692
- }
693
- this.snaps.push(chunk.raw)
694
-
695
- if ((num_parts - 1) == part && this.snaps.length == num_parts) {
696
- let mergedSnaps = Buffer.concat(this.snaps);
697
- let snapUnpacked = SnapUnpacker.unpackSnapshot(mergedSnaps.toJSON().data, 1)
698
-
699
- snapUnpacked.items.forEach((a, i) => {
700
- if (a.type_id == items.OBJ_CLIENT_INFO) {
701
- this.client_infos[a.id] = a.parsed as ClientInfo;
702
- // console.log(a.parsed, i)
703
- // console.log(this.client_infos[a.id])
704
- } else if (a.type_id == items.OBJ_PLAYER_INFO) {
705
- this.player_infos[i] = a.parsed as PlayerInfo;
706
- } else if (a.type_id == items.OBJ_EX || a.type_id > 0x4000) {
707
- if (a.data.length == 5 && ((a.parsed as DdnetCharacter).freeze_end > 0 || (a.parsed as DdnetCharacter).freeze_end == -1)) {
708
- // var packer = new MsgPacker(22, false)
709
- // this.SendMsgEx(packer, 1)
710
- }
711
- }
712
- })
713
- }
714
-
715
- })
716
- }
717
-
718
630
  }
719
631
  if (new Date().getTime() - this.time >= 1000 && this.State == States.STATE_ONLINE) {
720
632
  this.time = new Date().getTime();
@@ -731,9 +643,6 @@ export class Client extends EventEmitter {
731
643
  inputMsg.AddInt(this.AckGameTick);
732
644
  inputMsg.AddInt(this.PredGameTick);
733
645
  inputMsg.AddInt(40);
734
- // let playerflags = 2;
735
- // playerflags |= 8; // scoreboard
736
- // playerflags |= 16; // aimline
737
646
 
738
647
  let input_data = [
739
648
 
@@ -748,7 +657,6 @@ export class Client extends EventEmitter {
748
657
  input.m_NextWeapon,
749
658
  input.m_PrevWeapon
750
659
  ]
751
- // console.log(this.player_infos, this.client_infos)
752
660
  input_data.forEach(a => {
753
661
  inputMsg.AddInt(a);
754
662
  });
@@ -809,6 +717,3 @@ export class Client extends EventEmitter {
809
717
 
810
718
 
811
719
  }
812
-
813
- // export = Client;
814
- // module.exports = Client;
package/lib/snapshot.js CHANGED
@@ -69,7 +69,7 @@ var Snapshot = /** @class */ (function () {
69
69
  }
70
70
  pIntz.splice(-1, 1);
71
71
  pStr = decoder.decode(new Uint8Array(pIntz));
72
- pStr = pStr.replace(/\x00|\u0000/g, ""); //.replace(/タ/g, "")
72
+ pStr = pStr.replace(/\0.*/g, ''); // Remove content from first null char to end.
73
73
  return pStr;
74
74
  };
75
75
  Snapshot.prototype.parseItem = function (data, Type) {
@@ -290,18 +290,13 @@ var Snapshot = /** @class */ (function () {
290
290
  };
291
291
  Snapshot.prototype.unpackSnapshot = function (snap, lost) {
292
292
  if (lost === void 0) { lost = 0; }
293
- // var size = unpackInt(snap).result;
294
293
  var unpacker = new MsgUnpacker_1.MsgUnpacker(snap);
295
- // snap = unpackInt(snap).remaining; // size
296
294
  /* key = (((type_id) << 16) | (id))
297
295
  * key_to_id = ((key) & 0xffff)
298
296
  * key_to_type_id = ((key >> 16) & 0xffff)
299
297
  * https://github.com/heinrich5991/libtw2/blob/master/snapshot/src/
300
298
  * https://github.com/heinrich5991/libtw2/blob/master/doc/snapshot.md
301
299
  */
302
- // snap = unpackInt(snap).remaining;
303
- // console.log(unpackInt(snap).result, "tick?") // key?
304
- // snap = unpackInt(snap).remaining;
305
300
  var num_removed_items = unpacker.unpackInt();
306
301
  var num_item_deltas = unpacker.unpackInt();
307
302
  unpacker.unpackInt(); // _zero padding
@@ -336,10 +331,7 @@ var Snapshot = /** @class */ (function () {
336
331
  if (unpacker.remaining.length > 0)
337
332
  data.push(unpacker.unpackInt());
338
333
  }
339
- // console.log(type_id, id, _size, data);
340
334
  var parsed = this.parseItem(data, type_id);
341
- // console.log(data)
342
- // console.log('')
343
335
  items.items.push({ data: data, parsed: parsed, type_id: type_id, id: id, key: key });
344
336
  }
345
337
  return items;
@@ -347,5 +339,3 @@ var Snapshot = /** @class */ (function () {
347
339
  return Snapshot;
348
340
  }());
349
341
  exports.Snapshot = Snapshot;
350
- // module.exports = MsgPacker;
351
- // export {Snapshot};
package/lib/snapshot.ts CHANGED
@@ -67,7 +67,8 @@ export class Snapshot {
67
67
  }
68
68
  pIntz.splice(-1, 1)
69
69
  pStr = decoder.decode(new Uint8Array(pIntz));
70
- pStr = pStr.replace(/\x00|\u0000/g, "");//.replace(/タ/g, "")
70
+
71
+ pStr = pStr.replace(/\0.*/g, ''); // Remove content from first null char to end.
71
72
  return pStr;
72
73
  }
73
74
  private parseItem(data: number[], Type: number): Item {
@@ -290,10 +291,8 @@ export class Snapshot {
290
291
  return _item;
291
292
  }
292
293
  unpackSnapshot(snap: number[], lost = 0) {
293
- // var size = unpackInt(snap).result;
294
294
  let unpacker = new MsgUnpacker(snap);
295
295
 
296
- // snap = unpackInt(snap).remaining; // size
297
296
 
298
297
  /* key = (((type_id) << 16) | (id))
299
298
  * key_to_id = ((key) & 0xffff)
@@ -302,9 +301,6 @@ export class Snapshot {
302
301
  * https://github.com/heinrich5991/libtw2/blob/master/doc/snapshot.md
303
302
  */
304
303
 
305
- // snap = unpackInt(snap).remaining;
306
- // console.log(unpackInt(snap).result, "tick?") // key?
307
- // snap = unpackInt(snap).remaining;
308
304
  let num_removed_items = unpacker.unpackInt();
309
305
  let num_item_deltas = unpacker.unpackInt();
310
306
  unpacker.unpackInt(); // _zero padding
@@ -342,16 +338,12 @@ export class Snapshot {
342
338
  if (unpacker.remaining.length > 0)
343
339
  data.push(unpacker.unpackInt());
344
340
  }
345
- // console.log(type_id, id, _size, data);
341
+
346
342
  let parsed = this.parseItem(data, type_id)
347
343
 
348
- // console.log(data)
349
- // console.log('')
350
344
  items.items.push({data, parsed, type_id, id, key})
351
345
  }
352
346
 
353
347
 
354
348
  return items;
355
349
  }}
356
- // module.exports = MsgPacker;
357
- // export {Snapshot};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teeworlds",
3
- "version": "2.1.7",
3
+ "version": "2.1.8",
4
4
  "description": "Library for (ingame) teeworlds bots.",
5
5
  "license": "MIT",
6
6
  "main": "index.js",