quake2ts 0.0.288 → 0.0.290
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/package.json +1 -1
- package/packages/client/dist/browser/index.global.js +13 -13
- package/packages/client/dist/browser/index.global.js.map +1 -1
- package/packages/client/dist/cjs/index.cjs +554 -2
- package/packages/client/dist/cjs/index.cjs.map +1 -1
- package/packages/client/dist/esm/index.js +554 -2
- package/packages/client/dist/esm/index.js.map +1 -1
- package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/engine/dist/browser/index.global.js +16 -16
- package/packages/engine/dist/browser/index.global.js.map +1 -1
- package/packages/engine/dist/cjs/index.cjs +360 -35
- package/packages/engine/dist/cjs/index.cjs.map +1 -1
- package/packages/engine/dist/esm/index.js +360 -35
- package/packages/engine/dist/esm/index.js.map +1 -1
- package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/engine/dist/types/audio/constants.d.ts +1 -23
- package/packages/engine/dist/types/audio/constants.d.ts.map +1 -1
- package/packages/game/dist/browser/index.global.js +3 -3
- package/packages/game/dist/browser/index.global.js.map +1 -1
- package/packages/game/dist/cjs/index.cjs +556 -19
- package/packages/game/dist/cjs/index.cjs.map +1 -1
- package/packages/game/dist/esm/index.js +556 -19
- package/packages/game/dist/esm/index.js.map +1 -1
- package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/game/dist/types/entities/monsters/actor.d.ts.map +1 -1
- package/packages/game/dist/types/entities/monsters/arachnid.d.ts.map +1 -1
- package/packages/game/dist/types/entities/system.d.ts +1 -0
- package/packages/game/dist/types/entities/system.d.ts.map +1 -1
- package/packages/game/dist/types/index.d.ts +2 -0
- package/packages/game/dist/types/index.d.ts.map +1 -1
- package/packages/server/dist/index.cjs +54 -11
- package/packages/server/dist/index.d.cts +6 -1
- package/packages/server/dist/index.d.ts +6 -1
- package/packages/server/dist/index.js +56 -13
- package/packages/shared/dist/browser/index.global.js +1 -1
- package/packages/shared/dist/browser/index.global.js.map +1 -1
- package/packages/shared/dist/cjs/index.cjs +562 -0
- package/packages/shared/dist/cjs/index.cjs.map +1 -1
- package/packages/shared/dist/esm/index.js +549 -0
- package/packages/shared/dist/esm/index.js.map +1 -1
- package/packages/shared/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/shared/dist/types/audio/constants.d.ts +24 -0
- package/packages/shared/dist/types/audio/constants.d.ts.map +1 -0
- package/packages/shared/dist/types/index.d.ts +1 -0
- package/packages/shared/dist/types/index.d.ts.map +1 -1
- package/packages/shared/dist/types/net/index.d.ts +1 -0
- package/packages/shared/dist/types/net/index.d.ts.map +1 -1
- package/packages/shared/dist/types/protocol/crc.d.ts +5 -0
- package/packages/shared/dist/types/protocol/crc.d.ts.map +1 -0
- package/packages/shared/dist/types/protocol/index.d.ts +1 -0
- package/packages/shared/dist/types/protocol/index.d.ts.map +1 -1
- package/packages/tools/dist/tsconfig.tsbuildinfo +1 -1
|
@@ -2297,6 +2297,333 @@ var BinaryStream = class {
|
|
|
2297
2297
|
out.z = norm[2];
|
|
2298
2298
|
}
|
|
2299
2299
|
};
|
|
2300
|
+
var BinaryWriter = class {
|
|
2301
|
+
constructor(sizeOrBuffer = 1400) {
|
|
2302
|
+
if (typeof sizeOrBuffer === "number") {
|
|
2303
|
+
this.buffer = new Uint8Array(sizeOrBuffer);
|
|
2304
|
+
this.fixed = false;
|
|
2305
|
+
} else {
|
|
2306
|
+
this.buffer = sizeOrBuffer;
|
|
2307
|
+
this.fixed = true;
|
|
2308
|
+
}
|
|
2309
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
2310
|
+
this.offset = 0;
|
|
2311
|
+
}
|
|
2312
|
+
ensureSpace(bytes) {
|
|
2313
|
+
if (this.offset + bytes > this.buffer.byteLength) {
|
|
2314
|
+
if (this.fixed) {
|
|
2315
|
+
throw new Error(`Buffer overflow: capacity ${this.buffer.byteLength}, needed ${this.offset + bytes}`);
|
|
2316
|
+
}
|
|
2317
|
+
const newSize = Math.max(this.buffer.byteLength * 2, this.offset + bytes);
|
|
2318
|
+
const newBuffer = new Uint8Array(newSize);
|
|
2319
|
+
newBuffer.set(this.buffer);
|
|
2320
|
+
this.buffer = newBuffer;
|
|
2321
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
writeByte(value) {
|
|
2325
|
+
this.ensureSpace(1);
|
|
2326
|
+
this.view.setUint8(this.offset, value);
|
|
2327
|
+
this.offset += 1;
|
|
2328
|
+
}
|
|
2329
|
+
writeChar(value) {
|
|
2330
|
+
this.ensureSpace(1);
|
|
2331
|
+
this.view.setInt8(this.offset, value);
|
|
2332
|
+
this.offset += 1;
|
|
2333
|
+
}
|
|
2334
|
+
writeShort(value) {
|
|
2335
|
+
this.ensureSpace(2);
|
|
2336
|
+
this.view.setInt16(this.offset, value, true);
|
|
2337
|
+
this.offset += 2;
|
|
2338
|
+
}
|
|
2339
|
+
writeLong(value) {
|
|
2340
|
+
this.ensureSpace(4);
|
|
2341
|
+
this.view.setInt32(this.offset, value, true);
|
|
2342
|
+
this.offset += 4;
|
|
2343
|
+
}
|
|
2344
|
+
writeFloat(value) {
|
|
2345
|
+
this.ensureSpace(4);
|
|
2346
|
+
this.view.setFloat32(this.offset, value, true);
|
|
2347
|
+
this.offset += 4;
|
|
2348
|
+
}
|
|
2349
|
+
writeString(value) {
|
|
2350
|
+
const len2 = value.length;
|
|
2351
|
+
this.ensureSpace(len2 + 1);
|
|
2352
|
+
for (let i = 0; i < len2; i++) {
|
|
2353
|
+
this.view.setUint8(this.offset + i, value.charCodeAt(i));
|
|
2354
|
+
}
|
|
2355
|
+
this.view.setUint8(this.offset + len2, 0);
|
|
2356
|
+
this.offset += len2 + 1;
|
|
2357
|
+
}
|
|
2358
|
+
writeCoord(value) {
|
|
2359
|
+
this.writeShort(Math.trunc(value * 8));
|
|
2360
|
+
}
|
|
2361
|
+
writeAngle(value) {
|
|
2362
|
+
this.writeByte(Math.trunc(value * 256 / 360) & 255);
|
|
2363
|
+
}
|
|
2364
|
+
writeAngle16(value) {
|
|
2365
|
+
this.writeShort(Math.trunc(value * 65536 / 360) & 65535);
|
|
2366
|
+
}
|
|
2367
|
+
writePos(pos) {
|
|
2368
|
+
this.writeCoord(pos.x);
|
|
2369
|
+
this.writeCoord(pos.y);
|
|
2370
|
+
this.writeCoord(pos.z);
|
|
2371
|
+
}
|
|
2372
|
+
writeDir(dir) {
|
|
2373
|
+
let maxDot = -1;
|
|
2374
|
+
let bestIndex = 0;
|
|
2375
|
+
if (dir.x === 0 && dir.y === 0 && dir.z === 0) {
|
|
2376
|
+
this.writeByte(0);
|
|
2377
|
+
return;
|
|
2378
|
+
}
|
|
2379
|
+
for (let i = 0; i < ANORMS.length; i++) {
|
|
2380
|
+
const norm = ANORMS[i];
|
|
2381
|
+
const dot2 = dir.x * norm[0] + dir.y * norm[1] + dir.z * norm[2];
|
|
2382
|
+
if (dot2 > maxDot) {
|
|
2383
|
+
maxDot = dot2;
|
|
2384
|
+
bestIndex = i;
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
this.writeByte(bestIndex);
|
|
2388
|
+
}
|
|
2389
|
+
getData() {
|
|
2390
|
+
return this.buffer.slice(0, this.offset);
|
|
2391
|
+
}
|
|
2392
|
+
getBuffer() {
|
|
2393
|
+
return this.buffer;
|
|
2394
|
+
}
|
|
2395
|
+
getOffset() {
|
|
2396
|
+
return this.offset;
|
|
2397
|
+
}
|
|
2398
|
+
reset() {
|
|
2399
|
+
this.offset = 0;
|
|
2400
|
+
}
|
|
2401
|
+
};
|
|
2402
|
+
var _NetChan = class _NetChan2 {
|
|
2403
|
+
constructor() {
|
|
2404
|
+
this.qport = 0;
|
|
2405
|
+
this.incomingSequence = 0;
|
|
2406
|
+
this.outgoingSequence = 0;
|
|
2407
|
+
this.incomingAcknowledged = 0;
|
|
2408
|
+
this.incomingReliableAcknowledged = false;
|
|
2409
|
+
this.incomingReliableSequence = 0;
|
|
2410
|
+
this.outgoingReliableSequence = 0;
|
|
2411
|
+
this.reliableLength = 0;
|
|
2412
|
+
this.lastReceived = 0;
|
|
2413
|
+
this.lastSent = 0;
|
|
2414
|
+
this.remoteAddress = null;
|
|
2415
|
+
this.reliableMessage = new BinaryWriter(_NetChan2.MAX_MSGLEN);
|
|
2416
|
+
const now = Date.now();
|
|
2417
|
+
this.lastReceived = now;
|
|
2418
|
+
this.lastSent = now;
|
|
2419
|
+
this.qport = Math.floor(Math.random() * 65536);
|
|
2420
|
+
}
|
|
2421
|
+
/**
|
|
2422
|
+
* Setup the netchan with specific settings
|
|
2423
|
+
*/
|
|
2424
|
+
setup(qport, address = null) {
|
|
2425
|
+
this.qport = qport;
|
|
2426
|
+
this.remoteAddress = address;
|
|
2427
|
+
this.reset();
|
|
2428
|
+
}
|
|
2429
|
+
/**
|
|
2430
|
+
* Reset the netchan state
|
|
2431
|
+
*/
|
|
2432
|
+
reset() {
|
|
2433
|
+
this.incomingSequence = 0;
|
|
2434
|
+
this.outgoingSequence = 0;
|
|
2435
|
+
this.incomingAcknowledged = 0;
|
|
2436
|
+
this.incomingReliableAcknowledged = false;
|
|
2437
|
+
this.incomingReliableSequence = 0;
|
|
2438
|
+
this.outgoingReliableSequence = 0;
|
|
2439
|
+
this.reliableLength = 0;
|
|
2440
|
+
this.reliableMessage.reset();
|
|
2441
|
+
this.lastReceived = Date.now();
|
|
2442
|
+
this.lastSent = Date.now();
|
|
2443
|
+
}
|
|
2444
|
+
/**
|
|
2445
|
+
* Transmits a packet containing reliable and unreliable data
|
|
2446
|
+
*/
|
|
2447
|
+
transmit(unreliableData) {
|
|
2448
|
+
this.outgoingSequence++;
|
|
2449
|
+
this.lastSent = Date.now();
|
|
2450
|
+
const headerSize = _NetChan2.PACKET_HEADER;
|
|
2451
|
+
const reliableSize = this.reliableLength > 0 ? this.reliableLength + 2 : 0;
|
|
2452
|
+
let unreliableSize = unreliableData ? unreliableData.length : 0;
|
|
2453
|
+
if (headerSize + reliableSize + unreliableSize > _NetChan2.MAX_MSGLEN) {
|
|
2454
|
+
unreliableSize = _NetChan2.MAX_MSGLEN - headerSize - reliableSize;
|
|
2455
|
+
if (unreliableSize < 0) unreliableSize = 0;
|
|
2456
|
+
}
|
|
2457
|
+
const buffer = new ArrayBuffer(headerSize + reliableSize + unreliableSize);
|
|
2458
|
+
const view = new DataView(buffer);
|
|
2459
|
+
const result = new Uint8Array(buffer);
|
|
2460
|
+
let sequence = this.outgoingSequence;
|
|
2461
|
+
if (this.reliableLength > 0) {
|
|
2462
|
+
sequence |= 2147483648;
|
|
2463
|
+
if ((this.outgoingReliableSequence & 1) !== 0) {
|
|
2464
|
+
sequence |= 1073741824;
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
view.setUint32(0, sequence, true);
|
|
2468
|
+
let ack = this.incomingSequence;
|
|
2469
|
+
if ((this.incomingReliableSequence & 1) !== 0) {
|
|
2470
|
+
ack |= 2147483648;
|
|
2471
|
+
}
|
|
2472
|
+
view.setUint32(4, ack, true);
|
|
2473
|
+
view.setUint16(8, this.qport, true);
|
|
2474
|
+
let offset = headerSize;
|
|
2475
|
+
if (this.reliableLength > 0) {
|
|
2476
|
+
view.setUint16(offset, this.reliableLength, true);
|
|
2477
|
+
offset += 2;
|
|
2478
|
+
const reliableBuffer = this.reliableMessage.getBuffer();
|
|
2479
|
+
const reliableBytes = reliableBuffer.subarray(0, this.reliableLength);
|
|
2480
|
+
result.set(reliableBytes, offset);
|
|
2481
|
+
offset += this.reliableLength;
|
|
2482
|
+
}
|
|
2483
|
+
if (unreliableData && unreliableSize > 0) {
|
|
2484
|
+
const chunk = unreliableData.slice(0, unreliableSize);
|
|
2485
|
+
result.set(chunk, offset);
|
|
2486
|
+
}
|
|
2487
|
+
return result;
|
|
2488
|
+
}
|
|
2489
|
+
/**
|
|
2490
|
+
* Processes a received packet
|
|
2491
|
+
* Returns the payload data (reliable + unreliable) to be processed, or null if discarded
|
|
2492
|
+
*/
|
|
2493
|
+
process(packet) {
|
|
2494
|
+
if (packet.length < _NetChan2.PACKET_HEADER) {
|
|
2495
|
+
return null;
|
|
2496
|
+
}
|
|
2497
|
+
this.lastReceived = Date.now();
|
|
2498
|
+
const view = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);
|
|
2499
|
+
const sequence = view.getUint32(0, true);
|
|
2500
|
+
const ack = view.getUint32(4, true);
|
|
2501
|
+
const qport = view.getUint16(8, true);
|
|
2502
|
+
if (this.qport !== qport) {
|
|
2503
|
+
return null;
|
|
2504
|
+
}
|
|
2505
|
+
const seqNumberClean = sequence & ~(2147483648 | 1073741824);
|
|
2506
|
+
if ((seqNumberClean - this.incomingSequence | 0) <= 0) {
|
|
2507
|
+
return null;
|
|
2508
|
+
}
|
|
2509
|
+
this.incomingSequence = seqNumberClean;
|
|
2510
|
+
const ackNumber = ack & ~2147483648;
|
|
2511
|
+
const ackReliable = (ack & 2147483648) !== 0;
|
|
2512
|
+
if (ackNumber > this.incomingAcknowledged) {
|
|
2513
|
+
this.incomingAcknowledged = ackNumber;
|
|
2514
|
+
}
|
|
2515
|
+
if (this.reliableLength > 0) {
|
|
2516
|
+
const receivedAckBit = ackReliable ? 1 : 0;
|
|
2517
|
+
const currentReliableBit = this.outgoingReliableSequence & 1;
|
|
2518
|
+
if (receivedAckBit !== currentReliableBit) {
|
|
2519
|
+
this.reliableLength = 0;
|
|
2520
|
+
this.reliableMessage.reset();
|
|
2521
|
+
this.outgoingReliableSequence ^= 1;
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
const hasReliableData = (sequence & 2147483648) !== 0;
|
|
2525
|
+
const reliableSeqBit = (sequence & 1073741824) !== 0 ? 1 : 0;
|
|
2526
|
+
let payloadOffset = _NetChan2.PACKET_HEADER;
|
|
2527
|
+
let reliableData = null;
|
|
2528
|
+
if (hasReliableData) {
|
|
2529
|
+
if (payloadOffset + 2 > packet.byteLength) return null;
|
|
2530
|
+
const reliableLen = view.getUint16(payloadOffset, true);
|
|
2531
|
+
payloadOffset += 2;
|
|
2532
|
+
const expectedBit = this.incomingReliableSequence & 1;
|
|
2533
|
+
if (reliableSeqBit === expectedBit) {
|
|
2534
|
+
this.incomingReliableSequence++;
|
|
2535
|
+
if (payloadOffset + reliableLen > packet.byteLength) return null;
|
|
2536
|
+
reliableData = packet.slice(payloadOffset, payloadOffset + reliableLen);
|
|
2537
|
+
}
|
|
2538
|
+
payloadOffset += reliableLen;
|
|
2539
|
+
}
|
|
2540
|
+
const unreliableData = packet.slice(payloadOffset);
|
|
2541
|
+
if (reliableData && reliableData.length > 0) {
|
|
2542
|
+
const totalLen = reliableData.length + unreliableData.length;
|
|
2543
|
+
const result = new Uint8Array(totalLen);
|
|
2544
|
+
result.set(reliableData, 0);
|
|
2545
|
+
result.set(unreliableData, reliableData.length);
|
|
2546
|
+
return result;
|
|
2547
|
+
}
|
|
2548
|
+
if (unreliableData) {
|
|
2549
|
+
return unreliableData;
|
|
2550
|
+
}
|
|
2551
|
+
return new Uint8Array(0);
|
|
2552
|
+
}
|
|
2553
|
+
/**
|
|
2554
|
+
* Checks if reliable message buffer is empty and ready for new data
|
|
2555
|
+
*/
|
|
2556
|
+
canSendReliable() {
|
|
2557
|
+
return this.reliableLength === 0;
|
|
2558
|
+
}
|
|
2559
|
+
/**
|
|
2560
|
+
* Writes a byte to the reliable message buffer
|
|
2561
|
+
*/
|
|
2562
|
+
writeReliableByte(value) {
|
|
2563
|
+
if (this.reliableLength + 1 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
2564
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
2565
|
+
}
|
|
2566
|
+
this.reliableMessage.writeByte(value);
|
|
2567
|
+
this.reliableLength++;
|
|
2568
|
+
}
|
|
2569
|
+
/**
|
|
2570
|
+
* Writes a short to the reliable message buffer
|
|
2571
|
+
*/
|
|
2572
|
+
writeReliableShort(value) {
|
|
2573
|
+
if (this.reliableLength + 2 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
2574
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
2575
|
+
}
|
|
2576
|
+
this.reliableMessage.writeShort(value);
|
|
2577
|
+
this.reliableLength += 2;
|
|
2578
|
+
}
|
|
2579
|
+
/**
|
|
2580
|
+
* Writes a long to the reliable message buffer
|
|
2581
|
+
*/
|
|
2582
|
+
writeReliableLong(value) {
|
|
2583
|
+
if (this.reliableLength + 4 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
2584
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
2585
|
+
}
|
|
2586
|
+
this.reliableMessage.writeLong(value);
|
|
2587
|
+
this.reliableLength += 4;
|
|
2588
|
+
}
|
|
2589
|
+
/**
|
|
2590
|
+
* Writes a string to the reliable message buffer
|
|
2591
|
+
*/
|
|
2592
|
+
writeReliableString(value) {
|
|
2593
|
+
const len2 = value.length + 1;
|
|
2594
|
+
if (this.reliableLength + len2 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
2595
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
2596
|
+
}
|
|
2597
|
+
this.reliableMessage.writeString(value);
|
|
2598
|
+
this.reliableLength += len2;
|
|
2599
|
+
}
|
|
2600
|
+
/**
|
|
2601
|
+
* Returns the current reliable data buffer
|
|
2602
|
+
*/
|
|
2603
|
+
getReliableData() {
|
|
2604
|
+
if (this.reliableLength === 0) {
|
|
2605
|
+
return new Uint8Array(0);
|
|
2606
|
+
}
|
|
2607
|
+
const buffer = this.reliableMessage.getBuffer();
|
|
2608
|
+
return buffer.subarray(0, this.reliableLength);
|
|
2609
|
+
}
|
|
2610
|
+
/**
|
|
2611
|
+
* Checks if we need to send a keepalive packet
|
|
2612
|
+
*/
|
|
2613
|
+
needsKeepalive(currentTime) {
|
|
2614
|
+
return currentTime - this.lastSent > 1e3;
|
|
2615
|
+
}
|
|
2616
|
+
/**
|
|
2617
|
+
* Checks if the connection has timed out
|
|
2618
|
+
*/
|
|
2619
|
+
isTimedOut(currentTime, timeoutMs = 3e4) {
|
|
2620
|
+
return currentTime - this.lastReceived > timeoutMs;
|
|
2621
|
+
}
|
|
2622
|
+
};
|
|
2623
|
+
_NetChan.MAX_MSGLEN = 1400;
|
|
2624
|
+
_NetChan.FRAGMENT_SIZE = 1024;
|
|
2625
|
+
_NetChan.PACKET_HEADER = 10;
|
|
2626
|
+
_NetChan.HEADER_OVERHEAD = _NetChan.PACKET_HEADER + 2;
|
|
2300
2627
|
var AmmoType = /* @__PURE__ */ ((AmmoType22) => {
|
|
2301
2628
|
AmmoType22[AmmoType22["Bullets"] = 0] = "Bullets";
|
|
2302
2629
|
AmmoType22[AmmoType22["Shells"] = 1] = "Shells";
|
|
@@ -8827,7 +9154,7 @@ var BinaryStream2 = class {
|
|
|
8827
9154
|
out.z = norm[2];
|
|
8828
9155
|
}
|
|
8829
9156
|
};
|
|
8830
|
-
var
|
|
9157
|
+
var BinaryWriter2 = class {
|
|
8831
9158
|
constructor(sizeOrBuffer = 1400) {
|
|
8832
9159
|
if (typeof sizeOrBuffer === "number") {
|
|
8833
9160
|
this.buffer = new Uint8Array(sizeOrBuffer);
|
|
@@ -9019,6 +9346,231 @@ var NetworkMessageBuilder = class {
|
|
|
9019
9346
|
this.writeByte(best);
|
|
9020
9347
|
}
|
|
9021
9348
|
};
|
|
9349
|
+
var _NetChan3 = class _NetChan4 {
|
|
9350
|
+
constructor() {
|
|
9351
|
+
this.qport = 0;
|
|
9352
|
+
this.incomingSequence = 0;
|
|
9353
|
+
this.outgoingSequence = 0;
|
|
9354
|
+
this.incomingAcknowledged = 0;
|
|
9355
|
+
this.incomingReliableAcknowledged = false;
|
|
9356
|
+
this.incomingReliableSequence = 0;
|
|
9357
|
+
this.outgoingReliableSequence = 0;
|
|
9358
|
+
this.reliableLength = 0;
|
|
9359
|
+
this.lastReceived = 0;
|
|
9360
|
+
this.lastSent = 0;
|
|
9361
|
+
this.remoteAddress = null;
|
|
9362
|
+
this.reliableMessage = new BinaryWriter2(_NetChan4.MAX_MSGLEN);
|
|
9363
|
+
const now = Date.now();
|
|
9364
|
+
this.lastReceived = now;
|
|
9365
|
+
this.lastSent = now;
|
|
9366
|
+
this.qport = Math.floor(Math.random() * 65536);
|
|
9367
|
+
}
|
|
9368
|
+
/**
|
|
9369
|
+
* Setup the netchan with specific settings
|
|
9370
|
+
*/
|
|
9371
|
+
setup(qport, address = null) {
|
|
9372
|
+
this.qport = qport;
|
|
9373
|
+
this.remoteAddress = address;
|
|
9374
|
+
this.reset();
|
|
9375
|
+
}
|
|
9376
|
+
/**
|
|
9377
|
+
* Reset the netchan state
|
|
9378
|
+
*/
|
|
9379
|
+
reset() {
|
|
9380
|
+
this.incomingSequence = 0;
|
|
9381
|
+
this.outgoingSequence = 0;
|
|
9382
|
+
this.incomingAcknowledged = 0;
|
|
9383
|
+
this.incomingReliableAcknowledged = false;
|
|
9384
|
+
this.incomingReliableSequence = 0;
|
|
9385
|
+
this.outgoingReliableSequence = 0;
|
|
9386
|
+
this.reliableLength = 0;
|
|
9387
|
+
this.reliableMessage.reset();
|
|
9388
|
+
this.lastReceived = Date.now();
|
|
9389
|
+
this.lastSent = Date.now();
|
|
9390
|
+
}
|
|
9391
|
+
/**
|
|
9392
|
+
* Transmits a packet containing reliable and unreliable data
|
|
9393
|
+
*/
|
|
9394
|
+
transmit(unreliableData) {
|
|
9395
|
+
this.outgoingSequence++;
|
|
9396
|
+
this.lastSent = Date.now();
|
|
9397
|
+
const headerSize = _NetChan4.PACKET_HEADER;
|
|
9398
|
+
const reliableSize = this.reliableLength > 0 ? this.reliableLength + 2 : 0;
|
|
9399
|
+
let unreliableSize = unreliableData ? unreliableData.length : 0;
|
|
9400
|
+
if (headerSize + reliableSize + unreliableSize > _NetChan4.MAX_MSGLEN) {
|
|
9401
|
+
unreliableSize = _NetChan4.MAX_MSGLEN - headerSize - reliableSize;
|
|
9402
|
+
if (unreliableSize < 0) unreliableSize = 0;
|
|
9403
|
+
}
|
|
9404
|
+
const buffer = new ArrayBuffer(headerSize + reliableSize + unreliableSize);
|
|
9405
|
+
const view = new DataView(buffer);
|
|
9406
|
+
const result = new Uint8Array(buffer);
|
|
9407
|
+
let sequence = this.outgoingSequence;
|
|
9408
|
+
if (this.reliableLength > 0) {
|
|
9409
|
+
sequence |= 2147483648;
|
|
9410
|
+
if ((this.outgoingReliableSequence & 1) !== 0) {
|
|
9411
|
+
sequence |= 1073741824;
|
|
9412
|
+
}
|
|
9413
|
+
}
|
|
9414
|
+
view.setUint32(0, sequence, true);
|
|
9415
|
+
let ack = this.incomingSequence;
|
|
9416
|
+
if ((this.incomingReliableSequence & 1) !== 0) {
|
|
9417
|
+
ack |= 2147483648;
|
|
9418
|
+
}
|
|
9419
|
+
view.setUint32(4, ack, true);
|
|
9420
|
+
view.setUint16(8, this.qport, true);
|
|
9421
|
+
let offset = headerSize;
|
|
9422
|
+
if (this.reliableLength > 0) {
|
|
9423
|
+
view.setUint16(offset, this.reliableLength, true);
|
|
9424
|
+
offset += 2;
|
|
9425
|
+
const reliableBuffer = this.reliableMessage.getBuffer();
|
|
9426
|
+
const reliableBytes = reliableBuffer.subarray(0, this.reliableLength);
|
|
9427
|
+
result.set(reliableBytes, offset);
|
|
9428
|
+
offset += this.reliableLength;
|
|
9429
|
+
}
|
|
9430
|
+
if (unreliableData && unreliableSize > 0) {
|
|
9431
|
+
const chunk = unreliableData.slice(0, unreliableSize);
|
|
9432
|
+
result.set(chunk, offset);
|
|
9433
|
+
}
|
|
9434
|
+
return result;
|
|
9435
|
+
}
|
|
9436
|
+
/**
|
|
9437
|
+
* Processes a received packet
|
|
9438
|
+
* Returns the payload data (reliable + unreliable) to be processed, or null if discarded
|
|
9439
|
+
*/
|
|
9440
|
+
process(packet) {
|
|
9441
|
+
if (packet.length < _NetChan4.PACKET_HEADER) {
|
|
9442
|
+
return null;
|
|
9443
|
+
}
|
|
9444
|
+
this.lastReceived = Date.now();
|
|
9445
|
+
const view = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);
|
|
9446
|
+
const sequence = view.getUint32(0, true);
|
|
9447
|
+
const ack = view.getUint32(4, true);
|
|
9448
|
+
const qport = view.getUint16(8, true);
|
|
9449
|
+
if (this.qport !== qport) {
|
|
9450
|
+
return null;
|
|
9451
|
+
}
|
|
9452
|
+
const seqNumberClean = sequence & ~(2147483648 | 1073741824);
|
|
9453
|
+
if ((seqNumberClean - this.incomingSequence | 0) <= 0) {
|
|
9454
|
+
return null;
|
|
9455
|
+
}
|
|
9456
|
+
this.incomingSequence = seqNumberClean;
|
|
9457
|
+
const ackNumber = ack & ~2147483648;
|
|
9458
|
+
const ackReliable = (ack & 2147483648) !== 0;
|
|
9459
|
+
if (ackNumber > this.incomingAcknowledged) {
|
|
9460
|
+
this.incomingAcknowledged = ackNumber;
|
|
9461
|
+
}
|
|
9462
|
+
if (this.reliableLength > 0) {
|
|
9463
|
+
const receivedAckBit = ackReliable ? 1 : 0;
|
|
9464
|
+
const currentReliableBit = this.outgoingReliableSequence & 1;
|
|
9465
|
+
if (receivedAckBit !== currentReliableBit) {
|
|
9466
|
+
this.reliableLength = 0;
|
|
9467
|
+
this.reliableMessage.reset();
|
|
9468
|
+
this.outgoingReliableSequence ^= 1;
|
|
9469
|
+
}
|
|
9470
|
+
}
|
|
9471
|
+
const hasReliableData = (sequence & 2147483648) !== 0;
|
|
9472
|
+
const reliableSeqBit = (sequence & 1073741824) !== 0 ? 1 : 0;
|
|
9473
|
+
let payloadOffset = _NetChan4.PACKET_HEADER;
|
|
9474
|
+
let reliableData = null;
|
|
9475
|
+
if (hasReliableData) {
|
|
9476
|
+
if (payloadOffset + 2 > packet.byteLength) return null;
|
|
9477
|
+
const reliableLen = view.getUint16(payloadOffset, true);
|
|
9478
|
+
payloadOffset += 2;
|
|
9479
|
+
const expectedBit = this.incomingReliableSequence & 1;
|
|
9480
|
+
if (reliableSeqBit === expectedBit) {
|
|
9481
|
+
this.incomingReliableSequence++;
|
|
9482
|
+
if (payloadOffset + reliableLen > packet.byteLength) return null;
|
|
9483
|
+
reliableData = packet.slice(payloadOffset, payloadOffset + reliableLen);
|
|
9484
|
+
}
|
|
9485
|
+
payloadOffset += reliableLen;
|
|
9486
|
+
}
|
|
9487
|
+
const unreliableData = packet.slice(payloadOffset);
|
|
9488
|
+
if (reliableData && reliableData.length > 0) {
|
|
9489
|
+
const totalLen = reliableData.length + unreliableData.length;
|
|
9490
|
+
const result = new Uint8Array(totalLen);
|
|
9491
|
+
result.set(reliableData, 0);
|
|
9492
|
+
result.set(unreliableData, reliableData.length);
|
|
9493
|
+
return result;
|
|
9494
|
+
}
|
|
9495
|
+
if (unreliableData) {
|
|
9496
|
+
return unreliableData;
|
|
9497
|
+
}
|
|
9498
|
+
return new Uint8Array(0);
|
|
9499
|
+
}
|
|
9500
|
+
/**
|
|
9501
|
+
* Checks if reliable message buffer is empty and ready for new data
|
|
9502
|
+
*/
|
|
9503
|
+
canSendReliable() {
|
|
9504
|
+
return this.reliableLength === 0;
|
|
9505
|
+
}
|
|
9506
|
+
/**
|
|
9507
|
+
* Writes a byte to the reliable message buffer
|
|
9508
|
+
*/
|
|
9509
|
+
writeReliableByte(value) {
|
|
9510
|
+
if (this.reliableLength + 1 > _NetChan4.MAX_MSGLEN - _NetChan4.HEADER_OVERHEAD) {
|
|
9511
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
9512
|
+
}
|
|
9513
|
+
this.reliableMessage.writeByte(value);
|
|
9514
|
+
this.reliableLength++;
|
|
9515
|
+
}
|
|
9516
|
+
/**
|
|
9517
|
+
* Writes a short to the reliable message buffer
|
|
9518
|
+
*/
|
|
9519
|
+
writeReliableShort(value) {
|
|
9520
|
+
if (this.reliableLength + 2 > _NetChan4.MAX_MSGLEN - _NetChan4.HEADER_OVERHEAD) {
|
|
9521
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
9522
|
+
}
|
|
9523
|
+
this.reliableMessage.writeShort(value);
|
|
9524
|
+
this.reliableLength += 2;
|
|
9525
|
+
}
|
|
9526
|
+
/**
|
|
9527
|
+
* Writes a long to the reliable message buffer
|
|
9528
|
+
*/
|
|
9529
|
+
writeReliableLong(value) {
|
|
9530
|
+
if (this.reliableLength + 4 > _NetChan4.MAX_MSGLEN - _NetChan4.HEADER_OVERHEAD) {
|
|
9531
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
9532
|
+
}
|
|
9533
|
+
this.reliableMessage.writeLong(value);
|
|
9534
|
+
this.reliableLength += 4;
|
|
9535
|
+
}
|
|
9536
|
+
/**
|
|
9537
|
+
* Writes a string to the reliable message buffer
|
|
9538
|
+
*/
|
|
9539
|
+
writeReliableString(value) {
|
|
9540
|
+
const len2 = value.length + 1;
|
|
9541
|
+
if (this.reliableLength + len2 > _NetChan4.MAX_MSGLEN - _NetChan4.HEADER_OVERHEAD) {
|
|
9542
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
9543
|
+
}
|
|
9544
|
+
this.reliableMessage.writeString(value);
|
|
9545
|
+
this.reliableLength += len2;
|
|
9546
|
+
}
|
|
9547
|
+
/**
|
|
9548
|
+
* Returns the current reliable data buffer
|
|
9549
|
+
*/
|
|
9550
|
+
getReliableData() {
|
|
9551
|
+
if (this.reliableLength === 0) {
|
|
9552
|
+
return new Uint8Array(0);
|
|
9553
|
+
}
|
|
9554
|
+
const buffer = this.reliableMessage.getBuffer();
|
|
9555
|
+
return buffer.subarray(0, this.reliableLength);
|
|
9556
|
+
}
|
|
9557
|
+
/**
|
|
9558
|
+
* Checks if we need to send a keepalive packet
|
|
9559
|
+
*/
|
|
9560
|
+
needsKeepalive(currentTime) {
|
|
9561
|
+
return currentTime - this.lastSent > 1e3;
|
|
9562
|
+
}
|
|
9563
|
+
/**
|
|
9564
|
+
* Checks if the connection has timed out
|
|
9565
|
+
*/
|
|
9566
|
+
isTimedOut(currentTime, timeoutMs = 3e4) {
|
|
9567
|
+
return currentTime - this.lastReceived > timeoutMs;
|
|
9568
|
+
}
|
|
9569
|
+
};
|
|
9570
|
+
_NetChan3.MAX_MSGLEN = 1400;
|
|
9571
|
+
_NetChan3.FRAGMENT_SIZE = 1024;
|
|
9572
|
+
_NetChan3.PACKET_HEADER = 10;
|
|
9573
|
+
_NetChan3.HEADER_OVERHEAD = _NetChan3.PACKET_HEADER + 2;
|
|
9022
9574
|
var AmmoType2 = /* @__PURE__ */ ((AmmoType22) => {
|
|
9023
9575
|
AmmoType22[AmmoType22["Bullets"] = 0] = "Bullets";
|
|
9024
9576
|
AmmoType22[AmmoType22["Shells"] = 1] = "Shells";
|
|
@@ -11086,7 +11638,7 @@ var MultiplayerConnection = class {
|
|
|
11086
11638
|
if (this.commandHistory.length > CMD_BACKUP) {
|
|
11087
11639
|
this.commandHistory.shift();
|
|
11088
11640
|
}
|
|
11089
|
-
const writer = new
|
|
11641
|
+
const writer = new BinaryWriter2();
|
|
11090
11642
|
writer.writeLong(0);
|
|
11091
11643
|
writer.writeLong(0);
|
|
11092
11644
|
writer.writeByte(ClientCommand.move);
|