geforkt von Mirrors/Velocity
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,24 +45,16 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
connection.getProxyPlayer().getConnection().write(packet);
|
connection.getProxyPlayer().getConnection().write(packet);
|
||||||
} else if (packet instanceof PluginMessage) {
|
} else if (packet instanceof PluginMessage) {
|
||||||
PluginMessage pm = (PluginMessage) packet;
|
PluginMessage pm = (PluginMessage) packet;
|
||||||
try {
|
if (!canForwardPluginMessage(pm)) {
|
||||||
if (!canForwardPluginMessage(pm)) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PluginMessageUtil.isMCBrand(pm)) {
|
|
||||||
connection.getProxyPlayer().getConnection().write(PluginMessageUtil.rewriteMCBrand(pm));
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PluginMessageUtil.isMCBrand(pm)) {
|
||||||
|
connection.getProxyPlayer().getConnection().write(PluginMessageUtil.rewriteMCBrand(pm));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
connection.getProxyPlayer().getConnection().write(pm);
|
||||||
} else {
|
} else {
|
||||||
// Just forward the packet on. We don't have anything to handle at this time.
|
// Just forward the packet on. We don't have anything to handle at this time.
|
||||||
if (packet instanceof ScoreboardTeam ||
|
if (packet instanceof ScoreboardTeam ||
|
||||||
|
@ -191,46 +191,40 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
public void handleClientPluginMessage(PluginMessage packet) {
|
public void handleClientPluginMessage(PluginMessage packet) {
|
||||||
logger.info("Got client plugin message packet {}", packet);
|
logger.info("Got client plugin message packet {}", packet);
|
||||||
|
if (packet.getChannel().equals("REGISTER") || packet.getChannel().equals("minecraft:register")) {
|
||||||
try {
|
List<String> actuallyRegistered = new ArrayList<>();
|
||||||
if (packet.getChannel().equals("REGISTER") || packet.getChannel().equals("minecraft:register")) {
|
List<String> channels = PluginMessageUtil.getChannels(packet);
|
||||||
List<String> actuallyRegistered = new ArrayList<>();
|
for (String channel : channels) {
|
||||||
List<String> channels = PluginMessageUtil.getChannels(packet);
|
if (clientPluginMsgChannels.size() >= MAX_PLUGIN_CHANNELS &&
|
||||||
for (String channel : channels) {
|
!clientPluginMsgChannels.contains(channel)) {
|
||||||
if (clientPluginMsgChannels.size() >= MAX_PLUGIN_CHANNELS &&
|
throw new IllegalStateException("Too many plugin message channels registered");
|
||||||
!clientPluginMsgChannels.contains(channel)) {
|
|
||||||
throw new IllegalStateException("Too many plugin message channels registered");
|
|
||||||
}
|
|
||||||
if (clientPluginMsgChannels.add(channel)) {
|
|
||||||
actuallyRegistered.add(channel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (clientPluginMsgChannels.add(channel)) {
|
||||||
if (actuallyRegistered.size() > 0) {
|
actuallyRegistered.add(channel);
|
||||||
logger.info("Rewritten register packet: {}", actuallyRegistered);
|
|
||||||
PluginMessage newRegisterPacket = PluginMessageUtil.constructChannelsPacket(packet.getChannel(), actuallyRegistered);
|
|
||||||
player.getConnectedServer().getMinecraftConnection().write(newRegisterPacket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet.getChannel().equals("UNREGISTER") || packet.getChannel().equals("minecraft:unregister")) {
|
if (actuallyRegistered.size() > 0) {
|
||||||
List<String> channels = PluginMessageUtil.getChannels(packet);
|
logger.info("Rewritten register packet: {}", actuallyRegistered);
|
||||||
clientPluginMsgChannels.removeAll(channels);
|
PluginMessage newRegisterPacket = PluginMessageUtil.constructChannelsPacket(packet.getChannel(), actuallyRegistered);
|
||||||
|
player.getConnectedServer().getMinecraftConnection().write(newRegisterPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PluginMessageUtil.isMCBrand(packet)) {
|
return;
|
||||||
player.getConnectedServer().getMinecraftConnection().write(PluginMessageUtil.rewriteMCBrand(packet));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We're going to forward on the original packet.
|
|
||||||
packet.getData().retain();
|
|
||||||
player.getConnectedServer().getMinecraftConnection().write(packet);
|
|
||||||
} finally {
|
|
||||||
ReferenceCountUtil.release(packet.getData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (packet.getChannel().equals("UNREGISTER") || packet.getChannel().equals("minecraft:unregister")) {
|
||||||
|
List<String> channels = PluginMessageUtil.getChannels(packet);
|
||||||
|
clientPluginMsgChannels.removeAll(channels);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PluginMessageUtil.isMCBrand(packet)) {
|
||||||
|
player.getConnectedServer().getMinecraftConnection().write(PluginMessageUtil.rewriteMCBrand(packet));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We're going to forward on the original packet.
|
||||||
|
player.getConnectedServer().getMinecraftConnection().write(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleServerScoreboardPacket(MinecraftPacket packet) {
|
public void handleServerScoreboardPacket(MinecraftPacket packet) {
|
||||||
|
@ -8,7 +8,7 @@ import io.netty.buffer.ByteBufUtil;
|
|||||||
|
|
||||||
public class PluginMessage implements MinecraftPacket {
|
public class PluginMessage implements MinecraftPacket {
|
||||||
private String channel;
|
private String channel;
|
||||||
private ByteBuf data;
|
private byte[] data;
|
||||||
|
|
||||||
public String getChannel() {
|
public String getChannel() {
|
||||||
return channel;
|
return channel;
|
||||||
@ -18,11 +18,11 @@ public class PluginMessage implements MinecraftPacket {
|
|||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuf getData() {
|
public byte[] getData() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setData(ByteBuf data) {
|
public void setData(byte[] data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,8 @@ public class PluginMessage implements MinecraftPacket {
|
|||||||
@Override
|
@Override
|
||||||
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
|
||||||
this.channel = ProtocolUtils.readString(buf);
|
this.channel = ProtocolUtils.readString(buf);
|
||||||
this.data = buf.readRetainedSlice(buf.readableBytes());
|
this.data = new byte[buf.readableBytes()];
|
||||||
|
buf.readBytes(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,7 +27,7 @@ public enum PluginMessageUtil {
|
|||||||
message.getChannel().equals("minecraft:register") ||
|
message.getChannel().equals("minecraft:register") ||
|
||||||
message.getChannel().equals("minecraft:unregister"),
|
message.getChannel().equals("minecraft:unregister"),
|
||||||
"Unknown channel type " + message.getChannel());
|
"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"));
|
return ImmutableList.copyOf(channels.split("\0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,15 +37,7 @@ public enum PluginMessageUtil {
|
|||||||
|
|
||||||
PluginMessage message = new PluginMessage();
|
PluginMessage message = new PluginMessage();
|
||||||
message.setChannel(channel);
|
message.setChannel(channel);
|
||||||
|
message.setData(String.join("\0", channels).getBytes(StandardCharsets.UTF_8));
|
||||||
ByteBuf data = Unpooled.buffer();
|
|
||||||
for (String s : channels) {
|
|
||||||
ByteBufUtil.writeUtf8(data, s);
|
|
||||||
data.writeByte(0);
|
|
||||||
}
|
|
||||||
data.writerIndex(data.writerIndex() - 1);
|
|
||||||
|
|
||||||
message.setData(data);
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,13 +45,20 @@ public enum PluginMessageUtil {
|
|||||||
Preconditions.checkNotNull(message, "message");
|
Preconditions.checkNotNull(message, "message");
|
||||||
Preconditions.checkArgument(isMCBrand(message), "message is not a MC Brand plugin message");
|
Preconditions.checkArgument(isMCBrand(message), "message is not a MC Brand plugin message");
|
||||||
|
|
||||||
|
byte[] rewrittenData;
|
||||||
ByteBuf rewrittenBuf = Unpooled.buffer();
|
ByteBuf rewrittenBuf = Unpooled.buffer();
|
||||||
String currentBrand = ProtocolUtils.readString(message.getData());
|
try {
|
||||||
ProtocolUtils.writeString(rewrittenBuf, currentBrand + " (Velocity)");
|
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();
|
PluginMessage newMsg = new PluginMessage();
|
||||||
newMsg.setChannel(message.getChannel());
|
newMsg.setChannel(message.getChannel());
|
||||||
newMsg.setData(rewrittenBuf);
|
newMsg.setData(rewrittenData);
|
||||||
return newMsg;
|
return newMsg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren