teeworlds 2.4.4 → 2.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +0 -1
- package/index.ts +1 -2
- package/lib/client.js +24 -69
- package/lib/client.ts +44 -93
- package/lib/components/game.js +11 -11
- package/lib/components/game.ts +33 -21
- package/lib/{movement.js → components/movement.js} +0 -0
- package/lib/{movement.ts → components/movement.ts} +0 -0
- package/lib/components/snapshot.js +200 -0
- package/lib/components/snapshot.ts +174 -0
- package/lib/snapshot.js +33 -74
- package/lib/snapshot.ts +43 -81
- package/lib/snapshots.d.ts +26 -22
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -20,4 +20,3 @@ Object.defineProperty(exports, "Client", { enumerable: true, get: function () {
|
|
|
20
20
|
__exportStar(require("./lib/MsgPacker"), exports);
|
|
21
21
|
__exportStar(require("./lib/MsgUnpacker"), exports);
|
|
22
22
|
__exportStar(require("./lib/snapshot"), exports);
|
|
23
|
-
__exportStar(require("./lib/movement"), exports);
|
package/index.ts
CHANGED
package/lib/client.js
CHANGED
|
@@ -23,11 +23,12 @@ var crypto_1 = require("crypto");
|
|
|
23
23
|
var dgram_1 = __importDefault(require("dgram"));
|
|
24
24
|
var stream_1 = require("stream");
|
|
25
25
|
var MsgUnpacker_1 = require("./MsgUnpacker");
|
|
26
|
-
var movement_1 = __importDefault(require("./movement"));
|
|
26
|
+
var movement_1 = __importDefault(require("./components/movement"));
|
|
27
27
|
var MsgPacker_1 = require("./MsgPacker");
|
|
28
28
|
var snapshot_1 = require("./snapshot");
|
|
29
29
|
var huffman_1 = __importDefault(require("./huffman"));
|
|
30
30
|
var game_1 = require("./components/game");
|
|
31
|
+
var snapshot_2 = require("./components/snapshot");
|
|
31
32
|
var huff = new huffman_1.default();
|
|
32
33
|
var States;
|
|
33
34
|
(function (States) {
|
|
@@ -112,9 +113,6 @@ var NETMSG_Sys;
|
|
|
112
113
|
NETMSG_Sys[NETMSG_Sys["NETMSG_RCON_CMD_REM"] = 26] = "NETMSG_RCON_CMD_REM";
|
|
113
114
|
NETMSG_Sys[NETMSG_Sys["NUM_NETMSGS"] = 27] = "NUM_NETMSGS";
|
|
114
115
|
})(NETMSG_Sys || (NETMSG_Sys = {}));
|
|
115
|
-
function toHexStream(buff) {
|
|
116
|
-
return buff.toJSON().data.map(function (a) { return ('0' + (a & 0xff).toString(16)).slice(-2); }).join("");
|
|
117
|
-
}
|
|
118
116
|
var messageTypes = [
|
|
119
117
|
["none, starts at 1", "SV_MOTD", "SV_BROADCAST", "SV_CHAT", "SV_KILL_MSG", "SV_SOUND_GLOBAL", "SV_TUNE_PARAMS", "SV_EXTRA_PROJECTILE", "SV_READY_TO_ENTER", "SV_WEAPON_PICKUP", "SV_EMOTICON", "SV_VOTE_CLEAR_OPTIONS", "SV_VOTE_OPTION_LIST_ADD", "SV_VOTE_OPTION_ADD", "SV_VOTE_OPTION_REMOVE", "SV_VOTE_SET", "SV_VOTE_STATUS", "CL_SAY", "CL_SET_TEAM", "CL_SET_SPECTATOR_MODE", "CL_START_INFO", "CL_CHANGE_INFO", "CL_KILL", "CL_EMOTICON", "CL_VOTE", "CL_CALL_VOTE", "CL_IS_DDNET", "SV_DDRACE_TIME", "SV_RECORD", "UNUSED", "SV_TEAMS_STATE", "CL_SHOW_OTHERS_LEGACY"],
|
|
120
118
|
["none, starts at 1", "INFO", "MAP_CHANGE", "MAP_DATA", "CON_READY", "SNAP", "SNAP_EMPTY", "SNAP_SINGLE", "INPUT_TIMING", "RCON_AUTH_STATUS", "RCON_LINE", "READY", "ENTER_GAME", "INPUT", "RCON_CMD", "RCON_AUTH", "REQUEST_MAP_DATA", "PING", "PING_REPLY", "RCON_CMD_ADD", "RCON_CMD_REMOVE"]
|
|
@@ -128,17 +126,6 @@ var messageUUIDs = {
|
|
|
128
126
|
"CLIENT_VERSION": Buffer.from([0x8c, 0x00, 0x13, 0x04, 0x84, 0x61, 0x3e, 0x47, 0x87, 0x87, 0xf6, 0x72, 0xb3, 0x83, 0x5b, 0xd4]),
|
|
129
127
|
"CAPABILITIES": Buffer.from([0xf6, 0x21, 0xa5, 0xa1, 0xf5, 0x85, 0x37, 0x75, 0x8e, 0x73, 0x41, 0xbe, 0xee, 0x79, 0xf2, 0xb2]),
|
|
130
128
|
};
|
|
131
|
-
function arrStartsWith(arr, arrStart, start) {
|
|
132
|
-
if (start === void 0) { start = 0; }
|
|
133
|
-
arr.splice(0, start);
|
|
134
|
-
for (var i = 0; i < arrStart.length; i++) {
|
|
135
|
-
if (arr[i] == arrStart[i])
|
|
136
|
-
continue;
|
|
137
|
-
else
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
129
|
var Client = /** @class */ (function (_super) {
|
|
143
130
|
__extends(Client, _super);
|
|
144
131
|
function Client(ip, port, nickname, options) {
|
|
@@ -150,7 +137,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
150
137
|
_this.PredGameTick = 0;
|
|
151
138
|
_this.currentSnapshotGameTick = 0;
|
|
152
139
|
_this.SnapshotParts = 0;
|
|
153
|
-
_this.SnapUnpacker = new snapshot_1.Snapshot();
|
|
140
|
+
_this.SnapUnpacker = new snapshot_1.Snapshot(_this);
|
|
154
141
|
// this.eSnapHolder = [];
|
|
155
142
|
_this.requestResend = false;
|
|
156
143
|
_this.VoteList = [];
|
|
@@ -172,6 +159,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
172
159
|
_this.lastSentMessages = [];
|
|
173
160
|
_this.movement = new movement_1.default();
|
|
174
161
|
_this.game = new game_1.Game(_this);
|
|
162
|
+
_this.SnapshotUnpacker = new snapshot_2.SnapshotWrapper(_this);
|
|
175
163
|
return _this;
|
|
176
164
|
}
|
|
177
165
|
Client.prototype.ResendAfter = function (lastAck) {
|
|
@@ -224,7 +212,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
224
212
|
}
|
|
225
213
|
return unpacked;
|
|
226
214
|
};
|
|
227
|
-
|
|
215
|
+
/** Send a Control Msg to the server. (used for disconnect)*/
|
|
228
216
|
Client.prototype.SendControlMsg = function (msg, ExtraMsg) {
|
|
229
217
|
var _this = this;
|
|
230
218
|
if (ExtraMsg === void 0) { ExtraMsg = ""; }
|
|
@@ -244,7 +232,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
244
232
|
*/
|
|
245
233
|
});
|
|
246
234
|
};
|
|
247
|
-
|
|
235
|
+
/** Send a Msg (or Msg[]) to the server.*/
|
|
248
236
|
Client.prototype.SendMsgEx = function (Msgs) {
|
|
249
237
|
var _this = this;
|
|
250
238
|
if (this.State == States.STATE_OFFLINE)
|
|
@@ -303,11 +291,11 @@ var Client = /** @class */ (function (_super) {
|
|
|
303
291
|
return;
|
|
304
292
|
this.socket.send(packet, 0, packet.length, this.port, this.host);
|
|
305
293
|
};
|
|
306
|
-
|
|
294
|
+
/** Queue a chunk (It will get sent in the next packet). */
|
|
307
295
|
Client.prototype.QueueChunkEx = function (Msg) {
|
|
308
296
|
this.queueChunkEx.push(Msg);
|
|
309
297
|
};
|
|
310
|
-
|
|
298
|
+
/** Send a Raw Buffer (as chunk) to the server. */
|
|
311
299
|
Client.prototype.SendMsgRaw = function (chunks) {
|
|
312
300
|
if (this.State == States.STATE_OFFLINE)
|
|
313
301
|
return;
|
|
@@ -344,7 +332,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
344
332
|
});
|
|
345
333
|
return chunk;
|
|
346
334
|
};
|
|
347
|
-
|
|
335
|
+
/** Connect the client to the server. */
|
|
348
336
|
Client.prototype.connect = function () {
|
|
349
337
|
var _this = this;
|
|
350
338
|
var _a;
|
|
@@ -551,7 +539,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
551
539
|
var mergedSnaps = Buffer.concat(_this.snaps);
|
|
552
540
|
_this.SnapshotParts = 0;
|
|
553
541
|
var snapUnpacked = _this.SnapUnpacker.unpackSnapshot(mergedSnaps, DeltaTick, GameTick, Crc);
|
|
554
|
-
_this.emit("snapshot");
|
|
542
|
+
_this.emit("snapshot", snapUnpacked.items);
|
|
555
543
|
_this.AckGameTick = snapUnpacked.recvTick;
|
|
556
544
|
if (Math.abs(_this.PredGameTick - _this.AckGameTick) > 10)
|
|
557
545
|
_this.PredGameTick = _this.AckGameTick + 1;
|
|
@@ -596,8 +584,8 @@ var Client = /** @class */ (function (_super) {
|
|
|
596
584
|
};
|
|
597
585
|
if (unpacked_1.client_id != -1) {
|
|
598
586
|
unpacked_1.author = {
|
|
599
|
-
ClientInfo: _this.
|
|
600
|
-
PlayerInfo: _this.
|
|
587
|
+
ClientInfo: _this.SnapshotUnpacker.getObjClientInfo(unpacked_1.client_id),
|
|
588
|
+
PlayerInfo: _this.SnapshotUnpacker.getObjPlayerInfo(unpacked_1.client_id)
|
|
601
589
|
};
|
|
602
590
|
}
|
|
603
591
|
_this.emit("emote", unpacked_1);
|
|
@@ -615,8 +603,8 @@ var Client = /** @class */ (function (_super) {
|
|
|
615
603
|
};
|
|
616
604
|
if (unpacked_2.client_id != -1) {
|
|
617
605
|
unpacked_2.author = {
|
|
618
|
-
ClientInfo: _this.
|
|
619
|
-
PlayerInfo: _this.
|
|
606
|
+
ClientInfo: _this.SnapshotUnpacker.getObjClientInfo(unpacked_2.client_id),
|
|
607
|
+
PlayerInfo: _this.SnapshotUnpacker.getObjPlayerInfo(unpacked_2.client_id)
|
|
620
608
|
};
|
|
621
609
|
}
|
|
622
610
|
_this.emit("message", unpacked_2);
|
|
@@ -629,10 +617,10 @@ var Client = /** @class */ (function (_super) {
|
|
|
629
617
|
unpacked_3.weapon = unpacker.unpackInt();
|
|
630
618
|
unpacked_3.special_mode = unpacker.unpackInt();
|
|
631
619
|
if (unpacked_3.victim_id != -1 && unpacked_3.victim_id < 64) {
|
|
632
|
-
unpacked_3.victim = { ClientInfo: _this.
|
|
620
|
+
unpacked_3.victim = { ClientInfo: _this.SnapshotUnpacker.getObjClientInfo(unpacked_3.victim_id), PlayerInfo: _this.SnapshotUnpacker.getObjPlayerInfo(unpacked_3.victim_id) };
|
|
633
621
|
}
|
|
634
622
|
if (unpacked_3.killer_id != -1 && unpacked_3.killer_id < 64)
|
|
635
|
-
unpacked_3.killer = { ClientInfo: _this.
|
|
623
|
+
unpacked_3.killer = { ClientInfo: _this.SnapshotUnpacker.getObjClientInfo(unpacked_3.killer_id), PlayerInfo: _this.SnapshotUnpacker.getObjPlayerInfo(unpacked_3.killer_id) };
|
|
636
624
|
_this.emit("kill", unpacked_3);
|
|
637
625
|
}
|
|
638
626
|
else if (chunk.msgid == NETMSG_Game.SV_MOTD) {
|
|
@@ -654,7 +642,7 @@ var Client = /** @class */ (function (_super) {
|
|
|
654
642
|
}
|
|
655
643
|
});
|
|
656
644
|
};
|
|
657
|
-
|
|
645
|
+
/** Sending the input. (automatically done unless options.lightweight is on) */
|
|
658
646
|
Client.prototype.sendInput = function (input) {
|
|
659
647
|
if (input === void 0) { input = this.movement.input; }
|
|
660
648
|
if (this.State != States.STATE_ONLINE)
|
|
@@ -676,13 +664,14 @@ var Client = /** @class */ (function (_super) {
|
|
|
676
664
|
this.SendMsgEx(inputMsg);
|
|
677
665
|
};
|
|
678
666
|
Object.defineProperty(Client.prototype, "input", {
|
|
667
|
+
/** returns the movement object of the client */
|
|
679
668
|
get: function () {
|
|
680
669
|
return this.movement.input;
|
|
681
670
|
},
|
|
682
671
|
enumerable: false,
|
|
683
672
|
configurable: true
|
|
684
673
|
});
|
|
685
|
-
|
|
674
|
+
/** Disconnect the client. */
|
|
686
675
|
Client.prototype.Disconnect = function () {
|
|
687
676
|
var _this = this;
|
|
688
677
|
return new Promise(function (resolve) {
|
|
@@ -695,51 +684,17 @@ var Client = /** @class */ (function (_super) {
|
|
|
695
684
|
});
|
|
696
685
|
});
|
|
697
686
|
};
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
var delta = this.SnapUnpacker.deltas.filter(function (_delta) {
|
|
701
|
-
return _delta.type_id == 11
|
|
702
|
-
&& _delta.id == id;
|
|
703
|
-
});
|
|
704
|
-
if (delta.length == 0)
|
|
705
|
-
return undefined;
|
|
706
|
-
return delta[0].parsed;
|
|
707
|
-
// .sort((a, b) => a.id - b.id)
|
|
708
|
-
// .map(a => a.parsed as ClientInfo);
|
|
709
|
-
};
|
|
710
|
-
Object.defineProperty(Client.prototype, "client_infos", {
|
|
711
|
-
/* Get all client infos. */
|
|
712
|
-
get: function () {
|
|
713
|
-
return this.SnapUnpacker.deltas.filter(function (_delta) { return _delta.type_id == 11; })
|
|
714
|
-
.sort(function (a, b) { return a.id - b.id; })
|
|
715
|
-
.map(function (a) { return a.parsed; });
|
|
716
|
-
},
|
|
717
|
-
enumerable: false,
|
|
718
|
-
configurable: true
|
|
719
|
-
});
|
|
720
|
-
/* Get the player info from a specific player id. */
|
|
721
|
-
Client.prototype.player_info = function (id) {
|
|
722
|
-
var delta = this.SnapUnpacker.deltas.filter(function (_delta) {
|
|
723
|
-
return _delta.type_id == 10
|
|
724
|
-
&& _delta.id == id;
|
|
725
|
-
});
|
|
726
|
-
if (delta.length == 0)
|
|
727
|
-
return undefined;
|
|
728
|
-
return delta[0].parsed;
|
|
729
|
-
};
|
|
730
|
-
Object.defineProperty(Client.prototype, "player_infos", {
|
|
731
|
-
/* Get all player infos. */
|
|
687
|
+
Object.defineProperty(Client.prototype, "VoteOptionList", {
|
|
688
|
+
/** Get all available vote options (for example for map voting) */
|
|
732
689
|
get: function () {
|
|
733
|
-
return this.
|
|
734
|
-
.sort(function (a, b) { return a.id - b.id; })
|
|
735
|
-
.map(function (player) { return player.parsed; });
|
|
690
|
+
return this.VoteList;
|
|
736
691
|
},
|
|
737
692
|
enumerable: false,
|
|
738
693
|
configurable: true
|
|
739
694
|
});
|
|
740
|
-
Object.defineProperty(Client.prototype, "
|
|
695
|
+
Object.defineProperty(Client.prototype, "rawSnapUnpacker", {
|
|
741
696
|
get: function () {
|
|
742
|
-
return this.
|
|
697
|
+
return this.SnapUnpacker;
|
|
743
698
|
},
|
|
744
699
|
enumerable: false,
|
|
745
700
|
configurable: true
|
package/lib/client.ts
CHANGED
|
@@ -5,12 +5,14 @@ import { EventEmitter } from 'stream';
|
|
|
5
5
|
|
|
6
6
|
import { unpackString, MsgUnpacker } from "./MsgUnpacker";
|
|
7
7
|
|
|
8
|
-
import Movement from './movement';
|
|
8
|
+
import Movement from './components/movement';
|
|
9
|
+
import { PlayerInput, PlayerInfo, Projectile, Laser, Pickup, Flag, GameInfo, GameData, CharacterCore, Character, ClientInfo, SpectatorInfo, Common, Explosion, Spawn, HammerHit, Death, SoundGlobal, SoundWorld, DamageInd } from "./snapshots";
|
|
9
10
|
|
|
10
11
|
import { MsgPacker } from './MsgPacker';
|
|
11
|
-
import { Snapshot } from './snapshot';
|
|
12
|
+
import { Item, Snapshot } from './snapshot';
|
|
12
13
|
import Huffman from "./huffman";
|
|
13
14
|
import { Game } from "./components/game";
|
|
15
|
+
import { SnapshotWrapper } from "./components/snapshot";
|
|
14
16
|
|
|
15
17
|
const huff = new Huffman();
|
|
16
18
|
|
|
@@ -118,9 +120,7 @@ interface chunk {
|
|
|
118
120
|
raw: Buffer,
|
|
119
121
|
extended_msgid?: Buffer;
|
|
120
122
|
}
|
|
121
|
-
|
|
122
|
-
return buff.toJSON().data.map(a => ('0' + (a & 0xff).toString(16)).slice(-2)).join("");
|
|
123
|
-
}
|
|
123
|
+
|
|
124
124
|
interface _packet {
|
|
125
125
|
twprotocol: { flags: number, ack: number, chunkAmount: number, size: number },
|
|
126
126
|
chunks: chunk[]
|
|
@@ -141,32 +141,6 @@ var messageUUIDs = {
|
|
|
141
141
|
"CAPABILITIES": Buffer.from([0xf6, 0x21, 0xa5, 0xa1, 0xf5, 0x85, 0x37, 0x75, 0x8e, 0x73, 0x41, 0xbe, 0xee, 0x79, 0xf2, 0xb2]),
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
function arrStartsWith(arr: number[], arrStart: number[], start = 0) {
|
|
145
|
-
arr.splice(0, start)
|
|
146
|
-
for (let i = 0; i < arrStart.length; i++) {
|
|
147
|
-
if (arr[i] == arrStart[i])
|
|
148
|
-
continue;
|
|
149
|
-
else return false;
|
|
150
|
-
}
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
declare interface PlayerInfo {
|
|
154
|
-
local: number,
|
|
155
|
-
client_id: number,
|
|
156
|
-
team: number,
|
|
157
|
-
score: number,
|
|
158
|
-
latency: number,
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
declare interface ClientInfo {
|
|
162
|
-
name: string,
|
|
163
|
-
clan: string,
|
|
164
|
-
country: number,
|
|
165
|
-
skin: string,
|
|
166
|
-
use_custom_color: number,
|
|
167
|
-
color_body: number,
|
|
168
|
-
color_feet: number,
|
|
169
|
-
}
|
|
170
144
|
declare interface iMessage {
|
|
171
145
|
team: number,
|
|
172
146
|
client_id: number,
|
|
@@ -210,6 +184,7 @@ export declare interface Client {
|
|
|
210
184
|
on(event: 'kill', listener: (kill: iKillMsg) => void): this;
|
|
211
185
|
on(event: 'motd', listener: (message: string) => void): this;
|
|
212
186
|
|
|
187
|
+
on(event: 'snapshot', listener: (items: Item[]) => void): this;
|
|
213
188
|
}
|
|
214
189
|
|
|
215
190
|
export class Client extends EventEmitter {
|
|
@@ -226,6 +201,8 @@ export class Client extends EventEmitter {
|
|
|
226
201
|
private time: number;
|
|
227
202
|
private SnapUnpacker: Snapshot;
|
|
228
203
|
|
|
204
|
+
public SnapshotUnpacker: SnapshotWrapper;
|
|
205
|
+
|
|
229
206
|
private PredGameTick: number;
|
|
230
207
|
private AckGameTick: number;
|
|
231
208
|
|
|
@@ -265,7 +242,7 @@ export class Client extends EventEmitter {
|
|
|
265
242
|
|
|
266
243
|
this.SnapshotParts = 0;
|
|
267
244
|
|
|
268
|
-
this.SnapUnpacker = new Snapshot();
|
|
245
|
+
this.SnapUnpacker = new Snapshot(this);
|
|
269
246
|
// this.eSnapHolder = [];
|
|
270
247
|
this.requestResend = false;
|
|
271
248
|
|
|
@@ -296,6 +273,7 @@ export class Client extends EventEmitter {
|
|
|
296
273
|
this.movement = new Movement();
|
|
297
274
|
|
|
298
275
|
this.game = new Game(this);
|
|
276
|
+
this.SnapshotUnpacker = new SnapshotWrapper(this);
|
|
299
277
|
|
|
300
278
|
|
|
301
279
|
}
|
|
@@ -360,8 +338,9 @@ export class Client extends EventEmitter {
|
|
|
360
338
|
return unpacked
|
|
361
339
|
}
|
|
362
340
|
|
|
363
|
-
|
|
364
|
-
|
|
341
|
+
|
|
342
|
+
/** Send a Control Msg to the server. (used for disconnect)*/
|
|
343
|
+
SendControlMsg(msg: number, ExtraMsg: string = "") {
|
|
365
344
|
this.lastSendTime = new Date().getTime();
|
|
366
345
|
return new Promise((resolve, reject) => {
|
|
367
346
|
if (this.socket) {
|
|
@@ -380,8 +359,9 @@ export class Client extends EventEmitter {
|
|
|
380
359
|
})
|
|
381
360
|
}
|
|
382
361
|
|
|
383
|
-
|
|
384
|
-
|
|
362
|
+
|
|
363
|
+
/** Send a Msg (or Msg[]) to the server.*/
|
|
364
|
+
SendMsgEx(Msgs: MsgPacker[] | MsgPacker) {
|
|
385
365
|
if (this.State == States.STATE_OFFLINE)
|
|
386
366
|
return;
|
|
387
367
|
if (!this.socket)
|
|
@@ -439,12 +419,14 @@ export class Client extends EventEmitter {
|
|
|
439
419
|
return;
|
|
440
420
|
this.socket.send(packet, 0, packet.length, this.port, this.host)
|
|
441
421
|
}
|
|
442
|
-
|
|
422
|
+
|
|
423
|
+
/** Queue a chunk (It will get sent in the next packet). */
|
|
443
424
|
QueueChunkEx(Msg: MsgPacker) {
|
|
444
425
|
this.queueChunkEx.push(Msg);
|
|
445
426
|
}
|
|
446
|
-
|
|
447
|
-
|
|
427
|
+
|
|
428
|
+
/** Send a Raw Buffer (as chunk) to the server. */
|
|
429
|
+
SendMsgRaw(chunks: Buffer[]) {
|
|
448
430
|
if (this.State == States.STATE_OFFLINE)
|
|
449
431
|
return;
|
|
450
432
|
if (!this.socket)
|
|
@@ -485,8 +467,9 @@ export class Client extends EventEmitter {
|
|
|
485
467
|
return chunk;
|
|
486
468
|
}
|
|
487
469
|
|
|
488
|
-
|
|
489
|
-
|
|
470
|
+
|
|
471
|
+
/** Connect the client to the server. */
|
|
472
|
+
connect() {
|
|
490
473
|
this.State = States.STATE_CONNECTING;
|
|
491
474
|
|
|
492
475
|
let predTimer = setInterval(() => {
|
|
@@ -714,7 +697,7 @@ export class Client extends EventEmitter {
|
|
|
714
697
|
|
|
715
698
|
let snapUnpacked = this.SnapUnpacker.unpackSnapshot(mergedSnaps, DeltaTick, GameTick, Crc);
|
|
716
699
|
|
|
717
|
-
this.emit("snapshot");
|
|
700
|
+
this.emit("snapshot", snapUnpacked.items);
|
|
718
701
|
this.AckGameTick = snapUnpacked.recvTick;
|
|
719
702
|
if (Math.abs(this.PredGameTick - this.AckGameTick) > 10)
|
|
720
703
|
this.PredGameTick = this.AckGameTick + 1;
|
|
@@ -770,8 +753,8 @@ export class Client extends EventEmitter {
|
|
|
770
753
|
|
|
771
754
|
if (unpacked.client_id != -1) {
|
|
772
755
|
unpacked.author = {
|
|
773
|
-
ClientInfo: this.
|
|
774
|
-
PlayerInfo: this.
|
|
756
|
+
ClientInfo: this.SnapshotUnpacker.getObjClientInfo(unpacked.client_id),
|
|
757
|
+
PlayerInfo: this.SnapshotUnpacker.getObjPlayerInfo(unpacked.client_id)
|
|
775
758
|
}
|
|
776
759
|
}
|
|
777
760
|
this.emit("emote", unpacked)
|
|
@@ -792,8 +775,8 @@ export class Client extends EventEmitter {
|
|
|
792
775
|
|
|
793
776
|
if (unpacked.client_id != -1) {
|
|
794
777
|
unpacked.author = {
|
|
795
|
-
ClientInfo: this.
|
|
796
|
-
PlayerInfo: this.
|
|
778
|
+
ClientInfo: this.SnapshotUnpacker.getObjClientInfo(unpacked.client_id),
|
|
779
|
+
PlayerInfo: this.SnapshotUnpacker.getObjPlayerInfo(unpacked.client_id)
|
|
797
780
|
}
|
|
798
781
|
}
|
|
799
782
|
this.emit("message", unpacked)
|
|
@@ -805,11 +788,11 @@ export class Client extends EventEmitter {
|
|
|
805
788
|
unpacked.weapon = unpacker.unpackInt();
|
|
806
789
|
unpacked.special_mode = unpacker.unpackInt();
|
|
807
790
|
if (unpacked.victim_id != -1 && unpacked.victim_id < 64) {
|
|
808
|
-
unpacked.victim = { ClientInfo: this.
|
|
791
|
+
unpacked.victim = { ClientInfo: this.SnapshotUnpacker.getObjClientInfo(unpacked.victim_id), PlayerInfo: this.SnapshotUnpacker.getObjPlayerInfo(unpacked.victim_id) }
|
|
809
792
|
|
|
810
793
|
}
|
|
811
794
|
if (unpacked.killer_id != -1 && unpacked.killer_id < 64)
|
|
812
|
-
unpacked.killer = { ClientInfo: this.
|
|
795
|
+
unpacked.killer = { ClientInfo: this.SnapshotUnpacker.getObjClientInfo(unpacked.killer_id), PlayerInfo: this.SnapshotUnpacker.getObjPlayerInfo(unpacked.killer_id) }
|
|
813
796
|
this.emit("kill", unpacked)
|
|
814
797
|
} else if (chunk.msgid == NETMSG_Game.SV_MOTD) {
|
|
815
798
|
let unpacker = new MsgUnpacker(chunk.raw);
|
|
@@ -834,8 +817,9 @@ export class Client extends EventEmitter {
|
|
|
834
817
|
})
|
|
835
818
|
}
|
|
836
819
|
|
|
837
|
-
|
|
838
|
-
|
|
820
|
+
|
|
821
|
+
/** Sending the input. (automatically done unless options.lightweight is on) */
|
|
822
|
+
sendInput(input = this.movement.input) {
|
|
839
823
|
if (this.State != States.STATE_ONLINE)
|
|
840
824
|
return;
|
|
841
825
|
|
|
@@ -857,12 +841,14 @@ export class Client extends EventEmitter {
|
|
|
857
841
|
|
|
858
842
|
this.SendMsgEx(inputMsg);
|
|
859
843
|
}
|
|
860
|
-
|
|
844
|
+
/** returns the movement object of the client */
|
|
845
|
+
get input() {
|
|
861
846
|
return this.movement.input;
|
|
862
847
|
}
|
|
863
848
|
|
|
864
|
-
|
|
865
|
-
Disconnect
|
|
849
|
+
|
|
850
|
+
/** Disconnect the client. */
|
|
851
|
+
Disconnect() {
|
|
866
852
|
return new Promise((resolve) => {
|
|
867
853
|
this.SendControlMsg(4).then(() => {
|
|
868
854
|
resolve(true);
|
|
@@ -874,46 +860,11 @@ export class Client extends EventEmitter {
|
|
|
874
860
|
})
|
|
875
861
|
}
|
|
876
862
|
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
let delta = this.SnapUnpacker.deltas.filter(_delta =>
|
|
880
|
-
_delta.type_id == 11
|
|
881
|
-
&& _delta.id == id
|
|
882
|
-
);
|
|
883
|
-
|
|
884
|
-
if (delta.length == 0)
|
|
885
|
-
return undefined;
|
|
886
|
-
return delta[0].parsed as ClientInfo;
|
|
887
|
-
// .sort((a, b) => a.id - b.id)
|
|
888
|
-
// .map(a => a.parsed as ClientInfo);
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
/* Get all client infos. */
|
|
892
|
-
get client_infos(): ClientInfo[] {
|
|
893
|
-
|
|
894
|
-
return this.SnapUnpacker.deltas.filter(_delta => _delta.type_id == 11)
|
|
895
|
-
.sort((a, b) => a.id - b.id)
|
|
896
|
-
.map(a => a.parsed as ClientInfo);
|
|
897
|
-
}
|
|
898
|
-
/* Get the player info from a specific player id. */
|
|
899
|
-
player_info(id: number) {
|
|
900
|
-
let delta = this.SnapUnpacker.deltas.filter(_delta =>
|
|
901
|
-
_delta.type_id == 10
|
|
902
|
-
&& _delta.id == id
|
|
903
|
-
);
|
|
904
|
-
|
|
905
|
-
if (delta.length == 0)
|
|
906
|
-
return undefined;
|
|
907
|
-
return delta[0].parsed as PlayerInfo;
|
|
908
|
-
}
|
|
909
|
-
/* Get all player infos. */
|
|
910
|
-
get player_infos(): PlayerInfo[] {
|
|
911
|
-
return this.SnapUnpacker.deltas.filter(_delta => _delta.type_id == 10)
|
|
912
|
-
.sort((a, b) => a.id - b.id)
|
|
913
|
-
.map(player => player.parsed as PlayerInfo);
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
get VoteOptionList(): string[] {
|
|
863
|
+
/** Get all available vote options (for example for map voting) */
|
|
864
|
+
get VoteOptionList(): string[] {
|
|
917
865
|
return this.VoteList;
|
|
918
866
|
}
|
|
867
|
+
get rawSnapUnpacker(): Snapshot {
|
|
868
|
+
return this.SnapUnpacker;
|
|
869
|
+
}
|
|
919
870
|
}
|
package/lib/components/game.js
CHANGED
|
@@ -59,19 +59,19 @@ var Game = /** @class */ (function () {
|
|
|
59
59
|
packer.AddString(message);
|
|
60
60
|
this.send(packer);
|
|
61
61
|
};
|
|
62
|
-
|
|
62
|
+
/** Set the team of an bot. (-1 spectator team, 0 team red/normal team, 1 team blue) */
|
|
63
63
|
Game.prototype.SetTeam = function (team) {
|
|
64
64
|
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SETTEAM, false, 1);
|
|
65
65
|
packer.AddInt(team);
|
|
66
66
|
this.send(packer);
|
|
67
67
|
};
|
|
68
|
-
|
|
68
|
+
/** Spectate an player, taking their id as parameter. pretty useless */
|
|
69
69
|
Game.prototype.SpectatorMode = function (SpectatorID) {
|
|
70
70
|
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SETSPECTATORMODE, false, 1);
|
|
71
71
|
packer.AddInt(SpectatorID);
|
|
72
72
|
this.send(packer);
|
|
73
73
|
};
|
|
74
|
-
|
|
74
|
+
/** Change the player info */
|
|
75
75
|
Game.prototype.ChangePlayerInfo = function (playerInfo) {
|
|
76
76
|
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_CHANGEINFO, false, 1);
|
|
77
77
|
packer.AddString(playerInfo.name);
|
|
@@ -83,18 +83,18 @@ var Game = /** @class */ (function () {
|
|
|
83
83
|
packer.AddInt(playerInfo.color_feet);
|
|
84
84
|
this.send(packer);
|
|
85
85
|
};
|
|
86
|
-
|
|
86
|
+
/** Kill */
|
|
87
87
|
Game.prototype.Kill = function () {
|
|
88
88
|
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_KILL, false, 1);
|
|
89
89
|
this.send(packer);
|
|
90
90
|
};
|
|
91
|
-
|
|
91
|
+
/** Send emote */
|
|
92
92
|
Game.prototype.Emote = function (emote) {
|
|
93
93
|
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_EMOTICON, false, 1);
|
|
94
94
|
packer.AddInt(emote);
|
|
95
95
|
this.send(packer);
|
|
96
96
|
};
|
|
97
|
-
|
|
97
|
+
/** Vote for an already running vote (true = f3 / false = f4) */
|
|
98
98
|
Game.prototype.Vote = function (vote) {
|
|
99
99
|
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_VOTE, false, 1);
|
|
100
100
|
packer.AddInt(vote ? 1 : -1);
|
|
@@ -107,24 +107,24 @@ var Game = /** @class */ (function () {
|
|
|
107
107
|
packer.AddString(Reason);
|
|
108
108
|
this.send(packer);
|
|
109
109
|
};
|
|
110
|
-
|
|
110
|
+
/** Call a vote for an server option (for example ddnet maps) */
|
|
111
111
|
Game.prototype.CallVoteOption = function (Value, Reason) {
|
|
112
112
|
this.CallVote("option", Value, Reason);
|
|
113
113
|
};
|
|
114
|
-
|
|
114
|
+
/** Call a vote to kick a player. Requires the player id */
|
|
115
115
|
Game.prototype.CallVoteKick = function (PlayerID, Reason) {
|
|
116
116
|
this.CallVote("kick", PlayerID, Reason);
|
|
117
117
|
};
|
|
118
|
-
|
|
118
|
+
/** Call a vote to set a player in spectator mode. Requires the player id */
|
|
119
119
|
Game.prototype.CallVoteSpectate = function (PlayerID, Reason) {
|
|
120
120
|
this.CallVote("spectate", PlayerID, Reason);
|
|
121
121
|
};
|
|
122
|
-
/** probably some verification of using ddnet client
|
|
122
|
+
/** probably some verification of using ddnet client. */
|
|
123
123
|
Game.prototype.IsDDNetLegacy = function () {
|
|
124
124
|
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_ISDDNETLEGACY, false, 1);
|
|
125
125
|
this.send(packer);
|
|
126
126
|
};
|
|
127
|
-
|
|
127
|
+
/** returns the ping in ms (as a promise) */
|
|
128
128
|
Game.prototype.Ping = function () {
|
|
129
129
|
var _this = this;
|
|
130
130
|
return new Promise(function (resolve, reject) {
|