diff --git a/README_EAGLERXBUNGEE.md b/README_EAGLERXBUNGEE.md index 4c05972..466b855 100644 --- a/README_EAGLERXBUNGEE.md +++ b/README_EAGLERXBUNGEE.md @@ -46,7 +46,7 @@ The settings.yml file is primarily used for configuring the built-in skin and ca - **`disable_fnaw_skins_everywhere:`** Boolean, default value is `false`, can be used to globally disable FNAW skins if your players bitch about them a lot and are too lazy to just disable the FNAW skins locally on their clients. - **`disable_fnaw_skins_on_servers:`** List of strings, default value is nothing (`[]`), contains a list of names of registered servers on your BungeeCord proxy that the FNAW skins should be disabled on. Good for explicitly disabling them for PVP but allowing them everywhere else. - **`enable_backend_rpc_api:`** Boolean, default value is `false`, if support for servers running the EaglerXBukkitAPI plugin should be enabled or not. -- **use_modernized_channel_names:`** Boolean, default value is `false`, if "modernized" plugin channel names compatible with Minecraft 1.13+ should be used for EaglerXBukkitAPI plugin message packets +- **`use_modernized_channel_names:`** Boolean, default value is `false`, if "modernized" plugin channel names compatible with Minecraft 1.13+ should be used for EaglerXBukkitAPI plugin message packets ### `listeners.yml` @@ -65,9 +65,12 @@ Defines one or more "listeners" (open ports) for EaglercraftX players to use to - **`server_motd:`** List of up to 2 strings, default value is `'&6An EaglercraftX server'`, sets the contents of the listener's MOTD, which is the text displayed along with the `server_icon` when players add this server's listener address to their client's Multiplayer menu server list. - **`allow_motd:`** Boolean, default value is `true`, if this listener should respond to MOTD queries or not. - **`allow_query:`** Boolean, default value is `true`, if this listener should respond to all other types of queries or not. +- **`min_minecraft_protocol:`** Integer, default value is `47`, sets the minimum Minecraft [protocol version](https://wiki.vg/Protocol_version_numbers) that EaglercraftX-based clients are allowed to connect with (`47` = 1.8) +- **`max_minecraft_protocol:`** Integer, default value is `340`, sets the maximum Minecraft protocol version that EaglercraftX-based clients are allowed to connect with (`340` = 1.12.2) - **`allow_protocol_v3:`** Boolean, default value is `true`, if this listener should allow clients using the v1/v2/v3 protocols to join (pre-u37 clients). - **`allow_protocol_v4:`** Boolean, default value is `true`, if this listener should allow clients using the v4 protocol to join (post-u37 clients). - **`protocol_v4_defrag_send_delay:`** Integer, default value is `10`, the number of milliseconds to wait before flushing all pending EaglercraftX plugin message packets, saves bandwidth by combining multiple messages into a single plugin message packet. Setting this to `0` has the same effect on clientbound packets as setting `eaglerNoDelay` to `true` does on a post-u37 client for all serverbound packets. +- **`use_haproxy_protocol:`** Boolean, default value is `false`, can be used to enable support for the HAProxy proxy protocol. Make sure to also add the `check`, `check-send-proxy`, and `send-proxy-v2` parameters to your `server` directives in the HAProxy config file. - **`allow_cookie_revoke_query:`** Boolean, default value is `true`, If this listener should accept queries from post-u37 clients to revoke session tokens, you need to create your own BungeeCord plugin to go with EaglerXBungee that handles the `EaglercraftRevokeSessionQueryEvent` event it fires in order for this feature to work correctly. - **`request_motd_cache:`** Section that defines caching hints for server lists that cache the MOTD via the `MOTD.cache` query. As far as we know, not even the official Eaglercraft Server List on eaglercraft.com currently pays attention to these hints or attempts to cache MOTDs, so they can be ignored for now. - **`cache_ttl:`** Integer, default value is `7200`, sets how many seconds for the server list to store the MOTD in cache. diff --git a/gateway/EaglercraftXBungee/EaglerXBungee-Latest.jar b/gateway/EaglercraftXBungee/EaglerXBungee-Latest.jar index c0bf2b3..7625367 100644 Binary files a/gateway/EaglercraftXBungee/EaglerXBungee-Latest.jar and b/gateway/EaglercraftXBungee/EaglerXBungee-Latest.jar differ diff --git a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/EaglerXBungee.java b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/EaglerXBungee.java index a52d93a..224fe75 100644 --- a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/EaglerXBungee.java +++ b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/EaglerXBungee.java @@ -64,7 +64,7 @@ import net.md_5.bungee.BungeeCord; */ public class EaglerXBungee extends Plugin { - public static final String NATIVE_BUNGEECORD_BUILD = "1.21-R0.1-SNAPSHOT:2593130:1878"; + public static final String NATIVE_BUNGEECORD_BUILD = "1.21-R0.1-SNAPSHOT:4886c4b:1881"; public static final String NATIVE_WATERFALL_BUILD = "1.21-R0.1-SNAPSHOT:de8345a:579"; static { diff --git a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/config/EaglerListenerConfig.java b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/config/EaglerListenerConfig.java index 929b12d..79f4eee 100644 --- a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/config/EaglerListenerConfig.java +++ b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/config/EaglerListenerConfig.java @@ -76,12 +76,15 @@ public class EaglerListenerConfig extends ListenerInfo { } boolean allowMOTD = config.getBoolean("allow_motd", true); boolean allowQuery = config.getBoolean("allow_query", true); + int minMCProtocol = config.getInt("min_minecraft_protocol", 47); + int maxMCProtocol = config.getInt("max_minecraft_protocol", 340); boolean allowV3 = config.getBoolean("allow_protocol_v3", true); boolean allowV4 = config.getBoolean("allow_protocol_v4", true); if(!allowV3 && !allowV4) { throw new IllegalArgumentException("Both v3 and v4 protocol are disabled!"); } int defragSendDelay = config.getInt("protocol_v4_defrag_send_delay", 10); + boolean haproxyProtocol = config.getBoolean("use_haproxy_protocol", false); int cacheTTL = 7200; boolean cacheAnimation = false; @@ -157,8 +160,8 @@ public class EaglerListenerConfig extends ListenerInfo { cacheTrending, cachePortfolios); return new EaglerListenerConfig(hostv4, hostv6, maxPlayer, tabListType, defaultServer, forceDefaultServer, forwardIp, forwardIpHeader, redirectLegacyClientsTo, serverIcon, serverMOTD, allowMOTD, allowQuery, - allowV3, allowV4, defragSendDelay, cacheConfig, httpServer, enableVoiceChat, ratelimitIp, - ratelimitLogin, ratelimitMOTD, ratelimitQuery); + minMCProtocol, maxMCProtocol, allowV3, allowV4, defragSendDelay, haproxyProtocol, cacheConfig, + httpServer, enableVoiceChat, ratelimitIp, ratelimitLogin, ratelimitMOTD, ratelimitQuery); } private final InetSocketAddress address; @@ -174,9 +177,12 @@ public class EaglerListenerConfig extends ListenerInfo { private final List serverMOTD; private final boolean allowMOTD; private final boolean allowQuery; + private final int minMCProtocol; + private final int maxMCProtocol; private final boolean allowV3; private final boolean allowV4; private final int defragSendDelay; + private final boolean haproxyProtocol; private final MOTDCacheConfiguration motdCacheConfig; private final HttpWebServer webServer; private boolean serverIconSet = false; @@ -190,10 +196,10 @@ public class EaglerListenerConfig extends ListenerInfo { public EaglerListenerConfig(InetSocketAddress address, InetSocketAddress addressV6, int maxPlayer, String tabListType, String defaultServer, boolean forceDefaultServer, boolean forwardIp, String forwardIpHeader, String redirectLegacyClientsTo, String serverIcon, List serverMOTD, - boolean allowMOTD, boolean allowQuery, boolean allowV3, boolean allowV4, int defragSendDelay, - MOTDCacheConfiguration motdCacheConfig, HttpWebServer webServer, boolean enableVoiceChat, - EaglerRateLimiter ratelimitIp, EaglerRateLimiter ratelimitLogin, EaglerRateLimiter ratelimitMOTD, - EaglerRateLimiter ratelimitQuery) { + boolean allowMOTD, boolean allowQuery, int minMCProtocol, int maxMCProtocol, boolean allowV3, + boolean allowV4, int defragSendDelay, boolean haproxyProtocol, MOTDCacheConfiguration motdCacheConfig, + HttpWebServer webServer, boolean enableVoiceChat, EaglerRateLimiter ratelimitIp, + EaglerRateLimiter ratelimitLogin, EaglerRateLimiter ratelimitMOTD, EaglerRateLimiter ratelimitQuery) { super(address, String.join("\n", serverMOTD), maxPlayer, 60, Arrays.asList(defaultServer), forceDefaultServer, Collections.emptyMap(), tabListType, false, false, 0, false, false); this.address = address; @@ -209,9 +215,12 @@ public class EaglerListenerConfig extends ListenerInfo { this.serverMOTD = serverMOTD; this.allowMOTD = allowMOTD; this.allowQuery = allowQuery; + this.minMCProtocol = minMCProtocol; + this.maxMCProtocol = maxMCProtocol; this.allowV3 = allowV3; this.allowV4 = allowV4; this.defragSendDelay = defragSendDelay; + this.haproxyProtocol = haproxyProtocol; this.motdCacheConfig = motdCacheConfig; this.webServer = webServer; this.enableVoiceChat = enableVoiceChat; @@ -287,6 +296,14 @@ public class EaglerListenerConfig extends ListenerInfo { return allowQuery; } + public int getMinMCProtocol() { + return minMCProtocol; + } + + public int getMaxMCProtocol() { + return maxMCProtocol; + } + public boolean isAllowV3() { return allowV3; } @@ -299,6 +316,10 @@ public class EaglerListenerConfig extends ListenerInfo { return defragSendDelay; } + public boolean isHAProxyProtocol() { + return haproxyProtocol; + } + public HttpWebServer getWebServer() { return webServer; } diff --git a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/EaglerPipeline.java b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/EaglerPipeline.java index 8b355ee..6643820 100644 --- a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/EaglerPipeline.java +++ b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/EaglerPipeline.java @@ -24,6 +24,7 @@ import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; import io.netty.channel.WriteBufferWaterMark; import io.netty.handler.codec.compression.ZlibCodecFactory; +import io.netty.handler.codec.haproxy.HAProxyMessageDecoder; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; @@ -31,7 +32,6 @@ import io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensio import io.netty.handler.codec.http.websocketx.extensions.compression.DeflateFrameServerExtensionHandshaker; import io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateServerExtensionHandshaker; import io.netty.util.AttributeKey; -import net.lax1dude.eaglercraft.v1_8.plugin.backend_rpc_protocol.EaglerBackendRPCProtocol; import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.EaglerXBungee; import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.api.EaglerXBungeeAPIHelper; import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.config.EaglerBungeeConfig; @@ -256,7 +256,11 @@ public class EaglerPipeline { channel.config().setOption(ChannelOption.IP_TOS, 24); } catch (ChannelException var3) { } + EaglerListenerConfig listener = channel.attr(LISTENER).get(); ChannelPipeline pipeline = channel.pipeline(); + if(listener.isHAProxyProtocol()) { + pipeline.addLast("HAProxyMessageDecoder", new HAProxyMessageDecoder()); + } pipeline.addLast("HttpServerCodec", new HttpServerCodec()); pipeline.addLast("HttpObjectAggregator", new HttpObjectAggregator(65535)); int compressionLevel = EaglerXBungee.getEagler().getConfig().getHttpWebsocketCompressionLevel(); @@ -272,7 +276,7 @@ public class EaglerPipeline { pipeline.addLast("HttpCompressionHandler", new WebSocketServerExtensionHandler(deflateExtensionHandshaker, perMessageDeflateExtensionHandshaker)); } - pipeline.addLast("HttpHandshakeHandler", new HttpHandshakeHandler(channel.attr(LISTENER).get())); + pipeline.addLast("HttpHandshakeHandler", new HttpHandshakeHandler(listener)); channel.attr(CONNECTION_INSTANCE).set(new EaglerConnectionInstance(channel)); synchronized(openChannels) { openChannels.add(channel); diff --git a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/HttpHandshakeHandler.java b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/HttpHandshakeHandler.java index d5b998a..75a29d1 100644 --- a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/HttpHandshakeHandler.java +++ b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/HttpHandshakeHandler.java @@ -12,6 +12,7 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.handler.codec.haproxy.HAProxyMessage; import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaders; @@ -52,6 +53,9 @@ public class HttpHandshakeHandler extends ChannelInboundHandlerAdapter { private static final byte[] error429Bytes = "

429 Too Many Requests
(Try again later)

".getBytes(StandardCharsets.UTF_8); private final EaglerListenerConfig conf; + private boolean logExceptions; + private boolean healthCheck; + private InetSocketAddress haproxyRemoteAddr; public HttpHandshakeHandler(EaglerListenerConfig conf) { this.conf = conf; @@ -60,6 +64,7 @@ public class HttpHandshakeHandler extends ChannelInboundHandlerAdapter { public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception { try { if (msg instanceof HttpRequest) { + logExceptions = true; EaglerConnectionInstance pingTracker = ctx.channel().attr(EaglerPipeline.CONNECTION_INSTANCE).get(); HttpRequest req = (HttpRequest) msg; HttpHeaders headers = req.headers(); @@ -73,11 +78,15 @@ public class HttpHandshakeHandler extends ChannelInboundHandlerAdapter { rateLimitHost = str.split(",", 2)[0]; try { InetAddress inetAddr = InetAddress.getByName(rateLimitHost); - addr = ctx.channel().remoteAddress(); - if(addr instanceof InetSocketAddress) { - addr = new InetSocketAddress(inetAddr, ((InetSocketAddress)addr).getPort()); + if(haproxyRemoteAddr != null) { + addr = new InetSocketAddress(inetAddr, haproxyRemoteAddr.getPort()); }else { - addr = new InetSocketAddress(inetAddr, 0); + addr = ctx.channel().remoteAddress(); + if(addr instanceof InetSocketAddress) { + addr = new InetSocketAddress(inetAddr, ((InetSocketAddress)addr).getPort()); + }else { + addr = new InetSocketAddress(inetAddr, 0); + } } ctx.channel().attr(EaglerPipeline.REAL_ADDRESS).set(inetAddr); }catch(UnknownHostException ex) { @@ -90,6 +99,9 @@ public class HttpHandshakeHandler extends ChannelInboundHandlerAdapter { ctx.close(); return; } + }else if(haproxyRemoteAddr != null) { + addr = haproxyRemoteAddr; + ctx.channel().attr(EaglerPipeline.REAL_ADDRESS).set(haproxyRemoteAddr.getAddress()); }else { addr = ctx.channel().remoteAddress(); if(addr instanceof InetSocketAddress) { @@ -189,6 +201,19 @@ public class HttpHandshakeHandler extends ChannelInboundHandlerAdapter { .addListener(ChannelFutureListener.CLOSE); } } + }else if(msg instanceof HAProxyMessage) { + logExceptions = true; + HAProxyMessage proxy = (HAProxyMessage) msg; + if(proxy.sourceAddress() != null) { + if(!conf.isForwardIp()) { + try { + haproxyRemoteAddr = new InetSocketAddress(proxy.sourceAddress(), proxy.sourcePort()); + }catch(IllegalArgumentException t) { + } + } + }else { + healthCheck = true; + } }else { ctx.close(); } @@ -199,15 +224,13 @@ public class HttpHandshakeHandler extends ChannelInboundHandlerAdapter { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (ctx.channel().isActive()) { - EaglerXBungee.logger().log(Level.WARNING, "[Pre][" + ctx.channel().remoteAddress() + "]: Exception Caught: " + cause.toString(), cause); + if(logExceptions && !healthCheck) { + EaglerXBungee.logger().log(Level.WARNING, "[Pre][" + ctx.channel().remoteAddress() + "]: Exception Caught: " + cause.toString(), cause); + } ctx.close(); } } - private static String formatAddressFor404(String str) { - return "" + str.replace("<", "<").replace(">", ">") + ""; - } - public void channelInactive(ChannelHandlerContext ctx) { EaglerPipeline.closeChannel(ctx.channel()); } diff --git a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/HttpServerQueryHandler.java b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/HttpServerQueryHandler.java index 245b8d2..2f5e1de 100644 --- a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/HttpServerQueryHandler.java +++ b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/HttpServerQueryHandler.java @@ -13,6 +13,7 @@ import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.handler.codec.haproxy.HAProxyMessage; import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; @@ -136,6 +137,8 @@ public abstract class HttpServerQueryHandler extends ChannelInboundHandlerAdapte }else if(msg instanceof CloseWebSocketFrame) { ctx.close(); } + }else if(msg instanceof HAProxyMessage) { + EaglerXBungee.logger().warning("[" + ctx.channel().remoteAddress() + "]: Ignoring HAProxyMessage because the WebSocket connection has already been established"); }else { EaglerXBungee.logger().severe("Unexpected Packet: " + msg.getClass().getSimpleName()); } diff --git a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/HttpWebSocketHandler.java b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/HttpWebSocketHandler.java index 55a169d..aea4571 100644 --- a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/HttpWebSocketHandler.java +++ b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/HttpWebSocketHandler.java @@ -30,6 +30,7 @@ import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelPipeline; +import io.netty.handler.codec.haproxy.HAProxyMessage; import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; @@ -150,6 +151,8 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter { connectionClosed = true; ctx.close(); } + }else if(msg instanceof HAProxyMessage) { + EaglerXBungee.logger().warning("[" + ctx.channel().remoteAddress() + "]: Ignoring HAProxyMessage because the WebSocket connection has already been established"); }else { EaglerXBungee.logger().severe("Unexpected Packet: " + msg.getClass().getSimpleName()); } @@ -264,8 +267,6 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter { EaglerXBungee eaglerXBungee = EaglerXBungee.getEagler(); EaglerAuthConfig authConfig = eaglerXBungee.getConfig().getAuthConfig(); - final int minecraftProtocolVersion = 47; - int eaglerLegacyProtocolVersion = buffer.readUnsignedByte(); if(eaglerLegacyProtocolVersion == 1) { @@ -273,7 +274,8 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter { sendErrorCode(ctx, HandshakePacketTypes.SERVER_ERROR_CUSTOM_MESSAGE, "Please update your client to register on this server!") .addListener(ChannelFutureListener.CLOSE); return; - }else if(buffer.readUnsignedByte() != minecraftProtocolVersion || !conf.isAllowV3()) { + }else if(buffer.readUnsignedByte() != 47 || 47 < conf.getMinMCProtocol() + || 47 > conf.getMaxMCProtocol() || !conf.isAllowV3()) { clientLoginState = HandshakePacketTypes.STATE_CLIENT_COMPLETE; connectionClosed = true; ByteBuf buf = ctx.alloc().buffer(); @@ -294,8 +296,7 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter { int maxServerSupported = conf.isAllowV4() ? 4 : 3; int minAvailableProtVers = Integer.MAX_VALUE; int maxAvailableProtVers = Integer.MIN_VALUE; - int minSupportedProtVers = Integer.MAX_VALUE; - int maxSupportedProtVers = Integer.MIN_VALUE; + int protVers = -1; int cnt = buffer.readUnsignedShort(); for(int i = 0; i < cnt; ++i) { @@ -306,53 +307,52 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter { if(j < minAvailableProtVers) { minAvailableProtVers = j; } - if(j >= minServerSupported && j <= maxServerSupported) { - if(j > maxSupportedProtVers) { - maxSupportedProtVers = j; - } - if(j < minSupportedProtVers) { - minSupportedProtVers = j; - } + if(j >= minServerSupported && j <= maxServerSupported && j > protVers) { + protVers = j; } } - int minGameVers = Integer.MAX_VALUE; - int maxGameVers = -1; - boolean has47InList = false; + int minGameVers = conf.getMinMCProtocol(); + int maxGameVers = conf.getMaxMCProtocol(); + int minAvailableGameVers = Integer.MAX_VALUE; + int maxAvailableGameVers = Integer.MIN_VALUE; + int gameVers = -1; cnt = buffer.readUnsignedShort(); for(int i = 0; i < cnt; ++i) { int j = buffer.readUnsignedShort(); - if(j == minecraftProtocolVersion) { - has47InList = true; + if(j > maxAvailableGameVers) { + maxAvailableGameVers = j; } - if(j > maxGameVers) { - maxGameVers = j; + if(j < minAvailableGameVers) { + minAvailableGameVers = j; } - if(j < minGameVers) { - minGameVers = j; + if(j >= minGameVers && j <= maxGameVers && j > gameVers) { + gameVers = j; } } - if(maxAvailableProtVers == Integer.MIN_VALUE || maxGameVers == Integer.MIN_VALUE) { + if(maxAvailableProtVers == Integer.MIN_VALUE || maxAvailableGameVers == Integer.MIN_VALUE) { throw new IOException(); } boolean versMisMatch = false; boolean isServerProbablyOutdated = false; boolean isClientProbablyOutdated = false; - if(maxSupportedProtVers == Integer.MIN_VALUE) { + if(protVers == -1) { clientProtocolVersion = maxAvailableProtVers < 3 ? 2 : 3; versMisMatch = true; isServerProbablyOutdated = minAvailableProtVers > maxServerSupported && maxAvailableProtVers > maxServerSupported; isClientProbablyOutdated = minAvailableProtVers < minServerSupported && maxAvailableProtVers < minServerSupported; - }else if(!has47InList) { - clientProtocolVersion = 3; - versMisMatch = true; - isServerProbablyOutdated = minGameVers > minecraftProtocolVersion && maxGameVers > minecraftProtocolVersion; - isClientProbablyOutdated = minGameVers < minecraftProtocolVersion && maxGameVers < minecraftProtocolVersion; }else { - clientProtocolVersion = maxSupportedProtVers; + clientProtocolVersion = protVers; + if(gameVers == -1) { + versMisMatch = true; + isServerProbablyOutdated = minAvailableGameVers > maxGameVers && maxAvailableGameVers > maxGameVers; + isClientProbablyOutdated = minAvailableGameVers < minGameVers && maxAvailableGameVers < minGameVers; + }else { + gameProtocolVersion = gameVers; + } } if(versMisMatch) { @@ -370,8 +370,9 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter { buf.writeShort(4); } - buf.writeShort(1); - buf.writeShort(minecraftProtocolVersion); // want game version 47 + buf.writeShort(2); + buf.writeShort(minGameVers); + buf.writeShort(maxGameVers); String str = isClientProbablyOutdated ? "Outdated Client" : (isServerProbablyOutdated ? "Outdated Server" : "Unsupported Client Version"); buf.writeByte(str.length()); @@ -403,6 +404,7 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter { boolean useSnapshotFallbackProtocol = false; if(eaglerLegacyProtocolVersion == 1 && !authConfig.isEnableAuthentication()) { clientProtocolVersion = 2; + gameProtocolVersion = 47; useSnapshotFallbackProtocol = true; clientAuth = false; clientAuthUsername = null; @@ -434,7 +436,6 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter { final boolean final_useSnapshotFallbackProtocol = useSnapshotFallbackProtocol; Runnable continueThread = () -> { clientLoginState = HandshakePacketTypes.STATE_CLIENT_VERSION; - gameProtocolVersion = 47; clientBrandString = eaglerBrand; clientVersionString = eaglerVersionString; @@ -445,7 +446,7 @@ public class HttpWebSocketHandler extends ChannelInboundHandlerAdapter { buf.writeByte(1); }else { buf.writeShort(clientProtocolVersion); - buf.writeShort(minecraftProtocolVersion); + buf.writeShort(gameProtocolVersion); } String brandStr = eaglerXBungee.getDescription().getName(); diff --git a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/query/VersionQueryHandler.java b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/query/VersionQueryHandler.java index b2d8bfb..d8e1df7 100644 --- a/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/query/VersionQueryHandler.java +++ b/gateway/EaglercraftXBungee/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/server/query/VersionQueryHandler.java @@ -4,10 +4,11 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.api.query.EaglerQuerySimpleHandler; +import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.config.EaglerListenerConfig; import net.md_5.bungee.api.ProxyServer; /** - * Copyright (c) 2022-2023 lax1dude. All Rights Reserved. + * Copyright (c) 2022-2024 lax1dude. All Rights Reserved. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -27,20 +28,19 @@ public class VersionQueryHandler extends EaglerQuerySimpleHandler { protected void begin(String queryType) { JsonObject responseObj = new JsonObject(); JsonArray handshakeVersions = new JsonArray(); - if(this.getListener().isAllowV3()) { + EaglerListenerConfig cfg = this.getListener(); + if(cfg.isAllowV3()) { handshakeVersions.add(2); handshakeVersions.add(3); } - if(this.getListener().isAllowV4()) { + if(cfg.isAllowV4()) { handshakeVersions.add(4); } responseObj.add("handshakeVersions", handshakeVersions); - JsonArray protocolVersions = new JsonArray(); - protocolVersions.add(47); + JsonObject protocolVersions = new JsonObject(); + protocolVersions.addProperty("min", cfg.getMinMCProtocol()); + protocolVersions.addProperty("max", cfg.getMaxMCProtocol()); responseObj.add("protocolVersions", protocolVersions); - JsonArray gameVersions = new JsonArray(); - gameVersions.add("1.8"); - responseObj.add("gameVersions", gameVersions); JsonObject proxyInfo = new JsonObject(); proxyInfo.addProperty("brand", ProxyServer.getInstance().getName()); proxyInfo.addProperty("vers", ProxyServer.getInstance().getVersion()); diff --git a/gateway/EaglercraftXBungee/src/main/resources/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/config/default_listeners.yml b/gateway/EaglercraftXBungee/src/main/resources/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/config/default_listeners.yml index 4c4f608..6013e08 100644 --- a/gateway/EaglercraftXBungee/src/main/resources/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/config/default_listeners.yml +++ b/gateway/EaglercraftXBungee/src/main/resources/net/lax1dude/eaglercraft/v1_8/plugin/gateway_bungeecord/config/default_listeners.yml @@ -13,9 +13,12 @@ listener_01: - '&6An EaglercraftX server' allow_motd: true allow_query: true + min_minecraft_protocol: 47 + max_minecraft_protocol: 340 allow_protocol_v3: true allow_protocol_v4: true protocol_v4_defrag_send_delay: 10 + use_haproxy_protocol: false allow_cookie_revoke_query: true request_motd_cache: cache_ttl: 7200 diff --git a/gateway/EaglercraftXBungee/src/main/resources/plugin.yml b/gateway/EaglercraftXBungee/src/main/resources/plugin.yml index a6a8c29..ed91973 100644 --- a/gateway/EaglercraftXBungee/src/main/resources/plugin.yml +++ b/gateway/EaglercraftXBungee/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: EaglercraftXBungee main: net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.EaglerXBungee -version: 1.3.2 +version: 1.3.3 description: Plugin to allow EaglercraftX 1.8 players to join your network, or allow EaglercraftX 1.8 players to use your network as a proxy to join other networks author: lax1dude \ No newline at end of file diff --git a/gateway_version b/gateway_version index d5e98f7..785cda8 100644 --- a/gateway_version +++ b/gateway_version @@ -1 +1 @@ -1.3.2 \ No newline at end of file +1.3.3 \ No newline at end of file