From ff5c8301c2f25e3574b7c79b84ed6191d055ed1f Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Sun, 23 Jun 2024 21:40:33 +0200 Subject: [PATCH] Disable BungeeCord player info passthrough by default --- .../viaproxy/ViaProxyConfig.java | 14 ++++++++++++++ .../proxy/client2proxy/Client2ProxyHandler.java | 7 ++++++- src/main/resources/assets/viaproxy/viaproxy.yml | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/raphimc/viaproxy/protocoltranslator/viaproxy/ViaProxyConfig.java b/src/main/java/net/raphimc/viaproxy/protocoltranslator/viaproxy/ViaProxyConfig.java index 679a531..a43ea53 100644 --- a/src/main/java/net/raphimc/viaproxy/protocoltranslator/viaproxy/ViaProxyConfig.java +++ b/src/main/java/net/raphimc/viaproxy/protocoltranslator/viaproxy/ViaProxyConfig.java @@ -69,6 +69,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion. private final OptionSpec optionIgnoreProtocolTranslationErrors; private final OptionSpec optionSuppressClientProtocolErrors; private final OptionSpec optionAllowLegacyClientPassthrough; + private final OptionSpec optionBungeecordPlayerInfoPassthrough; private final OptionSpec optionCustomMotd; private final OptionSpec optionResourcePackUrl; private final OptionSpec optionWildcardDomainHandling; @@ -91,6 +92,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion. private boolean ignoreProtocolTranslationErrors = false; private boolean suppressClientProtocolErrors = false; private boolean allowLegacyClientPassthrough = false; + private boolean bungeecordPlayerInfoPassthrough = false; private String customMotd = ""; private String resourcePackUrl = ""; private WildcardDomainHandling wildcardDomainHandling = WildcardDomainHandling.NONE; @@ -118,6 +120,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion. this.optionIgnoreProtocolTranslationErrors = this.optionParser.accepts("ignore-protocol-translation-errors").withRequiredArg().ofType(Boolean.class).defaultsTo(this.ignoreProtocolTranslationErrors); this.optionSuppressClientProtocolErrors = this.optionParser.accepts("suppress-client-protocol-errors").withRequiredArg().ofType(Boolean.class).defaultsTo(this.suppressClientProtocolErrors); this.optionAllowLegacyClientPassthrough = this.optionParser.accepts("allow-legacy-client-passthrough").withRequiredArg().ofType(Boolean.class).defaultsTo(this.allowLegacyClientPassthrough); + this.optionBungeecordPlayerInfoPassthrough = this.optionParser.accepts("bungeecord-player-info-passthrough").withRequiredArg().ofType(Boolean.class).defaultsTo(this.bungeecordPlayerInfoPassthrough); this.optionCustomMotd = this.optionParser.accepts("custom-motd").withRequiredArg().ofType(String.class).defaultsTo(this.customMotd); this.optionResourcePackUrl = this.optionParser.accepts("resource-pack-url").withRequiredArg().ofType(String.class).defaultsTo(this.resourcePackUrl); this.optionWildcardDomainHandling = this.optionParser.accepts("wildcard-domain-handling").withRequiredArg().ofType(WildcardDomainHandling.class).defaultsTo(this.wildcardDomainHandling); @@ -152,6 +155,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion. this.ignoreProtocolTranslationErrors = this.getBoolean("ignore-protocol-translation-errors", this.ignoreProtocolTranslationErrors); this.suppressClientProtocolErrors = this.getBoolean("suppress-client-protocol-errors", this.suppressClientProtocolErrors); this.allowLegacyClientPassthrough = this.getBoolean("allow-legacy-client-passthrough", this.allowLegacyClientPassthrough); + this.bungeecordPlayerInfoPassthrough = this.getBoolean("bungeecord-player-info-passthrough", this.bungeecordPlayerInfoPassthrough); this.customMotd = this.getString("custom-motd", this.customMotd); this.resourcePackUrl = this.getString("resource-pack-url", this.resourcePackUrl); this.wildcardDomainHandling = WildcardDomainHandling.byName(this.getString("wildcard-domain-handling", this.wildcardDomainHandling.name())); @@ -190,6 +194,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion. this.ignoreProtocolTranslationErrors = options.valueOf(this.optionIgnoreProtocolTranslationErrors); this.suppressClientProtocolErrors = options.valueOf(this.optionSuppressClientProtocolErrors); this.allowLegacyClientPassthrough = options.valueOf(this.optionAllowLegacyClientPassthrough); + this.bungeecordPlayerInfoPassthrough = options.valueOf(this.optionBungeecordPlayerInfoPassthrough); this.customMotd = options.valueOf(this.optionCustomMotd); this.resourcePackUrl = options.valueOf(this.optionResourcePackUrl); this.wildcardDomainHandling = options.valueOf(this.optionWildcardDomainHandling); @@ -375,6 +380,15 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion. this.set("allow-legacy-client-passthrough", allowLegacyClientPassthrough); } + public boolean shouldPassthroughBungeecordPlayerInfo() { + return this.bungeecordPlayerInfoPassthrough; + } + + public void setPassthroughBungeecordPlayerInfo(final boolean bungeecordPlayerInfoPassthrough) { + this.bungeecordPlayerInfoPassthrough = bungeecordPlayerInfoPassthrough; + this.set("bungeecord-player-info-passthrough", bungeecordPlayerInfoPassthrough); + } + public String getCustomMotd() { return this.customMotd; } diff --git a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java index 4b02163..6d71644 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java @@ -124,7 +124,12 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler { this.proxyConnection.kickClient("§cYour client version is not supported by ViaProxy!"); } - final String[] handshakeParts = packet.address.split("\0"); + final String[] handshakeParts; + if (ViaProxy.getConfig().shouldPassthroughBungeecordPlayerInfo()) { + handshakeParts = packet.address.split("\0"); + } else { + handshakeParts = new String[]{packet.address}; + } SocketAddress serverAddress = ViaProxy.getConfig().getTargetAddress(); ProtocolVersion serverVersion = ViaProxy.getConfig().getTargetVersion(); diff --git a/src/main/resources/assets/viaproxy/viaproxy.yml b/src/main/resources/assets/viaproxy/viaproxy.yml index 60f8846..b64ee9d 100644 --- a/src/main/resources/assets/viaproxy/viaproxy.yml +++ b/src/main/resources/assets/viaproxy/viaproxy.yml @@ -59,6 +59,10 @@ suppress-client-protocol-errors: false # Allow <= 1.6.4 clients to connect through ViaProxy to the target server. (No protocol translation or packet handling) allow-legacy-client-passthrough: false # +# Allow additional information like player ip, player uuid to be passed through to the backend server. +# This is typically used by proxies like BungeeCord and requires support from the backend server as well. +bungeecord-player-info-passthrough: false +# # Custom MOTD to send when clients ping the proxy. Leave empty to use the target server's MOTD. custom-motd: "" #