From e6d9b4c5965253b58cc209128abecb8a00371339 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Sun, 28 Jan 2018 12:42:54 +0100 Subject: [PATCH] Fix implementation of Player.getVirtualHost()/getProtocolVersion() Right now, Player.getVirtualHost() returns the client's IP address. However, it is actually supposed to return the hostname/port the player used to connect to the server. Correct this and also make use of the version information in GlowSession instead of just returning the constant. --- src/main/java/net/glowstone/entity/GlowPlayer.java | 4 ++-- src/main/java/net/glowstone/net/GlowSession.java | 12 ++++++------ .../net/handler/handshake/HandshakeHandler.java | 4 +++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/glowstone/entity/GlowPlayer.java b/src/main/java/net/glowstone/entity/GlowPlayer.java index 3660e49a3b..d480ad23f7 100644 --- a/src/main/java/net/glowstone/entity/GlowPlayer.java +++ b/src/main/java/net/glowstone/entity/GlowPlayer.java @@ -1289,13 +1289,13 @@ public InetSocketAddress getAddress() { @Override public int getProtocolVersion() { - return GlowServer.PROTOCOL_VERSION; + return session.getVersion(); } @Nullable @Override public InetSocketAddress getVirtualHost() { - return session.getAddress(); + return session.getVirtualHost(); } @Override diff --git a/src/main/java/net/glowstone/net/GlowSession.java b/src/main/java/net/glowstone/net/GlowSession.java index 3e7f60b4a2..679642568a 100644 --- a/src/main/java/net/glowstone/net/GlowSession.java +++ b/src/main/java/net/glowstone/net/GlowSession.java @@ -104,12 +104,11 @@ public class GlowSession extends BasicSession { private String verifyUsername; /** - * Set the hostname the player used to connect to the server. - * - * @param hostname Hostname in "addr:port" format. + * The hostname/port the player used to connect to the server. */ + @Getter @Setter - private String hostname; + private InetSocketAddress virtualHost; /** * The version used to connect. @@ -182,7 +181,8 @@ public GlowSession(GlowServer server, Channel channel, ConnectionManager connect public void setProxyData(ProxyData proxyData) { this.proxyData = proxyData; address = proxyData.getAddress(); - hostname = proxyData.getHostname(); + virtualHost = InetSocketAddress.createUnresolved( + proxyData.getHostname(), virtualHost.getPort()); } /** @@ -264,7 +264,7 @@ public void setPlayer(GlowPlayerProfile profile) { } // login event - PlayerLoginEvent event = EventFactory.onPlayerLogin(player, hostname); + PlayerLoginEvent event = EventFactory.onPlayerLogin(player, virtualHost.toString()); if (event.getResult() != Result.ALLOWED) { disconnect(event.getKickMessage(), true); return; diff --git a/src/main/java/net/glowstone/net/handler/handshake/HandshakeHandler.java b/src/main/java/net/glowstone/net/handler/handshake/HandshakeHandler.java index e24b0786f1..720d3d0951 100644 --- a/src/main/java/net/glowstone/net/handler/handshake/HandshakeHandler.java +++ b/src/main/java/net/glowstone/net/handler/handshake/HandshakeHandler.java @@ -1,6 +1,7 @@ package net.glowstone.net.handler.handshake; import com.flowpowered.network.MessageHandler; +import java.net.InetSocketAddress; import java.util.logging.Level; import net.glowstone.GlowServer; import net.glowstone.net.GlowSession; @@ -23,7 +24,8 @@ public void handle(GlowSession session, HandshakeMessage message) { } session.setVersion(message.getVersion()); - session.setHostname(message.getAddress() + ":" + message.getPort()); + session.setVirtualHost(InetSocketAddress.createUnresolved( + message.getAddress(), message.getPort())); // Proxies modify the hostname in the HandshakeMessage to contain // the client's UUID and (optionally) properties