baltica 2.0.7 → 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.
- package/dist/bridge/bridge-player.js +38 -37
- package/package.json +1 -1
|
@@ -4,7 +4,6 @@ exports.BridgePlayer = void 0;
|
|
|
4
4
|
const protocol_1 = require("@serenityjs/protocol");
|
|
5
5
|
const utils_1 = require("@baltica/utils");
|
|
6
6
|
const client_1 = require("../client");
|
|
7
|
-
const raknet_1 = require("@baltica/raknet");
|
|
8
7
|
class BridgePlayer extends utils_1.Emitter {
|
|
9
8
|
bridge;
|
|
10
9
|
player;
|
|
@@ -36,6 +35,8 @@ class BridgePlayer extends utils_1.Emitter {
|
|
|
36
35
|
});
|
|
37
36
|
this.client.on("DisconnectPacket", () => this.bridge.disconnect(this));
|
|
38
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));
|
|
39
40
|
this.on("clientBound-DisconnectPacket", () => this.bridge.disconnect(this));
|
|
40
41
|
this.on("serverBound-DisconnectPacket", () => this.bridge.disconnect(this));
|
|
41
42
|
this.client.connect();
|
|
@@ -57,49 +58,49 @@ class BridgePlayer extends utils_1.Emitter {
|
|
|
57
58
|
const hasSpecific = this.listenerCount(event) > 0;
|
|
58
59
|
const hasWildcard = this.listenerCount(wildcard) > 0;
|
|
59
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;
|
|
60
69
|
let cancelled = false;
|
|
61
|
-
let
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
catch {
|
|
71
|
-
deserialized = rawBuffer;
|
|
72
|
-
}
|
|
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;
|
|
73
79
|
}
|
|
74
|
-
return deserialized;
|
|
75
|
-
},
|
|
76
|
-
set packet(v) { deserialized = v; },
|
|
77
|
-
cancelled: false,
|
|
78
|
-
modified: false,
|
|
79
|
-
};
|
|
80
|
-
try {
|
|
81
|
-
if (hasSpecific)
|
|
82
|
-
this.emit(event, ctx);
|
|
83
|
-
if (hasWildcard)
|
|
84
|
-
this.emit(wildcard, ctx, PacketClass.name);
|
|
85
|
-
if (hasCompleteWildCard)
|
|
86
|
-
this.emit(completeWildCard, ctx, PacketClass.name);
|
|
87
|
-
}
|
|
88
|
-
catch { }
|
|
89
|
-
cancelled = ctx.cancelled;
|
|
90
|
-
if (ctx.modified && deserialized) {
|
|
91
|
-
try {
|
|
92
|
-
outBuffer = deserialized.serialize();
|
|
93
80
|
}
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
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);
|
|
97
97
|
if (cancelled)
|
|
98
98
|
return;
|
|
99
|
+
const outBuffer = modified && deserialized ? deserialized.serialize() : rawBuffer;
|
|
99
100
|
if (clientBound)
|
|
100
|
-
this.player.send(outBuffer
|
|
101
|
+
this.player.send(outBuffer);
|
|
101
102
|
else
|
|
102
|
-
this.client.send(outBuffer
|
|
103
|
+
this.client.send(outBuffer);
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
exports.BridgePlayer = BridgePlayer;
|