geforkt von Mirrors/Velocity
Fix several problems and clean up the BungeeCord plugin messaging support.
Fixes #402
Dieser Commit ist enthalten in:
Ursprung
b1f7980c5d
Commit
f6078e9b74
@ -236,75 +236,52 @@ public class BungeeCordMessageResponder {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private ByteBuf prepareForwardMessage(ByteBufDataInput in) {
|
|
||||||
String channel = in.readUTF();
|
|
||||||
short messageLength = in.readShort();
|
|
||||||
|
|
||||||
ByteBuf buf = Unpooled.buffer();
|
|
||||||
ByteBufDataOutput forwarded = new ByteBufDataOutput(buf);
|
|
||||||
forwarded.writeUTF(channel);
|
|
||||||
forwarded.writeShort(messageLength);
|
|
||||||
buf.writeBytes(in.unwrap().readSlice(messageLength));
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processForwardToPlayer(ByteBufDataInput in) {
|
private void processForwardToPlayer(ByteBufDataInput in) {
|
||||||
proxy.getPlayer(in.readUTF())
|
Optional<Player> player = proxy.getPlayer(in.readUTF());
|
||||||
.ifPresent(foundPlayer -> sendServerResponse((ConnectedPlayer) foundPlayer,
|
if (player.isPresent()) {
|
||||||
prepareForwardMessage(in)));
|
ByteBuf toForward = in.unwrap().copy();
|
||||||
|
sendServerResponse((ConnectedPlayer) player.get(), toForward);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processForwardToServer(ByteBufDataInput in) {
|
private void processForwardToServer(ByteBufDataInput in) {
|
||||||
String target = in.readUTF();
|
String target = in.readUTF();
|
||||||
ByteBuf toForward = prepareForwardMessage(in);
|
ByteBuf toForward = in.unwrap().copy();
|
||||||
if (target.equals("ALL")) {
|
if (target.equals("ALL")) {
|
||||||
ByteBuf unreleasableForward = Unpooled.unreleasableBuffer(toForward);
|
|
||||||
try {
|
try {
|
||||||
for (RegisteredServer rs : proxy.getAllServers()) {
|
for (RegisteredServer rs : proxy.getAllServers()) {
|
||||||
((VelocityRegisteredServer) rs).sendPluginMessage(LEGACY_CHANNEL, unreleasableForward);
|
((VelocityRegisteredServer) rs).sendPluginMessage(LEGACY_CHANNEL,
|
||||||
|
toForward.retainedSlice());
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
toForward.release();
|
toForward.release();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
proxy.getServer(target).ifPresent(rs -> ((VelocityRegisteredServer) rs)
|
Optional<RegisteredServer> server = proxy.getServer(target);
|
||||||
.sendPluginMessage(LEGACY_CHANNEL, toForward));
|
if (server.isPresent()) {
|
||||||
|
((VelocityRegisteredServer) server.get()).sendPluginMessage(LEGACY_CHANNEL, toForward);
|
||||||
|
} else {
|
||||||
|
toForward.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: this method will always release the buffer!
|
|
||||||
private void sendResponseOnConnection(ByteBuf buf) {
|
|
||||||
sendServerResponse(this.player, buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static String getBungeeCordChannel(ProtocolVersion version) {
|
static String getBungeeCordChannel(ProtocolVersion version) {
|
||||||
return version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0 ? MODERN_CHANNEL.getId()
|
return version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0 ? MODERN_CHANNEL.getId()
|
||||||
: LEGACY_CHANNEL.getId();
|
: LEGACY_CHANNEL.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: this method will always release the buffer!
|
||||||
|
private void sendResponseOnConnection(ByteBuf buf) {
|
||||||
|
sendServerResponse(this.player, buf);
|
||||||
|
}
|
||||||
|
|
||||||
// Note: this method will always release the buffer!
|
// Note: this method will always release the buffer!
|
||||||
private static void sendServerResponse(ConnectedPlayer player, ByteBuf buf) {
|
private static void sendServerResponse(ConnectedPlayer player, ByteBuf buf) {
|
||||||
MinecraftConnection serverConnection = player.ensureAndGetCurrentServer().ensureConnected();
|
MinecraftConnection serverConnection = player.ensureAndGetCurrentServer().ensureConnected();
|
||||||
String chan = getBungeeCordChannel(serverConnection.getProtocolVersion());
|
String chan = getBungeeCordChannel(serverConnection.getProtocolVersion());
|
||||||
|
PluginMessage msg = new PluginMessage(chan, buf);
|
||||||
PluginMessage msg = null;
|
serverConnection.write(msg);
|
||||||
boolean released = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
VelocityServerConnection vsc = player.getConnectedServer();
|
|
||||||
if (vsc == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MinecraftConnection serverConn = vsc.ensureConnected();
|
|
||||||
msg = new PluginMessage(chan, buf);
|
|
||||||
serverConn.write(msg);
|
|
||||||
released = true;
|
|
||||||
} finally {
|
|
||||||
if (!released && msg != null) {
|
|
||||||
msg.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean process(PluginMessage message) {
|
boolean process(PluginMessage message) {
|
||||||
|
@ -125,7 +125,9 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a plugin message to the server through this connection.
|
* Sends a plugin message to the server through this connection. The message will be released
|
||||||
|
* afterwards.
|
||||||
|
*
|
||||||
* @param identifier the channel ID to use
|
* @param identifier the channel ID to use
|
||||||
* @param data the data
|
* @param data the data
|
||||||
* @return whether or not the message was sent
|
* @return whether or not the message was sent
|
||||||
@ -133,11 +135,12 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
|
|||||||
public boolean sendPluginMessage(ChannelIdentifier identifier, ByteBuf data) {
|
public boolean sendPluginMessage(ChannelIdentifier identifier, ByteBuf data) {
|
||||||
for (ConnectedPlayer player : players.values()) {
|
for (ConnectedPlayer player : players.values()) {
|
||||||
VelocityServerConnection connection = player.getConnectedServer();
|
VelocityServerConnection connection = player.getConnectedServer();
|
||||||
if (connection != null && connection.getServerInfo().equals(serverInfo)) {
|
if (connection != null && connection.getServer() == this) {
|
||||||
return connection.sendPluginMessage(identifier, data);
|
return connection.sendPluginMessage(identifier, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.release();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren