@@ -15,10 +15,10 @@ login plugin message packet.
15
15
16
16
diff --git a/src/main/java/com/destroystokyo/paper/proxy/VelocityProxy.java b/src/main/java/com/destroystokyo/paper/proxy/VelocityProxy.java
17
17
new file mode 100644
18
- index 0000000000000000000000000000000000000000..74b3265bba78491f462c15709a31bc44b4e4bea8
18
+ index 0000000000000000000000000000000000000000..980e2b4dc308adf9a6cb2596b28eaeee65d629a8
19
19
--- /dev/null
20
20
+++ b/src/main/java/com/destroystokyo/paper/proxy/VelocityProxy.java
21
- @@ -0,0 +1,66 @@
21
+ @@ -0,0 +1,68 @@
22
22
+ package com.destroystokyo.paper.proxy;
23
23
+
24
24
+ import io.papermc.paper.configuration.GlobalConfiguration;
@@ -34,9 +34,12 @@ index 0000000000000000000000000000000000000000..74b3265bba78491f462c15709a31bc44
34
34
+ import javax.crypto.spec.SecretKeySpec;
35
35
+ import net.minecraft.network.FriendlyByteBuf;
36
36
+ import net.minecraft.resources.ResourceLocation;
37
+ + import net.minecraft.world.entity.player.ProfilePublicKey;
37
38
+
38
39
+ public class VelocityProxy {
39
40
+ private static final int SUPPORTED_FORWARDING_VERSION = 1;
41
+ + public static final int MODERN_FORWARDING_WITH_KEY = 2;
42
+ + public static final byte MAX_SUPPORTED_FORWARDING_VERSION = 2;
40
43
+ public static final ResourceLocation PLAYER_INFO_CHANNEL = new ResourceLocation("velocity", "player_info");
41
44
+
42
45
+ public static boolean checkIntegrity(final FriendlyByteBuf buf) {
@@ -57,11 +60,6 @@ index 0000000000000000000000000000000000000000..74b3265bba78491f462c15709a31bc44
57
60
+ throw new AssertionError(e);
58
61
+ }
59
62
+
60
- + int version = buf.readVarInt();
61
- + if (version != SUPPORTED_FORWARDING_VERSION) {
62
- + throw new IllegalStateException("Unsupported forwarding version " + version + ", wanted " + SUPPORTED_FORWARDING_VERSION);
63
- + }
64
- +
65
63
+ return true;
66
64
+ }
67
65
+
@@ -84,9 +82,13 @@ index 0000000000000000000000000000000000000000..74b3265bba78491f462c15709a31bc44
84
82
+ profile.getProperties().put(name, new Property(name, value, signature));
85
83
+ }
86
84
+ }
85
+ +
86
+ + public static ProfilePublicKey.Data readForwardedKey(FriendlyByteBuf buf) {
87
+ + return new ProfilePublicKey.Data(buf);
88
+ + }
87
89
+ }
88
90
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
89
- index 1b075033f0640433341957f6e26ebe25f18928ee..b070624c7ee85b6692f1f44ded6c78139925b669 100644
91
+ index 1b075033f0640433341957f6e26ebe25f18928ee..8b5eddce4845619603ccfeec158d97cb86568e0d 100644
90
92
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
91
93
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
92
94
@@ -69,6 +69,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
@@ -97,22 +99,24 @@ index 1b075033f0640433341957f6e26ebe25f18928ee..b070624c7ee85b6692f1f44ded6c7813
97
99
98
100
public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection) {
99
101
this.state = ServerLoginPacketListenerImpl.State.HELLO;
100
- @@ -279,6 +280,14 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
102
+ @@ -279,6 +280,16 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
101
103
this.state = ServerLoginPacketListenerImpl.State.KEY;
102
104
this.connection.send(new ClientboundHelloPacket("", this.server.getKeyPair().getPublic().getEncoded(), this.nonce));
103
105
} else {
104
106
+ // Paper start - Velocity support
105
107
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) {
106
108
+ this.velocityLoginMessageId = java.util.concurrent.ThreadLocalRandom.current().nextInt();
107
- + net.minecraft.network.protocol.login.ClientboundCustomQueryPacket packet1 = new net.minecraft.network.protocol.login.ClientboundCustomQueryPacket(this.velocityLoginMessageId, com.destroystokyo.paper.proxy.VelocityProxy.PLAYER_INFO_CHANNEL, new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.EMPTY_BUFFER));
109
+ + net.minecraft.network.FriendlyByteBuf buf = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.buffer());
110
+ + buf.writeByte(com.destroystokyo.paper.proxy.VelocityProxy.MAX_SUPPORTED_FORWARDING_VERSION);
111
+ + net.minecraft.network.protocol.login.ClientboundCustomQueryPacket packet1 = new net.minecraft.network.protocol.login.ClientboundCustomQueryPacket(this.velocityLoginMessageId, com.destroystokyo.paper.proxy.VelocityProxy.PLAYER_INFO_CHANNEL, buf);
108
112
+ this.connection.send(packet1);
109
113
+ return;
110
114
+ }
111
115
+ // Paper end
112
116
// Spigot start
113
117
// Paper start - Cache authenticator threads
114
118
authenticatorPool.execute(new Runnable() {
115
- @@ -388,6 +397 ,12 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
119
+ @@ -388,6 +399 ,12 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
116
120
public class LoginHandler {
117
121
118
122
public void fireEvents() throws Exception {
@@ -125,7 +129,7 @@ index 1b075033f0640433341957f6e26ebe25f18928ee..b070624c7ee85b6692f1f44ded6c7813
125
129
String playerName = ServerLoginPacketListenerImpl.this.gameProfile.getName();
126
130
java.net.InetAddress address = ((java.net.InetSocketAddress) ServerLoginPacketListenerImpl.this.connection.getRemoteAddress()).getAddress();
127
131
java.util.UUID uniqueId = ServerLoginPacketListenerImpl.this.gameProfile.getId();
128
- @@ -435,6 +450,40 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
132
+ @@ -435,6 +452,58 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
129
133
// Spigot end
130
134
131
135
public void handleCustomQueryPacket(ServerboundCustomQueryPacket packet) {
@@ -142,6 +146,11 @@ index 1b075033f0640433341957f6e26ebe25f18928ee..b070624c7ee85b6692f1f44ded6c7813
142
146
+ return;
143
147
+ }
144
148
+
149
+ + int version = buf.readVarInt();
150
+ + if (version > com.destroystokyo.paper.proxy.VelocityProxy.MAX_SUPPORTED_FORWARDING_VERSION) {
151
+ + throw new IllegalStateException("Unsupported forwarding version " + version + ", wanted upto " + com.destroystokyo.paper.proxy.VelocityProxy.MAX_SUPPORTED_FORWARDING_VERSION);
152
+ + }
153
+ +
145
154
+ java.net.SocketAddress listening = this.connection.getRemoteAddress();
146
155
+ int port = 0;
147
156
+ if (listening instanceof java.net.InetSocketAddress) {
@@ -151,6 +160,19 @@ index 1b075033f0640433341957f6e26ebe25f18928ee..b070624c7ee85b6692f1f44ded6c7813
151
160
+
152
161
+ this.gameProfile = com.destroystokyo.paper.proxy.VelocityProxy.createProfile(buf);
153
162
+
163
+ + // We should already have this, but, we'll read it out anyway
164
+ + //noinspection NonStrictComparisonCanBeEquality
165
+ + if (version >= com.destroystokyo.paper.proxy.VelocityProxy.MODERN_FORWARDING_WITH_KEY) {
166
+ + final ProfilePublicKey.Data forwardedKey = com.destroystokyo.paper.proxy.VelocityProxy.readForwardedKey(buf);
167
+ + if (this.playerProfilePublicKey == null) {
168
+ + try {
169
+ + this.playerProfilePublicKey = ProfilePublicKey.createValidated(this.server.getServiceSignatureValidator(), forwardedKey);
170
+ + } catch (CryptException e) {
171
+ + this.disconnect("Unable to validate forwarded player key");
172
+ + }
173
+ + }
174
+ + }
175
+ +
154
176
+ // Proceed with login
155
177
+ authenticatorPool.execute(() -> {
156
178
+ try {
0 commit comments