Expose client protocol version and virtual host

This commit is contained in:
Minecrell
2017-10-10 18:45:20 +02:00
parent 70e24c1b60
commit 8838089321
4 changed files with 83 additions and 8 deletions

View File

@@ -0,0 +1,49 @@
package com.destroystokyo.paper.network;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;
import net.minecraft.network.Connection;
public class PaperNetworkClient implements NetworkClient {
private final Connection networkManager;
PaperNetworkClient(Connection networkManager) {
this.networkManager = networkManager;
}
@Override
public InetSocketAddress getAddress() {
return (InetSocketAddress) this.networkManager.getRemoteAddress();
}
@Override
public int getProtocolVersion() {
return this.networkManager.protocolVersion;
}
@Nullable
@Override
public InetSocketAddress getVirtualHost() {
return this.networkManager.virtualHost;
}
public static InetSocketAddress prepareVirtualHost(String host, int port) {
int len = host.length();
// FML appends a marker to the host to recognize FML clients (\0FML\0)
int pos = host.indexOf('\0');
if (pos >= 0) {
len = pos;
}
// When clients connect with a SRV record, their host contains a trailing '.'
if (len > 0 && host.charAt(len - 1) == '.') {
len--;
}
return InetSocketAddress.createUnresolved(host.substring(0, len), port);
}
}

View File

@@ -341,6 +341,20 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
this.getHandle().transferCookieConnection.sendPacket(new ClientboundTransferPacket(host, port));
}
// Paper start - Implement NetworkClient
@Override
public int getProtocolVersion() {
if (getHandle().connection == null) return -1;
return getHandle().connection.connection.protocolVersion;
}
@Override
public InetSocketAddress getVirtualHost() {
if (getHandle().connection == null) return null;
return getHandle().connection.connection.virtualHost;
}
// Paper end
@Override
public double getEyeHeight(boolean ignorePose) {
if (ignorePose) {