net/minecraft/network/protocol/login

This commit is contained in:
Noah van der Aa 2024-12-14 19:31:59 +01:00
parent 33efd7ee12
commit 27a47b77c7
No known key found for this signature in database
GPG key ID: 547D90BC6FF753CF
4 changed files with 33 additions and 36 deletions

View file

@ -1,13 +1,12 @@
--- a/net/minecraft/network/protocol/login/ClientboundCustomQueryPacket.java
+++ b/net/minecraft/network/protocol/login/ClientboundCustomQueryPacket.java
@@ -47,4 +47,14 @@
public void handle(ClientLoginPacketListener listener) {
listener.handleCustomQuery(this);
@@ -47,4 +_,13 @@
public void handle(ClientLoginPacketListener handler) {
handler.handleCustomQuery(this);
}
+
+ // Paper start - MC Utils - default query payloads
+ public static record PlayerInfoChannelPayload(ResourceLocation id, FriendlyByteBuf buffer) implements CustomQueryPayload {
+
+ @Override
+ public void write(final FriendlyByteBuf buf) {
+ buf.writeBytes(this.buffer.copy());

View file

@ -0,0 +1,21 @@
--- a/net/minecraft/network/protocol/login/ClientboundLoginDisconnectPacket.java
+++ b/net/minecraft/network/protocol/login/ClientboundLoginDisconnectPacket.java
@@ -18,11 +_,16 @@
}
private ClientboundLoginDisconnectPacket(FriendlyByteBuf buffer) {
- this.reason = Component.Serializer.fromJsonLenient(buffer.readUtf(262144), RegistryAccess.EMPTY);
+ this.reason = Component.Serializer.fromJsonLenient(buffer.readUtf(FriendlyByteBuf.MAX_COMPONENT_STRING_LENGTH), RegistryAccess.EMPTY); // Paper - diff on change
}
private void write(FriendlyByteBuf buffer) {
- buffer.writeUtf(Component.Serializer.toJson(this.reason, RegistryAccess.EMPTY));
+ // Paper start - Adventure
+ // buffer.writeUtf(Component.Serializer.toJson(this.reason, RegistryAccess.EMPTY));
+ // In the login phase, buffer.adventure$locale field is most likely null, but plugins may use internals to set it via the channel attribute
+ java.util.Locale bufLocale = buffer.adventure$locale;
+ buffer.writeJsonWithCodec(net.minecraft.network.chat.ComponentSerialization.localizedCodec(bufLocale == null ? java.util.Locale.US : bufLocale), this.reason, FriendlyByteBuf.MAX_COMPONENT_STRING_LENGTH);
+ // Paper end - Adventure
}
@Override

View file

@ -1,12 +1,12 @@
--- a/net/minecraft/network/protocol/login/ServerboundCustomQueryAnswerPacket.java
+++ b/net/minecraft/network/protocol/login/ServerboundCustomQueryAnswerPacket.java
@@ -20,7 +20,17 @@
@@ -20,7 +_,17 @@
}
private static CustomQueryAnswerPayload readPayload(int queryId, FriendlyByteBuf buf) {
- return readUnknownPayload(buf);
private static CustomQueryAnswerPayload readPayload(int transactionId, FriendlyByteBuf buffer) {
- return readUnknownPayload(buffer);
+ // Paper start - MC Utils - default query payloads
+ FriendlyByteBuf buffer = buf.readNullable((buf2) -> {
+ FriendlyByteBuf buf = buffer.readNullable((buf2) -> {
+ int i = buf2.readableBytes();
+ if (i >= 0 && i <= MAX_PAYLOAD_SIZE) {
+ return new FriendlyByteBuf(buf2.readBytes(i));
@ -14,19 +14,18 @@
+ throw new IllegalArgumentException("Payload may not be larger than " + MAX_PAYLOAD_SIZE + " bytes");
+ }
+ });
+ return buffer == null ? null : new net.minecraft.network.protocol.login.ServerboundCustomQueryAnswerPacket.QueryAnswerPayload(buffer);
+ return buf == null ? null : new net.minecraft.network.protocol.login.ServerboundCustomQueryAnswerPacket.QueryAnswerPayload(buf);
+ // Paper end - MC Utils - default query payloads
}
private static CustomQueryAnswerPayload readUnknownPayload(FriendlyByteBuf buf) {
@@ -47,4 +57,21 @@
public void handle(ServerLoginPacketListener listener) {
listener.handleCustomQueryPacket(this);
private static CustomQueryAnswerPayload readUnknownPayload(FriendlyByteBuf buffer) {
@@ -47,4 +_,19 @@
public void handle(ServerLoginPacketListener handler) {
handler.handleCustomQueryPacket(this);
}
+
+ // Paper start - MC Utils - default query payloads
+ public static final class QueryAnswerPayload implements CustomQueryAnswerPayload {
+
+ public final FriendlyByteBuf buffer;
+
+ public QueryAnswerPayload(final net.minecraft.network.FriendlyByteBuf buffer) {
@ -39,5 +38,4 @@
+ }
+ }
+ // Paper end - MC Utils - default query payloads
+
}

View file

@ -1,21 +0,0 @@
--- a/net/minecraft/network/protocol/login/ClientboundLoginDisconnectPacket.java
+++ b/net/minecraft/network/protocol/login/ClientboundLoginDisconnectPacket.java
@@ -18,11 +18,16 @@
}
private ClientboundLoginDisconnectPacket(FriendlyByteBuf buf) {
- this.reason = Component.Serializer.fromJsonLenient(buf.readUtf(262144), RegistryAccess.EMPTY);
+ this.reason = Component.Serializer.fromJsonLenient(buf.readUtf(FriendlyByteBuf.MAX_COMPONENT_STRING_LENGTH), RegistryAccess.EMPTY); // Paper - diff on change
}
private void write(FriendlyByteBuf buf) {
- buf.writeUtf(Component.Serializer.toJson(this.reason, RegistryAccess.EMPTY));
+ // Paper start - Adventure
+ // buf.writeUtf(Component.Serializer.toJson(this.reason, RegistryAccess.EMPTY));
+ // In the login phase, buf.adventure$locale field is most likely null, but plugins may use internals to set it via the channel attribute
+ java.util.Locale bufLocale = buf.adventure$locale;
+ buf.writeJsonWithCodec(net.minecraft.network.chat.ComponentSerialization.localizedCodec(bufLocale == null ? java.util.Locale.US : bufLocale), this.reason, FriendlyByteBuf.MAX_COMPONENT_STRING_LENGTH);
+ // Paper end - Adventure
}
@Override