From a44bb3b048ec2deb823d21a0977add170e6f2b80 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 29 Sep 2018 14:37:42 -0400 Subject: [PATCH] Remove more junk --- .../backend/LoginSessionHandler.java | 34 +++++-------------- .../backend/VelocityServerConnection.java | 7 +--- .../client/ClientPlaySessionHandler.java | 1 - 3 files changed, 10 insertions(+), 32 deletions(-) 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 b0b625c86..d204e8e2e 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 @@ -9,7 +9,6 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.VelocityConstants; import com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults; -import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.packet.*; @@ -28,11 +27,14 @@ import java.util.concurrent.CompletableFuture; public class LoginSessionHandler implements MinecraftSessionHandler { private final VelocityServer server; private final VelocityServerConnection serverConn; + private final CompletableFuture resultFuture; private boolean informationForwarded; - public LoginSessionHandler(VelocityServer server, VelocityServerConnection serverConn) { + public LoginSessionHandler(VelocityServer server, VelocityServerConnection serverConn, + CompletableFuture resultFuture) { this.server = server; this.serverConn = serverConn; + this.resultFuture = resultFuture; } @Override @@ -66,9 +68,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(Disconnect packet) { - Disconnect disconnect = (Disconnect) packet; - // Do we have an outstanding notification? If so, fulfill it. - doNotify(ConnectionRequestResults.forDisconnect(disconnect)); + resultFuture.complete(ConnectionRequestResults.forDisconnect(packet)); serverConn.disconnect(); return true; } @@ -82,7 +82,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ServerLoginSuccess packet) { if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && !informationForwarded) { - doNotify(ConnectionRequestResults.forDisconnect( + resultFuture.complete(ConnectionRequestResults.forDisconnect( TextComponent.of("Your server did not send a forwarding request to the proxy. Is it set up correctly?"))); serverConn.disconnect(); return true; @@ -103,7 +103,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { existingConnection.disconnect(); } - doNotify(ConnectionRequestResults.SUCCESSFUL); + resultFuture.complete(ConnectionRequestResults.SUCCESSFUL); serverConn.getConnection().setSessionHandler(new BackendPlaySessionHandler(server, serverConn)); serverConn.getPlayer().setConnectedServer(serverConn); return true; @@ -111,28 +111,12 @@ public class LoginSessionHandler implements MinecraftSessionHandler { @Override public void exception(Throwable throwable) { - CompletableFuture future = serverConn.getConnection().getChannel() - .attr(VelocityServerConnection.CONNECTION_NOTIFIER).getAndSet(null); - if (future != null) { - future.completeExceptionally(throwable); - } + resultFuture.completeExceptionally(throwable); } @Override public void disconnected() { - CompletableFuture future = serverConn.getConnection().getChannel() - .attr(VelocityServerConnection.CONNECTION_NOTIFIER).getAndSet(null); - if (future != null) { - future.completeExceptionally(new IOException("Unexpectedly disconnected from remote server")); - } - } - - private void doNotify(ConnectionRequestBuilder.Result result) { - CompletableFuture future = serverConn.getConnection().getChannel() - .attr(VelocityServerConnection.CONNECTION_NOTIFIER).getAndSet(null); - if (future != null) { - future.complete(result); - } + resultFuture.completeExceptionally(new IOException("Unexpectedly disconnected from remote server")); } private static ByteBuf createForwardingData(byte[] hmacSecret, String address, GameProfile profile) { 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 60b35c1a6..240e7c669 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 @@ -25,7 +25,6 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelInitializer; import io.netty.handler.timeout.ReadTimeoutHandler; -import io.netty.util.AttributeKey; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; @@ -34,9 +33,6 @@ import static com.velocitypowered.proxy.VelocityServer.GSON; import static com.velocitypowered.proxy.network.Connections.*; public class VelocityServerConnection implements MinecraftConnectionAssociation, ServerConnection { - static final AttributeKey> CONNECTION_NOTIFIER = - AttributeKey.newInstance("connection-notification-result"); - private final VelocityRegisteredServer registeredServer; private final ConnectedPlayer proxyPlayer; private final VelocityServer server; @@ -66,7 +62,6 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolConstants.Direction.CLIENTBOUND)) .addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolConstants.Direction.SERVERBOUND)); - ch.attr(CONNECTION_NOTIFIER).set(result); MinecraftConnection connection = new MinecraftConnection(ch, server); connection.setState(StateRegistry.HANDSHAKE); connection.setAssociation(VelocityServerConnection.this); @@ -81,7 +76,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, connection = future.channel().pipeline().get(MinecraftConnection.class); // Kick off the connection process - connection.setSessionHandler(new LoginSessionHandler(server, VelocityServerConnection.this)); + connection.setSessionHandler(new LoginSessionHandler(server, VelocityServerConnection.this, result)); startHandshake(); } else { result.completeExceptionally(future.cause()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index b2dfcb005..440b689b7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -180,7 +180,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // If we don't want to handle this packet, just forward it on. if (serverConnection.hasCompletedJoin()) { - logger.info("Will write {}", packet); serverConnection.getConnection().write(packet); } }