From 5dfe2f5a7424fd36d5b1fea55dbfcbd01117e001 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Wed, 5 Apr 2023 23:24:09 +0200 Subject: [PATCH] Cleaned up Options --- .../net/raphimc/viaproxy/cli/options/Options.java | 14 +++++++------- .../proxy/client2proxy/Client2ProxyHandler.java | 2 +- .../Proxy2ServerChannelInitializer.java | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/raphimc/viaproxy/cli/options/Options.java b/src/main/java/net/raphimc/viaproxy/cli/options/Options.java index 23b0882..3881e86 100644 --- a/src/main/java/net/raphimc/viaproxy/cli/options/Options.java +++ b/src/main/java/net/raphimc/viaproxy/cli/options/Options.java @@ -57,7 +57,7 @@ public class Options { public static boolean INTERNAL_SRV_MODE; // Example: ip\7port\7version\7mppass public static boolean LOCAL_SOCKET_AUTH; public static String RESOURCE_PACK_URL; // Example: http://example.com/resourcepack.zip - public static boolean HAPROXY_PROTOCOL; + public static boolean SERVER_HAPROXY_PROTOCOL; public static boolean LEGACY_CLIENT_PASSTHROUGH; public static void parse(final String[] args) throws IOException { @@ -75,11 +75,11 @@ public class Options { final OptionSpec version = parser.acceptsAll(asList("version", "v"), "The version of the target server").withRequiredArg().withValuesConvertedBy(new VersionEnumConverter()).required(); final OptionSpec openAuthModAuth = parser.acceptsAll(asList("openauthmod_auth", "oam_auth"), "Enable OpenAuthMod authentication"); final OptionSpec localSocketAuth = parser.accepts("local_socket_auth", "Enable authentication over a local socket"); - final OptionSpec betaCraftAuth = parser.accepts("betacraft_auth", "Use BetaCraft authentication servers for classic"); - final OptionSpec resourcePackUrl = parser.acceptsAll(asList("resource_pack_url", "resource_pack", "rpu", "rp"), "URL of a resource pack which all connecting clients can optionally download").withRequiredArg().ofType(String.class); - final OptionSpec proxyUrl = parser.acceptsAll(asList("proxy_url", "proxy"), "URL of a SOCKS(4/5)/HTTP(S) proxy which will be used for TCP connections").withRequiredArg().ofType(String.class); - final OptionSpec haProxyProtocol = parser.acceptsAll(asList("haproxy-protocol", "haproxy"), "Send HAProxy protocol messages to the backend server"); - final OptionSpec legacyClientPassthrough = parser.acceptsAll(asList("legacy_client_passthrough", "legacy_passthrough"), "Allow <= 1.6.4 clients to connect to the backend server instead of being kicked"); + final OptionSpec betaCraftAuth = parser.accepts("betacraft_auth", "Use BetaCraft authentication for classic servers"); + final OptionSpec resourcePackUrl = parser.acceptsAll(asList("resource_pack_url", "resource_pack", "rpu", "rp"), "URL of a resource pack which clients can optionally download").withRequiredArg().ofType(String.class); + final OptionSpec proxyUrl = parser.acceptsAll(asList("proxy_url", "proxy"), "URL of a SOCKS(4/5)/HTTP(S) proxy which will be used for backend TCP connections").withRequiredArg().ofType(String.class); + final OptionSpec serverHaProxyProtocol = parser.acceptsAll(asList("server-haproxy-protocol", "server-haproxy"), "Send HAProxy protocol messages to the backend server"); + final OptionSpec legacyClientPassthrough = parser.acceptsAll(asList("legacy_client_passthrough", "legacy_passthrough"), "Allow <= 1.6.4 clients to connect to the backend server"); PluginManager.EVENT_MANAGER.call(new PreOptionsParseEvent(parser)); final OptionSet options = parser.parse(args); @@ -117,7 +117,7 @@ public class Options { System.exit(1); } } - HAPROXY_PROTOCOL = options.has(haProxyProtocol); + SERVER_HAPROXY_PROTOCOL = options.has(serverHaProxyProtocol); LEGACY_CLIENT_PASSTHROUGH = options.has(legacyClientPassthrough); PluginManager.EVENT_MANAGER.call(new PostOptionsParseEvent(options)); } 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 85f26c9..672bc6e 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java @@ -252,7 +252,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler { } } - if (Options.HAPROXY_PROTOCOL) { + if (Options.SERVER_HAPROXY_PROTOCOL) { final InetSocketAddress sourceAddress = (InetSocketAddress) this.proxyConnection.getC2P().remoteAddress(); final InetSocketAddress targetAddress = (InetSocketAddress) this.proxyConnection.getChannel().remoteAddress(); final HAProxyProxiedProtocol protocol = sourceAddress.getAddress() instanceof Inet4Address ? HAProxyProxiedProtocol.TCP4 : HAProxyProxiedProtocol.TCP6; diff --git a/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerChannelInitializer.java b/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerChannelInitializer.java index 91f8420..f4149e1 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerChannelInitializer.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerChannelInitializer.java @@ -64,7 +64,7 @@ public class Proxy2ServerChannelInitializer extends MinecraftChannelInitializer if (Options.PROXY_URL != null && !proxyConnection.getServerVersion().equals(VersionEnum.bedrockLatest)) { channel.pipeline().addLast("viaproxy-proxy-handler", this.getProxyHandler()); } - if (Options.HAPROXY_PROTOCOL) { + if (Options.SERVER_HAPROXY_PROTOCOL) { channel.pipeline().addLast("viaproxy-haproxy-encoder", HAProxyMessageEncoder.INSTANCE); }