修复内容(FML2CRPMResetCompleteDecoder.java):
对于非 0x02 的数据包:直接释放缓冲区并返回。在重置阶段,唯一需要关注的是 0x02(Login Plugin Response)数据包。其他数据包(如延迟的 PLAY 状态数据包)无法被处于 LOGIN 状态的 MinecraftDecoder 解码,因此安全丢弃。 对于 0x02 + id=98 的数据包:在拦截后添加 buf.release() 来修复内存泄漏。
This commit is contained in:
parent
f8185ddb0d
commit
ac891c1ef1
|
|
@ -5,7 +5,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "org.adde0109"
|
group = "org.adde0109"
|
||||||
version = "1.4.5-fix1"
|
version = "1.4.5-fix2"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
||||||
|
|
@ -20,42 +20,35 @@ public class FML2CRPMResetCompleteDecoder extends ChannelInboundHandlerAdapter {
|
||||||
|
|
||||||
int originalReaderIndex = buf.readerIndex();
|
int originalReaderIndex = buf.readerIndex();
|
||||||
int packetId = ProtocolUtils.readVarInt(buf);
|
int packetId = ProtocolUtils.readVarInt(buf);
|
||||||
if (packetId == 0x02 && buf.readableBytes() > 1) {
|
if (packetId != 0x02) {
|
||||||
|
buf.release();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (buf.readableBytes() > 1) {
|
||||||
try {
|
try {
|
||||||
int id = ProtocolUtils.readVarInt(buf);
|
int id = ProtocolUtils.readVarInt(buf);
|
||||||
boolean success = buf.readBoolean();
|
boolean success = buf.readBoolean();
|
||||||
if (id == 98) {
|
if (id == 98) {
|
||||||
try {
|
try {
|
||||||
// 读取剩余的所有数据
|
|
||||||
int remainingBytes = buf.readableBytes();
|
int remainingBytes = buf.readableBytes();
|
||||||
ByteBuf remainingData;
|
|
||||||
|
|
||||||
if (remainingBytes > 0) {
|
if (remainingBytes > 0) {
|
||||||
// 有剩余数据,读取它们
|
ByteBuf remainingData = Unpooled.buffer(remainingBytes);
|
||||||
remainingData = Unpooled.buffer(remainingBytes);
|
|
||||||
remainingData.writeBytes(buf, remainingBytes);
|
remainingData.writeBytes(buf, remainingBytes);
|
||||||
|
IForgeLoginWrapperPacket packet = new GenericForgeLoginWrapperPacket(remainingData, id, success);
|
||||||
// 调试日志(可选,可删除)
|
ctx.fireChannelRead(packet);
|
||||||
System.out.println("[Ambassador] FML2CRPM packet - id: 98, success: " + success +
|
|
||||||
", captured " + remainingBytes + " extra bytes");
|
|
||||||
} else {
|
} else {
|
||||||
// 没有剩余数据,使用空缓冲区
|
IForgeLoginWrapperPacket packet = new GenericForgeLoginWrapperPacket(Unpooled.EMPTY_BUFFER, id, success);
|
||||||
remainingData = Unpooled.EMPTY_BUFFER;
|
ctx.fireChannelRead(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
IForgeLoginWrapperPacket packet = new GenericForgeLoginWrapperPacket(remainingData, id, success);
|
|
||||||
ctx.fireChannelRead(packet);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 出错时记录日志
|
|
||||||
System.err.println("[Ambassador] Error creating FML2CRPM packet: " + e.getMessage());
|
System.err.println("[Ambassador] Error creating FML2CRPM packet: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
buf.release();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
// 忽略解析错误,回退到正常处理
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 恢复读取位置
|
|
||||||
buf.readerIndex(originalReaderIndex);
|
buf.readerIndex(originalReaderIndex);
|
||||||
}
|
}
|
||||||
ctx.fireChannelRead(msg);
|
ctx.fireChannelRead(msg);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user