From e4209d4474f7362e1e2d8386d0aee76fbef297a0 Mon Sep 17 00:00:00 2001 From: cyilin Date: Fri, 23 Feb 2018 13:49:57 +0800 Subject: [PATCH] add support for bungeecord build 1300 --- build.gradle | 5 ++++- .../bungeecordusercontrol/BungeeProxy.java | 20 +++++-------------- .../nyaa/bungeecordusercontrol/MojangAPI.java | 4 ++-- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index ba51eac..549982e 100644 --- a/build.gradle +++ b/build.gradle @@ -32,9 +32,12 @@ if (System.getenv("TRAVIS_BUILD_NUMBER") != null) { dependencies { compile 'net.md-5:bungeecord-api:1.12-SNAPSHOT' - compile 'io.netty:netty-codec-haproxy:4.1.15.Final' + compile 'io.netty:netty-codec-haproxy:4.1.21.Final' } processResources { expand version:project.version +} +compileJava { + options.compilerArgs += ["-Xlint:deprecation", "-Xlint:unchecked"] } \ No newline at end of file diff --git a/src/main/java/cat/nyaa/bungeecordusercontrol/BungeeProxy.java b/src/main/java/cat/nyaa/bungeecordusercontrol/BungeeProxy.java index ff2ee2a..9834b9f 100644 --- a/src/main/java/cat/nyaa/bungeecordusercontrol/BungeeProxy.java +++ b/src/main/java/cat/nyaa/bungeecordusercontrol/BungeeProxy.java @@ -18,8 +18,9 @@ */ package cat.nyaa.bungeecordusercontrol; -import io.netty.channel.*; -import io.netty.handler.codec.haproxy.HAProxyMessage; +import io.netty.channel.AbstractChannel; +import io.netty.channel.Channel; +import io.netty.channel.ChannelInitializer; import io.netty.handler.codec.haproxy.HAProxyMessageDecoder; import java.lang.reflect.Field; @@ -52,19 +53,8 @@ protected void initChannel(Channel channel) throws Exception { initChannelMethod.invoke(bungeeChannelInitializer, channel); if (plugin.config.haproxy_enable && plugin.config.haproxy_address.contains(((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress())) { - channel.pipeline().addAfter("timeout", "haproxy-decoder", new HAProxyMessageDecoder() { - }); - channel.pipeline().addAfter("haproxy-decoder", "haproxy-handler", new ChannelInboundHandlerAdapter() { - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - if (msg instanceof HAProxyMessage) { - HAProxyMessage message = (HAProxyMessage) msg; - remoteAddressField.set(channel, new InetSocketAddress(message.sourceAddress(), message.sourcePort())); - } else { - super.channelRead(ctx, msg); - } - } - }); + channel.pipeline().addFirst(new HAProxyMessageDecoder()); + //https://github.com/SpigotMC/BungeeCord/blob/bd5a7e5b26b698c57e6f99933452bfc0659269f9/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java#L79 } } }); diff --git a/src/main/java/cat/nyaa/bungeecordusercontrol/MojangAPI.java b/src/main/java/cat/nyaa/bungeecordusercontrol/MojangAPI.java index 665f1de..a5a45ca 100644 --- a/src/main/java/cat/nyaa/bungeecordusercontrol/MojangAPI.java +++ b/src/main/java/cat/nyaa/bungeecordusercontrol/MojangAPI.java @@ -5,11 +5,11 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import javax.net.ssl.HttpsURLConnection; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; @@ -19,7 +19,7 @@ public class MojangAPI { public static User getUserByName(String name) { try { URL url = new URL("https://api.mojang.com/profiles/minecraft"); - HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setDoOutput(true);