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
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
|
|
2
|
+
import { MsgPacker } from "../MsgPacker";
|
|
3
|
+
|
|
4
|
+
import { Client } from "../client";
|
|
5
|
+
enum NETMSGTYPE { EX, SV_MOTD, SV_BROADCAST, SV_CHAT, SV_KILLMSG, SV_SOUNDGLOBAL, SV_TUNEPARAMS, SV_EXTRAPROJECTILE, SV_READYTOENTER, SV_WEAPONPICKUP, SV_EMOTICON, SV_VOTECLEAROPTIONS, SV_VOTEOPTIONLISTADD, SV_VOTEOPTIONADD, SV_VOTEOPTIONREMOVE, SV_VOTESET, SV_VOTESTATUS, CL_SAY, CL_SETTEAM, CL_SETSPECTATORMODE, CL_STARTINFO, CL_CHANGEINFO, CL_KILL, CL_EMOTICON, CL_VOTE, CL_CALLVOTE, CL_ISDDNETLEGACY, SV_DDRACETIMELEGACY, SV_RECORDLEGACY, UNUSED, SV_TEAMSSTATELEGACY, CL_SHOWOTHERSLEGACY, NUM };
|
|
6
|
+
|
|
7
|
+
export class Game {
|
|
8
|
+
// SendMsgEx: (Msgs: MsgPacker[] | MsgPacker) => void;
|
|
9
|
+
private _client: Client;
|
|
10
|
+
_ping_resolve: (_time: number) => void;
|
|
11
|
+
constructor(_client: Client) {
|
|
12
|
+
// this.SendMsgEx = callback;
|
|
13
|
+
this._client = _client;
|
|
14
|
+
this._ping_resolve = () => {};
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
private send(packer: MsgPacker) {
|
|
18
|
+
if (!this._client.options?.lightweight)
|
|
19
|
+
this._client.QueueChunkEx(packer);
|
|
20
|
+
else
|
|
21
|
+
this._client.SendMsgEx(packer);
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Say(message: string, team = false) {
|
|
26
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_SAY, false, 1);
|
|
27
|
+
packer.AddInt(team ? 1 : 0); // team
|
|
28
|
+
packer.AddString(message);
|
|
29
|
+
this.send(packer);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Set the team of an bot. (-1 spectator team, 0 team red/normal team, 1 team blue) */
|
|
33
|
+
SetTeam(team: number) {
|
|
34
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_SETTEAM, false, 1);
|
|
35
|
+
packer.AddInt(team);
|
|
36
|
+
this.send(packer);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* Spectate an player, taking their id as parameter. pretty useless */
|
|
40
|
+
SpectatorMode(SpectatorID: number) {
|
|
41
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_SETSPECTATORMODE, false, 1);
|
|
42
|
+
packer.AddInt(SpectatorID);
|
|
43
|
+
this.send(packer);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
/* Change the player info */
|
|
48
|
+
ChangePlayerInfo(playerInfo: ClientInfo) {
|
|
49
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_CHANGEINFO, false, 1);
|
|
50
|
+
packer.AddString(playerInfo.name);
|
|
51
|
+
packer.AddString(playerInfo.clan);
|
|
52
|
+
packer.AddInt(playerInfo.country);
|
|
53
|
+
packer.AddString(playerInfo.skin);
|
|
54
|
+
packer.AddInt(playerInfo.use_custom_color ? 1 : 0);
|
|
55
|
+
packer.AddInt(playerInfo.color_body);
|
|
56
|
+
packer.AddInt(playerInfo.color_feet);
|
|
57
|
+
this.send(packer);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* Kill */
|
|
61
|
+
Kill() {
|
|
62
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_KILL, false, 1);
|
|
63
|
+
this.send(packer);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* Send emote */
|
|
67
|
+
Emote(emote: number) {
|
|
68
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_EMOTICON, false, 1);
|
|
69
|
+
packer.AddInt(emote);
|
|
70
|
+
this.send(packer);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* Vote for an already running vote (f3 / f4) */
|
|
74
|
+
Vote(vote: boolean) {
|
|
75
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_VOTE, false, 1);
|
|
76
|
+
packer.AddInt(vote ? 1 : -1);
|
|
77
|
+
this.send(packer);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private CallVote(Type: "option" | "kick" | "spectate", Value: string|number, Reason: string) {
|
|
81
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_CALLVOTE, false, 1);
|
|
82
|
+
packer.AddString(Type);
|
|
83
|
+
packer.AddString(String(Value));
|
|
84
|
+
packer.AddString(Reason);
|
|
85
|
+
this.send(packer);
|
|
86
|
+
}
|
|
87
|
+
/* Call a vote for an server option (for example ddnet maps) */
|
|
88
|
+
CallVoteOption(Value: string, Reason: string) {
|
|
89
|
+
this.CallVote("option", Value, Reason)
|
|
90
|
+
}
|
|
91
|
+
/* Call a vote to kick a player. Requires the player id */
|
|
92
|
+
CallVoteKick(PlayerID: string|number, Reason: string) {
|
|
93
|
+
this.CallVote("kick", PlayerID, Reason)
|
|
94
|
+
}
|
|
95
|
+
/* Call a vote to set a player in spectator mode. Requires the player id */
|
|
96
|
+
CallVoteSpectate(PlayerID: string|number, Reason: string) {
|
|
97
|
+
this.CallVote("spectate", PlayerID, Reason)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
/** probably some verification of using ddnet client.*/
|
|
102
|
+
IsDDNetLegacy() {
|
|
103
|
+
var packer = new MsgPacker(NETMSGTYPE.CL_ISDDNETLEGACY, false, 1);
|
|
104
|
+
this.send(packer);
|
|
105
|
+
}
|
|
106
|
+
/* returns the ping in ms */
|
|
107
|
+
Ping(): Promise<number> {
|
|
108
|
+
return new Promise((resolve, reject) => {
|
|
109
|
+
var packer = new MsgPacker(22, true, 0);
|
|
110
|
+
let startTime = new Date().getTime();
|
|
111
|
+
this.send(packer);
|
|
112
|
+
|
|
113
|
+
let callback = (_time: number) => {
|
|
114
|
+
resolve(_time - startTime);
|
|
115
|
+
this._ping_resolve = () => {};
|
|
116
|
+
}
|
|
117
|
+
this._ping_resolve = callback;
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
}
|
package/lib/movement.js
CHANGED
|
@@ -19,7 +19,7 @@ var Movement = /** @class */ (function () {
|
|
|
19
19
|
this.input.m_Jump = state ? 1 : 0;
|
|
20
20
|
};
|
|
21
21
|
Movement.prototype.Fire = function () {
|
|
22
|
-
this.input.m_Fire
|
|
22
|
+
this.input.m_Fire++;
|
|
23
23
|
};
|
|
24
24
|
Movement.prototype.Hook = function (state) {
|
|
25
25
|
if (state === void 0) { state = true; }
|
package/lib/movement.ts
CHANGED
package/lib/snapshot.js
CHANGED
|
@@ -57,24 +57,24 @@ var Snapshot = /** @class */ (function () {
|
|
|
57
57
|
}
|
|
58
58
|
Snapshot.prototype.IntsToStr = function (pInts) {
|
|
59
59
|
var pIntz = [];
|
|
60
|
-
var pStr = ''
|
|
60
|
+
// var pStr = ''
|
|
61
61
|
for (var _i = 0, pInts_1 = pInts; _i < pInts_1.length; _i++) {
|
|
62
62
|
var x = pInts_1[_i];
|
|
63
|
-
pStr += String.fromCharCode((((x) >> 24) & 0xff) - 128);
|
|
63
|
+
// pStr += String.fromCharCode((((x) >> 24) & 0xff) - 128);
|
|
64
64
|
pIntz.push((((x) >> 24) & 0xff) - 128);
|
|
65
|
-
pStr += String.fromCharCode((((x) >> 16) & 0xff) - 128);
|
|
65
|
+
// pStr += String.fromCharCode((((x) >> 16) & 0xff) - 128);
|
|
66
66
|
pIntz.push((((x) >> 16) & 0xff) - 128);
|
|
67
|
-
pStr += String.fromCharCode((((x) >> 8) & 0xff) - 128);
|
|
67
|
+
// pStr += String.fromCharCode((((x) >> 8) & 0xff) - 128);
|
|
68
68
|
pIntz.push((((x) >> 8) & 0xff) - 128);
|
|
69
|
-
pStr += String.fromCharCode(((x) & 0xff) - 128);
|
|
69
|
+
// pStr += String.fromCharCode(((x) & 0xff) - 128);
|
|
70
70
|
pIntz.push(((x) & 0xff) - 128);
|
|
71
71
|
}
|
|
72
72
|
pIntz.splice(-1, 1);
|
|
73
|
-
pStr = decoder.decode(new Uint8Array(pIntz));
|
|
73
|
+
var pStr = decoder.decode(new Uint8Array(pIntz));
|
|
74
74
|
pStr = pStr.replace(/\0.*/g, ''); // Remove content from first null char to end.
|
|
75
75
|
return pStr;
|
|
76
76
|
};
|
|
77
|
-
Snapshot.prototype.parseItem = function (data, Type) {
|
|
77
|
+
Snapshot.prototype.parseItem = function (data, Type, id) {
|
|
78
78
|
var _item = {};
|
|
79
79
|
switch (Type) {
|
|
80
80
|
case items.OBJ_EX:
|
|
@@ -212,6 +212,7 @@ var Snapshot = /** @class */ (function () {
|
|
|
212
212
|
use_custom_color: Number(data.slice(14, 15)),
|
|
213
213
|
color_body: Number(data.slice(15, 16)),
|
|
214
214
|
color_feet: Number(data.slice(16, 17)),
|
|
215
|
+
id: id
|
|
215
216
|
};
|
|
216
217
|
break;
|
|
217
218
|
case items.OBJ_SPECTATOR_INFO:
|
|
@@ -302,8 +303,9 @@ var Snapshot = /** @class */ (function () {
|
|
|
302
303
|
}
|
|
303
304
|
if (snap.length == 0) {
|
|
304
305
|
// empty snap, copy old one into new ack
|
|
305
|
-
this.eSnapHolder.
|
|
306
|
-
|
|
306
|
+
this.eSnapHolder.forEach(function (snap) {
|
|
307
|
+
if (snap.ack == deltatick)
|
|
308
|
+
_this.eSnapHolder.push({ Snapshot: snap.Snapshot, ack: recvTick });
|
|
307
309
|
});
|
|
308
310
|
return { items: [], recvTick: recvTick };
|
|
309
311
|
}
|
|
@@ -316,15 +318,6 @@ var Snapshot = /** @class */ (function () {
|
|
|
316
318
|
var num_removed_items = unpacker.unpackInt();
|
|
317
319
|
var num_item_deltas = unpacker.unpackInt();
|
|
318
320
|
unpacker.unpackInt(); // _zero padding
|
|
319
|
-
var _loop_1 = function (i) {
|
|
320
|
-
var deleted_key = unpacker.unpackInt(); // removed_item_keys
|
|
321
|
-
var index = this_1.deltas.map(function (delta) { return delta.key; }).indexOf(deleted_key);
|
|
322
|
-
// console.log("deleting ", deleted_key, index)
|
|
323
|
-
if (index > -1)
|
|
324
|
-
this_1.deltas.splice(index, 1);
|
|
325
|
-
this_1.eSnapHolder = this_1.eSnapHolder.filter(function (a) { return a.Snapshot.Key !== deleted_key; });
|
|
326
|
-
};
|
|
327
|
-
var this_1 = this;
|
|
328
321
|
/*snapshot_delta:
|
|
329
322
|
[ 4] num_removed_items
|
|
330
323
|
[ 4] num_item_deltas
|
|
@@ -332,9 +325,22 @@ var Snapshot = /** @class */ (function () {
|
|
|
332
325
|
[*4] removed_item_keys
|
|
333
326
|
[ ] item_deltas
|
|
334
327
|
*/
|
|
328
|
+
var deleted = [];
|
|
329
|
+
var _loop_1 = function (i) {
|
|
330
|
+
var deleted_key = unpacker.unpackInt(); // removed_item_keys
|
|
331
|
+
// let index = this.deltas.map(delta => delta.key).indexOf(deleted_key);
|
|
332
|
+
var index = this_1.deltas.findIndex(function (delta) { return delta.key === deleted_key; });
|
|
333
|
+
// console.log("deleting ", deleted_key, index)
|
|
334
|
+
if (index > -1)
|
|
335
|
+
this_1.deltas.splice(index, 1);
|
|
336
|
+
deleted.push(deleted_key);
|
|
337
|
+
};
|
|
338
|
+
var this_1 = this;
|
|
335
339
|
for (var i = 0; i < num_removed_items; i++) {
|
|
336
340
|
_loop_1(i);
|
|
337
341
|
}
|
|
342
|
+
if (deleted.length)
|
|
343
|
+
this.eSnapHolder = this.eSnapHolder.filter(function (a) { return !deleted.includes(a.Snapshot.Key); });
|
|
338
344
|
/*item_delta:
|
|
339
345
|
[ 4] type_id
|
|
340
346
|
[ 4] id
|
|
@@ -350,7 +356,7 @@ var Snapshot = /** @class */ (function () {
|
|
|
350
356
|
deltaSnaps.forEach(function (a) {
|
|
351
357
|
newSnaps.push({ Snapshot: a.Snapshot, ack: recvTick });
|
|
352
358
|
});
|
|
353
|
-
|
|
359
|
+
var _loop_2 = function (i) {
|
|
354
360
|
var type_id = unpacker.unpackInt();
|
|
355
361
|
var id = unpacker.unpackInt();
|
|
356
362
|
var key = (((type_id) << 16) | (id));
|
|
@@ -369,31 +375,38 @@ var Snapshot = /** @class */ (function () {
|
|
|
369
375
|
}
|
|
370
376
|
// console.log(index, deltatick)
|
|
371
377
|
if (deltatick >= 0) {
|
|
372
|
-
|
|
378
|
+
// let index = deltaSnaps.map(delta => delta.Snapshot.Key).indexOf(key)
|
|
379
|
+
var index = deltaSnaps.findIndex(function (delta) { return delta.Snapshot.Key === key; });
|
|
373
380
|
if (index > -1) {
|
|
374
381
|
var out = UndiffItem(deltaSnaps[index].Snapshot.Data, data);
|
|
375
382
|
data = out;
|
|
376
383
|
} // else no previous, use new data
|
|
377
384
|
}
|
|
378
|
-
var parsed =
|
|
379
|
-
|
|
385
|
+
var parsed = this_2.parseItem(data, type_id, id);
|
|
386
|
+
this_2.eSnapHolder.push({ Snapshot: { Data: data, Key: key }, ack: recvTick });
|
|
380
387
|
items.items.push({ data: data, parsed: parsed, type_id: type_id, id: id, key: key });
|
|
388
|
+
};
|
|
389
|
+
var this_2 = this;
|
|
390
|
+
for (var i = 0; i < num_item_deltas; i++) {
|
|
391
|
+
_loop_2(i);
|
|
381
392
|
}
|
|
382
|
-
var
|
|
383
|
-
if (
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
var ____index = this_2.deltas.map(function (delta) { return delta.key; }).indexOf(newSnap.Snapshot.Key);
|
|
387
|
-
if (____index > -1 && deltatick > -1) {
|
|
388
|
-
this_2.deltas[____index] = { data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this_2.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff)) };
|
|
393
|
+
var _loop_3 = function (newSnap) {
|
|
394
|
+
if (this_3.eSnapHolder.findIndex(function (a) { return a.ack == newSnap.ack && a.Snapshot.Key == newSnap.Snapshot.Key; }) === -1) { // ugly copy new snap to eSnapHolder (if it isnt pushed already)
|
|
395
|
+
this_3.eSnapHolder.push({ Snapshot: { Data: newSnap.Snapshot.Data, Key: newSnap.Snapshot.Key }, ack: recvTick });
|
|
389
396
|
}
|
|
390
|
-
|
|
391
|
-
|
|
397
|
+
if (deltatick > -1) {
|
|
398
|
+
var ____index = this_3.deltas.findIndex(function (delta) { return delta.key == newSnap.Snapshot.Key; });
|
|
399
|
+
if (____index > -1) {
|
|
400
|
+
this_3.deltas[____index] = { data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this_3.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff), ((newSnap.Snapshot.Key) & 0xffff)) };
|
|
401
|
+
return "continue";
|
|
402
|
+
}
|
|
403
|
+
} // else
|
|
404
|
+
this_3.deltas.push({ data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this_3.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff), ((newSnap.Snapshot.Key) & 0xffff)) });
|
|
392
405
|
};
|
|
393
|
-
var
|
|
406
|
+
var this_3 = this;
|
|
394
407
|
for (var _i = 0, newSnaps_1 = newSnaps; _i < newSnaps_1.length; _i++) {
|
|
395
408
|
var newSnap = newSnaps_1[_i];
|
|
396
|
-
|
|
409
|
+
_loop_3(newSnap);
|
|
397
410
|
}
|
|
398
411
|
return { items: items, recvTick: recvTick };
|
|
399
412
|
};
|
package/lib/snapshot.ts
CHANGED
|
@@ -60,24 +60,24 @@ export class Snapshot {
|
|
|
60
60
|
|
|
61
61
|
private IntsToStr(pInts: number[]): string {
|
|
62
62
|
var pIntz: number[] = [];
|
|
63
|
-
var pStr = ''
|
|
63
|
+
// var pStr = ''
|
|
64
64
|
for (let x of pInts) {
|
|
65
|
-
pStr += String.fromCharCode((((x) >> 24) & 0xff) - 128);
|
|
65
|
+
// pStr += String.fromCharCode((((x) >> 24) & 0xff) - 128);
|
|
66
66
|
pIntz.push((((x) >> 24) & 0xff) - 128);
|
|
67
|
-
pStr += String.fromCharCode((((x) >> 16) & 0xff) - 128);
|
|
67
|
+
// pStr += String.fromCharCode((((x) >> 16) & 0xff) - 128);
|
|
68
68
|
pIntz.push((((x) >> 16) & 0xff) - 128);
|
|
69
|
-
pStr += String.fromCharCode((((x) >> 8) & 0xff) - 128);
|
|
69
|
+
// pStr += String.fromCharCode((((x) >> 8) & 0xff) - 128);
|
|
70
70
|
pIntz.push((((x) >> 8) & 0xff) - 128);
|
|
71
|
-
pStr += String.fromCharCode(((x) & 0xff) - 128);
|
|
71
|
+
// pStr += String.fromCharCode(((x) & 0xff) - 128);
|
|
72
72
|
pIntz.push(((x) & 0xff) - 128);
|
|
73
73
|
}
|
|
74
74
|
pIntz.splice(-1, 1)
|
|
75
|
-
pStr = decoder.decode(new Uint8Array(pIntz));
|
|
75
|
+
let pStr = decoder.decode(new Uint8Array(pIntz));
|
|
76
76
|
|
|
77
77
|
pStr = pStr.replace(/\0.*/g, ''); // Remove content from first null char to end.
|
|
78
78
|
return pStr;
|
|
79
79
|
}
|
|
80
|
-
private parseItem(data: number[], Type: number): Item {
|
|
80
|
+
private parseItem(data: number[], Type: number, id: number): Item {
|
|
81
81
|
var _item = {} as Item;
|
|
82
82
|
switch (Type) {
|
|
83
83
|
case items.OBJ_EX:
|
|
@@ -216,6 +216,7 @@ export class Snapshot {
|
|
|
216
216
|
use_custom_color: Number(data.slice(14, 15)),
|
|
217
217
|
color_body: Number(data.slice(15, 16)),
|
|
218
218
|
color_feet: Number(data.slice(16, 17)),
|
|
219
|
+
id: id
|
|
219
220
|
} as ClientInfo
|
|
220
221
|
break;
|
|
221
222
|
case items.OBJ_SPECTATOR_INFO:
|
|
@@ -306,7 +307,8 @@ export class Snapshot {
|
|
|
306
307
|
}
|
|
307
308
|
if (snap.length == 0) {
|
|
308
309
|
// empty snap, copy old one into new ack
|
|
309
|
-
this.eSnapHolder.
|
|
310
|
+
this.eSnapHolder.forEach(snap => {
|
|
311
|
+
if (snap.ack == deltatick)
|
|
310
312
|
this.eSnapHolder.push({Snapshot: snap.Snapshot, ack: recvTick});
|
|
311
313
|
|
|
312
314
|
})
|
|
@@ -330,14 +332,19 @@ export class Snapshot {
|
|
|
330
332
|
[ ] item_deltas
|
|
331
333
|
*/
|
|
332
334
|
|
|
335
|
+
var deleted: number[] = [];
|
|
333
336
|
for (let i = 0; i < num_removed_items; i++) {
|
|
334
337
|
let deleted_key = unpacker.unpackInt(); // removed_item_keys
|
|
335
|
-
let index = this.deltas.map(delta => delta.key).indexOf(deleted_key);
|
|
338
|
+
// let index = this.deltas.map(delta => delta.key).indexOf(deleted_key);
|
|
339
|
+
let index = this.deltas.findIndex(delta => delta.key === deleted_key);
|
|
336
340
|
// console.log("deleting ", deleted_key, index)
|
|
337
341
|
if (index > -1)
|
|
338
342
|
this.deltas.splice(index, 1);
|
|
339
|
-
|
|
343
|
+
deleted.push(deleted_key)
|
|
340
344
|
}
|
|
345
|
+
if (deleted.length)
|
|
346
|
+
this.eSnapHolder = this.eSnapHolder.filter(a => !deleted.includes(a.Snapshot.Key));
|
|
347
|
+
|
|
341
348
|
/*item_delta:
|
|
342
349
|
[ 4] type_id
|
|
343
350
|
[ 4] id
|
|
@@ -369,7 +376,7 @@ export class Snapshot {
|
|
|
369
376
|
} else
|
|
370
377
|
_size = unpacker.unpackInt();
|
|
371
378
|
|
|
372
|
-
let data = [];
|
|
379
|
+
let data: number[] = [];
|
|
373
380
|
for (let j = 0; j < _size; j++) {
|
|
374
381
|
if (unpacker.remaining.length > 0)
|
|
375
382
|
data.push(unpacker.unpackInt());
|
|
@@ -378,7 +385,8 @@ export class Snapshot {
|
|
|
378
385
|
}
|
|
379
386
|
// console.log(index, deltatick)
|
|
380
387
|
if (deltatick >= 0) {
|
|
381
|
-
let index = deltaSnaps.map(delta => delta.Snapshot.Key).indexOf(key)
|
|
388
|
+
// let index = deltaSnaps.map(delta => delta.Snapshot.Key).indexOf(key)
|
|
389
|
+
let index = deltaSnaps.findIndex(delta => delta.Snapshot.Key === key);
|
|
382
390
|
if (index > -1) {
|
|
383
391
|
|
|
384
392
|
let out = UndiffItem(deltaSnaps[index].Snapshot.Data, data)
|
|
@@ -386,7 +394,7 @@ export class Snapshot {
|
|
|
386
394
|
} // else no previous, use new data
|
|
387
395
|
}
|
|
388
396
|
|
|
389
|
-
let parsed = this.parseItem(data, type_id)
|
|
397
|
+
let parsed = this.parseItem(data, type_id, id)
|
|
390
398
|
this.eSnapHolder.push({Snapshot: {Data: data, Key: key}, ack: recvTick});
|
|
391
399
|
|
|
392
400
|
items.items.push({data, parsed, type_id, id, key})
|
|
@@ -395,21 +403,25 @@ export class Snapshot {
|
|
|
395
403
|
|
|
396
404
|
}
|
|
397
405
|
for (let newSnap of newSnaps) {
|
|
398
|
-
if (this.eSnapHolder.
|
|
406
|
+
if (this.eSnapHolder.findIndex(a => a.ack == newSnap.ack && a.Snapshot.Key == newSnap.Snapshot.Key) === -1) { // ugly copy new snap to eSnapHolder (if it isnt pushed already)
|
|
399
407
|
this.eSnapHolder.push({Snapshot: {Data: newSnap.Snapshot.Data, Key: newSnap.Snapshot.Key}, ack: recvTick});
|
|
400
408
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
409
|
+
if (deltatick > -1) {
|
|
410
|
+
let ____index = this.deltas.findIndex(delta => delta.key == newSnap.Snapshot.Key)
|
|
411
|
+
|
|
412
|
+
if (____index > -1) {
|
|
413
|
+
this.deltas[____index] = {data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff), ((newSnap.Snapshot.Key) & 0xffff))};
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
} // else
|
|
417
|
+
this.deltas.push({data: newSnap.Snapshot.Data, key: newSnap.Snapshot.Key, id: newSnap.Snapshot.Key & 0xffff, type_id: ((newSnap.Snapshot.Key >> 16) & 0xffff), parsed: this.parseItem(newSnap.Snapshot.Data, ((newSnap.Snapshot.Key >> 16) & 0xffff), ((newSnap.Snapshot.Key) & 0xffff))});
|
|
407
418
|
}
|
|
408
419
|
|
|
409
420
|
|
|
410
421
|
return {items, recvTick};
|
|
411
422
|
}
|
|
412
423
|
}
|
|
424
|
+
|
|
413
425
|
function UndiffItem(oldItem: number[], newItem: number[]): number[] {
|
|
414
426
|
let out: number[] = newItem;
|
|
415
427
|
if (JSON.stringify(newItem) === JSON.stringify(oldItem))
|