From 467fe34da38a7a8b820d7cbfcfcef9301fa97eea Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 27 Nov 2019 01:01:50 -0500 Subject: [PATCH] Provide useful information for "unexpectedly disconnected from server" Fixes #233 --- .../connection/backend/LoginSessionHandler.java | 17 ++++++++++++++--- .../proxy/util/except/QuietException.java | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 proxy/src/main/java/com/velocitypowered/proxy/util/except/QuietException.java diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java index d18951369..5627d9ba5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java @@ -17,9 +17,9 @@ import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage; import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse; import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess; import com.velocitypowered.proxy.protocol.packet.SetCompression; +import com.velocitypowered.proxy.util.except.QuietException; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import java.io.IOException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.concurrent.CompletableFuture; @@ -111,8 +111,19 @@ public class LoginSessionHandler implements MinecraftSessionHandler { @Override public void disconnected() { - resultFuture - .completeExceptionally(new IOException("Unexpectedly disconnected from remote server")); + if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.LEGACY) { + resultFuture.completeExceptionally( + new QuietException("The connection to the remote server was unexpectedly closed.\n" + + "This is usually because the remote server does not have BungeeCord IP forwarding " + + "correctly enabled.\nSee " + + "https://docs.velocitypowered.com/en/latest/users/player-info-forwarding.html " + + "for instructions on how to configure player info forwarding correctly.") + ); + } else { + resultFuture.completeExceptionally( + new QuietException("The connection to the remote server was unexpectedly closed.") + ); + } } private static ByteBuf createForwardingData(byte[] hmacSecret, String address, diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/except/QuietException.java b/proxy/src/main/java/com/velocitypowered/proxy/util/except/QuietException.java new file mode 100644 index 000000000..f095f5779 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/except/QuietException.java @@ -0,0 +1,17 @@ +package com.velocitypowered.proxy.util.except; + +/** + * A special-purpose exception thrown when we want to indicate an error condition but do not want + * to see a large stack trace in logs. + */ +public class QuietException extends Exception { + + public QuietException(String message) { + super(message); + } + + @Override + public synchronized Throwable fillInStackTrace() { + return this; + } +}