mcbe-ipc 3.4.0 → 3.4.2
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/dist/ipc.d.ts +1 -0
- package/dist/ipc.js +9 -6
- package/package.json +1 -1
package/dist/ipc.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export declare namespace PROTO {
|
|
|
51
51
|
to_uint8array(): Uint8Array;
|
|
52
52
|
}
|
|
53
53
|
namespace MIPS {
|
|
54
|
+
function is_valid(str: string): boolean;
|
|
54
55
|
function serialize(stream: PROTO.Buffer): Generator<void, string, void>;
|
|
55
56
|
function deserialize(str: string): Generator<void, PROTO.Buffer, void>;
|
|
56
57
|
}
|
package/dist/ipc.js
CHANGED
|
@@ -107,6 +107,10 @@ export var PROTO;
|
|
|
107
107
|
PROTO.Buffer = Buffer;
|
|
108
108
|
let MIPS;
|
|
109
109
|
(function (MIPS) {
|
|
110
|
+
function is_valid(str) {
|
|
111
|
+
return str.startsWith('(0x') && str.endsWith(')');
|
|
112
|
+
}
|
|
113
|
+
MIPS.is_valid = is_valid;
|
|
110
114
|
function* serialize(stream) {
|
|
111
115
|
const uint8array = stream.to_uint8array();
|
|
112
116
|
let str = '(0x';
|
|
@@ -120,7 +124,7 @@ export var PROTO;
|
|
|
120
124
|
}
|
|
121
125
|
MIPS.serialize = serialize;
|
|
122
126
|
function* deserialize(str) {
|
|
123
|
-
if (
|
|
127
|
+
if (is_valid(str)) {
|
|
124
128
|
const buffer = new Buffer();
|
|
125
129
|
const hex_str = str.slice(3, str.length - 1);
|
|
126
130
|
for (let i = 0; i < hex_str.length; i++) {
|
|
@@ -502,23 +506,22 @@ export var NET;
|
|
|
502
506
|
if (event.sourceType !== ScriptEventSource.Server)
|
|
503
507
|
return;
|
|
504
508
|
const [serialized_endpoint, serialized_header] = event.id.split(':');
|
|
509
|
+
if (!PROTO.MIPS.is_valid(serialized_endpoint))
|
|
510
|
+
return;
|
|
505
511
|
const endpoint_stream = yield* PROTO.MIPS.deserialize(serialized_endpoint);
|
|
506
512
|
const endpoint = yield* Endpoint.deserialize(endpoint_stream);
|
|
507
513
|
const listeners = LISTENERS.get(endpoint);
|
|
508
|
-
if (listeners !== undefined) {
|
|
514
|
+
if (listeners !== undefined && PROTO.MIPS.is_valid(serialized_header)) {
|
|
509
515
|
const header_stream = yield* PROTO.MIPS.deserialize(serialized_header);
|
|
510
516
|
const header = yield* Header.deserialize(header_stream);
|
|
511
|
-
const errors = [];
|
|
512
517
|
for (const listener of [...listeners]) {
|
|
513
518
|
try {
|
|
514
519
|
yield* listener(header, event.message);
|
|
515
520
|
}
|
|
516
521
|
catch (e) {
|
|
517
|
-
|
|
522
|
+
console.error(`[MCBE-IPC] listener error while handling packet on "${endpoint}":`, e);
|
|
518
523
|
}
|
|
519
524
|
}
|
|
520
|
-
if (errors.length > 0)
|
|
521
|
-
throw new AggregateError(errors, 'one or more listeners failed');
|
|
522
525
|
}
|
|
523
526
|
})());
|
|
524
527
|
});
|
package/package.json
CHANGED