quake2ts 0.0.286 → 0.0.289
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 +669 -79
- package/packages/client/dist/cjs/index.cjs.map +1 -1
- package/packages/client/dist/esm/index.js +669 -79
- package/packages/client/dist/esm/index.js.map +1 -1
- package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/client/dist/types/demo/handler.d.ts +9 -1
- package/packages/client/dist/types/demo/handler.d.ts.map +1 -1
- package/packages/client/dist/types/entities.d.ts +22 -2
- package/packages/client/dist/types/entities.d.ts.map +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 +327 -0
- package/packages/engine/dist/cjs/index.cjs.map +1 -1
- package/packages/engine/dist/esm/index.js +327 -0
- package/packages/engine/dist/esm/index.js.map +1 -1
- package/packages/engine/dist/tsconfig.tsbuildinfo +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 +492 -1
- package/packages/game/dist/cjs/index.cjs.map +1 -1
- package/packages/game/dist/esm/index.js +492 -1
- package/packages/game/dist/esm/index.js.map +1 -1
- package/packages/game/dist/tsconfig.tsbuildinfo +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 +509 -0
- package/packages/shared/dist/cjs/index.cjs.map +1 -1
- package/packages/shared/dist/esm/index.js +507 -0
- package/packages/shared/dist/esm/index.js.map +1 -1
- package/packages/shared/dist/tsconfig.tsbuildinfo +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
|
@@ -134,6 +134,7 @@ __export(index_exports, {
|
|
|
134
134
|
NUM_BITS_FOR_AMMO: () => NUM_BITS_FOR_AMMO,
|
|
135
135
|
NUM_BITS_FOR_POWERUP: () => NUM_BITS_FOR_POWERUP,
|
|
136
136
|
NUM_POWERUP_STATS: () => NUM_POWERUP_STATS,
|
|
137
|
+
NetChan: () => NetChan,
|
|
137
138
|
NetworkMessageBuilder: () => NetworkMessageBuilder,
|
|
138
139
|
PITCH: () => PITCH,
|
|
139
140
|
POWERUP_MAX: () => POWERUP_MAX,
|
|
@@ -212,6 +213,7 @@ __export(index_exports, {
|
|
|
212
213
|
concatRotationMatrices: () => concatRotationMatrices,
|
|
213
214
|
configStringSize: () => configStringSize,
|
|
214
215
|
copyVec3: () => copyVec3,
|
|
216
|
+
crc8: () => crc8,
|
|
215
217
|
createDefaultTrace: () => createDefaultTrace,
|
|
216
218
|
createEmptyBounds3: () => createEmptyBounds3,
|
|
217
219
|
createMat4Identity: () => createMat4Identity,
|
|
@@ -4094,6 +4096,273 @@ var RenderFx = /* @__PURE__ */ ((RenderFx2) => {
|
|
|
4094
4096
|
return RenderFx2;
|
|
4095
4097
|
})(RenderFx || {});
|
|
4096
4098
|
|
|
4099
|
+
// src/protocol/crc.ts
|
|
4100
|
+
var crc_table = [
|
|
4101
|
+
0,
|
|
4102
|
+
145,
|
|
4103
|
+
227,
|
|
4104
|
+
114,
|
|
4105
|
+
7,
|
|
4106
|
+
150,
|
|
4107
|
+
228,
|
|
4108
|
+
117,
|
|
4109
|
+
14,
|
|
4110
|
+
159,
|
|
4111
|
+
237,
|
|
4112
|
+
124,
|
|
4113
|
+
9,
|
|
4114
|
+
152,
|
|
4115
|
+
234,
|
|
4116
|
+
123,
|
|
4117
|
+
28,
|
|
4118
|
+
141,
|
|
4119
|
+
255,
|
|
4120
|
+
110,
|
|
4121
|
+
27,
|
|
4122
|
+
138,
|
|
4123
|
+
248,
|
|
4124
|
+
105,
|
|
4125
|
+
18,
|
|
4126
|
+
131,
|
|
4127
|
+
241,
|
|
4128
|
+
96,
|
|
4129
|
+
21,
|
|
4130
|
+
132,
|
|
4131
|
+
246,
|
|
4132
|
+
103,
|
|
4133
|
+
56,
|
|
4134
|
+
169,
|
|
4135
|
+
219,
|
|
4136
|
+
74,
|
|
4137
|
+
63,
|
|
4138
|
+
174,
|
|
4139
|
+
220,
|
|
4140
|
+
77,
|
|
4141
|
+
54,
|
|
4142
|
+
167,
|
|
4143
|
+
213,
|
|
4144
|
+
68,
|
|
4145
|
+
49,
|
|
4146
|
+
160,
|
|
4147
|
+
210,
|
|
4148
|
+
67,
|
|
4149
|
+
36,
|
|
4150
|
+
181,
|
|
4151
|
+
199,
|
|
4152
|
+
86,
|
|
4153
|
+
35,
|
|
4154
|
+
178,
|
|
4155
|
+
192,
|
|
4156
|
+
81,
|
|
4157
|
+
42,
|
|
4158
|
+
187,
|
|
4159
|
+
201,
|
|
4160
|
+
88,
|
|
4161
|
+
45,
|
|
4162
|
+
188,
|
|
4163
|
+
206,
|
|
4164
|
+
95,
|
|
4165
|
+
112,
|
|
4166
|
+
225,
|
|
4167
|
+
147,
|
|
4168
|
+
2,
|
|
4169
|
+
119,
|
|
4170
|
+
230,
|
|
4171
|
+
148,
|
|
4172
|
+
5,
|
|
4173
|
+
126,
|
|
4174
|
+
239,
|
|
4175
|
+
157,
|
|
4176
|
+
12,
|
|
4177
|
+
121,
|
|
4178
|
+
232,
|
|
4179
|
+
154,
|
|
4180
|
+
11,
|
|
4181
|
+
108,
|
|
4182
|
+
253,
|
|
4183
|
+
143,
|
|
4184
|
+
30,
|
|
4185
|
+
107,
|
|
4186
|
+
250,
|
|
4187
|
+
136,
|
|
4188
|
+
25,
|
|
4189
|
+
98,
|
|
4190
|
+
243,
|
|
4191
|
+
129,
|
|
4192
|
+
16,
|
|
4193
|
+
101,
|
|
4194
|
+
244,
|
|
4195
|
+
134,
|
|
4196
|
+
23,
|
|
4197
|
+
72,
|
|
4198
|
+
217,
|
|
4199
|
+
171,
|
|
4200
|
+
58,
|
|
4201
|
+
79,
|
|
4202
|
+
222,
|
|
4203
|
+
172,
|
|
4204
|
+
61,
|
|
4205
|
+
70,
|
|
4206
|
+
215,
|
|
4207
|
+
165,
|
|
4208
|
+
52,
|
|
4209
|
+
65,
|
|
4210
|
+
208,
|
|
4211
|
+
162,
|
|
4212
|
+
51,
|
|
4213
|
+
84,
|
|
4214
|
+
197,
|
|
4215
|
+
183,
|
|
4216
|
+
38,
|
|
4217
|
+
83,
|
|
4218
|
+
194,
|
|
4219
|
+
176,
|
|
4220
|
+
33,
|
|
4221
|
+
90,
|
|
4222
|
+
203,
|
|
4223
|
+
185,
|
|
4224
|
+
40,
|
|
4225
|
+
93,
|
|
4226
|
+
204,
|
|
4227
|
+
190,
|
|
4228
|
+
47,
|
|
4229
|
+
224,
|
|
4230
|
+
113,
|
|
4231
|
+
3,
|
|
4232
|
+
146,
|
|
4233
|
+
231,
|
|
4234
|
+
118,
|
|
4235
|
+
4,
|
|
4236
|
+
149,
|
|
4237
|
+
238,
|
|
4238
|
+
127,
|
|
4239
|
+
13,
|
|
4240
|
+
156,
|
|
4241
|
+
233,
|
|
4242
|
+
120,
|
|
4243
|
+
10,
|
|
4244
|
+
155,
|
|
4245
|
+
252,
|
|
4246
|
+
109,
|
|
4247
|
+
31,
|
|
4248
|
+
142,
|
|
4249
|
+
251,
|
|
4250
|
+
106,
|
|
4251
|
+
24,
|
|
4252
|
+
137,
|
|
4253
|
+
242,
|
|
4254
|
+
99,
|
|
4255
|
+
17,
|
|
4256
|
+
128,
|
|
4257
|
+
245,
|
|
4258
|
+
100,
|
|
4259
|
+
22,
|
|
4260
|
+
135,
|
|
4261
|
+
216,
|
|
4262
|
+
73,
|
|
4263
|
+
59,
|
|
4264
|
+
170,
|
|
4265
|
+
223,
|
|
4266
|
+
78,
|
|
4267
|
+
60,
|
|
4268
|
+
173,
|
|
4269
|
+
214,
|
|
4270
|
+
71,
|
|
4271
|
+
53,
|
|
4272
|
+
164,
|
|
4273
|
+
209,
|
|
4274
|
+
64,
|
|
4275
|
+
50,
|
|
4276
|
+
163,
|
|
4277
|
+
196,
|
|
4278
|
+
85,
|
|
4279
|
+
39,
|
|
4280
|
+
182,
|
|
4281
|
+
195,
|
|
4282
|
+
82,
|
|
4283
|
+
32,
|
|
4284
|
+
177,
|
|
4285
|
+
202,
|
|
4286
|
+
91,
|
|
4287
|
+
41,
|
|
4288
|
+
184,
|
|
4289
|
+
205,
|
|
4290
|
+
92,
|
|
4291
|
+
46,
|
|
4292
|
+
191,
|
|
4293
|
+
144,
|
|
4294
|
+
1,
|
|
4295
|
+
115,
|
|
4296
|
+
226,
|
|
4297
|
+
151,
|
|
4298
|
+
6,
|
|
4299
|
+
116,
|
|
4300
|
+
229,
|
|
4301
|
+
158,
|
|
4302
|
+
15,
|
|
4303
|
+
125,
|
|
4304
|
+
236,
|
|
4305
|
+
153,
|
|
4306
|
+
8,
|
|
4307
|
+
122,
|
|
4308
|
+
235,
|
|
4309
|
+
140,
|
|
4310
|
+
29,
|
|
4311
|
+
111,
|
|
4312
|
+
254,
|
|
4313
|
+
139,
|
|
4314
|
+
26,
|
|
4315
|
+
104,
|
|
4316
|
+
249,
|
|
4317
|
+
130,
|
|
4318
|
+
19,
|
|
4319
|
+
97,
|
|
4320
|
+
240,
|
|
4321
|
+
133,
|
|
4322
|
+
20,
|
|
4323
|
+
102,
|
|
4324
|
+
247,
|
|
4325
|
+
168,
|
|
4326
|
+
57,
|
|
4327
|
+
75,
|
|
4328
|
+
218,
|
|
4329
|
+
175,
|
|
4330
|
+
62,
|
|
4331
|
+
76,
|
|
4332
|
+
221,
|
|
4333
|
+
166,
|
|
4334
|
+
55,
|
|
4335
|
+
69,
|
|
4336
|
+
212,
|
|
4337
|
+
161,
|
|
4338
|
+
48,
|
|
4339
|
+
66,
|
|
4340
|
+
211,
|
|
4341
|
+
180,
|
|
4342
|
+
37,
|
|
4343
|
+
86,
|
|
4344
|
+
199,
|
|
4345
|
+
179,
|
|
4346
|
+
34,
|
|
4347
|
+
80,
|
|
4348
|
+
193,
|
|
4349
|
+
186,
|
|
4350
|
+
43,
|
|
4351
|
+
89,
|
|
4352
|
+
200,
|
|
4353
|
+
189,
|
|
4354
|
+
44,
|
|
4355
|
+
94,
|
|
4356
|
+
207
|
|
4357
|
+
];
|
|
4358
|
+
function crc8(data) {
|
|
4359
|
+
let crc = 0;
|
|
4360
|
+
for (let i = 0; i < data.length; i++) {
|
|
4361
|
+
crc = crc_table[(crc ^ data[i]) & 255];
|
|
4362
|
+
}
|
|
4363
|
+
return crc;
|
|
4364
|
+
}
|
|
4365
|
+
|
|
4097
4366
|
// src/protocol/entityFlags.ts
|
|
4098
4367
|
var entityFlags_exports = {};
|
|
4099
4368
|
__export(entityFlags_exports, {
|
|
@@ -4547,6 +4816,244 @@ var NetworkMessageBuilder = class {
|
|
|
4547
4816
|
}
|
|
4548
4817
|
};
|
|
4549
4818
|
|
|
4819
|
+
// src/net/netchan.ts
|
|
4820
|
+
var _NetChan = class _NetChan {
|
|
4821
|
+
constructor() {
|
|
4822
|
+
// +2 for reliable length prefix
|
|
4823
|
+
// Public state
|
|
4824
|
+
this.qport = 0;
|
|
4825
|
+
// qport value to distinguish multiple clients from same IP
|
|
4826
|
+
// Sequencing
|
|
4827
|
+
this.incomingSequence = 0;
|
|
4828
|
+
this.outgoingSequence = 0;
|
|
4829
|
+
this.incomingAcknowledged = 0;
|
|
4830
|
+
// Reliable messaging
|
|
4831
|
+
this.incomingReliableAcknowledged = false;
|
|
4832
|
+
// single bit
|
|
4833
|
+
this.incomingReliableSequence = 0;
|
|
4834
|
+
// last reliable message sequence received
|
|
4835
|
+
this.outgoingReliableSequence = 0;
|
|
4836
|
+
this.reliableLength = 0;
|
|
4837
|
+
// Timing
|
|
4838
|
+
this.lastReceived = 0;
|
|
4839
|
+
this.lastSent = 0;
|
|
4840
|
+
this.remoteAddress = null;
|
|
4841
|
+
this.reliableMessage = new BinaryWriter(_NetChan.MAX_MSGLEN);
|
|
4842
|
+
const now = Date.now();
|
|
4843
|
+
this.lastReceived = now;
|
|
4844
|
+
this.lastSent = now;
|
|
4845
|
+
this.qport = Math.floor(Math.random() * 65536);
|
|
4846
|
+
}
|
|
4847
|
+
/**
|
|
4848
|
+
* Setup the netchan with specific settings
|
|
4849
|
+
*/
|
|
4850
|
+
setup(qport, address = null) {
|
|
4851
|
+
this.qport = qport;
|
|
4852
|
+
this.remoteAddress = address;
|
|
4853
|
+
this.reset();
|
|
4854
|
+
}
|
|
4855
|
+
/**
|
|
4856
|
+
* Reset the netchan state
|
|
4857
|
+
*/
|
|
4858
|
+
reset() {
|
|
4859
|
+
this.incomingSequence = 0;
|
|
4860
|
+
this.outgoingSequence = 0;
|
|
4861
|
+
this.incomingAcknowledged = 0;
|
|
4862
|
+
this.incomingReliableAcknowledged = false;
|
|
4863
|
+
this.incomingReliableSequence = 0;
|
|
4864
|
+
this.outgoingReliableSequence = 0;
|
|
4865
|
+
this.reliableLength = 0;
|
|
4866
|
+
this.reliableMessage.reset();
|
|
4867
|
+
this.lastReceived = Date.now();
|
|
4868
|
+
this.lastSent = Date.now();
|
|
4869
|
+
}
|
|
4870
|
+
/**
|
|
4871
|
+
* Transmits a packet containing reliable and unreliable data
|
|
4872
|
+
*/
|
|
4873
|
+
transmit(unreliableData) {
|
|
4874
|
+
this.outgoingSequence++;
|
|
4875
|
+
this.lastSent = Date.now();
|
|
4876
|
+
const headerSize = _NetChan.PACKET_HEADER;
|
|
4877
|
+
const reliableSize = this.reliableLength > 0 ? this.reliableLength + 2 : 0;
|
|
4878
|
+
let unreliableSize = unreliableData ? unreliableData.length : 0;
|
|
4879
|
+
if (headerSize + reliableSize + unreliableSize > _NetChan.MAX_MSGLEN) {
|
|
4880
|
+
unreliableSize = _NetChan.MAX_MSGLEN - headerSize - reliableSize;
|
|
4881
|
+
if (unreliableSize < 0) unreliableSize = 0;
|
|
4882
|
+
}
|
|
4883
|
+
const buffer = new ArrayBuffer(headerSize + reliableSize + unreliableSize);
|
|
4884
|
+
const view = new DataView(buffer);
|
|
4885
|
+
const result = new Uint8Array(buffer);
|
|
4886
|
+
let sequence = this.outgoingSequence;
|
|
4887
|
+
if (this.reliableLength > 0) {
|
|
4888
|
+
sequence |= 2147483648;
|
|
4889
|
+
if ((this.outgoingReliableSequence & 1) !== 0) {
|
|
4890
|
+
sequence |= 1073741824;
|
|
4891
|
+
}
|
|
4892
|
+
}
|
|
4893
|
+
view.setUint32(0, sequence, true);
|
|
4894
|
+
let ack = this.incomingSequence;
|
|
4895
|
+
if ((this.incomingReliableSequence & 1) !== 0) {
|
|
4896
|
+
ack |= 2147483648;
|
|
4897
|
+
}
|
|
4898
|
+
view.setUint32(4, ack, true);
|
|
4899
|
+
view.setUint16(8, this.qport, true);
|
|
4900
|
+
let offset = headerSize;
|
|
4901
|
+
if (this.reliableLength > 0) {
|
|
4902
|
+
view.setUint16(offset, this.reliableLength, true);
|
|
4903
|
+
offset += 2;
|
|
4904
|
+
const reliableBuffer = this.reliableMessage.getBuffer();
|
|
4905
|
+
const reliableBytes = reliableBuffer.subarray(0, this.reliableLength);
|
|
4906
|
+
result.set(reliableBytes, offset);
|
|
4907
|
+
offset += this.reliableLength;
|
|
4908
|
+
}
|
|
4909
|
+
if (unreliableData && unreliableSize > 0) {
|
|
4910
|
+
const chunk = unreliableData.slice(0, unreliableSize);
|
|
4911
|
+
result.set(chunk, offset);
|
|
4912
|
+
}
|
|
4913
|
+
return result;
|
|
4914
|
+
}
|
|
4915
|
+
/**
|
|
4916
|
+
* Processes a received packet
|
|
4917
|
+
* Returns the payload data (reliable + unreliable) to be processed, or null if discarded
|
|
4918
|
+
*/
|
|
4919
|
+
process(packet) {
|
|
4920
|
+
if (packet.length < _NetChan.PACKET_HEADER) {
|
|
4921
|
+
return null;
|
|
4922
|
+
}
|
|
4923
|
+
this.lastReceived = Date.now();
|
|
4924
|
+
const view = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);
|
|
4925
|
+
const sequence = view.getUint32(0, true);
|
|
4926
|
+
const ack = view.getUint32(4, true);
|
|
4927
|
+
const qport = view.getUint16(8, true);
|
|
4928
|
+
if (this.qport !== qport) {
|
|
4929
|
+
return null;
|
|
4930
|
+
}
|
|
4931
|
+
const seqNumberClean = sequence & ~(2147483648 | 1073741824);
|
|
4932
|
+
if ((seqNumberClean - this.incomingSequence | 0) <= 0) {
|
|
4933
|
+
return null;
|
|
4934
|
+
}
|
|
4935
|
+
this.incomingSequence = seqNumberClean;
|
|
4936
|
+
const ackNumber = ack & ~2147483648;
|
|
4937
|
+
const ackReliable = (ack & 2147483648) !== 0;
|
|
4938
|
+
if (ackNumber > this.incomingAcknowledged) {
|
|
4939
|
+
this.incomingAcknowledged = ackNumber;
|
|
4940
|
+
}
|
|
4941
|
+
if (this.reliableLength > 0) {
|
|
4942
|
+
const receivedAckBit = ackReliable ? 1 : 0;
|
|
4943
|
+
const currentReliableBit = this.outgoingReliableSequence & 1;
|
|
4944
|
+
if (receivedAckBit !== currentReliableBit) {
|
|
4945
|
+
this.reliableLength = 0;
|
|
4946
|
+
this.reliableMessage.reset();
|
|
4947
|
+
this.outgoingReliableSequence ^= 1;
|
|
4948
|
+
}
|
|
4949
|
+
}
|
|
4950
|
+
const hasReliableData = (sequence & 2147483648) !== 0;
|
|
4951
|
+
const reliableSeqBit = (sequence & 1073741824) !== 0 ? 1 : 0;
|
|
4952
|
+
let payloadOffset = _NetChan.PACKET_HEADER;
|
|
4953
|
+
let reliableData = null;
|
|
4954
|
+
if (hasReliableData) {
|
|
4955
|
+
if (payloadOffset + 2 > packet.byteLength) return null;
|
|
4956
|
+
const reliableLen = view.getUint16(payloadOffset, true);
|
|
4957
|
+
payloadOffset += 2;
|
|
4958
|
+
const expectedBit = this.incomingReliableSequence & 1;
|
|
4959
|
+
if (reliableSeqBit === expectedBit) {
|
|
4960
|
+
this.incomingReliableSequence++;
|
|
4961
|
+
if (payloadOffset + reliableLen > packet.byteLength) return null;
|
|
4962
|
+
reliableData = packet.slice(payloadOffset, payloadOffset + reliableLen);
|
|
4963
|
+
}
|
|
4964
|
+
payloadOffset += reliableLen;
|
|
4965
|
+
}
|
|
4966
|
+
const unreliableData = packet.slice(payloadOffset);
|
|
4967
|
+
if (reliableData && reliableData.length > 0) {
|
|
4968
|
+
const totalLen = reliableData.length + unreliableData.length;
|
|
4969
|
+
const result = new Uint8Array(totalLen);
|
|
4970
|
+
result.set(reliableData, 0);
|
|
4971
|
+
result.set(unreliableData, reliableData.length);
|
|
4972
|
+
return result;
|
|
4973
|
+
}
|
|
4974
|
+
if (unreliableData) {
|
|
4975
|
+
return unreliableData;
|
|
4976
|
+
}
|
|
4977
|
+
return new Uint8Array(0);
|
|
4978
|
+
}
|
|
4979
|
+
/**
|
|
4980
|
+
* Checks if reliable message buffer is empty and ready for new data
|
|
4981
|
+
*/
|
|
4982
|
+
canSendReliable() {
|
|
4983
|
+
return this.reliableLength === 0;
|
|
4984
|
+
}
|
|
4985
|
+
/**
|
|
4986
|
+
* Writes a byte to the reliable message buffer
|
|
4987
|
+
*/
|
|
4988
|
+
writeReliableByte(value) {
|
|
4989
|
+
if (this.reliableLength + 1 > _NetChan.MAX_MSGLEN - _NetChan.HEADER_OVERHEAD) {
|
|
4990
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
4991
|
+
}
|
|
4992
|
+
this.reliableMessage.writeByte(value);
|
|
4993
|
+
this.reliableLength++;
|
|
4994
|
+
}
|
|
4995
|
+
/**
|
|
4996
|
+
* Writes a short to the reliable message buffer
|
|
4997
|
+
*/
|
|
4998
|
+
writeReliableShort(value) {
|
|
4999
|
+
if (this.reliableLength + 2 > _NetChan.MAX_MSGLEN - _NetChan.HEADER_OVERHEAD) {
|
|
5000
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
5001
|
+
}
|
|
5002
|
+
this.reliableMessage.writeShort(value);
|
|
5003
|
+
this.reliableLength += 2;
|
|
5004
|
+
}
|
|
5005
|
+
/**
|
|
5006
|
+
* Writes a long to the reliable message buffer
|
|
5007
|
+
*/
|
|
5008
|
+
writeReliableLong(value) {
|
|
5009
|
+
if (this.reliableLength + 4 > _NetChan.MAX_MSGLEN - _NetChan.HEADER_OVERHEAD) {
|
|
5010
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
5011
|
+
}
|
|
5012
|
+
this.reliableMessage.writeLong(value);
|
|
5013
|
+
this.reliableLength += 4;
|
|
5014
|
+
}
|
|
5015
|
+
/**
|
|
5016
|
+
* Writes a string to the reliable message buffer
|
|
5017
|
+
*/
|
|
5018
|
+
writeReliableString(value) {
|
|
5019
|
+
const len = value.length + 1;
|
|
5020
|
+
if (this.reliableLength + len > _NetChan.MAX_MSGLEN - _NetChan.HEADER_OVERHEAD) {
|
|
5021
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
5022
|
+
}
|
|
5023
|
+
this.reliableMessage.writeString(value);
|
|
5024
|
+
this.reliableLength += len;
|
|
5025
|
+
}
|
|
5026
|
+
/**
|
|
5027
|
+
* Returns the current reliable data buffer
|
|
5028
|
+
*/
|
|
5029
|
+
getReliableData() {
|
|
5030
|
+
if (this.reliableLength === 0) {
|
|
5031
|
+
return new Uint8Array(0);
|
|
5032
|
+
}
|
|
5033
|
+
const buffer = this.reliableMessage.getBuffer();
|
|
5034
|
+
return buffer.subarray(0, this.reliableLength);
|
|
5035
|
+
}
|
|
5036
|
+
/**
|
|
5037
|
+
* Checks if we need to send a keepalive packet
|
|
5038
|
+
*/
|
|
5039
|
+
needsKeepalive(currentTime) {
|
|
5040
|
+
return currentTime - this.lastSent > 1e3;
|
|
5041
|
+
}
|
|
5042
|
+
/**
|
|
5043
|
+
* Checks if the connection has timed out
|
|
5044
|
+
*/
|
|
5045
|
+
isTimedOut(currentTime, timeoutMs = 3e4) {
|
|
5046
|
+
return currentTime - this.lastReceived > timeoutMs;
|
|
5047
|
+
}
|
|
5048
|
+
};
|
|
5049
|
+
// Constants from net_chan.c
|
|
5050
|
+
_NetChan.MAX_MSGLEN = 1400;
|
|
5051
|
+
_NetChan.FRAGMENT_SIZE = 1024;
|
|
5052
|
+
_NetChan.PACKET_HEADER = 10;
|
|
5053
|
+
// sequence(4) + ack(4) + qport(2)
|
|
5054
|
+
_NetChan.HEADER_OVERHEAD = _NetChan.PACKET_HEADER + 2;
|
|
5055
|
+
var NetChan = _NetChan;
|
|
5056
|
+
|
|
4550
5057
|
// src/items/weapons.ts
|
|
4551
5058
|
var WeaponId = /* @__PURE__ */ ((WeaponId2) => {
|
|
4552
5059
|
WeaponId2["Blaster"] = "blaster";
|
|
@@ -4760,6 +5267,7 @@ var WEAPON_AMMO_MAP = {
|
|
|
4760
5267
|
NUM_BITS_FOR_AMMO,
|
|
4761
5268
|
NUM_BITS_FOR_POWERUP,
|
|
4762
5269
|
NUM_POWERUP_STATS,
|
|
5270
|
+
NetChan,
|
|
4763
5271
|
NetworkMessageBuilder,
|
|
4764
5272
|
PITCH,
|
|
4765
5273
|
POWERUP_MAX,
|
|
@@ -4838,6 +5346,7 @@ var WEAPON_AMMO_MAP = {
|
|
|
4838
5346
|
concatRotationMatrices,
|
|
4839
5347
|
configStringSize,
|
|
4840
5348
|
copyVec3,
|
|
5349
|
+
crc8,
|
|
4841
5350
|
createDefaultTrace,
|
|
4842
5351
|
createEmptyBounds3,
|
|
4843
5352
|
createMat4Identity,
|