13
0
geforkt von Mirrors/Velocity

Simplify the discard logic.

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-05-29 21:35:07 -04:00
Ursprung dd2e1ad241
Commit 11fb5f2be3
3 geänderte Dateien mit 5 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -16,7 +16,6 @@ import com.velocitypowered.natives.encryption.VelocityCipher;
import com.velocitypowered.natives.encryption.VelocityCipherFactory;
import com.velocitypowered.natives.util.Natives;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.network.netty.DiscardHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder;
@ -152,7 +151,6 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
}
}
installDiscardHandler(ctx);
ctx.close();
}
}
@ -168,18 +166,6 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
Preconditions.checkState(this.channel.eventLoop().inEventLoop(), "Not in event loop");
}
private void installDiscardHandler(ChannelHandlerContext ctx) {
if (ctx.pipeline().get("discard") == null) {
ctx.pipeline().addBefore(MINECRAFT_DECODER, "discard", DiscardHandler.HANDLER);
}
}
private void installDiscardHandler() {
if (channel.pipeline().get("discard") == null) {
channel.pipeline().addBefore(MINECRAFT_DECODER, "discard", DiscardHandler.HANDLER);
}
}
public EventLoop eventLoop() {
return channel.eventLoop();
}
@ -220,7 +206,6 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
public void closeWith(Object msg) {
if (channel.isActive()) {
knownDisconnect = true;
installDiscardHandler();
channel.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE);
}
}
@ -230,7 +215,6 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
*/
public void close() {
if (channel.isActive()) {
installDiscardHandler();
channel.close();
}
}

Datei anzeigen

@ -1,17 +0,0 @@
package com.velocitypowered.proxy.network.netty;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;
@Sharable
public class DiscardHandler extends ChannelInboundHandlerAdapter {
public static final DiscardHandler HANDLER = new DiscardHandler();
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ReferenceCountUtil.release(msg);
}
}

Datei anzeigen

@ -14,6 +14,11 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
if (!ctx.channel().isActive()) {
in.skipBytes(in.readableBytes());
return;
}
while (in.isReadable()) {
int varintEnd = in.forEachByte(reader);
if (varintEnd == -1) {