Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix implementation of Player.getVirtualHost()/getProtocolVersion() #824

Merged
merged 1 commit into from
Jan 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/net/glowstone/entity/GlowPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/glowstone/net/GlowSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down