mirror of
https://github.com/PaperMC/Paper.git
synced 2025-03-13 19:28:03 +01:00
Expose client protocol version and virtual host
This commit is contained in:
parent
70e24c1b60
commit
8838089321
4 changed files with 83 additions and 8 deletions
|
@ -29,11 +29,15 @@
|
|||
@Nullable
|
||||
private volatile PacketListener disconnectListener;
|
||||
@Nullable
|
||||
@@ -114,6 +119,19 @@
|
||||
@@ -114,6 +119,23 @@
|
||||
private volatile DisconnectionDetails delayedDisconnect;
|
||||
@Nullable
|
||||
BandwidthDebugMonitor bandwidthDebugMonitor;
|
||||
+ public String hostname = ""; // CraftBukkit - add field
|
||||
+ // Paper start - NetworkClient implementation
|
||||
+ public int protocolVersion;
|
||||
+ public java.net.InetSocketAddress virtualHost;
|
||||
+ // Paper end
|
||||
+
|
||||
+ // Paper start - add utility methods
|
||||
+ public final net.minecraft.server.level.ServerPlayer getPlayer() {
|
||||
|
@ -49,7 +53,7 @@
|
|||
|
||||
public Connection(PacketFlow side) {
|
||||
this.receiving = side;
|
||||
@@ -123,6 +141,9 @@
|
||||
@@ -123,6 +145,9 @@
|
||||
super.channelActive(channelhandlercontext);
|
||||
this.channel = channelhandlercontext.channel();
|
||||
this.address = this.channel.remoteAddress();
|
||||
|
@ -59,7 +63,7 @@
|
|||
if (this.delayedDisconnect != null) {
|
||||
this.disconnect(this.delayedDisconnect);
|
||||
}
|
||||
@@ -176,6 +197,7 @@
|
||||
@@ -176,6 +201,7 @@
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +71,7 @@
|
|||
}
|
||||
|
||||
protected void channelRead0(ChannelHandlerContext channelhandlercontext, Packet<?> packet) {
|
||||
@@ -205,7 +227,7 @@
|
||||
@@ -205,7 +231,7 @@
|
||||
}
|
||||
|
||||
private static <T extends PacketListener> void genericsFtw(Packet<T> packet, PacketListener listener) {
|
||||
|
@ -76,7 +80,7 @@
|
|||
}
|
||||
|
||||
private void validateListener(ProtocolInfo<?> state, PacketListener listener) {
|
||||
@@ -464,12 +486,15 @@
|
||||
@@ -464,12 +490,15 @@
|
||||
}
|
||||
|
||||
public void disconnect(DisconnectionDetails disconnectionInfo) {
|
||||
|
@ -93,7 +97,7 @@
|
|||
this.disconnectionDetails = disconnectionInfo;
|
||||
}
|
||||
|
||||
@@ -537,7 +562,7 @@
|
||||
@@ -537,7 +566,7 @@
|
||||
}
|
||||
|
||||
public void configurePacketHandler(ChannelPipeline pipeline) {
|
||||
|
@ -102,7 +106,7 @@
|
|||
public void write(ChannelHandlerContext channelhandlercontext, Object object, ChannelPromise channelpromise) throws Exception {
|
||||
super.write(channelhandlercontext, object, channelpromise);
|
||||
}
|
||||
@@ -661,6 +686,7 @@
|
||||
@@ -661,6 +690,7 @@
|
||||
|
||||
packetlistener1.onDisconnect(disconnectiondetails);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,15 @@
|
|||
switch (packet.intention()) {
|
||||
case LOGIN:
|
||||
this.beginLogin(packet, false);
|
||||
@@ -59,19 +74,112 @@
|
||||
@@ -55,23 +70,120 @@
|
||||
throw new UnsupportedOperationException("Invalid intention " + String.valueOf(packet.intention()));
|
||||
}
|
||||
|
||||
+ // Paper start - NetworkClient implementation
|
||||
+ this.connection.protocolVersion = packet.protocolVersion();
|
||||
+ this.connection.virtualHost = com.destroystokyo.paper.network.PaperNetworkClient.prepareVirtualHost(packet.hostName(), packet.port());
|
||||
+ // Paper end
|
||||
}
|
||||
|
||||
private void beginLogin(ClientIntentionPacket packet, boolean transfer) {
|
||||
this.connection.setupOutboundProtocol(LoginProtocols.CLIENTBOUND);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue