From c2fb4dbe06b458d24dcc57bf5534f875262ce702 Mon Sep 17 00:00:00 2001 From: Wafarm Date: Thu, 25 Jul 2024 10:31:32 +0800 Subject: [PATCH] Some minor changes --- .../proxy/config/VelocityConfiguration.java | 24 +++++++++---------- .../backend/LoginSessionHandler.java | 6 ++--- .../backend/VelocityServerConnection.java | 2 +- .../connection/client/AuthSessionHandler.java | 4 ++-- .../client/HandshakeSessionHandler.java | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 9a2da57a8..9d76c1215 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -70,7 +70,7 @@ public class VelocityConfiguration implements ProxyConfig { @Expose private boolean preventClientProxyConnections = false; @Expose - private PlayerInfoForwarding defaultPlayerInfoForwardingMode = PlayerInfoForwarding.NONE; + private PlayerInfoForwarding defaultForwardingMode = PlayerInfoForwarding.NONE; private byte[] forwardingSecret = generateRandomString(12).getBytes(StandardCharsets.UTF_8); @Expose private boolean announceForge = false; @@ -103,7 +103,7 @@ public class VelocityConfiguration implements ProxyConfig { private VelocityConfiguration(String bind, String motd, int showMaxPlayers, boolean onlineMode, boolean preventClientProxyConnections, boolean announceForge, - PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret, + PlayerInfoForwarding defaultForwardingMode, byte[] forwardingSecret, boolean onlineModeKickExistingPlayers, PingPassthroughMode pingPassthrough, boolean enablePlayerAddressLogging, Servers servers, ForcedHosts forcedHosts, Advanced advanced, Query query, Metrics metrics, boolean forceKeyAuthentication) { @@ -113,7 +113,7 @@ public class VelocityConfiguration implements ProxyConfig { this.onlineMode = onlineMode; this.preventClientProxyConnections = preventClientProxyConnections; this.announceForge = announceForge; - this.defaultPlayerInfoForwardingMode = playerInfoForwardingMode; + this.defaultForwardingMode = defaultForwardingMode; this.forwardingSecret = forwardingSecret; this.onlineModeKickExistingPlayers = onlineModeKickExistingPlayers; this.pingPassthrough = pingPassthrough; @@ -155,8 +155,8 @@ public class VelocityConfiguration implements ProxyConfig { for (Map.Entry entry : servers.getServerForwardingModes().entrySet()) { switch (entry.getValue()) { case NONE: - logger.warn("Player info forwarding is disabled for " + entry.getKey() + "!" - + " All players will appear to be connecting from the proxy and will have offline-mode UUIDs."); + logger.warn("Player info forwarding is disabled for {}!" + + " All players will appear to be connecting from the proxy and will have offline-mode UUIDs.", entry.getKey()); break; case MODERN: case BUNGEEGUARD: @@ -167,7 +167,7 @@ public class VelocityConfiguration implements ProxyConfig { } } - switch (defaultPlayerInfoForwardingMode) { + switch (defaultForwardingMode) { case NONE: logger.warn("Player info forwarding is disabled by default! All players will appear to be connecting " + "from the proxy and will have offline-mode UUIDs."); @@ -182,7 +182,7 @@ public class VelocityConfiguration implements ProxyConfig { if (requireForwardingSecret && (forwardingSecret == null || forwardingSecret.length == 0)) { logger.error("You don't have a forwarding secret set. This is required for security. " - + "See https://docs.papermc.io/velocity/player-information-forwarding for more details."); + + "See https://docs.papermc.io/velocity/player-information-forwarding#configuring-modern-forwarding for more details."); valid = false; } @@ -312,12 +312,12 @@ public class VelocityConfiguration implements ProxyConfig { return preventClientProxyConnections; } - public PlayerInfoForwarding getDefaultPlayerInfoForwardingMode() { - return defaultPlayerInfoForwardingMode; + public PlayerInfoForwarding getDefaultForwardingMode() { + return defaultForwardingMode; } - public PlayerInfoForwarding getServerPlayerInfoForwardingMode(String server) { - return servers.getServerForwardingModes().getOrDefault(server, defaultPlayerInfoForwardingMode); + public PlayerInfoForwarding getServerForwardingMode(String server) { + return servers.getServerForwardingModes().getOrDefault(server, defaultForwardingMode); } public byte[] getForwardingSecret() { @@ -437,7 +437,7 @@ public class VelocityConfiguration implements ProxyConfig { .add("motd", motd) .add("showMaxPlayers", showMaxPlayers) .add("onlineMode", onlineMode) - .add("defaultPlayerInfoForwardingMode", defaultPlayerInfoForwardingMode) + .add("defaultForwardingMode", defaultForwardingMode) .add("forwardingSecret", forwardingSecret) .add("announceForge", announceForge) .add("servers", servers) 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 9c67b6a8b..e5299240b 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 @@ -83,7 +83,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { public boolean handle(LoginPluginMessagePacket packet) { MinecraftConnection mc = serverConn.ensureConnected(); VelocityConfiguration configuration = server.getConfiguration(); - if (configuration.getServerPlayerInfoForwardingMode(serverConn.getServerInfo().getName()) == PlayerInfoForwarding.MODERN + if (configuration.getServerForwardingMode(serverConn.getServerInfo().getName()) == PlayerInfoForwarding.MODERN && packet.getChannel().equals(PlayerDataForwarding.CHANNEL)) { int requestedForwardingVersion = PlayerDataForwarding.MODERN_DEFAULT; @@ -143,7 +143,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ServerLoginSuccessPacket packet) { - if (server.getConfiguration().getServerPlayerInfoForwardingMode(serverConn.getServerInfo().getName()) == PlayerInfoForwarding.MODERN + if (server.getConfiguration().getServerForwardingMode(serverConn.getServerInfo().getName()) == PlayerInfoForwarding.MODERN && !informationForwarded) { resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE, serverConn.getServer())); serverConn.disconnect(); @@ -203,7 +203,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { @Override public void disconnected() { - if (server.getConfiguration().getServerPlayerInfoForwardingMode(serverConn.getServerInfo().getName()) == PlayerInfoForwarding.LEGACY) { + if (server.getConfiguration().getServerForwardingMode(serverConn.getServerInfo().getName()) == PlayerInfoForwarding.LEGACY) { resultFuture.completeExceptionally(new QuietRuntimeException( """ The connection to the remote server was unexpectedly closed. 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 c8aaff9bb..3de386c4a 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 @@ -163,7 +163,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, private void startHandshake() { final MinecraftConnection mc = ensureConnected(); - PlayerInfoForwarding forwardingMode = server.getConfiguration().getServerPlayerInfoForwardingMode(registeredServer.getServerInfo().getName()); + PlayerInfoForwarding forwardingMode = server.getConfiguration().getServerForwardingMode(registeredServer.getServerInfo().getName()); // Initiate the handshake. ProtocolVersion protocolVersion = proxyPlayer.getConnection().getProtocolVersion(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/AuthSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/AuthSessionHandler.java index 9ed11540a..0100ae00a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/AuthSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/AuthSessionHandler.java @@ -83,7 +83,7 @@ public class AuthSessionHandler implements MinecraftSessionHandler { public void activated() { // Some connection types may need to alter the game profile. profile = mcConnection.getType().addGameProfileTokensIfRequired(profile, - server.getConfiguration().getDefaultPlayerInfoForwardingMode()); + server.getConfiguration().getDefaultForwardingMode()); GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEvent(inbound, profile, onlineMode); final GameProfile finalProfile = profile; @@ -139,7 +139,7 @@ public class AuthSessionHandler implements MinecraftSessionHandler { } VelocityConfiguration configuration = server.getConfiguration(); UUID playerUniqueId = player.getUniqueId(); - if (configuration.getDefaultPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) { + if (configuration.getDefaultForwardingMode() == PlayerInfoForwarding.NONE) { playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername()); } 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 d1f8be837..831d4906c 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 @@ -146,7 +146,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { // If the proxy is configured for modern forwarding, we must deny connections from 1.12.2 // and lower, otherwise IP information will never get forwarded. - if (server.getConfiguration().getDefaultPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN + if (server.getConfiguration().getDefaultForwardingMode() == PlayerInfoForwarding.MODERN && handshake.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13)) { // Bump connection into correct protocol state so that we can send the disconnect packet. connection.setState(StateRegistry.LOGIN);