forked from PaperMC/Paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90fe0d5
commit be59951
Showing
598 changed files
with
377 additions
and
178 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
184 changes: 184 additions & 0 deletions
184
patches/server/0444-Rewrite-custom-payload-handler.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: LemonCaramel <[email protected]> | ||
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..f36204820cd4f8fc5793fa44c356e3f8efc3617e | ||
--- /dev/null | ||
+++ b/src/main/java/io/papermc/paper/network/payload/ChannelPayload.java | ||
@@ -0,0 +1,73 @@ | ||
+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.bukkit.craftbukkit.entity.CraftPlayer; | ||
+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"); | ||
+ } | ||
+ | ||
+ public abstract void handle(final CraftPlayer player, final String channel); | ||
+ | ||
+ | ||
+ /** | ||
+ * Channel register payload. (minecraft:register) | ||
+ */ | ||
+ public static final class Register extends ChannelPayload { | ||
+ | ||
+ public Register(final FriendlyByteBuf buf) { | ||
+ super(buf); | ||
+ } | ||
+ | ||
+ @Override | ||
+ public void handle(final CraftPlayer player, final String channel) { | ||
+ player.addChannel(channel); | ||
+ } | ||
+ | ||
+ @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 void handle(final CraftPlayer player, final String channel) { | ||
+ player.removeChannel(channel); | ||
+ } | ||
+ | ||
+ @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 975da2529d18391ed4ecc7359a2d7319129bd872..4c74a8e038781ef4c5c9a2caff181869c0b0c114 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().put(BrandPayload.ID, BrandPayload::new).build(); // CraftBukkit - decompile error | ||
+ // 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,15 @@ 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, io.netty.buffer.ByteBuf data) implements io.papermc.paper.network.payload.ReadableMessage { | ||
+ @Override | ||
+ public byte[] message() { | ||
+ final byte[] read = new byte[data.readableBytes()]; | ||
+ data.readBytes(read); | ||
+ return read; | ||
+ } | ||
+ // 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 d1808bf9dc19fad84da5eb3b4c3d549bc624b00a..b8d3e4f8d63499ff1cd25ec33ed5dff50fd59ba2 100644 | ||
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java | ||
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java | ||
@@ -104,6 +104,35 @@ 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 payload) { | ||
+ try { | ||
+ final CraftPlayer player = this.getCraftPlayer(); | ||
+ for (final String channel : payload.channels()) { | ||
+ payload.handle(player, channel); | ||
+ } | ||
+ } catch (final Exception exception) { | ||
+ final String type = payload.id().getPath(); | ||
+ ServerCommonPacketListenerImpl.LOGGER.error("Couldn't " + type + " custom payload", exception); | ||
+ this.disconnect("Invalid payload " + type.toUpperCase(java.util.Locale.US) + "!"); | ||
+ } | ||
+ 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 +177,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: DigitalRegent <[email protected]> | ||
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 4c74a8e038781ef4c5c9a2caff181869c0b0c114..a294bd8f92725494fedd3942ab4e50daad32f89c 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 4f98f80f6d8bebba33bad37fe6a722f778f93ed8..48985c0577fe1a09838137286e32128b29a60552 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 b8d3e4f8d63499ff1cd25ec33ed5dff50fd59ba2..9c346168532a6c2f730a60cbecdd1311c7e8070b 100644 | ||
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java | ||
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java | ||
@@ -121,6 +121,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 f4a15de92c3af88624f337c36fadbea67d339064..0656ea43e1d508d8f6af308475942c28d77655a4 100644 | ||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | ||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | ||
@@ -3007,6 +3007,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; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.