From 2d2258d66779e2ed9a4a767fd292b54bd2ccf830 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 29 Sep 2018 23:57:40 -0400 Subject: [PATCH] Misc cleanup --- .../backend/BackendPlaySessionHandler.java | 2 +- .../backend/LoginSessionHandler.java | 4 +-- .../backend/VelocityServerConnection.java | 25 ++++++------------- .../connection/client/ConnectedPlayer.java | 6 ++--- .../client/HandshakeSessionHandler.java | 1 - .../client/InitialConnectSessionHandler.java | 2 +- .../client/LoginSessionHandler.java | 5 ++-- .../client/StatusSessionHandler.java | 2 +- .../util/ConnectionRequestResults.java | 14 ++--------- .../protocol/util/PluginMessageUtil.java | 20 +++++++-------- 10 files changed, 30 insertions(+), 51 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index cb1ecad68..284c89e2b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -19,7 +19,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { private final VelocityServerConnection serverConn; private final ClientPlaySessionHandler playerSessionHandler; - public BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection serverConn) { + BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection serverConn) { this.server = server; this.serverConn = serverConn; this.playerSessionHandler = (ClientPlaySessionHandler) serverConn.getPlayer().getConnection().getSessionHandler(); 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 d204e8e2e..f56303d32 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 @@ -30,8 +30,8 @@ public class LoginSessionHandler implements MinecraftSessionHandler { private final CompletableFuture resultFuture; private boolean informationForwarded; - public LoginSessionHandler(VelocityServer server, VelocityServerConnection serverConn, - CompletableFuture resultFuture) { + LoginSessionHandler(VelocityServer server, VelocityServerConnection serverConn, + CompletableFuture resultFuture) { this.server = server; this.serverConn = serverConn; this.resultFuture = resultFuture; 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 240e7c669..d4ceb7402 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 @@ -69,18 +69,15 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, } }) .connect(registeredServer.getServerInfo().getAddress()) - .addListener(new ChannelFutureListener() { - @Override - public void operationComplete(ChannelFuture future) throws Exception { - if (future.isSuccess()) { - connection = future.channel().pipeline().get(MinecraftConnection.class); + .addListener((ChannelFutureListener) future -> { + if (future.isSuccess()) { + connection = future.channel().pipeline().get(MinecraftConnection.class); - // Kick off the connection process - connection.setSessionHandler(new LoginSessionHandler(server, VelocityServerConnection.this, result)); - startHandshake(); - } else { - result.completeExceptionally(future.cause()); - } + // Kick off the connection process + connection.setSessionHandler(new LoginSessionHandler(server, VelocityServerConnection.this, result)); + startHandshake(); + } else { + result.completeExceptionally(future.cause()); } }); return result; @@ -122,12 +119,6 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, connection.write(login); } - public void writeIfJoined(PluginMessage message) { - if (hasCompletedJoin) { - connection.write(message); - } - } - public MinecraftConnection getConnection() { return connection; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 3c8351df4..b9e44833b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -64,7 +64,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { private PlayerSettings settings; private final VelocityServer server; - public ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection, InetSocketAddress virtualHost) { + ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection, InetSocketAddress virtualHost) { this.server = server; this.profile = profile; this.connection = connection; @@ -99,7 +99,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return this.ping; } - public void setPing(long ping) { + void setPing(long ping) { this.ping = ping; } @@ -386,7 +386,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { connection.closeWith(Disconnect.create(reason)); } - public void teardown() { + void teardown() { if (connectionInFlight != null) { connectionInFlight.disconnect(); } 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 ff3ace842..859d70782 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 @@ -16,7 +16,6 @@ import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.packet.*; import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufUtil; import net.kyori.text.TextComponent; import net.kyori.text.TranslatableComponent; import net.kyori.text.format.TextColor; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java index 36044c720..6b9a7750f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java @@ -6,7 +6,7 @@ import com.velocitypowered.proxy.protocol.MinecraftPacket; public class InitialConnectSessionHandler implements MinecraftSessionHandler { private final ConnectedPlayer player; - public InitialConnectSessionHandler(ConnectedPlayer player) { + InitialConnectSessionHandler(ConnectedPlayer player) { this.player = player; } 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 8611d8ee6..ed942a40c 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 @@ -94,13 +94,12 @@ public class LoginSessionHandler implements MinecraftSessionHandler { public boolean handle(EncryptionResponse packet) { try { KeyPair serverKeyPair = server.getServerKeyPair(); - EncryptionResponse response = (EncryptionResponse) packet; - byte[] decryptedVerifyToken = EncryptionUtils.decryptRsa(serverKeyPair, response.getVerifyToken()); + byte[] decryptedVerifyToken = EncryptionUtils.decryptRsa(serverKeyPair, packet.getVerifyToken()); if (!Arrays.equals(verify, decryptedVerifyToken)) { throw new IllegalStateException("Unable to successfully decrypt the verification token."); } - byte[] decryptedSharedSecret = EncryptionUtils.decryptRsa(serverKeyPair, response.getSharedSecret()); + byte[] decryptedSharedSecret = EncryptionUtils.decryptRsa(serverKeyPair, packet.getSharedSecret()); String serverId = EncryptionUtils.generateServerId(decryptedSharedSecret, serverKeyPair.getPublic()); String playerIp = ((InetSocketAddress) inbound.getChannel().remoteAddress()).getHostString(); 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 a0c7e7aea..a172ec254 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 @@ -19,7 +19,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { private final MinecraftConnection connection; private final InboundConnection inboundWrapper; - public StatusSessionHandler(VelocityServer server, MinecraftConnection connection, InboundConnection inboundWrapper) { + StatusSessionHandler(VelocityServer server, MinecraftConnection connection, InboundConnection inboundWrapper) { this.server = server; this.connection = connection; this.inboundWrapper = inboundWrapper; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java index 0f6811fde..968e8f378 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java @@ -31,20 +31,10 @@ public class ConnectionRequestResults { public static ConnectionRequestBuilder.Result forDisconnect(Disconnect disconnect) { Component deserialized = ComponentSerializers.JSON.deserialize(disconnect.getReason()); - return new ConnectionRequestBuilder.Result() { - @Override - public ConnectionRequestBuilder.Status getStatus() { - return ConnectionRequestBuilder.Status.SERVER_DISCONNECTED; - } - - @Override - public Optional getReason() { - return Optional.of(deserialized); - } - }; + return forDisconnect(deserialized); } - public static ConnectionRequestBuilder.Result forDisconnect(TextComponent component) { + public static ConnectionRequestBuilder.Result forDisconnect(Component component) { return new ConnectionRequestBuilder.Result() { @Override public ConnectionRequestBuilder.Status getStatus() { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java index 04988d7f9..884f2a0a6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java @@ -13,12 +13,12 @@ import java.util.Collection; import java.util.List; public class PluginMessageUtil { - public static final String BRAND_CHANNEL = "MC|Brand"; - public static final String BRAND_CHANNEL_1_13 = "minecraft:brand"; - public static final String REGISTER_CHANNEL = "REGISTER"; - public static final String REGISTER_CHANNEL_1_13 = "minecraft:register"; - public static final String UNREGISTER_CHANNEL = "UNREGISTER"; - public static final String UNREGISTER_CHANNEL_1_13 = "minecraft:unregister"; + public static final String BRAND_CHANNEL_LEGACY = "MC|Brand"; + public static final String BRAND_CHANNEL = "minecraft:brand"; + public static final String REGISTER_CHANNEL_LEGACY = "REGISTER"; + public static final String REGISTER_CHANNEL = "minecraft:register"; + public static final String UNREGISTER_CHANNEL_LEGACY = "UNREGISTER"; + public static final String UNREGISTER_CHANNEL = "minecraft:unregister"; private PluginMessageUtil() { throw new AssertionError(); @@ -26,17 +26,17 @@ public class PluginMessageUtil { public static boolean isMCBrand(PluginMessage message) { Preconditions.checkNotNull(message, "message"); - return message.getChannel().equals(BRAND_CHANNEL) || message.getChannel().equals(BRAND_CHANNEL_1_13); + return message.getChannel().equals(BRAND_CHANNEL_LEGACY) || message.getChannel().equals(BRAND_CHANNEL); } public static boolean isMCRegister(PluginMessage message) { Preconditions.checkNotNull(message, "message"); - return message.getChannel().equals(REGISTER_CHANNEL) || message.getChannel().equals(REGISTER_CHANNEL_1_13); + return message.getChannel().equals(REGISTER_CHANNEL_LEGACY) || message.getChannel().equals(REGISTER_CHANNEL); } public static boolean isMCUnregister(PluginMessage message) { Preconditions.checkNotNull(message, "message"); - return message.getChannel().equals(UNREGISTER_CHANNEL) || message.getChannel().equals(UNREGISTER_CHANNEL_1_13); + return message.getChannel().equals(UNREGISTER_CHANNEL_LEGACY) || message.getChannel().equals(UNREGISTER_CHANNEL); } public static List getChannels(PluginMessage message) { @@ -49,7 +49,7 @@ public class PluginMessageUtil { public static PluginMessage constructChannelsPacket(int protocolVersion, Collection channels) { Preconditions.checkNotNull(channels, "channels"); - String channelName = protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ? REGISTER_CHANNEL_1_13 : REGISTER_CHANNEL; + String channelName = protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ? REGISTER_CHANNEL : REGISTER_CHANNEL_LEGACY; PluginMessage message = new PluginMessage(); message.setChannel(channelName); message.setData(String.join("\0", channels).getBytes(StandardCharsets.UTF_8));