3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-14 20:10:05 +01:00

Rewrite custom payload handler

Dieser Commit ist enthalten in:
LemonCaramel 2023-10-23 17:14:56 +09:00
Ursprung 274e54ba58
Commit e1febc7492
605 geänderte Dateien mit 318 neuen und 105 gelöschten Zeilen

Datei anzeigen

@ -1,76 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: DigitalRegent <misterwener@gmail.com>
Date: Sat, 11 Apr 2020 13:10:58 +0200
Subject: [PATCH] Brand support
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 2c2b1aef3f510edb9bb124581739f06692ab5673..567bfcdf5c946d09bb8188435ee13930082dccf5 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -271,6 +271,7 @@ public class ServerPlayer extends Player {
public boolean isRealPlayer; // Paper
public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> cachedSingleHashSet; // Paper
public PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper
+ public @Nullable String clientBrandName = null; // Paper - Brand name
// Paper start - replace player chunk loader
private final java.util.concurrent.atomic.AtomicReference<io.papermc.paper.chunk.system.RegionizedPlayerChunkLoader.ViewDistances> viewDistances = new java.util.concurrent.atomic.AtomicReference<>(new io.papermc.paper.chunk.system.RegionizedPlayerChunkLoader.ViewDistances(-1, -1, -1));
diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
index d25b6431ce617d90fd1d6489a308d6630b92c175..96ee68e6656a59d959ad7a7e78f5a3752d6e3dbb 100644
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
@@ -54,6 +54,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
private int latency;
private volatile boolean suspendFlushingOnServerThread = false;
private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit
+ protected static final ResourceLocation MINECRAFT_BRAND = new ResourceLocation("brand"); // Paper - Brand support
public ServerCommonPacketListenerImpl(MinecraftServer minecraftserver, Connection networkmanager, CommonListenerCookie commonlistenercookie, ServerPlayer player) { // CraftBukkit
this.server = minecraftserver;
@@ -109,6 +110,11 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
@Override
public void handleCustomPayload(ServerboundCustomPayloadPacket packet) {
+ // Paper start - handle brand payload packet
+ if (packet.payload() instanceof net.minecraft.network.protocol.common.custom.BrandPayload brandPayload) {
+ this.player.clientBrandName = brandPayload.brand();
+ }
+ // Paper end - handle brand payload
if (!(packet.payload() instanceof ServerboundCustomPayloadPacket.UnknownPayload)) {
return;
}
@@ -140,6 +146,15 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
try {
byte[] data = new byte[payload.readableBytes()];
payload.readBytes(data);
+ // Paper start - Brand support - Retain this incase upstream decides to 'break' the new mechanism in favour of backwards compat...
+ if (identifier.equals(MINECRAFT_BRAND)) {
+ try {
+ this.player.clientBrandName = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.copiedBuffer(data)).readUtf(256);
+ } catch (StringIndexOutOfBoundsException ex) {
+ this.player.clientBrandName = "illegal";
+ }
+ }
+ // Paper end
this.cserver.getMessenger().dispatchIncomingMessage(this.player.getBukkitEntity(), identifier.toString(), data);
} catch (Exception ex) {
ServerGamePacketListenerImpl.LOGGER.error("Couldn\'t dispatch custom payload", ex);
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index b92cc9f8d62cc3bfefe42c4c1fb08af4731dd48f..7b1404ac481ea9a059197b9f752327ef0bf72c5c 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -3009,6 +3009,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
// Paper end
};
+ // Paper start - brand support
+ @Override
+ public String getClientBrandName() {
+ return getHandle().clientBrandName;
+ }
+ // Paper end
+
public Player.Spigot spigot()
{
return this.spigot;

Datei anzeigen

@ -0,0 +1,189 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: LemonCaramel <admin@caramel.moe>
Date: Mon, 23 Oct 2023 15:03:59 +0900
Subject: [PATCH] Rewrite custom payload handler
diff --git a/src/main/java/io/papermc/paper/network/payload/ChannelPayload.java b/src/main/java/io/papermc/paper/network/payload/ChannelPayload.java
new file mode 100644
index 0000000000000000000000000000000000000000..c7a8636de412d880d89fae43bb2ecaa61915eed2
--- /dev/null
+++ b/src/main/java/io/papermc/paper/network/payload/ChannelPayload.java
@@ -0,0 +1,59 @@
+package io.papermc.paper.network.payload;
+
+import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
+import net.minecraft.resources.ResourceLocation;
+import org.jetbrains.annotations.NotNull;
+import java.nio.charset.StandardCharsets;
+
+public sealed abstract class ChannelPayload implements CustomPacketPayload permits ChannelPayload.Register, ChannelPayload.Unregister {
+
+ public static final ResourceLocation REGISTER = new ResourceLocation("register");
+ public static final ResourceLocation UNREGISTER = new ResourceLocation("unregister");
+
+ private final String channels;
+
+ private ChannelPayload(final FriendlyByteBuf buf) {
+ this.channels = buf.toString(StandardCharsets.UTF_8);
+ buf.readerIndex(buf.readerIndex() + channels.length());
+ }
+
+ @Override
+ public final void write(final FriendlyByteBuf buf) {
+ buf.writeBytes(channels.getBytes(StandardCharsets.UTF_8));
+ }
+
+ public final String[] channels() {
+ return channels.split("\0");
+ }
+
+ /**
+ * Channel register payload. (minecraft:register)
+ */
+ public static final class Register extends ChannelPayload {
+
+ public Register(final FriendlyByteBuf buf) {
+ super(buf);
+ }
+
+ @Override
+ public @NotNull ResourceLocation id() {
+ return REGISTER;
+ }
+ }
+
+ /**
+ * Channel unregister payload. (minecraft:unregister)
+ */
+ public static final class Unregister extends ChannelPayload {
+
+ public Unregister(final FriendlyByteBuf buf) {
+ super(buf);
+ }
+
+ @Override
+ public @NotNull ResourceLocation id() {
+ return UNREGISTER;
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/network/payload/ReadableMessage.java b/src/main/java/io/papermc/paper/network/payload/ReadableMessage.java
new file mode 100644
index 0000000000000000000000000000000000000000..df2d63ab6c557755ed740c1b57e1a71af9db4ba2
--- /dev/null
+++ b/src/main/java/io/papermc/paper/network/payload/ReadableMessage.java
@@ -0,0 +1,8 @@
+package io.papermc.paper.network.payload;
+
+import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
+
+public interface ReadableMessage extends CustomPacketPayload {
+
+ byte[] message();
+}
diff --git a/src/main/java/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java b/src/main/java/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
index af86f752c33a2990405fea058b7c41c437ba9d46..41c5a048ce768f067f0c8324ab30eccb7d13c3db 100644
--- a/src/main/java/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
@@ -12,7 +12,13 @@ import net.minecraft.resources.ResourceLocation;
public record ServerboundCustomPayloadPacket(CustomPacketPayload payload) implements Packet<ServerCommonPacketListener> {
private static final int MAX_PAYLOAD_SIZE = 32767;
- private static final Map<ResourceLocation, FriendlyByteBuf.Reader<? extends CustomPacketPayload>> KNOWN_TYPES = ImmutableMap.<ResourceLocation, FriendlyByteBuf.Reader<? extends CustomPacketPayload>>builder().build(); // CraftBukkit - no special handling
+ // Paper start - Rewrite custom payload handler
+ private static final Map<ResourceLocation, FriendlyByteBuf.Reader<? extends CustomPacketPayload>> KNOWN_TYPES =
+ ImmutableMap.<ResourceLocation, FriendlyByteBuf.Reader<? extends CustomPacketPayload>>builder()
+ .put(io.papermc.paper.network.payload.ChannelPayload.REGISTER, io.papermc.paper.network.payload.ChannelPayload.Register::new)
+ .put(io.papermc.paper.network.payload.ChannelPayload.UNREGISTER, io.papermc.paper.network.payload.ChannelPayload.Unregister::new)
+ .build();
+ // Paper end - Rewrite custom payload handler
public ServerboundCustomPayloadPacket(FriendlyByteBuf buf) {
this(readPayload(buf.readResourceLocation(), buf));
@@ -47,7 +53,24 @@ public record ServerboundCustomPayloadPacket(CustomPacketPayload payload) implem
}
// CraftBukkit start
- public record UnknownPayload(ResourceLocation id, io.netty.buffer.ByteBuf data) implements CustomPacketPayload {
+ // Paper start - Rewrite custom payload handler
+ public record UnknownPayload(ResourceLocation id, byte[] data) implements io.papermc.paper.network.payload.ReadableMessage {
+
+ public UnknownPayload(final ResourceLocation id, final io.netty.buffer.ByteBuf data) {
+ this(id, UnknownPayload.readMessage(data));
+ }
+
+ private static byte[] readMessage(final io.netty.buffer.ByteBuf data) {
+ final byte[] message = new byte[data.readableBytes()];
+ data.readBytes(message);
+ return message;
+ }
+
+ @Override
+ public byte[] message() {
+ return data;
+ }
+ // Paper end - Rewrite custom payload handler
@Override
public void write(FriendlyByteBuf buf) {
diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
index d25b6431ce617d90fd1d6489a308d6630b92c175..568a1252acb00a8547e95cf529fdf3be7f3ca839 100644
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
@@ -104,6 +104,45 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
public void handlePong(ServerboundPongPacket packet) {}
// CraftBukkit start
+ // Paper start - Rewrite custom payload handler
+ @Override
+ public void handleCustomPayload(ServerboundCustomPayloadPacket packet) {
+ PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
+ if (packet.payload() instanceof io.papermc.paper.network.payload.ChannelPayload.Register payload) {
+ try {
+ final CraftPlayer player = this.getCraftPlayer();
+ for (final String channel : payload.channels()) {
+ player.addChannel(channel);
+ }
+ } catch (final Exception exception) {
+ ServerGamePacketListenerImpl.LOGGER.error("Couldn't register custom payload", exception);
+ this.disconnect("Invalid payload REGISTER!");
+ }
+ return;
+ } else if (packet.payload() instanceof io.papermc.paper.network.payload.ChannelPayload.Unregister payload) {
+ try {
+ final CraftPlayer player = this.getCraftPlayer();
+ for (final String channel : payload.channels()) {
+ player.removeChannel(channel);
+ }
+ } catch (final Exception exception) {
+ ServerGamePacketListenerImpl.LOGGER.error("Couldn't unregister custom payload", exception);
+ this.disconnect("Invalid payload UNREGISTER!");
+ }
+ return;
+ }
+
+ // Dispatch Message
+ if (packet.payload() instanceof io.papermc.paper.network.payload.ReadableMessage payload) {
+ try {
+ this.cserver.getMessenger().dispatchIncomingMessage(this.player.getBukkitEntity(), payload.id().toString(), payload.message());
+ } catch (final Exception exception) {
+ ServerGamePacketListenerImpl.LOGGER.error("Couldn't dispatch custom payload", exception);
+ this.disconnect("Invalid custom payload!");
+ }
+ }
+ }
+ /*
private static final ResourceLocation CUSTOM_REGISTER = new ResourceLocation("register");
private static final ResourceLocation CUSTOM_UNREGISTER = new ResourceLocation("unregister");
@@ -148,6 +187,8 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
}
}
+ */
+ // Paper end - Rewrite custom payload handler
public final boolean isDisconnected() {
return (!this.player.joining && !this.connection.isConnected()) || this.processedDisconnect; // Paper

Datei anzeigen

@ -0,0 +1,100 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: DigitalRegent <misterwener@gmail.com>
Date: Sat, 11 Apr 2020 13:10:58 +0200
Subject: [PATCH] Brand support
diff --git a/src/main/java/io/papermc/paper/network/payload/BrandPayload.java b/src/main/java/io/papermc/paper/network/payload/BrandPayload.java
new file mode 100644
index 0000000000000000000000000000000000000000..da940967dd1f84093506f9d845d8ee8aaa53c693
--- /dev/null
+++ b/src/main/java/io/papermc/paper/network/payload/BrandPayload.java
@@ -0,0 +1,30 @@
+package io.papermc.paper.network.payload;
+
+import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.resources.ResourceLocation;
+import org.jetbrains.annotations.NotNull;
+import java.nio.charset.StandardCharsets;
+
+public record BrandPayload(@NotNull String raw, @NotNull String brand) implements ReadableMessage {
+
+ public static final ResourceLocation ID = new ResourceLocation("brand");
+
+ public BrandPayload(final FriendlyByteBuf buf) {
+ this(buf.toString(StandardCharsets.UTF_8), buf.readUtf());
+ }
+
+ @Override
+ public byte[] message() {
+ return raw.getBytes(StandardCharsets.UTF_8);
+ }
+
+ @Override
+ public void write(final FriendlyByteBuf buf) {
+ buf.writeUtf(this.brand);
+ }
+
+ @Override
+ public @NotNull ResourceLocation id() {
+ return ID;
+ }
+}
diff --git a/src/main/java/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java b/src/main/java/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
index 41c5a048ce768f067f0c8324ab30eccb7d13c3db..c566f552d38462386793ee1206791cc666806271 100644
--- a/src/main/java/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
@@ -17,6 +17,7 @@ public record ServerboundCustomPayloadPacket(CustomPacketPayload payload) implem
ImmutableMap.<ResourceLocation, FriendlyByteBuf.Reader<? extends CustomPacketPayload>>builder()
.put(io.papermc.paper.network.payload.ChannelPayload.REGISTER, io.papermc.paper.network.payload.ChannelPayload.Register::new)
.put(io.papermc.paper.network.payload.ChannelPayload.UNREGISTER, io.papermc.paper.network.payload.ChannelPayload.Unregister::new)
+ .put(io.papermc.paper.network.payload.BrandPayload.ID, io.papermc.paper.network.payload.BrandPayload::new) // Paper - brand support
.build();
// Paper end - Rewrite custom payload handler
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 2c2b1aef3f510edb9bb124581739f06692ab5673..567bfcdf5c946d09bb8188435ee13930082dccf5 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -271,6 +271,7 @@ public class ServerPlayer extends Player {
public boolean isRealPlayer; // Paper
public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> cachedSingleHashSet; // Paper
public PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper
+ public @Nullable String clientBrandName = null; // Paper - Brand name
// Paper start - replace player chunk loader
private final java.util.concurrent.atomic.AtomicReference<io.papermc.paper.chunk.system.RegionizedPlayerChunkLoader.ViewDistances> viewDistances = new java.util.concurrent.atomic.AtomicReference<>(new io.papermc.paper.chunk.system.RegionizedPlayerChunkLoader.ViewDistances(-1, -1, -1));
diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
index 568a1252acb00a8547e95cf529fdf3be7f3ca839..efc5543670af2b8bb83b862d4d7e70bbad5cda8c 100644
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
@@ -131,6 +131,11 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
}
return;
}
+ // Paper start - handle brand payload packet
+ else if (packet.payload() instanceof io.papermc.paper.network.payload.BrandPayload brandPayload) {
+ this.player.clientBrandName = brandPayload.brand();
+ }
+ // Paper end - handle brand payload
// Dispatch Message
if (packet.payload() instanceof io.papermc.paper.network.payload.ReadableMessage payload) {
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index b92cc9f8d62cc3bfefe42c4c1fb08af4731dd48f..7b1404ac481ea9a059197b9f752327ef0bf72c5c 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -3009,6 +3009,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
// Paper end
};
+ // Paper start - brand support
+ @Override
+ public String getClientBrandName() {
+ return getHandle().clientBrandName;
+ }
+ // Paper end
+
public Player.Spigot spigot()
{
return this.spigot;

Datei anzeigen

@ -37,10 +37,10 @@ index 567bfcdf5c946d09bb8188435ee13930082dccf5..bf637aae0dcd701dd31568b3c8485134
// Paper start - replace player chunk loader // Paper start - replace player chunk loader
private final java.util.concurrent.atomic.AtomicReference<io.papermc.paper.chunk.system.RegionizedPlayerChunkLoader.ViewDistances> viewDistances = new java.util.concurrent.atomic.AtomicReference<>(new io.papermc.paper.chunk.system.RegionizedPlayerChunkLoader.ViewDistances(-1, -1, -1)); private final java.util.concurrent.atomic.AtomicReference<io.papermc.paper.chunk.system.RegionizedPlayerChunkLoader.ViewDistances> viewDistances = new java.util.concurrent.atomic.AtomicReference<>(new io.papermc.paper.chunk.system.RegionizedPlayerChunkLoader.ViewDistances(-1, -1, -1));
diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
index 96ee68e6656a59d959ad7a7e78f5a3752d6e3dbb..d660041805bcd1bb97cf347d8b1cfe5c65469f56 100644 index efc5543670af2b8bb83b862d4d7e70bbad5cda8c..5d17a500a38a200730ffd170c267e3edc9937ad9 100644
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java --- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
@@ -302,6 +302,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack @@ -333,6 +333,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
final Component ichatbasecomponent = io.papermc.paper.adventure.PaperAdventure.asVanilla(event.reason()); // Paper - Adventure final Component ichatbasecomponent = io.papermc.paper.adventure.PaperAdventure.asVanilla(event.reason()); // Paper - Adventure
// CraftBukkit end // CraftBukkit end

Datei anzeigen

@ -5,7 +5,7 @@ Subject: [PATCH] Climbing should not bypass cramming gamerule
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index d4f89c87b989be9cfb4bd991bc69b85760df4bb2..9068a9646a7e436a5a0d9ea9deb52b78a316ba4a 100644 index 121139196c82eb87be771d93f0ca52b951c7eb52..9257855651f7605935ecab121e239bef7218e53c 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java --- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2057,6 +2057,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { @@ -2057,6 +2057,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen