teeworlds 2.3.7 → 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.
@@ -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 sign = ((src >> 6) & 1);
11
- result |= (src & 63);
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 ((src & 128) === 0)
14
+ if ((pSrc[srcIndex] & 128) === 0)
14
15
  break;
15
- src = iter.next();
16
- src = src.value;
17
- result |= ((src & 127)) << (6 + 7 * i);
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: Array.from(iter) };
22
+ return { result: result, remaining: pSrc.slice(srcIndex + 1) };
21
23
  }
22
24
  exports.unpackInt = unpackInt;
23
25
  function unpackString(pSrc) {
@@ -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
- var sign = ((src >> 6) & 1)
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 |= (src & 0b0011_1111)
11
+ result |= (pSrc[srcIndex] & 0b0011_1111)
11
12
  for (let i = 0; i < 4; i++) {
12
13
 
13
- if ((src & 0b1000_0000) === 0)
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
- result |= ((src & 0b0111_1111)) << (6+7*i)
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: Array.from(iter)};
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
@@ -298,6 +298,7 @@ var Client = /** @class */ (function (_super) {
298
298
  };
299
299
  Client.prototype.connect = function () {
300
300
  var _this = this;
301
+ var _a;
301
302
  this.State = States.STATE_CONNECTING;
302
303
  var predTimer = setInterval(function () {
303
304
  if (_this.State == States.STATE_ONLINE) {
@@ -314,14 +315,16 @@ var Client = /** @class */ (function (_super) {
314
315
  else
315
316
  clearInterval(connectInterval);
316
317
  }, 500);
317
- var inputInterval = setInterval(function () {
318
- if (_this.State == States.STATE_OFFLINE)
319
- clearInterval(inputInterval);
320
- if (_this.State != States.STATE_ONLINE)
321
- return;
322
- _this.time = new Date().getTime();
323
- _this.sendInput();
324
- }, 500);
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
+ }
325
328
  var resendTimeout = setInterval(function () {
326
329
  if (_this.State != States.STATE_OFFLINE) {
327
330
  if (((new Date().getTime()) - _this.lastSendTime) > 900 && _this.sentChunkQueue.length > 0) {
@@ -344,7 +347,7 @@ var Client = /** @class */ (function (_super) {
344
347
  this.time = new Date().getTime() + 2000; // start sending keepalives after 2s
345
348
  if (this.socket)
346
349
  this.socket.on("message", function (a, rinfo) {
347
- var _a, _b, _c, _d, _e, _f, _g;
350
+ var _a, _b, _c, _d, _e, _f, _g, _h;
348
351
  if (_this.State == 0 || rinfo.address != _this.host || rinfo.port != _this.port)
349
352
  return;
350
353
  clearInterval(connectInterval);
@@ -418,7 +421,9 @@ var Client = /** @class */ (function (_super) {
418
421
  _this.sentChunkQueue.splice(i, 1);
419
422
  }
420
423
  });
421
- var snapChunks = unpacked.chunks.filter(function (a) { return a.msg === "SNAP" || a.msg === "SNAP_SINGLE" || a.msg === "SNAP_EMPTY"; });
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"; });
422
427
  if (snapChunks.length > 0) {
423
428
  var part = 0;
424
429
  var num_parts = 1;
@@ -517,7 +522,7 @@ var Client = /** @class */ (function (_super) {
517
522
  }
518
523
  else if ((unpacked.chunks[0] && chunkMessages.includes("CON_READY"))) {
519
524
  var info = new MsgPacker_1.MsgPacker(20, false, 1);
520
- if ((_g = _this.options) === null || _g === void 0 ? void 0 : _g.identity) {
525
+ if ((_h = _this.options) === null || _h === void 0 ? void 0 : _h.identity) {
521
526
  info.AddString(_this.options.identity.name);
522
527
  info.AddString(_this.options.identity.clan);
523
528
  info.AddInt(_this.options.identity.country);
@@ -602,18 +607,27 @@ var Client = /** @class */ (function (_super) {
602
607
  });
603
608
  };
604
609
  Client.prototype.Say = function (message, team) {
610
+ var _a;
605
611
  if (team === void 0) { team = false; }
606
612
  var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SAY, false, 1);
607
613
  packer.AddInt(team ? 1 : 0); // team
608
614
  packer.AddString(message);
609
- this.QueueChunkEx(packer);
615
+ if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
616
+ this.QueueChunkEx(packer);
617
+ else
618
+ this.SendMsgEx(packer);
610
619
  };
611
620
  Client.prototype.Vote = function (vote) {
621
+ var _a;
612
622
  var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_VOTE, false, 1);
613
623
  packer.AddInt(vote ? 1 : -1);
614
- this.QueueChunkEx(packer);
624
+ if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
625
+ this.QueueChunkEx(packer);
626
+ else
627
+ this.SendMsgEx(packer);
615
628
  };
616
629
  Client.prototype.ChangePlayerInfo = function (playerInfo) {
630
+ var _a;
617
631
  var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_CHANGEINFO, false, 1);
618
632
  packer.AddString(playerInfo.name); //m_pName);
619
633
  packer.AddString(playerInfo.clan); //m_pClan);
@@ -622,21 +636,36 @@ var Client = /** @class */ (function (_super) {
622
636
  packer.AddInt(playerInfo.use_custom_color ? 1 : 0); //m_UseCustomColor);
623
637
  packer.AddInt(playerInfo.color_body); //m_ColorBody);
624
638
  packer.AddInt(playerInfo.color_feet); //m_ColorFeet);
625
- this.QueueChunkEx(packer);
639
+ if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
640
+ this.QueueChunkEx(packer);
641
+ else
642
+ this.SendMsgEx(packer);
626
643
  };
627
644
  Client.prototype.Kill = function () {
645
+ var _a;
628
646
  var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_KILL, false, 1);
629
- this.QueueChunkEx(packer);
647
+ if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
648
+ this.QueueChunkEx(packer);
649
+ else
650
+ this.SendMsgEx(packer);
630
651
  };
631
652
  Client.prototype.ChangeTeam = function (team) {
653
+ var _a;
632
654
  var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SETTEAM, false, 1);
633
655
  packer.AddInt(team);
634
- this.QueueChunkEx(packer);
656
+ if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
657
+ this.QueueChunkEx(packer);
658
+ else
659
+ this.SendMsgEx(packer);
635
660
  };
636
661
  Client.prototype.Emote = function (emote) {
662
+ var _a;
637
663
  var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_EMOTICON, false, 1);
638
664
  packer.AddInt(emote);
639
- this.QueueChunkEx(packer);
665
+ if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
666
+ this.QueueChunkEx(packer);
667
+ else
668
+ this.SendMsgEx(packer);
640
669
  };
641
670
  Client.prototype.client_info = function (id) {
642
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 {
@@ -434,15 +435,16 @@ export class Client extends EventEmitter {
434
435
  else
435
436
  clearInterval(connectInterval)
436
437
  }, 500);
437
-
438
- let inputInterval = setInterval(() => {
439
- if (this.State == States.STATE_OFFLINE)
440
- clearInterval(inputInterval)
441
- if (this.State != States.STATE_ONLINE)
442
- return;
443
- this.time = new Date().getTime();
444
- this.sendInput();
445
- }, 500)
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
+ }
446
448
 
447
449
  let resendTimeout = setInterval(() => {
448
450
  if (this.State != States.STATE_OFFLINE) {
@@ -549,7 +551,9 @@ export class Client extends EventEmitter {
549
551
  this.sentChunkQueue.splice(i, 1);
550
552
  }
551
553
  })
552
- var snapChunks = unpacked.chunks.filter(a => a.msg === "SNAP" || a.msg === "SNAP_SINGLE" || a.msg === "SNAP_EMPTY");
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");
553
557
  if (snapChunks.length > 0) {
554
558
  let part = 0;
555
559
  let num_parts = 1;
@@ -749,12 +753,18 @@ export class Client extends EventEmitter {
749
753
  var packer = new MsgPacker(NETMSGTYPE.CL_SAY, false, 1);
750
754
  packer.AddInt(team ? 1 : 0); // team
751
755
  packer.AddString(message);
752
- this.QueueChunkEx(packer);
756
+ if (!this.options?.lightweight)
757
+ this.QueueChunkEx(packer);
758
+ else
759
+ this.SendMsgEx(packer);
753
760
  }
754
761
  Vote(vote: boolean) {
755
762
  var packer = new MsgPacker(NETMSGTYPE.CL_VOTE, false, 1);
756
763
  packer.AddInt(vote ? 1 : -1);
757
- this.QueueChunkEx(packer);
764
+ if (!this.options?.lightweight)
765
+ this.QueueChunkEx(packer);
766
+ else
767
+ this.SendMsgEx(packer);
758
768
  }
759
769
  ChangePlayerInfo(playerInfo: ClientInfo) {
760
770
  var packer = new MsgPacker(NETMSGTYPE.CL_CHANGEINFO, false, 1);
@@ -765,21 +775,33 @@ export class Client extends EventEmitter {
765
775
  packer.AddInt(playerInfo.use_custom_color ? 1 : 0); //m_UseCustomColor);
766
776
  packer.AddInt(playerInfo.color_body); //m_ColorBody);
767
777
  packer.AddInt(playerInfo.color_feet); //m_ColorFeet);
768
- this.QueueChunkEx(packer);
778
+ if (!this.options?.lightweight)
779
+ this.QueueChunkEx(packer);
780
+ else
781
+ this.SendMsgEx(packer);
769
782
  }
770
783
  Kill() {
771
784
  var packer = new MsgPacker(NETMSGTYPE.CL_KILL, false, 1);
772
- this.QueueChunkEx(packer);
785
+ if (!this.options?.lightweight)
786
+ this.QueueChunkEx(packer);
787
+ else
788
+ this.SendMsgEx(packer);
773
789
  }
774
790
  ChangeTeam(team: number) {
775
791
  var packer = new MsgPacker(NETMSGTYPE.CL_SETTEAM, false, 1);
776
792
  packer.AddInt(team);
777
- this.QueueChunkEx(packer);
793
+ if (!this.options?.lightweight)
794
+ this.QueueChunkEx(packer);
795
+ else
796
+ this.SendMsgEx(packer);
778
797
  }
779
798
  Emote(emote: number) {
780
799
  var packer = new MsgPacker(NETMSGTYPE.CL_EMOTICON, false, 1);
781
800
  packer.AddInt(emote);
782
- this.QueueChunkEx(packer);
801
+ if (!this.options?.lightweight)
802
+ this.QueueChunkEx(packer);
803
+ else
804
+ this.SendMsgEx(packer);
783
805
  }
784
806
  client_info(id: number) {
785
807
  let delta = this.SnapUnpacker.deltas.filter(a =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teeworlds",
3
- "version": "2.3.7",
3
+ "version": "2.3.8",
4
4
  "description": "Library for (ingame) teeworlds bots.",
5
5
  "license": "MIT",
6
6
  "main": "index.js",