geforkt von Mirrors/Velocity
Upon connection exception, discard all incoming packets instead
Dieser Commit ist enthalten in:
Ursprung
599adc6d2c
Commit
8ae7945b9f
@ -16,6 +16,7 @@ import com.velocitypowered.natives.encryption.VelocityCipher;
|
|||||||
import com.velocitypowered.natives.encryption.VelocityCipherFactory;
|
import com.velocitypowered.natives.encryption.VelocityCipherFactory;
|
||||||
import com.velocitypowered.natives.util.Natives;
|
import com.velocitypowered.natives.util.Natives;
|
||||||
import com.velocitypowered.proxy.VelocityServer;
|
import com.velocitypowered.proxy.VelocityServer;
|
||||||
|
import com.velocitypowered.proxy.network.netty.DiscardHandler;
|
||||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||||
import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder;
|
import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder;
|
||||||
@ -144,6 +145,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.pipeline().addBefore(MINECRAFT_DECODER, "discard", DiscardHandler.HANDLER);
|
||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -2,17 +2,26 @@ package com.velocitypowered.proxy.protocol.netty;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.velocitypowered.api.network.ProtocolVersion;
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
|
import com.velocitypowered.proxy.network.Connections;
|
||||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||||
|
import com.velocitypowered.proxy.util.except.QuietException;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
import io.netty.handler.codec.CorruptedFrameException;
|
import io.netty.handler.codec.CorruptedFrameException;
|
||||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||||
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf> {
|
public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf> {
|
||||||
|
|
||||||
|
private static final boolean DEBUG = Boolean.getBoolean("velocity.packet-decode-logging");
|
||||||
|
private static final QuietException DECODE_FAILED =
|
||||||
|
new QuietException("A packet did not decode successfully (invalid data). If you are a " +
|
||||||
|
"developer, launch Velocity with -Dvelocity.packet-decode-logging=true to see more.");
|
||||||
|
|
||||||
private final ProtocolUtils.Direction direction;
|
private final ProtocolUtils.Direction direction;
|
||||||
private StateRegistry state;
|
private StateRegistry state;
|
||||||
private StateRegistry.PacketRegistry.ProtocolRegistry registry;
|
private StateRegistry.PacketRegistry.ProtocolRegistry registry;
|
||||||
@ -46,17 +55,34 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf> {
|
|||||||
try {
|
try {
|
||||||
packet.decode(msg, direction, registry.version);
|
packet.decode(msg, direction, registry.version);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CorruptedFrameException(
|
throw handleDecodeFailure(e, packet, packetId);
|
||||||
"Error decoding " + packet.getClass() + " " + getExtraConnectionDetail(packetId), e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.isReadable()) {
|
if (msg.isReadable()) {
|
||||||
throw new CorruptedFrameException("Did not read full packet for " + packet.getClass() + " "
|
throw handleNotReadEnough(packet, packetId);
|
||||||
+ getExtraConnectionDetail(packetId));
|
|
||||||
}
|
}
|
||||||
out.add(packet);
|
out.add(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Exception handleNotReadEnough(MinecraftPacket packet, int packetId) {
|
||||||
|
if (DEBUG) {
|
||||||
|
return new CorruptedFrameException("Did not read full packet for " + packet.getClass() + " "
|
||||||
|
+ getExtraConnectionDetail(packetId));
|
||||||
|
} else {
|
||||||
|
return DECODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Exception handleDecodeFailure(Exception cause, MinecraftPacket packet, int packetId) {
|
||||||
|
if (DEBUG) {
|
||||||
|
return new CorruptedFrameException(
|
||||||
|
"Error decoding " + packet.getClass() + " " + getExtraConnectionDetail(packetId), cause);
|
||||||
|
} else {
|
||||||
|
return DECODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String getExtraConnectionDetail(int packetId) {
|
private String getExtraConnectionDetail(int packetId) {
|
||||||
return "Direction " + direction + " Protocol " + registry.version + " State " + state
|
return "Direction " + direction + " Protocol " + registry.version + " State " + state
|
||||||
+ " ID " + Integer.toHexString(packetId);
|
+ " ID " + Integer.toHexString(packetId);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren