mcbe-ipc 2.0.1 → 3.0.1
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/LICENSE +1 -1
- package/README.md +1 -71
- package/dist/direct.ipc.d.ts +61 -0
- package/dist/direct.ipc.js +369 -0
- package/dist/ipc.d.ts +69 -56
- package/dist/ipc.js +492 -426
- package/dist/proto.d.ts +82 -0
- package/dist/proto.js +396 -0
- package/package.json +7 -7
- package/dist/ipc.min.js +0 -1
package/dist/proto.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* MIT License
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2025 OmniacDev
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
export declare namespace PROTO {
|
|
26
|
+
interface Serializable<T> {
|
|
27
|
+
serialize(value: T, stream: ByteQueue): Generator<void, void, void>;
|
|
28
|
+
deserialize(stream: ByteQueue): Generator<void, T, void>;
|
|
29
|
+
}
|
|
30
|
+
class ByteQueue {
|
|
31
|
+
private _buffer;
|
|
32
|
+
private _data_view;
|
|
33
|
+
private _length;
|
|
34
|
+
private _offset;
|
|
35
|
+
get end(): number;
|
|
36
|
+
get front(): number;
|
|
37
|
+
get data_view(): DataView;
|
|
38
|
+
constructor(size?: number);
|
|
39
|
+
write(...values: number[]): void;
|
|
40
|
+
read(amount?: number): number[];
|
|
41
|
+
ensure_capacity(size: number): void;
|
|
42
|
+
static from_uint8array(array: Uint8Array): ByteQueue;
|
|
43
|
+
to_uint8array(): Uint8Array;
|
|
44
|
+
}
|
|
45
|
+
namespace MIPS {
|
|
46
|
+
function serialize(byte_queue: PROTO.ByteQueue): Generator<void, string, void>;
|
|
47
|
+
function deserialize(str: string): Generator<void, PROTO.ByteQueue, void>;
|
|
48
|
+
}
|
|
49
|
+
const Void: PROTO.Serializable<void>;
|
|
50
|
+
const Int8: PROTO.Serializable<number>;
|
|
51
|
+
const Int16: PROTO.Serializable<number>;
|
|
52
|
+
const Int32: PROTO.Serializable<number>;
|
|
53
|
+
const UInt8: PROTO.Serializable<number>;
|
|
54
|
+
const UInt16: PROTO.Serializable<number>;
|
|
55
|
+
const UInt32: PROTO.Serializable<number>;
|
|
56
|
+
const UVarInt32: PROTO.Serializable<number>;
|
|
57
|
+
const Float32: PROTO.Serializable<number>;
|
|
58
|
+
const Float64: PROTO.Serializable<number>;
|
|
59
|
+
const String: PROTO.Serializable<string>;
|
|
60
|
+
const Boolean: PROTO.Serializable<boolean>;
|
|
61
|
+
const UInt8Array: PROTO.Serializable<Uint8Array>;
|
|
62
|
+
const Date: PROTO.Serializable<Date>;
|
|
63
|
+
function Object<T extends object>(obj: {
|
|
64
|
+
[K in keyof T]: PROTO.Serializable<T[K]>;
|
|
65
|
+
}): PROTO.Serializable<T>;
|
|
66
|
+
function Array<T>(value: PROTO.Serializable<T>): PROTO.Serializable<T[]>;
|
|
67
|
+
function Tuple<T extends any[]>(...values: {
|
|
68
|
+
[K in keyof T]: PROTO.Serializable<T[K]>;
|
|
69
|
+
}): PROTO.Serializable<T>;
|
|
70
|
+
function Optional<T>(value: PROTO.Serializable<T>): PROTO.Serializable<T | undefined>;
|
|
71
|
+
function Map<K, V>(key: PROTO.Serializable<K>, value: PROTO.Serializable<V>): PROTO.Serializable<Map<K, V>>;
|
|
72
|
+
function Set<V>(value: PROTO.Serializable<V>): PROTO.Serializable<Set<V>>;
|
|
73
|
+
type Endpoint = string;
|
|
74
|
+
type Header = {
|
|
75
|
+
guid: string;
|
|
76
|
+
encoding: string;
|
|
77
|
+
index: number;
|
|
78
|
+
final: boolean;
|
|
79
|
+
};
|
|
80
|
+
const Endpoint: PROTO.Serializable<Endpoint>;
|
|
81
|
+
const Header: PROTO.Serializable<Header>;
|
|
82
|
+
}
|
package/dist/proto.js
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* MIT License
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2025 OmniacDev
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
export var PROTO;
|
|
26
|
+
(function (PROTO) {
|
|
27
|
+
class ByteQueue {
|
|
28
|
+
get end() {
|
|
29
|
+
return this._length + this._offset;
|
|
30
|
+
}
|
|
31
|
+
get front() {
|
|
32
|
+
return this._offset;
|
|
33
|
+
}
|
|
34
|
+
get data_view() {
|
|
35
|
+
return this._data_view;
|
|
36
|
+
}
|
|
37
|
+
constructor(size = 256) {
|
|
38
|
+
this._buffer = new Uint8Array(size);
|
|
39
|
+
this._data_view = new DataView(this._buffer.buffer);
|
|
40
|
+
this._length = 0;
|
|
41
|
+
this._offset = 0;
|
|
42
|
+
}
|
|
43
|
+
write(...values) {
|
|
44
|
+
this.ensure_capacity(values.length);
|
|
45
|
+
this._buffer.set(values, this.end);
|
|
46
|
+
this._length += values.length;
|
|
47
|
+
}
|
|
48
|
+
read(amount = 1) {
|
|
49
|
+
if (this._length > 0) {
|
|
50
|
+
const max_amount = amount > this._length ? this._length : amount;
|
|
51
|
+
const values = this._buffer.subarray(this._offset, this._offset + max_amount);
|
|
52
|
+
this._length -= max_amount;
|
|
53
|
+
this._offset += max_amount;
|
|
54
|
+
return globalThis.Array.from(values);
|
|
55
|
+
}
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
ensure_capacity(size) {
|
|
59
|
+
if (this.end + size > this._buffer.length) {
|
|
60
|
+
const larger_buffer = new Uint8Array((this.end + size) * 2);
|
|
61
|
+
larger_buffer.set(this._buffer.subarray(this._offset, this.end), 0);
|
|
62
|
+
this._buffer = larger_buffer;
|
|
63
|
+
this._offset = 0;
|
|
64
|
+
this._data_view = new DataView(this._buffer.buffer);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
static from_uint8array(array) {
|
|
68
|
+
const byte_queue = new ByteQueue();
|
|
69
|
+
byte_queue._buffer = array;
|
|
70
|
+
byte_queue._length = array.length;
|
|
71
|
+
byte_queue._offset = 0;
|
|
72
|
+
byte_queue._data_view = new DataView(array.buffer);
|
|
73
|
+
return byte_queue;
|
|
74
|
+
}
|
|
75
|
+
to_uint8array() {
|
|
76
|
+
return this._buffer.subarray(this._offset, this.end);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
PROTO.ByteQueue = ByteQueue;
|
|
80
|
+
let MIPS;
|
|
81
|
+
(function (MIPS) {
|
|
82
|
+
function* serialize(byte_queue) {
|
|
83
|
+
const uint8array = byte_queue.to_uint8array();
|
|
84
|
+
let str = '(0x';
|
|
85
|
+
for (let i = 0; i < uint8array.length; i++) {
|
|
86
|
+
const hex = uint8array[i].toString(16).padStart(2, '0').toUpperCase();
|
|
87
|
+
str += hex;
|
|
88
|
+
yield;
|
|
89
|
+
}
|
|
90
|
+
str += ')';
|
|
91
|
+
return str;
|
|
92
|
+
}
|
|
93
|
+
MIPS.serialize = serialize;
|
|
94
|
+
function* deserialize(str) {
|
|
95
|
+
if (str.startsWith('(0x') && str.endsWith(')')) {
|
|
96
|
+
const result = [];
|
|
97
|
+
const hex_str = str.slice(3, str.length - 1);
|
|
98
|
+
for (let i = 0; i < hex_str.length; i++) {
|
|
99
|
+
const hex = hex_str[i] + hex_str[++i];
|
|
100
|
+
result.push(parseInt(hex, 16));
|
|
101
|
+
yield;
|
|
102
|
+
}
|
|
103
|
+
return ByteQueue.from_uint8array(new Uint8Array(result));
|
|
104
|
+
}
|
|
105
|
+
return new ByteQueue();
|
|
106
|
+
}
|
|
107
|
+
MIPS.deserialize = deserialize;
|
|
108
|
+
})(MIPS = PROTO.MIPS || (PROTO.MIPS = {}));
|
|
109
|
+
PROTO.Void = {
|
|
110
|
+
*serialize() { },
|
|
111
|
+
*deserialize() { }
|
|
112
|
+
};
|
|
113
|
+
PROTO.Int8 = {
|
|
114
|
+
*serialize(value, stream) {
|
|
115
|
+
const length = 1;
|
|
116
|
+
stream.write(...globalThis.Array(length).fill(0));
|
|
117
|
+
stream.data_view.setInt8(stream.end - length, value);
|
|
118
|
+
},
|
|
119
|
+
*deserialize(stream) {
|
|
120
|
+
const value = stream.data_view.getInt8(stream.front);
|
|
121
|
+
stream.read(1);
|
|
122
|
+
return value;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
PROTO.Int16 = {
|
|
126
|
+
*serialize(value, stream) {
|
|
127
|
+
const length = 2;
|
|
128
|
+
stream.write(...globalThis.Array(length).fill(0));
|
|
129
|
+
stream.data_view.setInt16(stream.end - length, value);
|
|
130
|
+
},
|
|
131
|
+
*deserialize(stream) {
|
|
132
|
+
const value = stream.data_view.getInt16(stream.front);
|
|
133
|
+
stream.read(2);
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
PROTO.Int32 = {
|
|
138
|
+
*serialize(value, stream) {
|
|
139
|
+
const length = 4;
|
|
140
|
+
stream.write(...globalThis.Array(length).fill(0));
|
|
141
|
+
stream.data_view.setInt32(stream.end - length, value);
|
|
142
|
+
},
|
|
143
|
+
*deserialize(stream) {
|
|
144
|
+
const value = stream.data_view.getInt32(stream.front);
|
|
145
|
+
stream.read(4);
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
PROTO.UInt8 = {
|
|
150
|
+
*serialize(value, stream) {
|
|
151
|
+
const length = 1;
|
|
152
|
+
stream.write(...globalThis.Array(length).fill(0));
|
|
153
|
+
stream.data_view.setUint8(stream.end - length, value);
|
|
154
|
+
},
|
|
155
|
+
*deserialize(stream) {
|
|
156
|
+
const value = stream.data_view.getUint8(stream.front);
|
|
157
|
+
stream.read(1);
|
|
158
|
+
return value;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
PROTO.UInt16 = {
|
|
162
|
+
*serialize(value, stream) {
|
|
163
|
+
const length = 2;
|
|
164
|
+
stream.write(...globalThis.Array(length).fill(0));
|
|
165
|
+
stream.data_view.setUint16(stream.end - length, value);
|
|
166
|
+
},
|
|
167
|
+
*deserialize(stream) {
|
|
168
|
+
const value = stream.data_view.getUint16(stream.front);
|
|
169
|
+
stream.read(2);
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
PROTO.UInt32 = {
|
|
174
|
+
*serialize(value, stream) {
|
|
175
|
+
const length = 4;
|
|
176
|
+
stream.write(...globalThis.Array(length).fill(0));
|
|
177
|
+
stream.data_view.setUint32(stream.end - length, value);
|
|
178
|
+
},
|
|
179
|
+
*deserialize(stream) {
|
|
180
|
+
const value = stream.data_view.getUint32(stream.front);
|
|
181
|
+
stream.read(4);
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
PROTO.UVarInt32 = {
|
|
186
|
+
*serialize(value, stream) {
|
|
187
|
+
while (value >= 0x80) {
|
|
188
|
+
stream.write((value & 0x7f) | 0x80);
|
|
189
|
+
value >>= 7;
|
|
190
|
+
yield;
|
|
191
|
+
}
|
|
192
|
+
stream.write(value);
|
|
193
|
+
},
|
|
194
|
+
*deserialize(stream) {
|
|
195
|
+
let value = 0;
|
|
196
|
+
let size = 0;
|
|
197
|
+
let byte;
|
|
198
|
+
do {
|
|
199
|
+
byte = stream.read()[0];
|
|
200
|
+
value |= (byte & 0x7f) << (size * 7);
|
|
201
|
+
size += 1;
|
|
202
|
+
yield;
|
|
203
|
+
} while ((byte & 0x80) !== 0 && size < 10);
|
|
204
|
+
return value;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
PROTO.Float32 = {
|
|
208
|
+
*serialize(value, stream) {
|
|
209
|
+
const length = 4;
|
|
210
|
+
stream.write(...globalThis.Array(length).fill(0));
|
|
211
|
+
stream.data_view.setFloat32(stream.end - length, value);
|
|
212
|
+
},
|
|
213
|
+
*deserialize(stream) {
|
|
214
|
+
const value = stream.data_view.getFloat32(stream.front);
|
|
215
|
+
stream.read(4);
|
|
216
|
+
return value;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
PROTO.Float64 = {
|
|
220
|
+
*serialize(value, stream) {
|
|
221
|
+
const length = 8;
|
|
222
|
+
stream.write(...globalThis.Array(length).fill(0));
|
|
223
|
+
stream.data_view.setFloat64(stream.end - length, value);
|
|
224
|
+
},
|
|
225
|
+
*deserialize(stream) {
|
|
226
|
+
const value = stream.data_view.getFloat64(stream.front);
|
|
227
|
+
stream.read(8);
|
|
228
|
+
return value;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
PROTO.String = {
|
|
232
|
+
*serialize(value, stream) {
|
|
233
|
+
yield* PROTO.UVarInt32.serialize(value.length, stream);
|
|
234
|
+
for (let i = 0; i < value.length; i++) {
|
|
235
|
+
const code = value.charCodeAt(i);
|
|
236
|
+
yield* PROTO.UVarInt32.serialize(code, stream);
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
*deserialize(stream) {
|
|
240
|
+
const length = yield* PROTO.UVarInt32.deserialize(stream);
|
|
241
|
+
let value = '';
|
|
242
|
+
for (let i = 0; i < length; i++) {
|
|
243
|
+
const code = yield* PROTO.UVarInt32.deserialize(stream);
|
|
244
|
+
value += globalThis.String.fromCharCode(code);
|
|
245
|
+
}
|
|
246
|
+
return value;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
PROTO.Boolean = {
|
|
250
|
+
*serialize(value, stream) {
|
|
251
|
+
stream.write(value ? 1 : 0);
|
|
252
|
+
},
|
|
253
|
+
*deserialize(stream) {
|
|
254
|
+
const value = stream.read()[0];
|
|
255
|
+
return value === 1;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
PROTO.UInt8Array = {
|
|
259
|
+
*serialize(value, stream) {
|
|
260
|
+
yield* PROTO.UVarInt32.serialize(value.length, stream);
|
|
261
|
+
stream.write(...value);
|
|
262
|
+
},
|
|
263
|
+
*deserialize(stream) {
|
|
264
|
+
const length = yield* PROTO.UVarInt32.deserialize(stream);
|
|
265
|
+
return new Uint8Array(stream.read(length));
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
PROTO.Date = {
|
|
269
|
+
*serialize(value, stream) {
|
|
270
|
+
yield* PROTO.Float64.serialize(value.getTime(), stream);
|
|
271
|
+
},
|
|
272
|
+
*deserialize(stream) {
|
|
273
|
+
return new globalThis.Date(yield* PROTO.Float64.deserialize(stream));
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
function Object(obj) {
|
|
277
|
+
return {
|
|
278
|
+
*serialize(value, stream) {
|
|
279
|
+
for (const key in obj) {
|
|
280
|
+
yield* obj[key].serialize(value[key], stream);
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
*deserialize(stream) {
|
|
284
|
+
const result = {};
|
|
285
|
+
for (const key in obj) {
|
|
286
|
+
result[key] = yield* obj[key].deserialize(stream);
|
|
287
|
+
}
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
PROTO.Object = Object;
|
|
293
|
+
function Array(value) {
|
|
294
|
+
return {
|
|
295
|
+
*serialize(array, stream) {
|
|
296
|
+
yield* PROTO.UVarInt32.serialize(array.length, stream);
|
|
297
|
+
for (const item of array) {
|
|
298
|
+
yield* value.serialize(item, stream);
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
*deserialize(stream) {
|
|
302
|
+
const result = [];
|
|
303
|
+
const length = yield* PROTO.UVarInt32.deserialize(stream);
|
|
304
|
+
for (let i = 0; i < length; i++) {
|
|
305
|
+
result[i] = yield* value.deserialize(stream);
|
|
306
|
+
}
|
|
307
|
+
return result;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
PROTO.Array = Array;
|
|
312
|
+
function Tuple(...values) {
|
|
313
|
+
return {
|
|
314
|
+
*serialize(tuple, stream) {
|
|
315
|
+
for (let i = 0; i < values.length; i++) {
|
|
316
|
+
yield* values[i].serialize(tuple[i], stream);
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
*deserialize(stream) {
|
|
320
|
+
const result = [];
|
|
321
|
+
for (let i = 0; i < values.length; i++) {
|
|
322
|
+
result[i] = yield* values[i].deserialize(stream);
|
|
323
|
+
}
|
|
324
|
+
return result;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
PROTO.Tuple = Tuple;
|
|
329
|
+
function Optional(value) {
|
|
330
|
+
return {
|
|
331
|
+
*serialize(optional, stream) {
|
|
332
|
+
yield* PROTO.Boolean.serialize(value !== undefined, stream);
|
|
333
|
+
if (optional !== undefined) {
|
|
334
|
+
yield* value.serialize(optional, stream);
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
*deserialize(stream) {
|
|
338
|
+
const defined = yield* PROTO.Boolean.deserialize(stream);
|
|
339
|
+
if (defined) {
|
|
340
|
+
return yield* value.deserialize(stream);
|
|
341
|
+
}
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
PROTO.Optional = Optional;
|
|
347
|
+
function Map(key, value) {
|
|
348
|
+
return {
|
|
349
|
+
*serialize(map, stream) {
|
|
350
|
+
yield* PROTO.UVarInt32.serialize(map.size, stream);
|
|
351
|
+
for (const [k, v] of map.entries()) {
|
|
352
|
+
yield* key.serialize(k, stream);
|
|
353
|
+
yield* value.serialize(v, stream);
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
*deserialize(stream) {
|
|
357
|
+
const size = yield* PROTO.UVarInt32.deserialize(stream);
|
|
358
|
+
const result = new globalThis.Map();
|
|
359
|
+
for (let i = 0; i < size; i++) {
|
|
360
|
+
const k = yield* key.deserialize(stream);
|
|
361
|
+
const v = yield* value.deserialize(stream);
|
|
362
|
+
result.set(k, v);
|
|
363
|
+
}
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
PROTO.Map = Map;
|
|
369
|
+
function Set(value) {
|
|
370
|
+
return {
|
|
371
|
+
*serialize(set, stream) {
|
|
372
|
+
yield* PROTO.UVarInt32.serialize(set.size, stream);
|
|
373
|
+
for (const [_, v] of set.entries()) {
|
|
374
|
+
yield* value.serialize(v, stream);
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
*deserialize(stream) {
|
|
378
|
+
const size = yield* PROTO.UVarInt32.deserialize(stream);
|
|
379
|
+
const result = new globalThis.Set();
|
|
380
|
+
for (let i = 0; i < size; i++) {
|
|
381
|
+
const v = yield* value.deserialize(stream);
|
|
382
|
+
result.add(v);
|
|
383
|
+
}
|
|
384
|
+
return result;
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
PROTO.Set = Set;
|
|
389
|
+
PROTO.Endpoint = PROTO.String;
|
|
390
|
+
PROTO.Header = PROTO.Object({
|
|
391
|
+
guid: PROTO.String,
|
|
392
|
+
encoding: PROTO.String,
|
|
393
|
+
index: PROTO.UVarInt32,
|
|
394
|
+
final: PROTO.Boolean
|
|
395
|
+
});
|
|
396
|
+
})(PROTO || (PROTO = {}));
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "OmniacDev",
|
|
4
4
|
"description": "IPC system for MCBE Script API projects",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "
|
|
6
|
+
"version": "3.0.1",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/OmniacDev/mcbe-ipc.git"
|
|
@@ -15,17 +15,17 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"main": "dist/ipc.js",
|
|
17
17
|
"types": "dist/ipc.d.ts",
|
|
18
|
-
"files": [
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
19
21
|
"scripts": {
|
|
20
|
-
"build": "tsc
|
|
22
|
+
"build": "tsc",
|
|
21
23
|
"format": "prettier --write src",
|
|
22
|
-
"
|
|
23
|
-
"prepublishOnly": "npm run build-clean"
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"prettier": "^3.3.3",
|
|
27
|
-
"typescript": "^5.5.4"
|
|
28
|
-
"uglify-js": "^3.19.3"
|
|
28
|
+
"typescript": "^5.5.4"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@minecraft/server": "^1.13.0"
|
package/dist/ipc.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{world,system,ScriptEventSource}from"@minecraft/server";var IPC,SERDE,CRYPTO,NET;(e=>{class _{*MAYBE_ENCRYPT(e){return!1!==this._enc?yield*CRYPTO.encrypt(JSON.stringify(e),this._enc):e}*MAYBE_DECRYPT(e){return!1!==this._enc?JSON.parse(yield*CRYPTO.decrypt(e[1],this._enc)):e[1]}get from(){return this._from}get to(){return this._to}constructor(e,t,n){this._from=e,this._to=t,this._enc=n,this._terminators=new Array}terminate(e=!0){var t=this;t._terminators.forEach(e=>e()),t._terminators.length=0,e&&system.runJob(NET.emit("ipc",t._to+":terminate",[t._from]))}send(t,...n){let i=this;system.runJob(function*(){var e=yield*i.MAYBE_ENCRYPT(n);yield*NET.emit("ipc",i._to+`:${t}:send`,[i._from,e])}())}invoke(i,...t){let r=this;return system.runJob(function*(){var e=yield*r.MAYBE_ENCRYPT(t);yield*NET.emit("ipc",r._to+`:${i}:invoke`,[r._from,e])}()),new Promise(t=>{let n=NET.listen("ipc",r._from+`:${i}:handle`,function*(e){e[0]===r._to&&(e=yield*r.MAYBE_DECRYPT(e),t(e),n())})})}on(e,t){let n=this;e=NET.listen("ipc",n._from+`:${e}:send`,function*(e){e[0]===n._to&&(e=yield*n.MAYBE_DECRYPT(e),t(...e))});return n._terminators.push(e),e}once(e,t){let n=this,i=NET.listen("ipc",n._from+`:${e}:send`,function*(e){e[0]===n._to&&(e=yield*n.MAYBE_DECRYPT(e),t(...e),i())});return n._terminators.push(i),i}handle(t,n){let i=this;var e=NET.listen("ipc",i._from+`:${t}:invoke`,function*(e){e[0]===i._to&&(e=yield*i.MAYBE_DECRYPT(e),e=n(...e),e=yield*i.MAYBE_ENCRYPT([e]),yield*NET.emit("ipc",i._to+`:${t}:handle`,[i._from,e]))});return i._terminators.push(e),e}}e.Connection=_,e.ConnectionManager=class{*MAYBE_ENCRYPT(e,t){return!1!==t?yield*CRYPTO.encrypt(JSON.stringify(e),t):e}*MAYBE_DECRYPT(e,t){return!1!==t?JSON.parse(yield*CRYPTO.decrypt(e[1],t)):e[1]}get id(){return this._id}constructor(e,t=!1){let i=this;this._id=e,this._enc_map=new Map,this._con_map=new Map,this._enc_force=t,NET.listen("ipc",this._id+":handshake:SYN",function*(e){var t=CRYPTO.make_secret(e[4]),n=yield*CRYPTO.make_public(t,e[4],e[3]),t=!(1!==e[1]&&!i._enc_force)&&(yield*CRYPTO.make_shared(t,e[2],e[3]));i._enc_map.set(e[0],t),yield*NET.emit("ipc",e[0]+":handshake:ACK",[i._id,i._enc_force?1:0,n])}),NET.listen("ipc",this._id+":terminate",function*(e){i._enc_map.delete(e[0])})}connect(l,d=!1,c=20){let a=this;return new Promise((r,o)=>{var e=this._con_map.get(l);if(void 0!==e)e.terminate(!1),r(e);else{let t=CRYPTO.make_secret(),n=d?1:0;function s(){i(),system.clearRun(e)}system.runJob(function*(){var e=yield*CRYPTO.make_public(t);yield*NET.emit("ipc",l+":handshake:SYN",[a._id,n,e,CRYPTO.PRIME,CRYPTO.MOD])}());let e=system.runTimeout(()=>{o(),s()},c),i=NET.listen("ipc",this._id+":handshake:ACK",function*(e){e[0]===l&&(e=!(1!==e[1]&&!d)&&(yield*CRYPTO.make_shared(t,e[2])),e=new _(a._id,l,e),a._con_map.set(l,e),r(e),s())})}})}send(n,...i){let r=this;system.runJob(function*(){for(var[e,t]of r._enc_map){t=yield*r.MAYBE_ENCRYPT(i,t);yield*NET.emit("ipc",e+`:${n}:send`,[r._id,t])}}())}invoke(o,...t){let s=this;var e=[];for(let[i,r]of s._enc_map)system.runJob(function*(){var e=yield*s.MAYBE_ENCRYPT(t,r);yield*NET.emit("ipc",i+`:${o}:invoke`,[s._id,e])}()),e.push(new Promise(t=>{let n=NET.listen("ipc",s._id+`:${o}:handle`,function*(e){e[0]===i&&(e=yield*s.MAYBE_DECRYPT(e,r),t(e),n())})}));return e}on(e,n){let i=this;return NET.listen("ipc",i._id+`:${e}:send`,function*(e){var t=i._enc_map.get(e[0]);void 0!==t&&(e=yield*i.MAYBE_DECRYPT(e,t),n(...e))})}once(e,n){let i=this,r=NET.listen("ipc",i._id+`:${e}:send`,function*(e){var t=i._enc_map.get(e[0]);void 0!==t&&(e=yield*i.MAYBE_DECRYPT(e,t),n(...e),r())});return r}handle(i,r){let o=this;return NET.listen("ipc",o._id+`:${i}:invoke`,function*(e){var t,n=o._enc_map.get(e[0]);void 0!==n&&(t=yield*o.MAYBE_DECRYPT(e,n),t=r(...t),t=yield*o.MAYBE_ENCRYPT([t],n),yield*NET.emit("ipc",e[0]+`:${i}:handle`,[o._id,t]))})}},e.send=function(e,...t){system.runJob(NET.emit("ipc",e+":send",t))},e.invoke=function(e,...t){return system.runJob(NET.emit("ipc",e+":invoke",t)),new Promise(t=>{let n=NET.listen("ipc",e+":handle",function*(e){t(e[0]),n()})})},e.on=function(e,t){return NET.listen("ipc",e+":send",function*(e){t(...e)})},e.once=function(e,t){let n=NET.listen("ipc",e+":send",function*(e){t(...e),n()});return n},e.handle=function(t,n){return NET.listen("ipc",t+":invoke",function*(e){e=n(...e);yield*NET.emit("ipc",t+":handle",[e])})}})(IPC=IPC||{});export default IPC;(e=>{let o=[48,49,50,51,52,53,54,55,56,57],s=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,42,43,44,47,58,59,60,61,62,63,64,91,92,93,94,96,123,124,125,126,127],r=/\?[0-9a-zA-Z.\-]{2}|[^?]+/g,l=/^\?[0-9a-zA-Z.\-]{2}$/,d="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-";e.encode=function*(t){let n="";for(let e=0;e<t.length;e++){var i=t.charAt(e),r=i.charCodeAt(0);0===e&&o.includes(r)||s.includes(r)?n+="?"+(yield*function*(t){let n="";for(let e=t.charCodeAt(0);0<e;e=Math.floor(e/64))n=d[e%64]+n,yield;return n}(i)).padStart(2,"0"):n+=i,yield}return n},e.decode=function*(e){let t="";var n=e.match(r)??[];for(let e=0;e<n.length;e++){var i=n[e];i.startsWith("?")&&l.test(i)?t+=yield*function*(t){let n=0;for(let e=0;e<t.length;e++)n+=64**(t.length-1-e)*d.indexOf(t[e]),yield;return String.fromCharCode(n)}(i.slice(1)):t+=i,yield}return t}})(SERDE=SERDE||{}),(i=>{i.PRIME=19893121,i.MOD=341;let r=e=>e.toString(16).toUpperCase();function*o(e,t,n){let i=1,r=e%n;for(let e=t;0<e;e=Math.floor(e/2))e%2==1&&(i=i*r%n),r=r*r%n,yield;return i}i.make_secret=function(e=i.MOD){return Math.floor(Math.random()*(e-1))+1},i.make_public=function*(e,t=i.MOD,n=i.PRIME){return r(yield*o(t,e,n))},i.make_shared=function*(e,t,n=i.PRIME){return r(yield*o(parseInt(t,16),e,n))},i.encrypt=function*(t,n){let i="";for(let e=0;e<t.length;e++)i+=String.fromCharCode(t.charCodeAt(e)^n.charCodeAt(e%n.length)),yield;return i},i.decrypt=function*(t,n){let i="";for(let e=0;e<t.length;e++)i+=String.fromCharCode(t.charCodeAt(e)^n.charCodeAt(e%n.length)),yield;return i}})(CRYPTO=CRYPTO||{}),(e=>{let o=new Map;system.afterEvents.scriptEventReceive.subscribe(r=>{system.runJob(function*(){var e=r.id.split(":"),t=yield*SERDE.decode(e[0]),n=o.get(t);if(r.sourceType===ScriptEventSource.Server&&n){var i=E.fromString(yield*SERDE.decode(e[1]));for(let e=0;e<n.length;e++)yield*n[e](i,r.message)}}())});let E;var t;(t=E=E||{}).toString=function(e){return JSON.stringify(e)},t.fromString=function(e){return JSON.parse(e)},e.emit=function*(e,t,n){var i,r=((255&(i=4294967296*Math.random()>>>0)).toString(16).padStart(2,"0")+(i>>8&255).toString(16).padStart(2,"0")+(i>>16&255).toString(16).padStart(2,"0")+(i>>24&255).toString(16).padStart(2,"0")).toUpperCase();let o=yield*SERDE.encode(e);function*s(e,t){e=yield*SERDE.encode(E.toString(e)),world.getDimension("overworld").runCommand(`scriptevent ${o}:${e} `+t)}var l=yield*SERDE.encode(JSON.stringify(n));let d=0,c="",a=0;for(let e=0;e<l.length;e++){var _=l[e],u=_.charCodeAt(0),u=u<=127?1:u<=2047?2:u<=65535?3:4;a+u<2048?(c+=_,a+=u):(yield*s([t,r,d],c),d++,c=_,a=u),yield}yield*s(0===d?[t,r]:[t,r,d,1],c)},e.listen=function(e,n,s){let l=new Map;{var i=e,r=function*([e,i,t,r],o){if(e===n)if(void 0===t)yield*s(JSON.parse(yield*SERDE.decode(o)));else{let n=l.get(i);if(n||(n={size:-1,data_strs:[],data_size:0},l.set(i,n)),1===r&&(n.size=t+1),n.data_strs[t]=o,n.data_size+=t+1,-1!==n.size&&n.data_size===n.size*(n.size+1)/2){let t="";for(let e=0;e<n.data_strs.length;e++)t+=n.data_strs[e],yield;yield*s(JSON.parse(yield*SERDE.decode(t))),l.delete(i)}}};let t=o.get(i);return t||(t=new Array,o.set(i,t)),t.push(r),()=>{var e=t.indexOf(r);-1!==e&&t.splice(e,1),0===t.length&&o.delete(i)}}}})(NET=NET||{});export{NET};
|