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
|
@@ -3817,6 +3817,273 @@ var RenderFx = /* @__PURE__ */ ((RenderFx2) => {
|
|
|
3817
3817
|
return RenderFx2;
|
|
3818
3818
|
})(RenderFx || {});
|
|
3819
3819
|
|
|
3820
|
+
// src/protocol/crc.ts
|
|
3821
|
+
var crc_table = [
|
|
3822
|
+
0,
|
|
3823
|
+
145,
|
|
3824
|
+
227,
|
|
3825
|
+
114,
|
|
3826
|
+
7,
|
|
3827
|
+
150,
|
|
3828
|
+
228,
|
|
3829
|
+
117,
|
|
3830
|
+
14,
|
|
3831
|
+
159,
|
|
3832
|
+
237,
|
|
3833
|
+
124,
|
|
3834
|
+
9,
|
|
3835
|
+
152,
|
|
3836
|
+
234,
|
|
3837
|
+
123,
|
|
3838
|
+
28,
|
|
3839
|
+
141,
|
|
3840
|
+
255,
|
|
3841
|
+
110,
|
|
3842
|
+
27,
|
|
3843
|
+
138,
|
|
3844
|
+
248,
|
|
3845
|
+
105,
|
|
3846
|
+
18,
|
|
3847
|
+
131,
|
|
3848
|
+
241,
|
|
3849
|
+
96,
|
|
3850
|
+
21,
|
|
3851
|
+
132,
|
|
3852
|
+
246,
|
|
3853
|
+
103,
|
|
3854
|
+
56,
|
|
3855
|
+
169,
|
|
3856
|
+
219,
|
|
3857
|
+
74,
|
|
3858
|
+
63,
|
|
3859
|
+
174,
|
|
3860
|
+
220,
|
|
3861
|
+
77,
|
|
3862
|
+
54,
|
|
3863
|
+
167,
|
|
3864
|
+
213,
|
|
3865
|
+
68,
|
|
3866
|
+
49,
|
|
3867
|
+
160,
|
|
3868
|
+
210,
|
|
3869
|
+
67,
|
|
3870
|
+
36,
|
|
3871
|
+
181,
|
|
3872
|
+
199,
|
|
3873
|
+
86,
|
|
3874
|
+
35,
|
|
3875
|
+
178,
|
|
3876
|
+
192,
|
|
3877
|
+
81,
|
|
3878
|
+
42,
|
|
3879
|
+
187,
|
|
3880
|
+
201,
|
|
3881
|
+
88,
|
|
3882
|
+
45,
|
|
3883
|
+
188,
|
|
3884
|
+
206,
|
|
3885
|
+
95,
|
|
3886
|
+
112,
|
|
3887
|
+
225,
|
|
3888
|
+
147,
|
|
3889
|
+
2,
|
|
3890
|
+
119,
|
|
3891
|
+
230,
|
|
3892
|
+
148,
|
|
3893
|
+
5,
|
|
3894
|
+
126,
|
|
3895
|
+
239,
|
|
3896
|
+
157,
|
|
3897
|
+
12,
|
|
3898
|
+
121,
|
|
3899
|
+
232,
|
|
3900
|
+
154,
|
|
3901
|
+
11,
|
|
3902
|
+
108,
|
|
3903
|
+
253,
|
|
3904
|
+
143,
|
|
3905
|
+
30,
|
|
3906
|
+
107,
|
|
3907
|
+
250,
|
|
3908
|
+
136,
|
|
3909
|
+
25,
|
|
3910
|
+
98,
|
|
3911
|
+
243,
|
|
3912
|
+
129,
|
|
3913
|
+
16,
|
|
3914
|
+
101,
|
|
3915
|
+
244,
|
|
3916
|
+
134,
|
|
3917
|
+
23,
|
|
3918
|
+
72,
|
|
3919
|
+
217,
|
|
3920
|
+
171,
|
|
3921
|
+
58,
|
|
3922
|
+
79,
|
|
3923
|
+
222,
|
|
3924
|
+
172,
|
|
3925
|
+
61,
|
|
3926
|
+
70,
|
|
3927
|
+
215,
|
|
3928
|
+
165,
|
|
3929
|
+
52,
|
|
3930
|
+
65,
|
|
3931
|
+
208,
|
|
3932
|
+
162,
|
|
3933
|
+
51,
|
|
3934
|
+
84,
|
|
3935
|
+
197,
|
|
3936
|
+
183,
|
|
3937
|
+
38,
|
|
3938
|
+
83,
|
|
3939
|
+
194,
|
|
3940
|
+
176,
|
|
3941
|
+
33,
|
|
3942
|
+
90,
|
|
3943
|
+
203,
|
|
3944
|
+
185,
|
|
3945
|
+
40,
|
|
3946
|
+
93,
|
|
3947
|
+
204,
|
|
3948
|
+
190,
|
|
3949
|
+
47,
|
|
3950
|
+
224,
|
|
3951
|
+
113,
|
|
3952
|
+
3,
|
|
3953
|
+
146,
|
|
3954
|
+
231,
|
|
3955
|
+
118,
|
|
3956
|
+
4,
|
|
3957
|
+
149,
|
|
3958
|
+
238,
|
|
3959
|
+
127,
|
|
3960
|
+
13,
|
|
3961
|
+
156,
|
|
3962
|
+
233,
|
|
3963
|
+
120,
|
|
3964
|
+
10,
|
|
3965
|
+
155,
|
|
3966
|
+
252,
|
|
3967
|
+
109,
|
|
3968
|
+
31,
|
|
3969
|
+
142,
|
|
3970
|
+
251,
|
|
3971
|
+
106,
|
|
3972
|
+
24,
|
|
3973
|
+
137,
|
|
3974
|
+
242,
|
|
3975
|
+
99,
|
|
3976
|
+
17,
|
|
3977
|
+
128,
|
|
3978
|
+
245,
|
|
3979
|
+
100,
|
|
3980
|
+
22,
|
|
3981
|
+
135,
|
|
3982
|
+
216,
|
|
3983
|
+
73,
|
|
3984
|
+
59,
|
|
3985
|
+
170,
|
|
3986
|
+
223,
|
|
3987
|
+
78,
|
|
3988
|
+
60,
|
|
3989
|
+
173,
|
|
3990
|
+
214,
|
|
3991
|
+
71,
|
|
3992
|
+
53,
|
|
3993
|
+
164,
|
|
3994
|
+
209,
|
|
3995
|
+
64,
|
|
3996
|
+
50,
|
|
3997
|
+
163,
|
|
3998
|
+
196,
|
|
3999
|
+
85,
|
|
4000
|
+
39,
|
|
4001
|
+
182,
|
|
4002
|
+
195,
|
|
4003
|
+
82,
|
|
4004
|
+
32,
|
|
4005
|
+
177,
|
|
4006
|
+
202,
|
|
4007
|
+
91,
|
|
4008
|
+
41,
|
|
4009
|
+
184,
|
|
4010
|
+
205,
|
|
4011
|
+
92,
|
|
4012
|
+
46,
|
|
4013
|
+
191,
|
|
4014
|
+
144,
|
|
4015
|
+
1,
|
|
4016
|
+
115,
|
|
4017
|
+
226,
|
|
4018
|
+
151,
|
|
4019
|
+
6,
|
|
4020
|
+
116,
|
|
4021
|
+
229,
|
|
4022
|
+
158,
|
|
4023
|
+
15,
|
|
4024
|
+
125,
|
|
4025
|
+
236,
|
|
4026
|
+
153,
|
|
4027
|
+
8,
|
|
4028
|
+
122,
|
|
4029
|
+
235,
|
|
4030
|
+
140,
|
|
4031
|
+
29,
|
|
4032
|
+
111,
|
|
4033
|
+
254,
|
|
4034
|
+
139,
|
|
4035
|
+
26,
|
|
4036
|
+
104,
|
|
4037
|
+
249,
|
|
4038
|
+
130,
|
|
4039
|
+
19,
|
|
4040
|
+
97,
|
|
4041
|
+
240,
|
|
4042
|
+
133,
|
|
4043
|
+
20,
|
|
4044
|
+
102,
|
|
4045
|
+
247,
|
|
4046
|
+
168,
|
|
4047
|
+
57,
|
|
4048
|
+
75,
|
|
4049
|
+
218,
|
|
4050
|
+
175,
|
|
4051
|
+
62,
|
|
4052
|
+
76,
|
|
4053
|
+
221,
|
|
4054
|
+
166,
|
|
4055
|
+
55,
|
|
4056
|
+
69,
|
|
4057
|
+
212,
|
|
4058
|
+
161,
|
|
4059
|
+
48,
|
|
4060
|
+
66,
|
|
4061
|
+
211,
|
|
4062
|
+
180,
|
|
4063
|
+
37,
|
|
4064
|
+
86,
|
|
4065
|
+
199,
|
|
4066
|
+
179,
|
|
4067
|
+
34,
|
|
4068
|
+
80,
|
|
4069
|
+
193,
|
|
4070
|
+
186,
|
|
4071
|
+
43,
|
|
4072
|
+
89,
|
|
4073
|
+
200,
|
|
4074
|
+
189,
|
|
4075
|
+
44,
|
|
4076
|
+
94,
|
|
4077
|
+
207
|
|
4078
|
+
];
|
|
4079
|
+
function crc8(data) {
|
|
4080
|
+
let crc = 0;
|
|
4081
|
+
for (let i = 0; i < data.length; i++) {
|
|
4082
|
+
crc = crc_table[(crc ^ data[i]) & 255];
|
|
4083
|
+
}
|
|
4084
|
+
return crc;
|
|
4085
|
+
}
|
|
4086
|
+
|
|
3820
4087
|
// src/protocol/entityFlags.ts
|
|
3821
4088
|
var entityFlags_exports = {};
|
|
3822
4089
|
__export(entityFlags_exports, {
|
|
@@ -4270,6 +4537,244 @@ var NetworkMessageBuilder = class {
|
|
|
4270
4537
|
}
|
|
4271
4538
|
};
|
|
4272
4539
|
|
|
4540
|
+
// src/net/netchan.ts
|
|
4541
|
+
var _NetChan = class _NetChan {
|
|
4542
|
+
constructor() {
|
|
4543
|
+
// +2 for reliable length prefix
|
|
4544
|
+
// Public state
|
|
4545
|
+
this.qport = 0;
|
|
4546
|
+
// qport value to distinguish multiple clients from same IP
|
|
4547
|
+
// Sequencing
|
|
4548
|
+
this.incomingSequence = 0;
|
|
4549
|
+
this.outgoingSequence = 0;
|
|
4550
|
+
this.incomingAcknowledged = 0;
|
|
4551
|
+
// Reliable messaging
|
|
4552
|
+
this.incomingReliableAcknowledged = false;
|
|
4553
|
+
// single bit
|
|
4554
|
+
this.incomingReliableSequence = 0;
|
|
4555
|
+
// last reliable message sequence received
|
|
4556
|
+
this.outgoingReliableSequence = 0;
|
|
4557
|
+
this.reliableLength = 0;
|
|
4558
|
+
// Timing
|
|
4559
|
+
this.lastReceived = 0;
|
|
4560
|
+
this.lastSent = 0;
|
|
4561
|
+
this.remoteAddress = null;
|
|
4562
|
+
this.reliableMessage = new BinaryWriter(_NetChan.MAX_MSGLEN);
|
|
4563
|
+
const now = Date.now();
|
|
4564
|
+
this.lastReceived = now;
|
|
4565
|
+
this.lastSent = now;
|
|
4566
|
+
this.qport = Math.floor(Math.random() * 65536);
|
|
4567
|
+
}
|
|
4568
|
+
/**
|
|
4569
|
+
* Setup the netchan with specific settings
|
|
4570
|
+
*/
|
|
4571
|
+
setup(qport, address = null) {
|
|
4572
|
+
this.qport = qport;
|
|
4573
|
+
this.remoteAddress = address;
|
|
4574
|
+
this.reset();
|
|
4575
|
+
}
|
|
4576
|
+
/**
|
|
4577
|
+
* Reset the netchan state
|
|
4578
|
+
*/
|
|
4579
|
+
reset() {
|
|
4580
|
+
this.incomingSequence = 0;
|
|
4581
|
+
this.outgoingSequence = 0;
|
|
4582
|
+
this.incomingAcknowledged = 0;
|
|
4583
|
+
this.incomingReliableAcknowledged = false;
|
|
4584
|
+
this.incomingReliableSequence = 0;
|
|
4585
|
+
this.outgoingReliableSequence = 0;
|
|
4586
|
+
this.reliableLength = 0;
|
|
4587
|
+
this.reliableMessage.reset();
|
|
4588
|
+
this.lastReceived = Date.now();
|
|
4589
|
+
this.lastSent = Date.now();
|
|
4590
|
+
}
|
|
4591
|
+
/**
|
|
4592
|
+
* Transmits a packet containing reliable and unreliable data
|
|
4593
|
+
*/
|
|
4594
|
+
transmit(unreliableData) {
|
|
4595
|
+
this.outgoingSequence++;
|
|
4596
|
+
this.lastSent = Date.now();
|
|
4597
|
+
const headerSize = _NetChan.PACKET_HEADER;
|
|
4598
|
+
const reliableSize = this.reliableLength > 0 ? this.reliableLength + 2 : 0;
|
|
4599
|
+
let unreliableSize = unreliableData ? unreliableData.length : 0;
|
|
4600
|
+
if (headerSize + reliableSize + unreliableSize > _NetChan.MAX_MSGLEN) {
|
|
4601
|
+
unreliableSize = _NetChan.MAX_MSGLEN - headerSize - reliableSize;
|
|
4602
|
+
if (unreliableSize < 0) unreliableSize = 0;
|
|
4603
|
+
}
|
|
4604
|
+
const buffer = new ArrayBuffer(headerSize + reliableSize + unreliableSize);
|
|
4605
|
+
const view = new DataView(buffer);
|
|
4606
|
+
const result = new Uint8Array(buffer);
|
|
4607
|
+
let sequence = this.outgoingSequence;
|
|
4608
|
+
if (this.reliableLength > 0) {
|
|
4609
|
+
sequence |= 2147483648;
|
|
4610
|
+
if ((this.outgoingReliableSequence & 1) !== 0) {
|
|
4611
|
+
sequence |= 1073741824;
|
|
4612
|
+
}
|
|
4613
|
+
}
|
|
4614
|
+
view.setUint32(0, sequence, true);
|
|
4615
|
+
let ack = this.incomingSequence;
|
|
4616
|
+
if ((this.incomingReliableSequence & 1) !== 0) {
|
|
4617
|
+
ack |= 2147483648;
|
|
4618
|
+
}
|
|
4619
|
+
view.setUint32(4, ack, true);
|
|
4620
|
+
view.setUint16(8, this.qport, true);
|
|
4621
|
+
let offset = headerSize;
|
|
4622
|
+
if (this.reliableLength > 0) {
|
|
4623
|
+
view.setUint16(offset, this.reliableLength, true);
|
|
4624
|
+
offset += 2;
|
|
4625
|
+
const reliableBuffer = this.reliableMessage.getBuffer();
|
|
4626
|
+
const reliableBytes = reliableBuffer.subarray(0, this.reliableLength);
|
|
4627
|
+
result.set(reliableBytes, offset);
|
|
4628
|
+
offset += this.reliableLength;
|
|
4629
|
+
}
|
|
4630
|
+
if (unreliableData && unreliableSize > 0) {
|
|
4631
|
+
const chunk = unreliableData.slice(0, unreliableSize);
|
|
4632
|
+
result.set(chunk, offset);
|
|
4633
|
+
}
|
|
4634
|
+
return result;
|
|
4635
|
+
}
|
|
4636
|
+
/**
|
|
4637
|
+
* Processes a received packet
|
|
4638
|
+
* Returns the payload data (reliable + unreliable) to be processed, or null if discarded
|
|
4639
|
+
*/
|
|
4640
|
+
process(packet) {
|
|
4641
|
+
if (packet.length < _NetChan.PACKET_HEADER) {
|
|
4642
|
+
return null;
|
|
4643
|
+
}
|
|
4644
|
+
this.lastReceived = Date.now();
|
|
4645
|
+
const view = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);
|
|
4646
|
+
const sequence = view.getUint32(0, true);
|
|
4647
|
+
const ack = view.getUint32(4, true);
|
|
4648
|
+
const qport = view.getUint16(8, true);
|
|
4649
|
+
if (this.qport !== qport) {
|
|
4650
|
+
return null;
|
|
4651
|
+
}
|
|
4652
|
+
const seqNumberClean = sequence & ~(2147483648 | 1073741824);
|
|
4653
|
+
if ((seqNumberClean - this.incomingSequence | 0) <= 0) {
|
|
4654
|
+
return null;
|
|
4655
|
+
}
|
|
4656
|
+
this.incomingSequence = seqNumberClean;
|
|
4657
|
+
const ackNumber = ack & ~2147483648;
|
|
4658
|
+
const ackReliable = (ack & 2147483648) !== 0;
|
|
4659
|
+
if (ackNumber > this.incomingAcknowledged) {
|
|
4660
|
+
this.incomingAcknowledged = ackNumber;
|
|
4661
|
+
}
|
|
4662
|
+
if (this.reliableLength > 0) {
|
|
4663
|
+
const receivedAckBit = ackReliable ? 1 : 0;
|
|
4664
|
+
const currentReliableBit = this.outgoingReliableSequence & 1;
|
|
4665
|
+
if (receivedAckBit !== currentReliableBit) {
|
|
4666
|
+
this.reliableLength = 0;
|
|
4667
|
+
this.reliableMessage.reset();
|
|
4668
|
+
this.outgoingReliableSequence ^= 1;
|
|
4669
|
+
}
|
|
4670
|
+
}
|
|
4671
|
+
const hasReliableData = (sequence & 2147483648) !== 0;
|
|
4672
|
+
const reliableSeqBit = (sequence & 1073741824) !== 0 ? 1 : 0;
|
|
4673
|
+
let payloadOffset = _NetChan.PACKET_HEADER;
|
|
4674
|
+
let reliableData = null;
|
|
4675
|
+
if (hasReliableData) {
|
|
4676
|
+
if (payloadOffset + 2 > packet.byteLength) return null;
|
|
4677
|
+
const reliableLen = view.getUint16(payloadOffset, true);
|
|
4678
|
+
payloadOffset += 2;
|
|
4679
|
+
const expectedBit = this.incomingReliableSequence & 1;
|
|
4680
|
+
if (reliableSeqBit === expectedBit) {
|
|
4681
|
+
this.incomingReliableSequence++;
|
|
4682
|
+
if (payloadOffset + reliableLen > packet.byteLength) return null;
|
|
4683
|
+
reliableData = packet.slice(payloadOffset, payloadOffset + reliableLen);
|
|
4684
|
+
}
|
|
4685
|
+
payloadOffset += reliableLen;
|
|
4686
|
+
}
|
|
4687
|
+
const unreliableData = packet.slice(payloadOffset);
|
|
4688
|
+
if (reliableData && reliableData.length > 0) {
|
|
4689
|
+
const totalLen = reliableData.length + unreliableData.length;
|
|
4690
|
+
const result = new Uint8Array(totalLen);
|
|
4691
|
+
result.set(reliableData, 0);
|
|
4692
|
+
result.set(unreliableData, reliableData.length);
|
|
4693
|
+
return result;
|
|
4694
|
+
}
|
|
4695
|
+
if (unreliableData) {
|
|
4696
|
+
return unreliableData;
|
|
4697
|
+
}
|
|
4698
|
+
return new Uint8Array(0);
|
|
4699
|
+
}
|
|
4700
|
+
/**
|
|
4701
|
+
* Checks if reliable message buffer is empty and ready for new data
|
|
4702
|
+
*/
|
|
4703
|
+
canSendReliable() {
|
|
4704
|
+
return this.reliableLength === 0;
|
|
4705
|
+
}
|
|
4706
|
+
/**
|
|
4707
|
+
* Writes a byte to the reliable message buffer
|
|
4708
|
+
*/
|
|
4709
|
+
writeReliableByte(value) {
|
|
4710
|
+
if (this.reliableLength + 1 > _NetChan.MAX_MSGLEN - _NetChan.HEADER_OVERHEAD) {
|
|
4711
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
4712
|
+
}
|
|
4713
|
+
this.reliableMessage.writeByte(value);
|
|
4714
|
+
this.reliableLength++;
|
|
4715
|
+
}
|
|
4716
|
+
/**
|
|
4717
|
+
* Writes a short to the reliable message buffer
|
|
4718
|
+
*/
|
|
4719
|
+
writeReliableShort(value) {
|
|
4720
|
+
if (this.reliableLength + 2 > _NetChan.MAX_MSGLEN - _NetChan.HEADER_OVERHEAD) {
|
|
4721
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
4722
|
+
}
|
|
4723
|
+
this.reliableMessage.writeShort(value);
|
|
4724
|
+
this.reliableLength += 2;
|
|
4725
|
+
}
|
|
4726
|
+
/**
|
|
4727
|
+
* Writes a long to the reliable message buffer
|
|
4728
|
+
*/
|
|
4729
|
+
writeReliableLong(value) {
|
|
4730
|
+
if (this.reliableLength + 4 > _NetChan.MAX_MSGLEN - _NetChan.HEADER_OVERHEAD) {
|
|
4731
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
4732
|
+
}
|
|
4733
|
+
this.reliableMessage.writeLong(value);
|
|
4734
|
+
this.reliableLength += 4;
|
|
4735
|
+
}
|
|
4736
|
+
/**
|
|
4737
|
+
* Writes a string to the reliable message buffer
|
|
4738
|
+
*/
|
|
4739
|
+
writeReliableString(value) {
|
|
4740
|
+
const len = value.length + 1;
|
|
4741
|
+
if (this.reliableLength + len > _NetChan.MAX_MSGLEN - _NetChan.HEADER_OVERHEAD) {
|
|
4742
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
4743
|
+
}
|
|
4744
|
+
this.reliableMessage.writeString(value);
|
|
4745
|
+
this.reliableLength += len;
|
|
4746
|
+
}
|
|
4747
|
+
/**
|
|
4748
|
+
* Returns the current reliable data buffer
|
|
4749
|
+
*/
|
|
4750
|
+
getReliableData() {
|
|
4751
|
+
if (this.reliableLength === 0) {
|
|
4752
|
+
return new Uint8Array(0);
|
|
4753
|
+
}
|
|
4754
|
+
const buffer = this.reliableMessage.getBuffer();
|
|
4755
|
+
return buffer.subarray(0, this.reliableLength);
|
|
4756
|
+
}
|
|
4757
|
+
/**
|
|
4758
|
+
* Checks if we need to send a keepalive packet
|
|
4759
|
+
*/
|
|
4760
|
+
needsKeepalive(currentTime) {
|
|
4761
|
+
return currentTime - this.lastSent > 1e3;
|
|
4762
|
+
}
|
|
4763
|
+
/**
|
|
4764
|
+
* Checks if the connection has timed out
|
|
4765
|
+
*/
|
|
4766
|
+
isTimedOut(currentTime, timeoutMs = 3e4) {
|
|
4767
|
+
return currentTime - this.lastReceived > timeoutMs;
|
|
4768
|
+
}
|
|
4769
|
+
};
|
|
4770
|
+
// Constants from net_chan.c
|
|
4771
|
+
_NetChan.MAX_MSGLEN = 1400;
|
|
4772
|
+
_NetChan.FRAGMENT_SIZE = 1024;
|
|
4773
|
+
_NetChan.PACKET_HEADER = 10;
|
|
4774
|
+
// sequence(4) + ack(4) + qport(2)
|
|
4775
|
+
_NetChan.HEADER_OVERHEAD = _NetChan.PACKET_HEADER + 2;
|
|
4776
|
+
var NetChan = _NetChan;
|
|
4777
|
+
|
|
4273
4778
|
// src/items/weapons.ts
|
|
4274
4779
|
var WeaponId = /* @__PURE__ */ ((WeaponId2) => {
|
|
4275
4780
|
WeaponId2["Blaster"] = "blaster";
|
|
@@ -4367,10 +4872,46 @@ var WEAPON_AMMO_MAP = {
|
|
|
4367
4872
|
["disruptor" /* Disruptor */]: 10 /* Disruptor */,
|
|
4368
4873
|
["trap" /* Trap */]: 7 /* Trap */
|
|
4369
4874
|
};
|
|
4875
|
+
|
|
4876
|
+
// src/audio/constants.ts
|
|
4877
|
+
var MAX_SOUND_CHANNELS = 32;
|
|
4878
|
+
var SoundChannel = /* @__PURE__ */ ((SoundChannel2) => {
|
|
4879
|
+
SoundChannel2[SoundChannel2["Auto"] = 0] = "Auto";
|
|
4880
|
+
SoundChannel2[SoundChannel2["Weapon"] = 1] = "Weapon";
|
|
4881
|
+
SoundChannel2[SoundChannel2["Voice"] = 2] = "Voice";
|
|
4882
|
+
SoundChannel2[SoundChannel2["Item"] = 3] = "Item";
|
|
4883
|
+
SoundChannel2[SoundChannel2["Body"] = 4] = "Body";
|
|
4884
|
+
SoundChannel2[SoundChannel2["Aux"] = 5] = "Aux";
|
|
4885
|
+
SoundChannel2[SoundChannel2["Footstep"] = 6] = "Footstep";
|
|
4886
|
+
SoundChannel2[SoundChannel2["Aux3"] = 7] = "Aux3";
|
|
4887
|
+
SoundChannel2[SoundChannel2["NoPhsAdd"] = 8] = "NoPhsAdd";
|
|
4888
|
+
SoundChannel2[SoundChannel2["Reliable"] = 16] = "Reliable";
|
|
4889
|
+
SoundChannel2[SoundChannel2["ForcePos"] = 32] = "ForcePos";
|
|
4890
|
+
return SoundChannel2;
|
|
4891
|
+
})(SoundChannel || {});
|
|
4892
|
+
var ATTN_LOOP_NONE = -1;
|
|
4893
|
+
var ATTN_NONE = 0;
|
|
4894
|
+
var ATTN_NORM = 1;
|
|
4895
|
+
var ATTN_IDLE = 2;
|
|
4896
|
+
var ATTN_STATIC = 3;
|
|
4897
|
+
var SOUND_FULLVOLUME = 80;
|
|
4898
|
+
var SOUND_LOOP_ATTENUATE = 3e-3;
|
|
4899
|
+
function attenuationToDistanceMultiplier(attenuation) {
|
|
4900
|
+
return attenuation === ATTN_STATIC ? attenuation * 1e-3 : attenuation * 5e-4;
|
|
4901
|
+
}
|
|
4902
|
+
function calculateMaxAudibleDistance(attenuation) {
|
|
4903
|
+
const distMult = attenuationToDistanceMultiplier(attenuation);
|
|
4904
|
+
return distMult <= 0 ? Number.POSITIVE_INFINITY : SOUND_FULLVOLUME + 1 / distMult;
|
|
4905
|
+
}
|
|
4370
4906
|
export {
|
|
4371
4907
|
AMMO_MAX,
|
|
4372
4908
|
AMMO_TYPE_COUNT,
|
|
4373
4909
|
ANORMS,
|
|
4910
|
+
ATTN_IDLE,
|
|
4911
|
+
ATTN_LOOP_NONE,
|
|
4912
|
+
ATTN_NONE,
|
|
4913
|
+
ATTN_NORM,
|
|
4914
|
+
ATTN_STATIC,
|
|
4374
4915
|
AmmoItemId,
|
|
4375
4916
|
AmmoType,
|
|
4376
4917
|
BinaryStream,
|
|
@@ -4459,6 +5000,7 @@ export {
|
|
|
4459
5000
|
MAX_QPATH,
|
|
4460
5001
|
MAX_SHADOW_LIGHTS,
|
|
4461
5002
|
MAX_SOUNDS,
|
|
5003
|
+
MAX_SOUND_CHANNELS,
|
|
4462
5004
|
MAX_STRING_CHARS,
|
|
4463
5005
|
MAX_STRING_TOKENS,
|
|
4464
5006
|
MAX_TOKEN_CHARS,
|
|
@@ -4482,6 +5024,7 @@ export {
|
|
|
4482
5024
|
NUM_BITS_FOR_AMMO,
|
|
4483
5025
|
NUM_BITS_FOR_POWERUP,
|
|
4484
5026
|
NUM_POWERUP_STATS,
|
|
5027
|
+
NetChan,
|
|
4485
5028
|
NetworkMessageBuilder,
|
|
4486
5029
|
PITCH,
|
|
4487
5030
|
POWERUP_MAX,
|
|
@@ -4498,6 +5041,8 @@ export {
|
|
|
4498
5041
|
replay_exports as Replay,
|
|
4499
5042
|
SLIDEMOVE_BLOCKED_FLOOR,
|
|
4500
5043
|
SLIDEMOVE_BLOCKED_WALL,
|
|
5044
|
+
SOUND_FULLVOLUME,
|
|
5045
|
+
SOUND_LOOP_ATTENUATE,
|
|
4501
5046
|
STOP_EPSILON,
|
|
4502
5047
|
SURF_ALPHATEST,
|
|
4503
5048
|
SURF_FLOWING,
|
|
@@ -4514,6 +5059,7 @@ export {
|
|
|
4514
5059
|
SURF_TRANS66,
|
|
4515
5060
|
SURF_WARP,
|
|
4516
5061
|
ServerCommand,
|
|
5062
|
+
SoundChannel,
|
|
4517
5063
|
TempEntity,
|
|
4518
5064
|
UPDATE_BACKUP,
|
|
4519
5065
|
WEAPON_AMMO_MAP,
|
|
@@ -4539,12 +5085,14 @@ export {
|
|
|
4539
5085
|
applyPmoveFriction,
|
|
4540
5086
|
applyPmoveWaterMove,
|
|
4541
5087
|
assertContract,
|
|
5088
|
+
attenuationToDistanceMultiplier,
|
|
4542
5089
|
boxContents,
|
|
4543
5090
|
boxOnPlaneSide,
|
|
4544
5091
|
boxesIntersect,
|
|
4545
5092
|
buildAirGroundWish,
|
|
4546
5093
|
buildCollisionModel,
|
|
4547
5094
|
buildWaterWish,
|
|
5095
|
+
calculateMaxAudibleDistance,
|
|
4548
5096
|
categorizePosition,
|
|
4549
5097
|
checkDuckState,
|
|
4550
5098
|
checkJump,
|
|
@@ -4560,6 +5108,7 @@ export {
|
|
|
4560
5108
|
concatRotationMatrices,
|
|
4561
5109
|
configStringSize,
|
|
4562
5110
|
copyVec3,
|
|
5111
|
+
crc8,
|
|
4563
5112
|
createDefaultTrace,
|
|
4564
5113
|
createEmptyBounds3,
|
|
4565
5114
|
createMat4Identity,
|