Fixed leakage

This commit is contained in:
Adrian Bergqvist 2022-11-20 23:58:07 +01:00
parent 099c228261
commit a315289a85
No known key found for this signature in database
GPG Key ID: FAE7D8EDE225E686
6 changed files with 12 additions and 22 deletions

View File

@ -4,7 +4,7 @@ plugins {
}
group 'org.adde0109'
version '1.1.3-alpha'
version '1.1.4-alpha'
repositories {
maven {

View File

@ -25,7 +25,7 @@ import org.slf4j.Logger;
import java.nio.file.Path;
@Plugin(id = "ambassador", name = "Ambassador", version = "1.1.3-alpha", authors = {"adde0109"})
@Plugin(id = "ambassador", name = "Ambassador", version = "1.1.4-alpha", authors = {"adde0109"})
public class Ambassador {
public ProxyServer server;

View File

@ -4,6 +4,7 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;
public class FML2CRPMResetCompleteListener extends ChannelInboundHandlerAdapter {
@ -24,6 +25,7 @@ public class FML2CRPMResetCompleteListener extends ChannelInboundHandlerAdapter
int originalReaderIndex = buf.readerIndex();
int packetId = ProtocolUtils.readVarInt(buf);
if (packetId == 0x02 && buf.readableBytes() > 1) {
ReferenceCountUtil.release(msg);
ctx.pipeline().remove(this);
whenComplete.run();
return;

View File

@ -105,12 +105,12 @@ public class FML2ClientConnectionPhase extends VelocityForgeClientConnectionPhas
@Override
public void handleForward(VelocityServerConnection serverConnection, LoginPluginMessage payload) {
ByteBuf buf = payload.content().copy();
final ByteBuf buf = payload.content().duplicate();
ProtocolUtils.readString(buf); //Channel
ProtocolUtils.readVarInt(buf); //Length
if (ProtocolUtils.readVarInt(buf) == 1) {
getPayloadManager().listenFor(payload.getId()).thenAccept(rawResponse -> {
ByteBuf response = rawResponse.copy();
final ByteBuf response = rawResponse.duplicate();
ProtocolUtils.readString(response); //Channel
ProtocolUtils.readVarInt(response); //Length
if (ProtocolUtils.readVarInt(response) == 2) {
@ -119,9 +119,7 @@ public class FML2ClientConnectionPhase extends VelocityForgeClientConnectionPhas
serverConnection.getPlayer().setPhase(new FML2CRPMClientConnectionPhase(clientPhase,getPayloadManager()));
}
}
ReferenceCountUtil.release(response);
});
ReferenceCountUtil.release(buf);
}
}
}

View File

@ -12,6 +12,7 @@ import com.velocitypowered.api.event.player.ServerPreConnectEvent;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.protocol.packet.ClientSettings;
import org.adde0109.ambassador.Ambassador;
import org.adde0109.ambassador.forge.FML2CRPMClientConnectionPhase;
import org.adde0109.ambassador.forge.FML2ClientConnectionPhase;

View File

@ -13,7 +13,6 @@ import java.util.List;
public class VelocityForgeBackendConnectionPhase implements BackendConnectionPhase {
private List<LoginPluginMessage> queuedHandshakePackets = new ArrayList<>();
public VelocityForgeBackendConnectionPhase() {
}
@ -27,27 +26,17 @@ public class VelocityForgeBackendConnectionPhase implements BackendConnectionPha
public boolean handle(VelocityServerConnection server, ConnectedPlayer player, LoginPluginMessage message) throws Exception {
VelocityForgeClientConnectionPhase clientPhase = ((VelocityForgeClientConnectionPhase) player.getPhase());
message.retain();
if (clientPhase.clientPhase == VelocityForgeClientConnectionPhase.ClientPhase.VANILLA) {
server.getConnection().getChannel().config().setAutoRead(false);
message.retain();
clientPhase.reset(server,player).thenAccept((success) -> {
if (success) {
for (LoginPluginMessage msg: queuedHandshakePackets) {
((VelocityForgeClientConnectionPhase) player.getPhase()).forwardPayload(server,msg);
}
player.getConnection().flush();
} else {
for (LoginPluginMessage msg: queuedHandshakePackets) {
ReferenceCountUtil.release(msg);
}
clientPhase.forwardPayload(server,message);
server.getConnection().getChannel().config().setAutoRead(true);
}
queuedHandshakePackets = null;
});
queuedHandshakePackets = new ArrayList<>();
queuedHandshakePackets.add(message);
} else if (clientPhase.clientPhase != null) {
clientPhase.forwardPayload(server,message);
} else {
queuedHandshakePackets.add(message);
clientPhase.forwardPayload(server, (LoginPluginMessage) message.retain());
}
return true;
}