Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Clear bytes instead of reading them, close streams when done. (May fix a few memory leaks)
Dieser Commit ist enthalten in:
Ursprung
99eadbe343
Commit
fc7cdb4244
@ -1,7 +1,7 @@
|
|||||||
package us.myles.ViaVersion;
|
package us.myles.ViaVersion;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.*;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -32,10 +32,10 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
|
|||||||
ByteBuf newPacket = ctx.alloc().buffer();
|
ByteBuf newPacket = ctx.alloc().buffer();
|
||||||
try {
|
try {
|
||||||
incomingTransformer.transform(id, bytebuf, newPacket);
|
incomingTransformer.transform(id, bytebuf, newPacket);
|
||||||
bytebuf.readBytes(bytebuf.readableBytes());
|
bytebuf.clear();
|
||||||
bytebuf = newPacket;
|
bytebuf = newPacket;
|
||||||
} catch (CancelException e) {
|
} catch (CancelException e) {
|
||||||
bytebuf.readBytes(bytebuf.readableBytes());
|
bytebuf.clear();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void encode(final ChannelHandlerContext ctx, Object o, final ByteBuf bytebuf) throws Exception {
|
protected void encode(final ChannelHandlerContext ctx, Object o, final ByteBuf bytebuf) throws Exception {
|
||||||
// handle the packet type
|
// handle the packet type
|
||||||
@ -57,13 +56,8 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Synced allows timings to work properly.
|
|
||||||
// if (ViaVersion.getInstance().isSyncedChunks()) {
|
|
||||||
// ((ViaVersionPlugin) ViaVersion.getInstance()).run(chunks, false);
|
|
||||||
// } else {
|
|
||||||
chunks.run();
|
chunks.run();
|
||||||
// }
|
bytebuf.clear();
|
||||||
bytebuf.readBytes(bytebuf.readableBytes());
|
|
||||||
throw new CancelException();
|
throw new CancelException();
|
||||||
}
|
}
|
||||||
// call minecraft encoder
|
// call minecraft encoder
|
||||||
@ -80,7 +74,7 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
|
|||||||
try {
|
try {
|
||||||
outgoingTransformer.transform(id, oldPacket, bytebuf);
|
outgoingTransformer.transform(id, oldPacket, bytebuf);
|
||||||
} catch (CancelException e) {
|
} catch (CancelException e) {
|
||||||
bytebuf.readBytes(bytebuf.readableBytes());
|
bytebuf.clear();
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
oldPacket.release();
|
oldPacket.release();
|
||||||
|
@ -193,6 +193,7 @@ public class IncomingTransformer {
|
|||||||
ByteBuf in = Unpooled.wrappedBuffer(b);
|
ByteBuf in = Unpooled.wrappedBuffer(b);
|
||||||
try {
|
try {
|
||||||
ItemSlotRewriter.ItemStack stack = ItemSlotRewriter.readItemStack(in);
|
ItemSlotRewriter.ItemStack stack = ItemSlotRewriter.readItemStack(in);
|
||||||
|
if (stack != null)
|
||||||
stack.id = (short) Material.WRITTEN_BOOK.getId();
|
stack.id = (short) Material.WRITTEN_BOOK.getId();
|
||||||
// write
|
// write
|
||||||
ItemSlotRewriter.writeItemStack(stack, output);
|
ItemSlotRewriter.writeItemStack(stack, output);
|
||||||
@ -234,7 +235,7 @@ public class IncomingTransformer {
|
|||||||
output.writeLong(position);
|
output.writeLong(position);
|
||||||
int face = PacketUtil.readVarInt(input);
|
int face = PacketUtil.readVarInt(input);
|
||||||
output.writeByte(face);
|
output.writeByte(face);
|
||||||
int hand = PacketUtil.readVarInt(input);
|
PacketUtil.readVarInt(input);
|
||||||
|
|
||||||
ItemStack inHand = ViaVersionPlugin.getHandItem(info);
|
ItemStack inHand = ViaVersionPlugin.getHandItem(info);
|
||||||
try {
|
try {
|
||||||
|
@ -42,7 +42,6 @@ public class OutgoingTransformer {
|
|||||||
private final Map<Integer, UUID> uuidMap = new HashMap<>();
|
private final Map<Integer, UUID> uuidMap = new HashMap<>();
|
||||||
private final Map<Integer, EntityType> clientEntityTypes = new HashMap<>();
|
private final Map<Integer, EntityType> clientEntityTypes = new HashMap<>();
|
||||||
private final Map<Integer, Integer> vehicleMap = new HashMap<>();
|
private final Map<Integer, Integer> vehicleMap = new HashMap<>();
|
||||||
private boolean cancel = false;
|
|
||||||
private boolean autoTeam = false;
|
private boolean autoTeam = false;
|
||||||
|
|
||||||
public OutgoingTransformer(ConnectionInfo info) {
|
public OutgoingTransformer(ConnectionInfo info) {
|
||||||
@ -72,10 +71,6 @@ public class OutgoingTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void transform(int packetID, ByteBuf input, ByteBuf output) throws CancelException {
|
public void transform(int packetID, ByteBuf input, ByteBuf output) throws CancelException {
|
||||||
if (cancel) {
|
|
||||||
throw new CancelException();
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketType packet = PacketType.getOutgoingPacket(info.getState(), packetID);
|
PacketType packet = PacketType.getOutgoingPacket(info.getState(), packetID);
|
||||||
int original = packetID;
|
int original = packetID;
|
||||||
if (packet == null) {
|
if (packet == null) {
|
||||||
|
@ -48,7 +48,13 @@ public class PacketUtil {
|
|||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
input.readerIndex(readerIndex);
|
input.readerIndex(readerIndex);
|
||||||
return (CompoundTag) NBTIO.readTag(new DataInputStream(new ByteBufInputStream(input)));
|
ByteBufInputStream bytebufStream = new ByteBufInputStream(input);
|
||||||
|
DataInputStream dataInputStream = new DataInputStream(bytebufStream);
|
||||||
|
try {
|
||||||
|
return (CompoundTag) NBTIO.readTag(dataInputStream);
|
||||||
|
} finally {
|
||||||
|
dataInputStream.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +62,12 @@ public class PacketUtil {
|
|||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
output.writeByte(0);
|
output.writeByte(0);
|
||||||
} else {
|
} else {
|
||||||
NBTIO.writeTag(new DataOutputStream(new ByteBufOutputStream(output)), tag);
|
ByteBufOutputStream bytebufStream = new ByteBufOutputStream(output);
|
||||||
|
DataOutputStream dataOutputStream = new DataOutputStream(bytebufStream);
|
||||||
|
|
||||||
|
NBTIO.writeTag(dataOutputStream, tag);
|
||||||
|
|
||||||
|
dataOutputStream.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren