diff --git a/src/main/java/net/raphimc/viaproxy/protocoltranslator/viaproxy/ViaProxyConfig.java b/src/main/java/net/raphimc/viaproxy/protocoltranslator/viaproxy/ViaProxyConfig.java index 1602424..ad40fa4 100644 --- a/src/main/java/net/raphimc/viaproxy/protocoltranslator/viaproxy/ViaProxyConfig.java +++ b/src/main/java/net/raphimc/viaproxy/protocoltranslator/viaproxy/ViaProxyConfig.java @@ -67,6 +67,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion. private final OptionSpec optionCompressionThreshold; private final OptionSpec optionAllowBetaPinging; private final OptionSpec optionIgnoreProtocolTranslationErrors; + private final OptionSpec optionSuppressClientProtocolErrors; private final OptionSpec optionAllowLegacyClientPassthrough; private final OptionSpec optionCustomMotd; private final OptionSpec optionResourcePackUrl; @@ -87,6 +88,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion. private int compressionThreshold = 256; private boolean allowBetaPinging = false; private boolean ignoreProtocolTranslationErrors = false; + private boolean suppressClientProtocolErrors = false; private boolean allowLegacyClientPassthrough = false; private String customMotd = ""; private String resourcePackUrl = ""; @@ -112,6 +114,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion. this.optionCompressionThreshold = this.optionParser.accepts("compression-threshold").withRequiredArg().ofType(Integer.class).defaultsTo(this.compressionThreshold); this.optionAllowBetaPinging = this.optionParser.accepts("allow-beta-pinging").withRequiredArg().ofType(Boolean.class).defaultsTo(this.allowBetaPinging); this.optionIgnoreProtocolTranslationErrors = this.optionParser.accepts("ignore-protocol-translation-errors").withRequiredArg().ofType(Boolean.class).defaultsTo(this.ignoreProtocolTranslationErrors); + this.optionSuppressClientProtocolErrors = this.optionParser.accepts("suppress-client-protocol-errors").withRequiredArg().ofType(Boolean.class).defaultsTo(this.suppressClientProtocolErrors); this.optionAllowLegacyClientPassthrough = this.optionParser.accepts("allow-legacy-client-passthrough").withRequiredArg().ofType(Boolean.class).defaultsTo(this.allowLegacyClientPassthrough); this.optionCustomMotd = this.optionParser.accepts("custom-motd").withRequiredArg().ofType(String.class).defaultsTo(this.customMotd); this.optionResourcePackUrl = this.optionParser.accepts("resource-pack-url").withRequiredArg().ofType(String.class).defaultsTo(this.resourcePackUrl); @@ -144,6 +147,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion. this.compressionThreshold = this.getInt("compression-threshold", this.compressionThreshold); this.allowBetaPinging = this.getBoolean("allow-beta-pinging", this.allowBetaPinging); this.ignoreProtocolTranslationErrors = this.getBoolean("ignore-protocol-translation-errors", this.ignoreProtocolTranslationErrors); + this.suppressClientProtocolErrors = this.getBoolean("suppress-client-protocol-errors", this.suppressClientProtocolErrors); this.allowLegacyClientPassthrough = this.getBoolean("allow-legacy-client-passthrough", this.allowLegacyClientPassthrough); this.customMotd = this.getString("custom-motd", this.customMotd); this.resourcePackUrl = this.getString("resource-pack-url", this.resourcePackUrl); @@ -180,6 +184,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion. this.compressionThreshold = options.valueOf(this.optionCompressionThreshold); this.allowBetaPinging = options.valueOf(this.optionAllowBetaPinging); this.ignoreProtocolTranslationErrors = options.valueOf(this.optionIgnoreProtocolTranslationErrors); + this.suppressClientProtocolErrors = options.valueOf(this.optionSuppressClientProtocolErrors); this.allowLegacyClientPassthrough = options.valueOf(this.optionAllowLegacyClientPassthrough); this.customMotd = options.valueOf(this.optionCustomMotd); this.resourcePackUrl = options.valueOf(this.optionResourcePackUrl); @@ -347,6 +352,15 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion. this.set("ignore-protocol-translation-errors", ignoreProtocolTranslationErrors); } + public boolean shouldSuppressClientProtocolErrors() { + return this.suppressClientProtocolErrors; + } + + public void setSuppressClientProtocolErrors(final boolean suppressClientProtocolErrors) { + this.suppressClientProtocolErrors = suppressClientProtocolErrors; + this.set("suppress-client-protocol-errors", suppressClientProtocolErrors); + } + public boolean shouldAllowLegacyClientPassthrough() { return this.allowLegacyClientPassthrough; } diff --git a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java index 0c08384..020e12a 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java @@ -107,7 +107,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - ExceptionUtil.handleNettyException(ctx, cause, this.proxyConnection); + ExceptionUtil.handleNettyException(ctx, cause, this.proxyConnection, true); } private void handleHandshake(final C2SHandshakingClientIntentionPacket packet) { diff --git a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/passthrough/LegacyPassthroughInitialHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/passthrough/LegacyPassthroughInitialHandler.java index 1b1b975..2a92534 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/passthrough/LegacyPassthroughInitialHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/passthrough/LegacyPassthroughInitialHandler.java @@ -53,7 +53,7 @@ public class LegacyPassthroughInitialHandler extends SimpleChannelInboundHandler @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - ExceptionUtil.handleNettyException(ctx, cause, null); + ExceptionUtil.handleNettyException(ctx, cause, null, true); } } diff --git a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/passthrough/PassthroughClient2ProxyHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/passthrough/PassthroughClient2ProxyHandler.java index 9e0999e..7be42c5 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/passthrough/PassthroughClient2ProxyHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/passthrough/PassthroughClient2ProxyHandler.java @@ -69,7 +69,7 @@ public class PassthroughClient2ProxyHandler extends SimpleChannelInboundHandler< @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - ExceptionUtil.handleNettyException(ctx, cause, null); + ExceptionUtil.handleNettyException(ctx, cause, null, true); } protected void connectToServer(final Channel c2pChannel) { diff --git a/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerHandler.java index 381e5d7..e0e982e 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerHandler.java @@ -66,7 +66,7 @@ public class Proxy2ServerHandler extends SimpleChannelInboundHandler { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - ExceptionUtil.handleNettyException(ctx, cause, this.proxyConnection); + ExceptionUtil.handleNettyException(ctx, cause, this.proxyConnection, false); } } diff --git a/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/passthrough/PassthroughProxy2ServerHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/passthrough/PassthroughProxy2ServerHandler.java index c42966d..564e644 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/passthrough/PassthroughProxy2ServerHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/passthrough/PassthroughProxy2ServerHandler.java @@ -52,7 +52,7 @@ public class PassthroughProxy2ServerHandler extends SimpleChannelInboundHandler< @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - ExceptionUtil.handleNettyException(ctx, cause, null); + ExceptionUtil.handleNettyException(ctx, cause, null, false); } } diff --git a/src/main/java/net/raphimc/viaproxy/proxy/util/ExceptionUtil.java b/src/main/java/net/raphimc/viaproxy/proxy/util/ExceptionUtil.java index da8b67e..54565e2 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/util/ExceptionUtil.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/util/ExceptionUtil.java @@ -21,6 +21,7 @@ import com.viaversion.viaversion.exception.InformativeException; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.EncoderException; +import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.proxy.session.ProxyConnection; import net.raphimc.viaproxy.util.logging.Logger; @@ -41,7 +42,7 @@ public class ExceptionUtil { } } - public static void handleNettyException(ChannelHandlerContext ctx, Throwable cause, ProxyConnection proxyConnection) { + public static void handleNettyException(ChannelHandlerContext ctx, Throwable cause, ProxyConnection proxyConnection, boolean client2Proxy) { if (!ctx.channel().isOpen()) return; if (cause instanceof ClosedChannelException) return; if (cause instanceof IOException) return; @@ -49,12 +50,14 @@ public class ExceptionUtil { ctx.channel().close(); return; } - Logger.LOGGER.error("Caught unhandled netty exception", cause); - try { - if (proxyConnection != null) { - proxyConnection.kickClient("§cAn unhandled error occurred in your connection and it has been closed.\n§aError details for report:§f" + ExceptionUtil.prettyPrint(cause)); + if (!client2Proxy || !ViaProxy.getConfig().shouldSuppressClientProtocolErrors()) { + Logger.LOGGER.error("Caught unhandled netty exception", cause); + try { + if (proxyConnection != null) { + proxyConnection.kickClient("§cAn unhandled error occurred in your connection and it has been closed.\n§aError details for report:§f" + ExceptionUtil.prettyPrint(cause)); + } + } catch (Throwable ignored) { } - } catch (Throwable ignored) { } ctx.channel().close(); } diff --git a/src/main/resources/assets/viaproxy/viaproxy.yml b/src/main/resources/assets/viaproxy/viaproxy.yml index d00cae7..942cbc2 100644 --- a/src/main/resources/assets/viaproxy/viaproxy.yml +++ b/src/main/resources/assets/viaproxy/viaproxy.yml @@ -52,6 +52,10 @@ allow-beta-pinging: false # This may cause issues depending on the type of packet which failed to translate. ignore-protocol-translation-errors: false # +# Enabling this will suppress client protocol errors to prevent lag when ViaProxy is getting spammed with invalid packets. +# This may cause issues with debugging client connection issues because no error messages will be printed. +suppress-client-protocol-errors: false +# # Allow <= 1.6.4 clients to connect through ViaProxy to the target server. (No protocol translation or packet handling) allow-legacy-client-passthrough: false #