Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-12-24 15:20:35 +01:00
Remove PluginMessage slicing for now.
This was causing leak issues and needs to be reimplemented. If anyone's willing to undertake the work, I will gladly accept the PR!
Dieser Commit ist enthalten in:
Ursprung
d38c7467d9
Commit
0c481d828d
@ -45,7 +45,6 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
connection.getProxyPlayer().getConnection().write(packet);
|
||||
} else if (packet instanceof PluginMessage) {
|
||||
PluginMessage pm = (PluginMessage) packet;
|
||||
try {
|
||||
if (!canForwardPluginMessage(pm)) {
|
||||
return;
|
||||
}
|
||||
@ -55,14 +54,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
// we'll decrement this twice: once when writing to the server, once just below this block,
|
||||
// and once in the MinecraftConnection (since this is a slice)
|
||||
pm.getData().retain();
|
||||
|
||||
connection.getProxyPlayer().getConnection().write(pm);
|
||||
} finally {
|
||||
pm.getData().release();
|
||||
}
|
||||
} else {
|
||||
// Just forward the packet on. We don't have anything to handle at this time.
|
||||
if (packet instanceof ScoreboardTeam ||
|
||||
|
@ -191,8 +191,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
public void handleClientPluginMessage(PluginMessage packet) {
|
||||
logger.info("Got client plugin message packet {}", packet);
|
||||
|
||||
try {
|
||||
if (packet.getChannel().equals("REGISTER") || packet.getChannel().equals("minecraft:register")) {
|
||||
List<String> actuallyRegistered = new ArrayList<>();
|
||||
List<String> channels = PluginMessageUtil.getChannels(packet);
|
||||
@ -226,11 +224,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
// We're going to forward on the original packet.
|
||||
packet.getData().retain();
|
||||
player.getConnectedServer().getMinecraftConnection().write(packet);
|
||||
} finally {
|
||||
ReferenceCountUtil.release(packet.getData());
|
||||
}
|
||||
}
|
||||
|
||||
public void handleServerScoreboardPacket(MinecraftPacket packet) {
|
||||
|
@ -8,7 +8,7 @@ import io.netty.buffer.ByteBufUtil;
|
||||
|
||||
public class PluginMessage implements MinecraftPacket {
|
||||
private String channel;
|
||||
private ByteBuf data;
|
||||
private byte[] data;
|
||||
|
||||
public String getChannel() {
|
||||
return channel;
|
||||
@ -18,11 +18,11 @@ public class PluginMessage implements MinecraftPacket {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public ByteBuf getData() {
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(ByteBuf data) {
|
||||
public void setData(byte[] data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@ -37,7 +37,8 @@ public class PluginMessage implements MinecraftPacket {
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||
this.channel = ProtocolUtils.readString(buf);
|
||||
this.data = buf.readRetainedSlice(buf.readableBytes());
|
||||
this.data = new byte[buf.readableBytes()];
|
||||
buf.readBytes(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,7 +27,7 @@ public enum PluginMessageUtil {
|
||||
message.getChannel().equals("minecraft:register") ||
|
||||
message.getChannel().equals("minecraft:unregister"),
|
||||
"Unknown channel type " + message.getChannel());
|
||||
String channels = message.getData().toString(StandardCharsets.UTF_8);
|
||||
String channels = new String(message.getData(), StandardCharsets.UTF_8);
|
||||
return ImmutableList.copyOf(channels.split("\0"));
|
||||
}
|
||||
|
||||
@ -37,15 +37,7 @@ public enum PluginMessageUtil {
|
||||
|
||||
PluginMessage message = new PluginMessage();
|
||||
message.setChannel(channel);
|
||||
|
||||
ByteBuf data = Unpooled.buffer();
|
||||
for (String s : channels) {
|
||||
ByteBufUtil.writeUtf8(data, s);
|
||||
data.writeByte(0);
|
||||
}
|
||||
data.writerIndex(data.writerIndex() - 1);
|
||||
|
||||
message.setData(data);
|
||||
message.setData(String.join("\0", channels).getBytes(StandardCharsets.UTF_8));
|
||||
return message;
|
||||
}
|
||||
|
||||
@ -53,13 +45,20 @@ public enum PluginMessageUtil {
|
||||
Preconditions.checkNotNull(message, "message");
|
||||
Preconditions.checkArgument(isMCBrand(message), "message is not a MC Brand plugin message");
|
||||
|
||||
byte[] rewrittenData;
|
||||
ByteBuf rewrittenBuf = Unpooled.buffer();
|
||||
String currentBrand = ProtocolUtils.readString(message.getData());
|
||||
try {
|
||||
String currentBrand = ProtocolUtils.readString(Unpooled.wrappedBuffer(message.getData()));
|
||||
ProtocolUtils.writeString(rewrittenBuf, currentBrand + " (Velocity)");
|
||||
rewrittenData = new byte[rewrittenBuf.readableBytes()];
|
||||
rewrittenBuf.readBytes(rewrittenData);
|
||||
} finally {
|
||||
rewrittenBuf.release();
|
||||
}
|
||||
|
||||
PluginMessage newMsg = new PluginMessage();
|
||||
newMsg.setChannel(message.getChannel());
|
||||
newMsg.setData(rewrittenBuf);
|
||||
newMsg.setData(rewrittenData);
|
||||
return newMsg;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren