From fd231c71fd36ee74a78c0db9144d636e01ae9c77 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 23 Jun 2020 21:56:59 -0400 Subject: [PATCH] Restore server disconnect messages. --- build.gradle | 8 +++++--- .../proxy/connection/MinecraftConnection.java | 14 +++++++++----- .../backend/VelocityServerConnection.java | 2 +- .../connection/client/HandshakeSessionHandler.java | 6 +++--- .../connection/client/LoginSessionHandler.java | 8 ++++---- .../connection/client/StatusSessionHandler.java | 2 +- .../proxy/server/PingSessionHandler.java | 2 +- 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 8cb7655e4..959a24739 100644 --- a/build.gradle +++ b/build.gradle @@ -15,9 +15,6 @@ allprojects { group 'com.velocitypowered' version '1.1.0-SNAPSHOT' - sourceCompatibility = 1.8 - targetCompatibility = 1.8 - ext { // dependency versions textVersion = '3.0.3' @@ -41,6 +38,11 @@ allprojects { } } + java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + repositories { mavenLocal() mavenCentral() diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index dad6bdb3e..3b11e48d1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -92,8 +92,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { sessionHandler.disconnected(); } - if (association != null && !knownDisconnect - && !(association instanceof InitialInboundConnection)) { + if (association != null && !knownDisconnect) { logger.info("{} has disconnected", association); } } @@ -226,15 +225,20 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { /** * Immediately closes the connection. + * @param markKnown whether the disconnection is known */ - public void close() { + public void close(boolean markKnown) { if (channel.isActive()) { if (channel.eventLoop().inEventLoop()) { - knownDisconnect = true; + if (markKnown) { + knownDisconnect = true; + } channel.close(); } else { channel.eventLoop().execute(() -> { - knownDisconnect = true; + if (markKnown) { + knownDisconnect = true; + } channel.close(); }); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index 1f13c7b0c..0db532f62 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -188,7 +188,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, public void disconnect() { if (connection != null) { gracefulDisconnect = true; - connection.close(); + connection.close(false); connection = null; } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java index b372010a3..64a234dff 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java @@ -66,7 +66,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { StateRegistry nextState = getStateForProtocol(handshake.getNextStatus()); if (nextState == null) { LOGGER.error("{} provided invalid protocol {}", ic, handshake.getNextStatus()); - connection.close(); + connection.close(true); } else { connection.setState(nextState); connection.setProtocolVersion(handshake.getProtocolVersion()); @@ -171,13 +171,13 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { @Override public void handleGeneric(MinecraftPacket packet) { // Unknown packet received. Better to close the connection. - connection.close(); + connection.close(true); } @Override public void handleUnknown(ByteBuf buf) { // Unknown packet received. Better to close the connection. - connection.close(); + connection.close(true); } private static class LegacyInboundConnection implements InboundConnection { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 7dcf61584..2f185652b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -134,11 +134,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler { logger.error( "Got an unexpected error code {} whilst contacting Mojang to log in {} ({})", profileResponse.getStatusCode(), login.getUsername(), playerIp); - mcConnection.close(); + mcConnection.close(true); } } catch (ExecutionException e) { logger.error("Unable to authenticate with Mojang", e); - mcConnection.close(); + mcConnection.close(true); } catch (InterruptedException e) { // not much we can do usefully Thread.currentThread().interrupt(); @@ -146,7 +146,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { }, mcConnection.eventLoop()); } catch (GeneralSecurityException e) { logger.error("Unable to enable encryption", e); - mcConnection.close(); + mcConnection.close(true); } return true; } @@ -286,7 +286,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { @Override public void handleUnknown(ByteBuf buf) { - mcConnection.close(); + mcConnection.close(true); } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java index 4b3627ec9..04a96e0ef 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java @@ -183,6 +183,6 @@ public class StatusSessionHandler implements MinecraftSessionHandler { @Override public void handleUnknown(ByteBuf buf) { // what even is going on? - connection.close(); + connection.close(true); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java index 93094cc36..bf2d2e286 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java @@ -48,7 +48,7 @@ public class PingSessionHandler implements MinecraftSessionHandler { public boolean handle(StatusResponse packet) { // All good! completed = true; - connection.close(); + connection.close(true); ServerPing ping = VelocityServer.GSON.fromJson(packet.getStatus(), ServerPing.class); result.complete(ping);