teeworlds 2.1.2 → 2.1.7
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 +16 -5
- package/index.ts +5 -5
- package/lib/MsgPacker.js +5 -1
- package/lib/MsgPacker.ts +2 -2
- package/lib/MsgUnpacker.js +2 -2
- package/lib/MsgUnpacker.ts +3 -3
- package/lib/client.js +450 -275
- package/lib/client.ts +459 -183
- package/lib/movement.js +54 -0
- package/lib/movement.ts +63 -0
- package/lib/snapshot.js +7 -5
- package/lib/snapshot.ts +7 -5
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -12,54 +12,32 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
12
12
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
13
|
};
|
|
14
14
|
})();
|
|
15
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
16
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
17
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
18
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
19
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
20
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
21
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
25
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
26
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
27
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
28
|
-
function step(op) {
|
|
29
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
30
|
-
while (_) try {
|
|
31
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
32
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
33
|
-
switch (op[0]) {
|
|
34
|
-
case 0: case 1: t = op; break;
|
|
35
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
36
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
37
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
38
|
-
default:
|
|
39
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
40
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
41
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
42
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
43
|
-
if (t[2]) _.ops.pop();
|
|
44
|
-
_.trys.pop(); continue;
|
|
45
|
-
}
|
|
46
|
-
op = body.call(thisArg, _);
|
|
47
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
48
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
15
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
52
16
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
53
17
|
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.Client = void 0;
|
|
54
20
|
var crypto_1 = require("crypto");
|
|
55
21
|
var dgram_1 = __importDefault(require("dgram"));
|
|
56
22
|
var stream_1 = require("stream");
|
|
57
23
|
var MsgUnpacker_1 = require("./MsgUnpacker");
|
|
58
|
-
var
|
|
24
|
+
var movement_1 = __importDefault(require("./movement"));
|
|
25
|
+
var MsgPacker_1 = require("./MsgPacker");
|
|
59
26
|
var snapshot_1 = require("./snapshot");
|
|
60
27
|
var huffman_1 = __importDefault(require("./huffman"));
|
|
61
28
|
var huff = new huffman_1.default();
|
|
62
29
|
var SnapUnpacker = new snapshot_1.Snapshot();
|
|
30
|
+
var States;
|
|
31
|
+
(function (States) {
|
|
32
|
+
States[States["STATE_OFFLINE"] = 0] = "STATE_OFFLINE";
|
|
33
|
+
States[States["STATE_CONNECTING"] = 1] = "STATE_CONNECTING";
|
|
34
|
+
States[States["STATE_LOADING"] = 2] = "STATE_LOADING";
|
|
35
|
+
States[States["STATE_ONLINE"] = 3] = "STATE_ONLINE";
|
|
36
|
+
States[States["STATE_DEMOPLAYBACK"] = 4] = "STATE_DEMOPLAYBACK";
|
|
37
|
+
States[States["STATE_QUITTING"] = 5] = "STATE_QUITTING";
|
|
38
|
+
States[States["STATE_RESTARTING"] = 6] = "STATE_RESTARTING";
|
|
39
|
+
})(States || (States = {}));
|
|
40
|
+
;
|
|
63
41
|
var NETMSGTYPE;
|
|
64
42
|
(function (NETMSGTYPE) {
|
|
65
43
|
NETMSGTYPE[NETMSGTYPE["EX"] = 0] = "EX";
|
|
@@ -149,73 +127,75 @@ function arrStartsWith(arr, arrStart, start) {
|
|
|
149
127
|
}
|
|
150
128
|
var Client = /** @class */ (function (_super) {
|
|
151
129
|
__extends(Client, _super);
|
|
152
|
-
function Client(ip, port, nickname) {
|
|
130
|
+
function Client(ip, port, nickname, options) {
|
|
153
131
|
var _this = _super.call(this) || this;
|
|
154
132
|
_this.host = ip;
|
|
155
133
|
_this.port = port;
|
|
156
134
|
_this.name = nickname;
|
|
135
|
+
_this.AckGameTick = 0;
|
|
136
|
+
_this.PredGameTick = 0;
|
|
137
|
+
if (options)
|
|
138
|
+
_this.options = options;
|
|
139
|
+
_this.timer = 0;
|
|
140
|
+
_this.movement = new movement_1.default();
|
|
157
141
|
_this.snaps = [];
|
|
158
142
|
_this.client_infos = [];
|
|
159
143
|
_this.player_infos = [];
|
|
160
|
-
_this.
|
|
144
|
+
_this.sentChunkQueue = [];
|
|
145
|
+
_this.State = States.STATE_OFFLINE; // 0 = offline; 1 = STATE_CONNECTING = 1, STATE_LOADING = 2, STATE_ONLINE = 3
|
|
161
146
|
_this.ack = 0; // ack of messages the client has received
|
|
162
147
|
_this.clientAck = 0; // ack of messages the client has sent
|
|
163
148
|
_this.receivedSnaps = 0; /* wait for 2 snaps before seeing self as connected */
|
|
164
149
|
_this.lastMsg = "";
|
|
165
|
-
_this._port = Math.floor(Math.random() * 65535);
|
|
166
150
|
_this.socket = dgram_1.default.createSocket("udp4");
|
|
167
151
|
_this.socket.bind();
|
|
168
152
|
_this.TKEN = Buffer.from([255, 255, 255, 255]);
|
|
169
153
|
_this.time = new Date().getTime() + 2000; // time (used for keepalives, start to send keepalives after 2 seconds)
|
|
170
|
-
_this.
|
|
154
|
+
_this.lastSendTime = new Date().getTime();
|
|
171
155
|
return _this;
|
|
172
156
|
}
|
|
173
157
|
Client.prototype.Unpack = function (packet) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
chunk.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
chunk.extended_msgid = a;
|
|
205
|
-
// chunk.type = 'sys';
|
|
206
|
-
chunk.msg = Object.keys(messageUUIDs)[i];
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
packet = packet.slice(chunk.bytes); // +1 cuz it adds an extra \x00 for easier parsing i guess
|
|
210
|
-
unpacked.chunks.push(chunk);
|
|
158
|
+
var unpacked = { twprotocol: { flags: packet[0], ack: packet[1], chunkAmount: packet[2], size: packet.byteLength - 3 }, chunks: [] };
|
|
159
|
+
if (packet.indexOf(Buffer.from([0xff, 0xff, 0xff, 0xff])) == 0 && !(unpacked.twprotocol.flags & 8) || unpacked.twprotocol.flags == 255) // flags == 255 is connectionless (used for sending usernames)
|
|
160
|
+
return unpacked;
|
|
161
|
+
packet = packet.slice(3);
|
|
162
|
+
if (unpacked.twprotocol.flags & 128) {
|
|
163
|
+
packet = huff.decompress(packet);
|
|
164
|
+
if (packet.length == 1 && packet[0] == -1)
|
|
165
|
+
return unpacked;
|
|
166
|
+
}
|
|
167
|
+
// return unpacked;
|
|
168
|
+
for (var i = 0; i < unpacked.twprotocol.chunkAmount; i++) {
|
|
169
|
+
var chunk = {};
|
|
170
|
+
chunk.bytes = ((packet[0] & 0x3f) << 4) | (packet[1] & ((1 << 4) - 1)); // idk what this shit is but it works
|
|
171
|
+
chunk.flags = (packet[0] >> 6) & 3;
|
|
172
|
+
chunk.sequence = -1;
|
|
173
|
+
if (chunk.flags & 1) {
|
|
174
|
+
chunk.seq = ((packet[1] & 0xf0) << 2) | packet[2];
|
|
175
|
+
packet = packet.slice(3); // remove flags & size
|
|
176
|
+
}
|
|
177
|
+
else
|
|
178
|
+
packet = packet.slice(2);
|
|
179
|
+
chunk.type = packet[0] & 1 ? "sys" : "game"; // & 1 = binary, ****_***1. e.g 0001_0111 sys, 0001_0110 game
|
|
180
|
+
chunk.msgid = (packet[0] - (packet[0] & 1)) / 2;
|
|
181
|
+
chunk.msg = messageTypes[packet[0] & 1][chunk.msgid];
|
|
182
|
+
chunk.raw = packet.slice(1, chunk.bytes);
|
|
183
|
+
Object.values(messageUUIDs).forEach(function (a, i) {
|
|
184
|
+
if (a.compare(packet.slice(0, 16)) == 0) {
|
|
185
|
+
chunk.extended_msgid = a;
|
|
186
|
+
// chunk.type = 'sys';
|
|
187
|
+
chunk.msg = Object.keys(messageUUIDs)[i];
|
|
211
188
|
}
|
|
212
|
-
return [2 /*return*/, unpacked];
|
|
213
189
|
});
|
|
214
|
-
|
|
190
|
+
packet = packet.slice(chunk.bytes); // +1 cuz it adds an extra \x00 for easier parsing i guess
|
|
191
|
+
unpacked.chunks.push(chunk);
|
|
192
|
+
}
|
|
193
|
+
return unpacked;
|
|
215
194
|
};
|
|
216
195
|
Client.prototype.SendControlMsg = function (msg, ExtraMsg) {
|
|
217
196
|
var _this = this;
|
|
218
197
|
if (ExtraMsg === void 0) { ExtraMsg = ""; }
|
|
198
|
+
this.lastSendTime = new Date().getTime();
|
|
219
199
|
return new Promise(function (resolve, reject) {
|
|
220
200
|
if (_this.socket) {
|
|
221
201
|
var latestBuf = Buffer.from([0x10 + (((16 << 4) & 0xf0) | ((_this.ack >> 8) & 0xf)), _this.ack & 0xff, 0x00, msg]);
|
|
@@ -231,229 +211,423 @@ var Client = /** @class */ (function (_super) {
|
|
|
231
211
|
*/
|
|
232
212
|
});
|
|
233
213
|
};
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
+
Client.prototype.SendMsgEx = function (Msgs, Flags) {
|
|
252
236
|
var _this = this;
|
|
253
|
-
if (this.State ==
|
|
254
|
-
throw new Error("Client is not connected");
|
|
237
|
+
if (this.State == States.STATE_OFFLINE)
|
|
238
|
+
return; //throw new Error("Client is not connected");
|
|
255
239
|
if (!this.socket)
|
|
256
240
|
return;
|
|
241
|
+
var _Msgs;
|
|
242
|
+
if (Msgs instanceof Array)
|
|
243
|
+
_Msgs = Msgs;
|
|
244
|
+
else
|
|
245
|
+
_Msgs = [Msgs];
|
|
246
|
+
this.lastSendTime = new Date().getTime();
|
|
257
247
|
var header = [];
|
|
258
|
-
|
|
259
|
-
header[index] =
|
|
248
|
+
_Msgs.forEach(function (Msg, index) {
|
|
249
|
+
header[index] = Buffer.alloc((Flags & 1 ? 3 : 2));
|
|
260
250
|
header[index][0] = ((Flags & 3) << 6) | ((Msg.size >> 4) & 0x3f);
|
|
261
251
|
header[index][1] = (Msg.size & 0xf);
|
|
262
252
|
if (Flags & 1) {
|
|
263
253
|
_this.clientAck = (_this.clientAck + 1) % (1 << 10);
|
|
264
254
|
header[index][1] |= (_this.clientAck >> 2) & 0xf0;
|
|
265
255
|
header[index][2] = _this.clientAck & 0xff;
|
|
256
|
+
header[index][0] = (((Flags | 2) & 3) << 6) | ((Msg.size >> 4) & 0x3f); // 2 is resend flag (ugly hack for queue)
|
|
257
|
+
_this.sentChunkQueue.push(Buffer.concat([header[index], Msg.buffer]));
|
|
258
|
+
header[index][0] = (((Flags) & 3) << 6) | ((Msg.size >> 4) & 0x3f);
|
|
266
259
|
}
|
|
267
260
|
});
|
|
268
|
-
var packetHeader = Buffer.from([0x0 + (((16 << 4) & 0xf0) | ((this.ack >> 8) & 0xf)), this.ack & 0xff,
|
|
261
|
+
var packetHeader = Buffer.from([0x0 + (((16 << 4) & 0xf0) | ((this.ack >> 8) & 0xf)), this.ack & 0xff, _Msgs.length]);
|
|
269
262
|
var chunks = Buffer.from([]);
|
|
270
|
-
|
|
263
|
+
_Msgs.forEach(function (Msg, index) {
|
|
271
264
|
chunks = Buffer.concat([chunks, Buffer.from(header[index]), Msg.buffer]);
|
|
272
265
|
});
|
|
273
266
|
var packet = Buffer.concat([(packetHeader), chunks, this.TKEN]);
|
|
274
267
|
this.socket.send(packet, 0, packet.length, this.port, this.host);
|
|
275
268
|
};
|
|
269
|
+
Client.prototype.SendMsgRaw = function (chunks) {
|
|
270
|
+
if (this.State == States.STATE_OFFLINE)
|
|
271
|
+
return console.log(chunks, "client not connected"); //throw new Error("Client is not connected");
|
|
272
|
+
if (!this.socket)
|
|
273
|
+
return;
|
|
274
|
+
this.lastSendTime = new Date().getTime();
|
|
275
|
+
var packetHeader = Buffer.from([0x0 + (((16 << 4) & 0xf0) | ((this.ack >> 8) & 0xf)), this.ack & 0xff, chunks.length]);
|
|
276
|
+
var packet = Buffer.concat([(packetHeader), Buffer.concat(chunks), this.TKEN]);
|
|
277
|
+
this.socket.send(packet, 0, packet.length, this.port, this.host);
|
|
278
|
+
};
|
|
279
|
+
Client.prototype.MsgToChunk = function (packet) {
|
|
280
|
+
var chunk = {};
|
|
281
|
+
// let packet = Msg.buffer;
|
|
282
|
+
chunk.bytes = ((packet[0] & 0x3f) << 4) | (packet[1] & ((1 << 4) - 1));
|
|
283
|
+
chunk.flags = (packet[0] >> 6) & 3;
|
|
284
|
+
chunk.sequence = -1;
|
|
285
|
+
if (chunk.flags & 1) {
|
|
286
|
+
chunk.seq = ((packet[1] & 0xf0) << 2) | packet[2];
|
|
287
|
+
packet = packet.slice(3); // remove flags & size
|
|
288
|
+
}
|
|
289
|
+
else
|
|
290
|
+
packet = packet.slice(2);
|
|
291
|
+
chunk.type = packet[0] & 1 ? "sys" : "game"; // & 1 = binary, ****_***1. e.g 0001_0111 sys, 0001_0110 game
|
|
292
|
+
chunk.msgid = (packet[0] - (packet[0] & 1)) / 2;
|
|
293
|
+
chunk.msg = messageTypes[packet[0] & 1][chunk.msgid];
|
|
294
|
+
// if (chunk.msg == undefined)
|
|
295
|
+
// console.log(packet)
|
|
296
|
+
chunk.raw = packet.slice(1, chunk.bytes);
|
|
297
|
+
Object.values(messageUUIDs).forEach(function (a, i) {
|
|
298
|
+
if (a.compare(packet.slice(0, 16)) === 0) {
|
|
299
|
+
chunk.extended_msgid = a;
|
|
300
|
+
// chunk.type = 'sys';
|
|
301
|
+
chunk.msg = Object.keys(messageUUIDs)[i];
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
return chunk;
|
|
305
|
+
};
|
|
276
306
|
Client.prototype.connect = function () {
|
|
277
307
|
var _this = this;
|
|
308
|
+
this.State = States.STATE_CONNECTING;
|
|
309
|
+
var predTimer = setInterval(function () {
|
|
310
|
+
if (_this.State == States.STATE_ONLINE) {
|
|
311
|
+
if (_this.AckGameTick > 0)
|
|
312
|
+
_this.PredGameTick++;
|
|
313
|
+
// console.log(this.PredGameTick, this.AckGameTick)
|
|
314
|
+
}
|
|
315
|
+
else if (_this.State == States.STATE_OFFLINE)
|
|
316
|
+
clearInterval(predTimer);
|
|
317
|
+
}, 20);
|
|
278
318
|
this.SendControlMsg(1, "TKEN");
|
|
279
319
|
var connectInterval = setInterval(function () {
|
|
280
|
-
if (_this.State ==
|
|
320
|
+
if (_this.State == States.STATE_CONNECTING)
|
|
281
321
|
_this.SendControlMsg(1, "TKEN");
|
|
282
322
|
else
|
|
283
323
|
clearInterval(connectInterval);
|
|
284
324
|
}, 500);
|
|
325
|
+
var inputInterval = setInterval(function () {
|
|
326
|
+
// if (new Date().getTime() - this.time >= 1000) {
|
|
327
|
+
if (_this.State == States.STATE_OFFLINE)
|
|
328
|
+
clearInterval(inputInterval);
|
|
329
|
+
if (_this.State != States.STATE_ONLINE)
|
|
330
|
+
return;
|
|
331
|
+
_this.time = new Date().getTime();
|
|
332
|
+
// this.SendControlMsg(0);
|
|
333
|
+
// console.log("sending with " + this.AckGameTick)
|
|
334
|
+
_this.sendInput();
|
|
335
|
+
// }
|
|
336
|
+
}, 500);
|
|
337
|
+
var resendTimeout = setInterval(function () {
|
|
338
|
+
// this.sentChunkQueue.forEach((chunk) => {
|
|
339
|
+
// if (this.State == 0) // disconnected
|
|
340
|
+
// return;
|
|
341
|
+
if (_this.State != States.STATE_OFFLINE) {
|
|
342
|
+
if (((new Date().getTime()) - _this.lastSendTime) > 900 && _this.sentChunkQueue.length > 0) {
|
|
343
|
+
_this.SendMsgRaw([_this.sentChunkQueue[0]]);
|
|
344
|
+
console.log(_this.sentChunkQueue, _this.State);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
else
|
|
348
|
+
clearInterval(resendTimeout);
|
|
349
|
+
// })
|
|
350
|
+
}, 1000);
|
|
285
351
|
this.time = new Date().getTime() + 2000; // start sending keepalives after 2s
|
|
286
352
|
if (this.socket)
|
|
287
|
-
this.socket.on("message", function (a
|
|
288
|
-
var
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
353
|
+
this.socket.on("message", function (a, rinfo) {
|
|
354
|
+
var _a, _b, _c, _d, _e, _f;
|
|
355
|
+
if (_this.State == 0 || rinfo.address != _this.host || rinfo.port != _this.port)
|
|
356
|
+
return;
|
|
357
|
+
clearInterval(connectInterval);
|
|
358
|
+
if (a.toJSON().data[0] == 0x10) {
|
|
359
|
+
if (a.toString().includes("TKEN") || a.toJSON().data[3] == 0x2) {
|
|
360
|
+
clearInterval(connectInterval);
|
|
361
|
+
_this.TKEN = Buffer.from(a.toJSON().data.slice(a.toJSON().data.length - 4, a.toJSON().data.length));
|
|
362
|
+
_this.SendControlMsg(3);
|
|
363
|
+
_this.State = States.STATE_LOADING; // loading state
|
|
364
|
+
_this.receivedSnaps = 0;
|
|
365
|
+
var info = new MsgPacker_1.MsgPacker(1, true);
|
|
366
|
+
info.AddString("0.6 626fce9a778df4d4");
|
|
367
|
+
info.AddString(((_a = _this.options) === null || _a === void 0 ? void 0 : _a.password) === undefined ? "" : (_b = _this.options) === null || _b === void 0 ? void 0 : _b.password); // password
|
|
368
|
+
var client_version = new MsgPacker_1.MsgPacker(0, true);
|
|
369
|
+
client_version.AddBuffer(Buffer.from("8c00130484613e478787f672b3835bd4", 'hex'));
|
|
370
|
+
var randomUuid = Buffer.alloc(16);
|
|
371
|
+
crypto_1.randomBytes(16).copy(randomUuid);
|
|
372
|
+
client_version.AddBuffer(randomUuid);
|
|
373
|
+
if (((_c = _this.options) === null || _c === void 0 ? void 0 : _c.ddnet_version) !== undefined) {
|
|
374
|
+
client_version.AddInt((_d = _this.options) === null || _d === void 0 ? void 0 : _d.ddnet_version.version);
|
|
375
|
+
client_version.AddString("DDNet " + ((_e = _this.options) === null || _e === void 0 ? void 0 : _e.ddnet_version.release_version));
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
client_version.AddInt(16003);
|
|
379
|
+
client_version.AddString("DDNet 16.0.3");
|
|
380
|
+
}
|
|
381
|
+
_this.SendMsgEx([client_version, info], 1);
|
|
382
|
+
}
|
|
383
|
+
else if (a.toJSON().data[3] == 0x4) {
|
|
384
|
+
// disconnected
|
|
385
|
+
_this.State = States.STATE_OFFLINE;
|
|
386
|
+
var reason = (MsgUnpacker_1.unpackString(a.toJSON().data.slice(4)).result);
|
|
387
|
+
// this.State = -1;
|
|
388
|
+
_this.emit("disconnect", reason);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
var unpacked = _this.Unpack(a);
|
|
392
|
+
unpacked.chunks.forEach(function (a) {
|
|
393
|
+
if (a.flags & 1) { // vital
|
|
394
|
+
if (a.seq != undefined && a.seq != -1)
|
|
395
|
+
_this.ack = a.seq;
|
|
396
|
+
else
|
|
397
|
+
console.log("no seq", a);
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
_this.sentChunkQueue.forEach(function (buff, i) {
|
|
401
|
+
var chunk = _this.MsgToChunk(buff);
|
|
402
|
+
if (chunk.flags & 1) {
|
|
403
|
+
if (chunk.seq && chunk.seq < _this.ack) {
|
|
404
|
+
_this.sentChunkQueue.splice(i, 1);
|
|
405
|
+
// this.ack = (this.ack + 1) % (1 << 10);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
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
|
+
if (snapChunks.length > 0) {
|
|
412
|
+
var part_1 = 0;
|
|
413
|
+
var num_parts_1 = 1;
|
|
414
|
+
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)
|
|
419
|
+
if (AckGameTick > _this.AckGameTick) {
|
|
420
|
+
_this.AckGameTick = AckGameTick;
|
|
421
|
+
if (Math.abs(_this.PredGameTick - _this.AckGameTick) > 10)
|
|
422
|
+
_this.PredGameTick = AckGameTick + 1;
|
|
423
|
+
// console.log(this.AckGameTick)
|
|
424
|
+
}
|
|
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;
|
|
428
|
+
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);
|
|
433
|
+
}
|
|
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) {
|
|
439
|
+
_this.snaps = [];
|
|
440
|
+
}
|
|
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
|
|
442
|
+
_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) {
|
|
445
|
+
var mergedSnaps_1 = Buffer.concat(_this.snaps);
|
|
446
|
+
var snapUnpacked = SnapUnpacker.unpackSnapshot(mergedSnaps_1.toJSON().data, 1);
|
|
447
|
+
// console.log(snapUnpacked)
|
|
448
|
+
snapUnpacked.items.forEach(function (a, i) {
|
|
449
|
+
if (a.type_id === items.OBJ_CLIENT_INFO) {
|
|
450
|
+
// console.log(a.parsed, i)
|
|
451
|
+
_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());
|
|
337
454
|
}
|
|
338
|
-
|
|
339
|
-
}
|
|
340
|
-
if (a.toJSON().data[0] == 0x10) {
|
|
341
|
-
if (a.toString().includes("TKEN") || arrStartsWith(a.toJSON().data, [0x10, 0x0, 0x0, 0x0])) {
|
|
342
|
-
clearInterval(connectInterval);
|
|
343
|
-
this.TKEN = Buffer.from(a.toJSON().data.slice(a.toJSON().data.length - 4, a.toJSON().data.length));
|
|
344
|
-
this.SendControlMsg(3);
|
|
345
|
-
this.State = 2; // loading state
|
|
346
|
-
info = new MsgPacker_1.default(1, true);
|
|
347
|
-
info.AddString("0.6 626fce9a778df4d4");
|
|
348
|
-
info.AddString(""); // password
|
|
349
|
-
client_version = new MsgPacker_1.default(0, true);
|
|
350
|
-
client_version.AddBuffer(Buffer.from("8c00130484613e478787f672b3835bd4", 'hex'));
|
|
351
|
-
randomUuid = new Uint8Array(16);
|
|
352
|
-
crypto_1.randomBytes(16).copy(randomUuid);
|
|
353
|
-
client_version.AddBuffer(Buffer.from(randomUuid));
|
|
354
|
-
client_version.AddInt(15091);
|
|
355
|
-
client_version.AddString("DDNet 15.9.1");
|
|
356
|
-
this.SendMsgExWithChunks([client_version, info], 1);
|
|
357
|
-
}
|
|
358
|
-
else if (a.toJSON().data[3] == 0x4) {
|
|
359
|
-
// disconnected
|
|
360
|
-
this.State = 0;
|
|
361
|
-
reason = (MsgUnpacker_1.unpackString(a.toJSON().data.slice(4)).result);
|
|
362
|
-
this.State = -1;
|
|
363
|
-
this.emit("disconnect", reason);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
if (unpacked.chunks[0] && chunkMessages.includes("SV_READY_TO_ENTER")) {
|
|
367
|
-
Msg = new MsgPacker_1.default(15, true);
|
|
368
|
-
this.SendMsgEx(Msg, 1);
|
|
369
|
-
}
|
|
370
|
-
else if ((unpacked.chunks[0] && chunkMessages.includes("CAPABILITIES") || unpacked.chunks[0] && chunkMessages.includes("MAP_CHANGE"))) {
|
|
371
|
-
Msg = new MsgPacker_1.default(14, true);
|
|
372
|
-
this.SendMsgEx(Msg, 1);
|
|
373
|
-
}
|
|
374
|
-
else if ((unpacked.chunks[0] && chunkMessages.includes("CON_READY") || unpacked.chunks[0] && chunkMessages.includes("SV_MOTD"))) {
|
|
375
|
-
info = new MsgPacker_1.default(20, false);
|
|
376
|
-
info.AddString(this.name); /* name */
|
|
377
|
-
info.AddString(""); /* clan */
|
|
378
|
-
info.AddInt(-1); /* country */
|
|
379
|
-
info.AddString("greyfox"); /* skin */
|
|
380
|
-
info.AddInt(1); /* use custom color */
|
|
381
|
-
info.AddInt(10346103); /* color body */
|
|
382
|
-
info.AddInt(65535); /* color feet */
|
|
383
|
-
this.SendMsgEx(info, 1);
|
|
384
|
-
}
|
|
385
|
-
else if (unpacked.chunks[0] && chunkMessages.includes("SV_READY_TO_ENTER")) {
|
|
386
|
-
if (this.State != 3) {
|
|
387
|
-
this.emit('connected');
|
|
455
|
+
console.log(_this.client_infos[a.id].name, _this.client_infos[a.id].clan, [a.id]);
|
|
388
456
|
}
|
|
389
|
-
|
|
457
|
+
// else if (a.type_id === items.OBJ_PLAYER_INFO) {
|
|
458
|
+
// this.player_infos[a.id] = a.parsed as PlayerInfo;
|
|
459
|
+
// }
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
var chunkMessages = unpacked.chunks.map(function (a) { return a.msg; });
|
|
465
|
+
if (chunkMessages.includes("SV_CHAT")) {
|
|
466
|
+
var chat = unpacked.chunks.filter(function (a) { return a.msg == "SV_CHAT"; });
|
|
467
|
+
chat.forEach(function (a) {
|
|
468
|
+
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;
|
|
475
|
+
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)
|
|
478
|
+
_this.emit("message", unpacked);
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
if (chunkMessages.includes("SV_KILL_MSG")) {
|
|
483
|
+
var chat = unpacked.chunks.filter(function (a) { return a.msg == "SV_KILL_MSG"; });
|
|
484
|
+
chat.forEach(function (a) {
|
|
485
|
+
if (a.msg == "SV_KILL_MSG") {
|
|
486
|
+
var unpacked = {};
|
|
487
|
+
var unpacker = new MsgUnpacker_1.MsgUnpacker(a.raw.toJSON().data);
|
|
488
|
+
unpacked.killer_id = unpacker.unpackInt();
|
|
489
|
+
unpacked.victim_id = unpacker.unpackInt();
|
|
490
|
+
unpacked.weapon = unpacker.unpackInt();
|
|
491
|
+
unpacked.special_mode = unpacker.unpackInt();
|
|
492
|
+
if (unpacked.victim_id != -1)
|
|
493
|
+
unpacked.victim = { ClientInfo: _this.client_infos[unpacked.victim_id], PlayerInfo: _this.player_infos[unpacked.victim_id] };
|
|
494
|
+
if (unpacked.killer_id != -1)
|
|
495
|
+
unpacked.killer = { ClientInfo: _this.client_infos[unpacked.killer_id], PlayerInfo: _this.player_infos[unpacked.killer_id] };
|
|
496
|
+
// console.log(unpacked)
|
|
497
|
+
_this.emit("kill", unpacked);
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
if (unpacked.chunks[0] && chunkMessages.includes("SV_READY_TO_ENTER")) {
|
|
502
|
+
var Msg = new MsgPacker_1.MsgPacker(15, true); /* entergame */
|
|
503
|
+
_this.SendMsgEx(Msg, 1);
|
|
504
|
+
}
|
|
505
|
+
else if ((unpacked.chunks[0] && chunkMessages.includes("CAPABILITIES") || unpacked.chunks[0] && chunkMessages.includes("MAP_CHANGE"))) {
|
|
506
|
+
// send ready
|
|
507
|
+
var Msg = new MsgPacker_1.MsgPacker(14, true); /* ready */
|
|
508
|
+
_this.SendMsgEx(Msg, 1);
|
|
509
|
+
}
|
|
510
|
+
else if ((unpacked.chunks[0] && chunkMessages.includes("CON_READY") || unpacked.chunks[0] && chunkMessages.includes("SV_MOTD"))) {
|
|
511
|
+
var info = new MsgPacker_1.MsgPacker(20, false);
|
|
512
|
+
if ((_f = _this.options) === null || _f === void 0 ? void 0 : _f.identity) {
|
|
513
|
+
info.AddString(_this.options.identity.name);
|
|
514
|
+
info.AddString(_this.options.identity.clan);
|
|
515
|
+
info.AddInt(_this.options.identity.country);
|
|
516
|
+
info.AddString(_this.options.identity.skin);
|
|
517
|
+
info.AddInt(_this.options.identity.use_custom_color);
|
|
518
|
+
info.AddInt(_this.options.identity.color_body);
|
|
519
|
+
info.AddInt(_this.options.identity.color_feet);
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
info.AddString(_this.name); /* name */
|
|
523
|
+
info.AddString(""); /* clan */
|
|
524
|
+
info.AddInt(-1); /* country */
|
|
525
|
+
info.AddString("greyfox"); /* skin */
|
|
526
|
+
info.AddInt(1); /* use custom color */
|
|
527
|
+
info.AddInt(10346103); /* color body */
|
|
528
|
+
info.AddInt(65535); /* color feet */
|
|
529
|
+
}
|
|
530
|
+
_this.SendMsgEx(info, 1);
|
|
531
|
+
}
|
|
532
|
+
else if (unpacked.chunks[0] && chunkMessages.includes("PING")) {
|
|
533
|
+
var info = new MsgPacker_1.MsgPacker(23, true);
|
|
534
|
+
_this.SendMsgEx(info, 1);
|
|
535
|
+
}
|
|
536
|
+
if (chunkMessages.includes("SNAP") || chunkMessages.includes("SNAP_EMPTY") || chunkMessages.includes("SNAP_SINGLE")) {
|
|
537
|
+
_this.receivedSnaps++; /* wait for 2 ss before seeing self as connected */
|
|
538
|
+
if (_this.receivedSnaps == 2) {
|
|
539
|
+
if (_this.State != States.STATE_ONLINE)
|
|
540
|
+
_this.emit('connected');
|
|
541
|
+
_this.State = States.STATE_ONLINE;
|
|
542
|
+
}
|
|
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);
|
|
390
557
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
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 = [];
|
|
394
564
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
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
|
|
413
|
-
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);
|
|
414
|
-
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
|
|
415
|
-
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);
|
|
416
|
-
}
|
|
417
|
-
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
|
|
418
|
-
if (chunk.msg != "SNAP_EMPTY")
|
|
419
|
-
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
|
|
420
|
-
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
|
|
421
|
-
if (part_1 == 0 || _this.snaps.length > 30) {
|
|
422
|
-
_this.snaps = [];
|
|
423
|
-
}
|
|
424
|
-
_this.snaps.push(chunk.raw);
|
|
425
|
-
if ((num_parts_1 - 1) == part_1 && _this.snaps.length == num_parts_1) {
|
|
426
|
-
var mergedSnaps = Buffer.concat(_this.snaps);
|
|
427
|
-
var snapUnpacked = SnapUnpacker.unpackSnapshot(mergedSnaps.toJSON().data, 1);
|
|
428
|
-
snapUnpacked.items.forEach(function (a, i) {
|
|
429
|
-
if (a.type_id == items.OBJ_CLIENT_INFO) {
|
|
430
|
-
_this.client_infos[a.id] = a.parsed;
|
|
431
|
-
// console.log(a.parsed, i)
|
|
432
|
-
// console.log(this.client_infos[a.id])
|
|
433
|
-
}
|
|
434
|
-
else if (a.type_id == items.OBJ_PLAYER_INFO) {
|
|
435
|
-
_this.player_infos[i] = a.parsed;
|
|
436
|
-
}
|
|
437
|
-
else if (a.type_id == items.OBJ_EX || a.type_id > 0x4000) {
|
|
438
|
-
if (a.data.length == 5 && (a.parsed.freeze_end > 0 || a.parsed.freeze_end == -1)) {
|
|
439
|
-
// var packer = new MsgPacker(22, false)
|
|
440
|
-
// this.SendMsgEx(packer, 1)
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
});
|
|
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)
|
|
444
582
|
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
if (new Date().getTime() - this.time >= 1000) {
|
|
449
|
-
this.time = new Date().getTime();
|
|
450
|
-
this.SendControlMsg(0);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
451
585
|
}
|
|
452
|
-
|
|
586
|
+
});
|
|
453
587
|
}
|
|
454
|
-
}
|
|
455
|
-
|
|
588
|
+
}
|
|
589
|
+
if (new Date().getTime() - _this.time >= 1000 && _this.State == States.STATE_ONLINE) {
|
|
590
|
+
_this.time = new Date().getTime();
|
|
591
|
+
_this.SendControlMsg(0);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
};
|
|
595
|
+
Client.prototype.sendInput = function (input) {
|
|
596
|
+
if (input === void 0) { input = this.movement.input; }
|
|
597
|
+
if (this.State != States.STATE_ONLINE)
|
|
598
|
+
return;
|
|
599
|
+
var inputMsg = new MsgPacker_1.MsgPacker(16, true);
|
|
600
|
+
inputMsg.AddInt(this.AckGameTick);
|
|
601
|
+
inputMsg.AddInt(this.PredGameTick);
|
|
602
|
+
inputMsg.AddInt(40);
|
|
603
|
+
// let playerflags = 2;
|
|
604
|
+
// playerflags |= 8; // scoreboard
|
|
605
|
+
// playerflags |= 16; // aimline
|
|
606
|
+
var input_data = [
|
|
607
|
+
input.m_Direction,
|
|
608
|
+
input.m_TargetX,
|
|
609
|
+
input.m_TargetY,
|
|
610
|
+
input.m_Jump,
|
|
611
|
+
input.m_Fire,
|
|
612
|
+
input.m_Hook,
|
|
613
|
+
input.m_PlayerFlags,
|
|
614
|
+
input.m_WantedWeapon,
|
|
615
|
+
input.m_NextWeapon,
|
|
616
|
+
input.m_PrevWeapon
|
|
617
|
+
];
|
|
618
|
+
// console.log(this.player_infos, this.client_infos)
|
|
619
|
+
input_data.forEach(function (a) {
|
|
620
|
+
inputMsg.AddInt(a);
|
|
621
|
+
});
|
|
622
|
+
this.SendMsgEx(inputMsg, 0);
|
|
456
623
|
};
|
|
624
|
+
Object.defineProperty(Client.prototype, "input", {
|
|
625
|
+
get: function () {
|
|
626
|
+
return this.movement.input;
|
|
627
|
+
},
|
|
628
|
+
enumerable: false,
|
|
629
|
+
configurable: true
|
|
630
|
+
});
|
|
457
631
|
Client.prototype.Disconnect = function () {
|
|
458
632
|
var _this = this;
|
|
459
633
|
return new Promise(function (resolve) {
|
|
@@ -462,24 +636,24 @@ var Client = /** @class */ (function (_super) {
|
|
|
462
636
|
if (_this.socket)
|
|
463
637
|
_this.socket.close();
|
|
464
638
|
_this.socket = undefined;
|
|
465
|
-
_this.State =
|
|
639
|
+
_this.State = States.STATE_OFFLINE;
|
|
466
640
|
});
|
|
467
641
|
});
|
|
468
642
|
};
|
|
469
643
|
Client.prototype.Say = function (message, team) {
|
|
470
644
|
if (team === void 0) { team = false; }
|
|
471
|
-
var packer = new MsgPacker_1.
|
|
645
|
+
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SAY, false);
|
|
472
646
|
packer.AddInt(team ? 1 : 0); // team
|
|
473
647
|
packer.AddString(message);
|
|
474
648
|
this.SendMsgEx(packer, 1);
|
|
475
649
|
};
|
|
476
650
|
Client.prototype.Vote = function (vote) {
|
|
477
|
-
var packer = new MsgPacker_1.
|
|
651
|
+
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_VOTE, false);
|
|
478
652
|
packer.AddInt(vote ? 1 : 0);
|
|
479
653
|
this.SendMsgEx(packer, 1);
|
|
480
654
|
};
|
|
481
655
|
Client.prototype.ChangePlayerInfo = function (playerInfo) {
|
|
482
|
-
var packer = new MsgPacker_1.
|
|
656
|
+
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_CHANGEINFO, false);
|
|
483
657
|
packer.AddString(playerInfo.name); //m_pName);
|
|
484
658
|
packer.AddString(playerInfo.clan); //m_pClan);
|
|
485
659
|
packer.AddInt(playerInfo.country); //m_Country);
|
|
@@ -490,20 +664,21 @@ var Client = /** @class */ (function (_super) {
|
|
|
490
664
|
this.SendMsgEx(packer, 1);
|
|
491
665
|
};
|
|
492
666
|
Client.prototype.Kill = function () {
|
|
493
|
-
var packer = new MsgPacker_1.
|
|
667
|
+
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_KILL, false);
|
|
494
668
|
this.SendMsgEx(packer, 1);
|
|
495
669
|
};
|
|
496
670
|
Client.prototype.ChangeTeam = function (team) {
|
|
497
|
-
var packer = new MsgPacker_1.
|
|
671
|
+
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_SETTEAM, false);
|
|
498
672
|
packer.AddInt(team);
|
|
499
673
|
this.SendMsgEx(packer, 1);
|
|
500
674
|
};
|
|
501
675
|
Client.prototype.Emote = function (emote) {
|
|
502
|
-
var packer = new MsgPacker_1.
|
|
676
|
+
var packer = new MsgPacker_1.MsgPacker(NETMSGTYPE.CL_EMOTICON, false);
|
|
503
677
|
packer.AddInt(emote);
|
|
504
678
|
this.SendMsgEx(packer, 1);
|
|
505
679
|
};
|
|
506
680
|
return Client;
|
|
507
681
|
}(stream_1.EventEmitter));
|
|
508
|
-
|
|
682
|
+
exports.Client = Client;
|
|
683
|
+
// export = Client;
|
|
509
684
|
// module.exports = Client;
|