baltica 2.0.6 → 2.0.8
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.
|
@@ -35,6 +35,8 @@ class BridgePlayer extends utils_1.Emitter {
|
|
|
35
35
|
});
|
|
36
36
|
this.client.on("DisconnectPacket", () => this.bridge.disconnect(this));
|
|
37
37
|
this.player.on("DisconnectPacket", () => this.bridge.disconnect(this));
|
|
38
|
+
this.client.raknet.on("disconnect", () => this.bridge.disconnect(this));
|
|
39
|
+
this.player.connection.on("disconnect", () => this.bridge.disconnect(this));
|
|
38
40
|
this.on("clientBound-DisconnectPacket", () => this.bridge.disconnect(this));
|
|
39
41
|
this.on("serverBound-DisconnectPacket", () => this.bridge.disconnect(this));
|
|
40
42
|
this.client.connect();
|
|
@@ -52,45 +54,49 @@ class BridgePlayer extends utils_1.Emitter {
|
|
|
52
54
|
const direction = clientBound ? "clientBound" : "serverBound";
|
|
53
55
|
const event = `${direction}-${PacketClass.name}`;
|
|
54
56
|
const wildcard = `${direction}-*`;
|
|
57
|
+
const completeWildCard = `*`;
|
|
55
58
|
const hasSpecific = this.listenerCount(event) > 0;
|
|
56
59
|
const hasWildcard = this.listenerCount(wildcard) > 0;
|
|
60
|
+
const hasCompleteWildCard = this.listenerCount(completeWildCard) > 0;
|
|
61
|
+
if (!hasSpecific && !hasWildcard && !hasCompleteWildCard) {
|
|
62
|
+
if (clientBound)
|
|
63
|
+
this.player.send(rawBuffer);
|
|
64
|
+
else
|
|
65
|
+
this.client.send(rawBuffer);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
let deserialized = null;
|
|
57
69
|
let cancelled = false;
|
|
58
|
-
let
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
catch {
|
|
68
|
-
deserialized = rawBuffer;
|
|
69
|
-
}
|
|
70
|
+
let modified = false;
|
|
71
|
+
const ctx = {
|
|
72
|
+
get packet() {
|
|
73
|
+
if (!deserialized) {
|
|
74
|
+
try {
|
|
75
|
+
deserialized = new PacketClass(rawBuffer).deserialize();
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
deserialized = rawBuffer;
|
|
70
79
|
}
|
|
71
|
-
return deserialized;
|
|
72
|
-
},
|
|
73
|
-
set packet(v) { deserialized = v; },
|
|
74
|
-
cancelled: false,
|
|
75
|
-
modified: false,
|
|
76
|
-
};
|
|
77
|
-
try {
|
|
78
|
-
if (hasSpecific)
|
|
79
|
-
this.emit(event, ctx);
|
|
80
|
-
if (hasWildcard)
|
|
81
|
-
this.emit(wildcard, ctx, PacketClass.name);
|
|
82
|
-
}
|
|
83
|
-
catch { }
|
|
84
|
-
cancelled = ctx.cancelled;
|
|
85
|
-
if (ctx.modified && deserialized) {
|
|
86
|
-
try {
|
|
87
|
-
outBuffer = deserialized.serialize();
|
|
88
80
|
}
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
81
|
+
return deserialized;
|
|
82
|
+
},
|
|
83
|
+
set packet(v) {
|
|
84
|
+
deserialized = v;
|
|
85
|
+
},
|
|
86
|
+
get cancelled() { return cancelled; },
|
|
87
|
+
set cancelled(v) { cancelled = v; },
|
|
88
|
+
get modified() { return modified; },
|
|
89
|
+
set modified(v) { modified = v; },
|
|
90
|
+
};
|
|
91
|
+
if (hasSpecific)
|
|
92
|
+
this.emit(event, ctx);
|
|
93
|
+
if (!cancelled && hasWildcard)
|
|
94
|
+
this.emit(wildcard, ctx, PacketClass.name);
|
|
95
|
+
if (!cancelled && hasCompleteWildCard)
|
|
96
|
+
this.emit(completeWildCard, ctx, PacketClass.name);
|
|
92
97
|
if (cancelled)
|
|
93
98
|
return;
|
|
99
|
+
const outBuffer = modified && deserialized ? deserialized.serialize() : rawBuffer;
|
|
94
100
|
if (clientBound)
|
|
95
101
|
this.player.send(outBuffer);
|
|
96
102
|
else
|
package/dist/bridge/bridge.js
CHANGED
|
@@ -6,6 +6,7 @@ const protocol_1 = require("@serenityjs/protocol");
|
|
|
6
6
|
const server_1 = require("../server");
|
|
7
7
|
const bridge_player_1 = require("./bridge-player");
|
|
8
8
|
const types_1 = require("./types");
|
|
9
|
+
const raknet_1 = require("@baltica/raknet");
|
|
9
10
|
class Bridge extends utils_1.Emitter {
|
|
10
11
|
options;
|
|
11
12
|
server;
|
|
@@ -32,7 +33,7 @@ class Bridge extends utils_1.Emitter {
|
|
|
32
33
|
packet.hideDisconnectScreen = false;
|
|
33
34
|
packet.message = new protocol_1.DisconnectMessage("Client leaving", "");
|
|
34
35
|
packet.reason = protocol_1.DisconnectReason.LegacyDisconnect;
|
|
35
|
-
player.client?.send(packet.serialize());
|
|
36
|
+
player.client?.send(packet.serialize(), raknet_1.Priority.High);
|
|
36
37
|
}
|
|
37
38
|
catch { }
|
|
38
39
|
this.emit("disconnect", player);
|
|
@@ -12,4 +12,5 @@ export type BridgePlayerEvents = {
|
|
|
12
12
|
} & {
|
|
13
13
|
"clientBound-*": [signal: BridgePacketSignal<Protocol.DataPacket>, name: string];
|
|
14
14
|
"serverBound-*": [signal: BridgePacketSignal<Protocol.DataPacket>, name: string];
|
|
15
|
+
"*": [signal: BridgePacketSignal<Protocol.DataPacket>, name: string];
|
|
15
16
|
};
|