teeworlds 2.3.8 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -61
- package/lib/MsgUnpacker.js +3 -9
- package/lib/MsgUnpacker.ts +5 -11
- package/lib/client.js +78 -122
- package/lib/client.ts +146 -170
- package/lib/components/game.js +143 -0
- package/lib/components/game.ts +122 -0
- package/lib/movement.js +1 -1
- package/lib/movement.ts +1 -1
- package/lib/snapshot.js +46 -33
- package/lib/snapshot.ts +32 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,8 @@ https://www.npmjs.com/package/teeworlds
|
|
|
6
6
|
|
|
7
7
|
# Usage
|
|
8
8
|
Example file:
|
|
9
|
-
```
|
|
9
|
+
```
|
|
10
|
+
const teeworlds = require('teeworlds')
|
|
10
11
|
let client = new teeworlds.Client("127.0.0.1", 8303, "nameless tee");
|
|
11
12
|
|
|
12
13
|
client.connect();
|
|
@@ -16,83 +17,73 @@ client.on("connected", () => {
|
|
|
16
17
|
})
|
|
17
18
|
|
|
18
19
|
client.on("disconnect", reason => {
|
|
19
|
-
//
|
|
20
|
+
// you got kicked from the server
|
|
20
21
|
console.log("Disconnected: " + reason);
|
|
21
22
|
})
|
|
22
23
|
|
|
23
24
|
client.on("message", message => {
|
|
24
25
|
/* {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
26
|
+
team: 0,
|
|
27
|
+
client_id: 14,
|
|
28
|
+
message: 'a',
|
|
29
|
+
author: {
|
|
30
|
+
ClientInfo: {
|
|
31
|
+
name: 'Nudelsaft c:',
|
|
32
|
+
clan: '',
|
|
33
|
+
country: 276,
|
|
34
|
+
skin: 'coala_toptri',
|
|
35
|
+
use_custom_color: 0,
|
|
36
|
+
color_body: 4718592,
|
|
37
|
+
color_feet: 5046016
|
|
38
|
+
},
|
|
39
|
+
PlayerInfo: { local: 0, client_id: 4, team: 0, score: 36, latency: 0 }
|
|
40
|
+
}
|
|
41
|
+
}
|
|
41
42
|
*/
|
|
42
43
|
console.log(message);
|
|
43
44
|
})
|
|
44
45
|
|
|
45
46
|
client.on("kill", info => {
|
|
46
47
|
/* {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
48
|
+
killer_id: 14,
|
|
49
|
+
victim_id: 14,
|
|
50
|
+
weapon: -3,
|
|
51
|
+
special_mode: 0,
|
|
52
|
+
victim: {
|
|
53
|
+
ClientInfo: {
|
|
54
|
+
name: 'Nudelsaft c:',
|
|
55
|
+
clan: '',
|
|
56
|
+
country: 276,
|
|
57
|
+
skin: 'coala_toptri',
|
|
58
|
+
use_custom_color: 0,
|
|
59
|
+
color_body: 4718592,
|
|
60
|
+
color_feet: 5046016
|
|
61
|
+
},
|
|
62
|
+
PlayerInfo: { local: 0, client_id: 4, team: 0, score: 36, latency: 0 }
|
|
63
|
+
},
|
|
64
|
+
killer: {
|
|
65
|
+
ClientInfo: {
|
|
66
|
+
name: 'Nudelsaft c:',
|
|
67
|
+
clan: '',
|
|
68
|
+
country: 276,
|
|
69
|
+
skin: 'coala_toptri',
|
|
70
|
+
use_custom_color: 0,
|
|
71
|
+
color_body: 4718592,
|
|
72
|
+
color_feet: 5046016
|
|
73
|
+
},
|
|
74
|
+
PlayerInfo: { local: 0, client_id: 4, team: 0, score: 36, latency: 0 }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
76
77
|
*/
|
|
77
78
|
console.log(info)
|
|
78
79
|
})
|
|
79
80
|
|
|
80
81
|
process.on("SIGINT", () => {
|
|
81
|
-
client.Disconnect(); // disconnect on ctrl + c
|
|
82
|
+
client.Disconnect().then(() => process.exit(0)); // disconnect on ctrl + c
|
|
83
|
+
// process.exit()
|
|
82
84
|
})
|
|
83
85
|
process.stdin.on("data", data => {
|
|
84
|
-
client.Say(data.toString()); // write input in chat
|
|
86
|
+
client.game.Say(data.toString()); // write input in chat
|
|
85
87
|
|
|
86
88
|
})
|
|
87
|
-
|
|
88
|
-
function change() {
|
|
89
|
-
client.ChangePlayerInfo({
|
|
90
|
-
name: "new name",
|
|
91
|
-
clan: "new clan",
|
|
92
|
-
country: 12,
|
|
93
|
-
skin: "default",
|
|
94
|
-
use_custom_color: true,
|
|
95
|
-
color_body: 12,
|
|
96
|
-
color_feet: 1111
|
|
97
|
-
})
|
|
98
|
-
}```
|
|
89
|
+
```
|
package/lib/MsgUnpacker.js
CHANGED
|
@@ -3,20 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MsgUnpacker = exports.unpackString = exports.unpackInt = void 0;
|
|
4
4
|
var decoder = new TextDecoder('utf-8');
|
|
5
5
|
function unpackInt(pSrc) {
|
|
6
|
-
var result = 0;
|
|
7
|
-
// var iter = pSrc[Symbol.iterator]()
|
|
8
|
-
// var src: any = iter.next()
|
|
9
|
-
// src = src.value
|
|
10
6
|
var srcIndex = 0;
|
|
11
7
|
var sign = ((pSrc[srcIndex] >> 6) & 1);
|
|
12
|
-
result
|
|
13
|
-
|
|
8
|
+
var result = (pSrc[srcIndex] & 63);
|
|
9
|
+
while (srcIndex <= 4) {
|
|
14
10
|
if ((pSrc[srcIndex] & 128) === 0)
|
|
15
11
|
break;
|
|
16
|
-
// src = iter.next()
|
|
17
|
-
// src = src.value;
|
|
18
12
|
srcIndex++;
|
|
19
|
-
result |= ((pSrc[srcIndex] & 127)) << (6 + 7 *
|
|
13
|
+
result |= ((pSrc[srcIndex] & 127)) << (6 + 7 * (srcIndex - 1));
|
|
20
14
|
}
|
|
21
15
|
result ^= -sign;
|
|
22
16
|
return { result: result, remaining: pSrc.slice(srcIndex + 1) };
|
package/lib/MsgUnpacker.ts
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
const decoder = new TextDecoder('utf-8');
|
|
2
2
|
export function unpackInt(pSrc: number[]): {result: number, remaining: number[]} {
|
|
3
|
-
var result = 0;
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// src = src.value
|
|
8
|
-
let srcIndex = 0;
|
|
9
|
-
var sign = ((pSrc[srcIndex] >> 6) & 1)
|
|
4
|
+
var srcIndex = 0;
|
|
5
|
+
const sign = ((pSrc[srcIndex] >> 6) & 1)
|
|
10
6
|
|
|
11
|
-
result
|
|
12
|
-
|
|
7
|
+
var result = (pSrc[srcIndex] & 0b0011_1111)
|
|
8
|
+
while (srcIndex <= 4) {
|
|
13
9
|
|
|
14
10
|
if ((pSrc[srcIndex] & 0b1000_0000) === 0)
|
|
15
11
|
break;
|
|
16
|
-
// src = iter.next()
|
|
17
12
|
|
|
18
|
-
// src = src.value;
|
|
19
13
|
srcIndex++;
|
|
20
|
-
result |= ((pSrc[srcIndex] & 0b0111_1111)) << (6+7*
|
|
14
|
+
result |= ((pSrc[srcIndex] & 0b0111_1111)) << (6+7*(srcIndex-1))
|
|
21
15
|
|
|
22
16
|
}
|
|
23
17
|
result ^= -sign;
|
package/lib/client.js
CHANGED
|
@@ -25,6 +25,7 @@ var movement_1 = __importDefault(require("./movement"));
|
|
|
25
25
|
var MsgPacker_1 = require("./MsgPacker");
|
|
26
26
|
var snapshot_1 = require("./snapshot");
|
|
27
27
|
var huffman_1 = __importDefault(require("./huffman"));
|
|
28
|
+
var game_1 = require("./components/game");
|
|
28
29
|
var huff = new huffman_1.default();
|
|
29
30
|
var States;
|
|
30
31
|
(function (States) {
|
|
@@ -108,13 +109,13 @@ var Client = /** @class */ (function (_super) {
|
|
|
108
109
|
_this.name = nickname;
|
|
109
110
|
_this.AckGameTick = 0;
|
|
110
111
|
_this.PredGameTick = 0;
|
|
112
|
+
_this.currentSnapshotGameTick = 0;
|
|
113
|
+
_this.SnapshotParts = 0;
|
|
111
114
|
_this.SnapUnpacker = new snapshot_1.Snapshot();
|
|
112
115
|
// this.eSnapHolder = [];
|
|
113
116
|
_this.requestResend = false;
|
|
114
117
|
if (options)
|
|
115
118
|
_this.options = options;
|
|
116
|
-
_this.timer = 0;
|
|
117
|
-
_this.movement = new movement_1.default();
|
|
118
119
|
_this.snaps = [];
|
|
119
120
|
_this.sentChunkQueue = [];
|
|
120
121
|
_this.queueChunkEx = [];
|
|
@@ -122,7 +123,6 @@ var Client = /** @class */ (function (_super) {
|
|
|
122
123
|
_this.ack = 0; // ack of messages the client has received
|
|
123
124
|
_this.clientAck = 0; // ack of messages the client has sent
|
|
124
125
|
_this.receivedSnaps = 0; /* wait for 2 snaps before seeing self as connected */
|
|
125
|
-
_this.lastMsg = "";
|
|
126
126
|
_this.socket = dgram_1.default.createSocket("udp4");
|
|
127
127
|
_this.socket.bind();
|
|
128
128
|
_this.TKEN = Buffer.from([255, 255, 255, 255]);
|
|
@@ -130,6 +130,8 @@ var Client = /** @class */ (function (_super) {
|
|
|
130
130
|
_this.lastSendTime = new Date().getTime();
|
|
131
131
|
_this.lastRecvTime = new Date().getTime();
|
|
132
132
|
_this.lastSentMessages = [];
|
|
133
|
+
_this.movement = new movement_1.default();
|
|
134
|
+
_this.game = new game_1.Game(_this);
|
|
133
135
|
return _this;
|
|
134
136
|
}
|
|
135
137
|
Client.prototype.ResendAfter = function (lastAck) {
|
|
@@ -181,6 +183,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
181
183
|
}
|
|
182
184
|
return unpacked;
|
|
183
185
|
};
|
|
186
|
+
/* Send a Control Msg to the server. (used for disconnect)*/
|
|
184
187
|
Client.prototype.SendControlMsg = function (msg, ExtraMsg) {
|
|
185
188
|
var _this = this;
|
|
186
189
|
if (ExtraMsg === void 0) { ExtraMsg = ""; }
|
|
@@ -200,6 +203,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
200
203
|
*/
|
|
201
204
|
});
|
|
202
205
|
};
|
|
206
|
+
/* Send a Msg (or Msg[]) to the server.*/
|
|
203
207
|
Client.prototype.SendMsgEx = function (Msgs) {
|
|
204
208
|
var _this = this;
|
|
205
209
|
if (this.State == States.STATE_OFFLINE)
|
|
@@ -258,9 +262,11 @@ var Client = /** @class */ (function (_super) {
|
|
|
258
262
|
return;
|
|
259
263
|
this.socket.send(packet, 0, packet.length, this.port, this.host);
|
|
260
264
|
};
|
|
265
|
+
/* Queue a chunk (It will get sent in the next packet). */
|
|
261
266
|
Client.prototype.QueueChunkEx = function (Msg) {
|
|
262
267
|
this.queueChunkEx.push(Msg);
|
|
263
268
|
};
|
|
269
|
+
/* Send a Raw Buffer (as chunk) to the server. */
|
|
264
270
|
Client.prototype.SendMsgRaw = function (chunks) {
|
|
265
271
|
if (this.State == States.STATE_OFFLINE)
|
|
266
272
|
return;
|
|
@@ -296,6 +302,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
296
302
|
});
|
|
297
303
|
return chunk;
|
|
298
304
|
};
|
|
305
|
+
/* Connect the client to the server. */
|
|
299
306
|
Client.prototype.connect = function () {
|
|
300
307
|
var _this = this;
|
|
301
308
|
var _a;
|
|
@@ -346,15 +353,15 @@ var Client = /** @class */ (function (_super) {
|
|
|
346
353
|
}, 5000);
|
|
347
354
|
this.time = new Date().getTime() + 2000; // start sending keepalives after 2s
|
|
348
355
|
if (this.socket)
|
|
349
|
-
this.socket.on("message", function (
|
|
356
|
+
this.socket.on("message", function (packet, rinfo) {
|
|
350
357
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
351
358
|
if (_this.State == 0 || rinfo.address != _this.host || rinfo.port != _this.port)
|
|
352
359
|
return;
|
|
353
360
|
clearInterval(connectInterval);
|
|
354
|
-
if (
|
|
355
|
-
if (
|
|
361
|
+
if (packet.toJSON().data[0] == 0x10) {
|
|
362
|
+
if (packet.toString().includes("TKEN") || packet.toJSON().data[3] == 0x2) {
|
|
356
363
|
clearInterval(connectInterval);
|
|
357
|
-
_this.TKEN = Buffer.from(
|
|
364
|
+
_this.TKEN = Buffer.from(packet.toJSON().data.slice(packet.toJSON().data.length - 4, packet.toJSON().data.length));
|
|
358
365
|
_this.SendControlMsg(3);
|
|
359
366
|
_this.State = States.STATE_LOADING; // loading state
|
|
360
367
|
_this.receivedSnaps = 0;
|
|
@@ -376,41 +383,42 @@ var Client = /** @class */ (function (_super) {
|
|
|
376
383
|
}
|
|
377
384
|
_this.SendMsgEx([client_version, info]);
|
|
378
385
|
}
|
|
379
|
-
else if (
|
|
386
|
+
else if (packet.toJSON().data[3] == 0x4) {
|
|
380
387
|
// disconnected
|
|
381
388
|
_this.State = States.STATE_OFFLINE;
|
|
382
|
-
var reason = (MsgUnpacker_1.unpackString(
|
|
389
|
+
var reason = (MsgUnpacker_1.unpackString(packet.toJSON().data.slice(4)).result);
|
|
383
390
|
_this.emit("disconnect", reason);
|
|
384
391
|
}
|
|
385
|
-
if (
|
|
392
|
+
if (packet.toJSON().data[3] !== 0x0) { // keepalive
|
|
386
393
|
_this.lastRecvTime = new Date().getTime();
|
|
387
394
|
}
|
|
388
395
|
}
|
|
389
396
|
else {
|
|
390
397
|
_this.lastRecvTime = new Date().getTime();
|
|
391
398
|
}
|
|
392
|
-
var unpacked = _this.Unpack(
|
|
393
|
-
unpacked.chunks.
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
399
|
+
var unpacked = _this.Unpack(packet);
|
|
400
|
+
unpacked.chunks = unpacked.chunks.filter(function (chunk) { return ((chunk.flags & 2) && (chunk.flags & 1)) ? chunk.seq > _this.ack : true; }); // filter out already received chunks
|
|
401
|
+
unpacked.chunks.forEach(function (chunk) {
|
|
402
|
+
if (chunk.flags & 1 && (chunk.flags !== 15)) { // vital and not connless
|
|
403
|
+
if (chunk.seq === (_this.ack + 1) % (1 << 10)) { // https://github.com/nobody-mb/twchatonly/blob/master/chatonly.cpp#L237
|
|
404
|
+
_this.ack = chunk.seq;
|
|
397
405
|
_this.requestResend = false;
|
|
398
406
|
}
|
|
399
407
|
else { //IsSeqInBackroom (old packet that we already got)
|
|
400
408
|
var Bottom = (_this.ack - (1 << 10) / 2);
|
|
401
409
|
if (Bottom < 0) {
|
|
402
|
-
if ((
|
|
410
|
+
if ((chunk.seq <= _this.ack) || (chunk.seq >= (Bottom + (1 << 10))))
|
|
403
411
|
return;
|
|
404
412
|
}
|
|
405
413
|
else {
|
|
406
|
-
if (
|
|
414
|
+
if (chunk.seq <= _this.ack && chunk.seq >= Bottom)
|
|
407
415
|
return;
|
|
408
416
|
}
|
|
409
417
|
_this.requestResend = true;
|
|
410
418
|
}
|
|
411
419
|
}
|
|
412
420
|
});
|
|
413
|
-
unpacked.chunks.filter(function (
|
|
421
|
+
unpacked.chunks.filter(function (chunk) { return chunk.msgid == NETMSGTYPE.SV_BROADCAST && chunk.type == 'game'; }).forEach(function (a) {
|
|
414
422
|
var unpacker = new MsgUnpacker_1.MsgUnpacker(a.raw.toJSON().data);
|
|
415
423
|
_this.emit("broadcast", unpacker.unpackString());
|
|
416
424
|
});
|
|
@@ -423,52 +431,55 @@ var Client = /** @class */ (function (_super) {
|
|
|
423
431
|
});
|
|
424
432
|
var snapChunks = [];
|
|
425
433
|
if (((_g = _this.options) === null || _g === void 0 ? void 0 : _g.lightweight) !== true)
|
|
426
|
-
snapChunks = unpacked.chunks.filter(function (
|
|
434
|
+
snapChunks = unpacked.chunks.filter(function (chunk) { return chunk.msg === "SNAP" || chunk.msg === "SNAP_SINGLE" || chunk.msg === "SNAP_EMPTY"; });
|
|
427
435
|
if (snapChunks.length > 0) {
|
|
428
|
-
|
|
429
|
-
|
|
436
|
+
if (Math.abs(_this.PredGameTick - _this.AckGameTick) > 10)
|
|
437
|
+
_this.PredGameTick = _this.AckGameTick + 1;
|
|
430
438
|
snapChunks.forEach(function (chunk) {
|
|
431
439
|
var unpacker = new MsgUnpacker_1.MsgUnpacker(chunk.raw.toJSON().data);
|
|
432
|
-
var
|
|
433
|
-
var
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
var part_size = 0;
|
|
452
|
-
if (chunk.msg != "SNAP_EMPTY") {
|
|
453
|
-
crc = unpacker.unpackInt(); // crc
|
|
454
|
-
part_size = unpacker.unpackInt();
|
|
455
|
-
}
|
|
456
|
-
if (part_1 === 0 || _this.snaps.length > 30) {
|
|
440
|
+
var NumParts = 1;
|
|
441
|
+
var Part = 0;
|
|
442
|
+
var GameTick = unpacker.unpackInt();
|
|
443
|
+
var DeltaTick = GameTick - unpacker.unpackInt();
|
|
444
|
+
var PartSize = 0;
|
|
445
|
+
var Crc = 0;
|
|
446
|
+
var CompleteSize = 0;
|
|
447
|
+
if (chunk.msg == "SNAP") {
|
|
448
|
+
NumParts = unpacker.unpackInt();
|
|
449
|
+
Part = unpacker.unpackInt();
|
|
450
|
+
}
|
|
451
|
+
if (chunk.msg != "SNAP_EMPTY") {
|
|
452
|
+
Crc = unpacker.unpackInt();
|
|
453
|
+
PartSize = unpacker.unpackInt();
|
|
454
|
+
}
|
|
455
|
+
if (PartSize < 1 || NumParts > 64 || Part < 0 || Part >= NumParts || PartSize <= 0 || PartSize > 900)
|
|
456
|
+
return;
|
|
457
|
+
if (GameTick >= _this.currentSnapshotGameTick) {
|
|
458
|
+
if (GameTick != _this.currentSnapshotGameTick) {
|
|
457
459
|
_this.snaps = [];
|
|
460
|
+
_this.SnapshotParts = 0;
|
|
461
|
+
_this.currentSnapshotGameTick = GameTick;
|
|
458
462
|
}
|
|
459
|
-
chunk.raw = Buffer.from(unpacker.remaining);
|
|
460
|
-
_this.snaps.
|
|
461
|
-
|
|
463
|
+
// chunk.raw = Buffer.from(unpacker.remaining);
|
|
464
|
+
_this.snaps[Part] = Buffer.from(unpacker.remaining);
|
|
465
|
+
_this.SnapshotParts |= 1 << Part;
|
|
466
|
+
if (_this.SnapshotParts == ((1 << NumParts) - 1)) {
|
|
462
467
|
var mergedSnaps = Buffer.concat(_this.snaps);
|
|
463
|
-
|
|
464
|
-
_this.
|
|
468
|
+
_this.SnapshotParts = 0;
|
|
469
|
+
var snapUnpacked = _this.SnapUnpacker.unpackSnapshot(mergedSnaps.toJSON().data, DeltaTick, GameTick);
|
|
465
470
|
_this.emit("snapshot");
|
|
471
|
+
_this.AckGameTick = snapUnpacked.recvTick;
|
|
472
|
+
if (Math.abs(_this.PredGameTick - _this.AckGameTick) > 10)
|
|
473
|
+
_this.PredGameTick = _this.AckGameTick + 1;
|
|
466
474
|
_this.sendInput();
|
|
467
475
|
}
|
|
468
476
|
}
|
|
469
477
|
});
|
|
470
478
|
}
|
|
471
479
|
var chunkMessages = unpacked.chunks.map(function (a) { return a.msg; });
|
|
480
|
+
if (unpacked.chunks.findIndex(function (chunk) { return chunk.msgid == 23 && chunk.type == "sys"; }) !== -1) {
|
|
481
|
+
_this.game._ping_resolve(new Date().getTime());
|
|
482
|
+
}
|
|
472
483
|
if (chunkMessages.includes("SV_CHAT")) {
|
|
473
484
|
var chat = unpacked.chunks.filter(function (a) { return a.msg == "SV_CHAT"; });
|
|
474
485
|
chat.forEach(function (a) {
|
|
@@ -489,7 +500,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
489
500
|
}
|
|
490
501
|
});
|
|
491
502
|
}
|
|
492
|
-
var chat = unpacked.chunks.filter(function (
|
|
503
|
+
var chat = unpacked.chunks.filter(function (chunk) { return chunk.msg == "SV_KILL_MSG" || chunk.msg == "SV_MOTD"; });
|
|
493
504
|
chat.forEach(function (a) {
|
|
494
505
|
if (a.msg == "SV_KILL_MSG") {
|
|
495
506
|
var unpacked = {};
|
|
@@ -562,6 +573,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
562
573
|
}
|
|
563
574
|
});
|
|
564
575
|
};
|
|
576
|
+
/* Sending the input. (automatically done unless options.lightweight is on) */
|
|
565
577
|
Client.prototype.sendInput = function (input) {
|
|
566
578
|
if (input === void 0) { input = this.movement.input; }
|
|
567
579
|
if (this.State != States.STATE_ONLINE)
|
|
@@ -594,6 +606,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
594
606
|
enumerable: false,
|
|
595
607
|
configurable: true
|
|
596
608
|
});
|
|
609
|
+
/* Disconnect the client. */
|
|
597
610
|
Client.prototype.Disconnect = function () {
|
|
598
611
|
var _this = this;
|
|
599
612
|
return new Promise(function (resolve) {
|
|
@@ -606,71 +619,11 @@ var Client = /** @class */ (function (_super) {
|
|
|
606
619
|
});
|
|
607
620
|
});
|
|
608
621
|
};
|
|
609
|
-
|
|
610
|
-
var _a;
|
|
611
|
-
if (team === void 0) { team = false; }
|
|
612
|
-
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SAY, false, 1);
|
|
613
|
-
packer.AddInt(team ? 1 : 0); // team
|
|
614
|
-
packer.AddString(message);
|
|
615
|
-
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
|
|
616
|
-
this.QueueChunkEx(packer);
|
|
617
|
-
else
|
|
618
|
-
this.SendMsgEx(packer);
|
|
619
|
-
};
|
|
620
|
-
Client.prototype.Vote = function (vote) {
|
|
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);
|
|
628
|
-
};
|
|
629
|
-
Client.prototype.ChangePlayerInfo = function (playerInfo) {
|
|
630
|
-
var _a;
|
|
631
|
-
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_CHANGEINFO, false, 1);
|
|
632
|
-
packer.AddString(playerInfo.name); //m_pName);
|
|
633
|
-
packer.AddString(playerInfo.clan); //m_pClan);
|
|
634
|
-
packer.AddInt(playerInfo.country); //m_Country);
|
|
635
|
-
packer.AddString(playerInfo.skin); //m_pSkin);
|
|
636
|
-
packer.AddInt(playerInfo.use_custom_color ? 1 : 0); //m_UseCustomColor);
|
|
637
|
-
packer.AddInt(playerInfo.color_body); //m_ColorBody);
|
|
638
|
-
packer.AddInt(playerInfo.color_feet); //m_ColorFeet);
|
|
639
|
-
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
|
|
640
|
-
this.QueueChunkEx(packer);
|
|
641
|
-
else
|
|
642
|
-
this.SendMsgEx(packer);
|
|
643
|
-
};
|
|
644
|
-
Client.prototype.Kill = function () {
|
|
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);
|
|
651
|
-
};
|
|
652
|
-
Client.prototype.ChangeTeam = function (team) {
|
|
653
|
-
var _a;
|
|
654
|
-
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SETTEAM, false, 1);
|
|
655
|
-
packer.AddInt(team);
|
|
656
|
-
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
|
|
657
|
-
this.QueueChunkEx(packer);
|
|
658
|
-
else
|
|
659
|
-
this.SendMsgEx(packer);
|
|
660
|
-
};
|
|
661
|
-
Client.prototype.Emote = function (emote) {
|
|
662
|
-
var _a;
|
|
663
|
-
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_EMOTICON, false, 1);
|
|
664
|
-
packer.AddInt(emote);
|
|
665
|
-
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.lightweight))
|
|
666
|
-
this.QueueChunkEx(packer);
|
|
667
|
-
else
|
|
668
|
-
this.SendMsgEx(packer);
|
|
669
|
-
};
|
|
622
|
+
/* Get the client_info from a specific player id. */
|
|
670
623
|
Client.prototype.client_info = function (id) {
|
|
671
|
-
var delta = this.SnapUnpacker.deltas.filter(function (
|
|
672
|
-
return
|
|
673
|
-
&&
|
|
624
|
+
var delta = this.SnapUnpacker.deltas.filter(function (_delta) {
|
|
625
|
+
return _delta.type_id == 11
|
|
626
|
+
&& _delta.id == id;
|
|
674
627
|
});
|
|
675
628
|
if (delta.length == 0)
|
|
676
629
|
return undefined;
|
|
@@ -679,28 +632,31 @@ var Client = /** @class */ (function (_super) {
|
|
|
679
632
|
// .map(a => a.parsed as ClientInfo);
|
|
680
633
|
};
|
|
681
634
|
Object.defineProperty(Client.prototype, "client_infos", {
|
|
635
|
+
/* Get all client infos. */
|
|
682
636
|
get: function () {
|
|
683
|
-
return this.SnapUnpacker.deltas.filter(function (
|
|
637
|
+
return this.SnapUnpacker.deltas.filter(function (_delta) { return _delta.type_id == 11; })
|
|
684
638
|
.sort(function (a, b) { return a.id - b.id; })
|
|
685
639
|
.map(function (a) { return a.parsed; });
|
|
686
640
|
},
|
|
687
641
|
enumerable: false,
|
|
688
642
|
configurable: true
|
|
689
643
|
});
|
|
644
|
+
/* Get the player info from a specific player id. */
|
|
690
645
|
Client.prototype.player_info = function (id) {
|
|
691
|
-
var delta = this.SnapUnpacker.deltas.filter(function (
|
|
692
|
-
return
|
|
693
|
-
&&
|
|
646
|
+
var delta = this.SnapUnpacker.deltas.filter(function (_delta) {
|
|
647
|
+
return _delta.type_id == 10
|
|
648
|
+
&& _delta.id == id;
|
|
694
649
|
});
|
|
695
650
|
if (delta.length == 0)
|
|
696
651
|
return undefined;
|
|
697
652
|
return delta[0].parsed;
|
|
698
653
|
};
|
|
699
654
|
Object.defineProperty(Client.prototype, "player_infos", {
|
|
655
|
+
/* Get all player infos. */
|
|
700
656
|
get: function () {
|
|
701
|
-
return this.SnapUnpacker.deltas.filter(function (
|
|
657
|
+
return this.SnapUnpacker.deltas.filter(function (_delta) { return _delta.type_id == 10; })
|
|
702
658
|
.sort(function (a, b) { return a.id - b.id; })
|
|
703
|
-
.map(function (
|
|
659
|
+
.map(function (player) { return player.parsed; });
|
|
704
660
|
},
|
|
705
661
|
enumerable: false,
|
|
706
662
|
configurable: true
|