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
8493340
commit 7fee3b2
Showing
601 changed files
with
358 additions
and
154 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
180 changes: 180 additions & 0 deletions
180
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,180 @@ | ||
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..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..8f5ab7d6cceb3558960eeea1b90a75d227ba367a 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,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[] message = new byte[data.readableBytes()]; | ||
+ data.readBytes(message); | ||
+ return message; | ||
+ } | ||
+ // 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 |
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 8f5ab7d6cceb3558960eeea1b90a75d227ba367a..c4a5eca07ad0622d6e8d503ba53d9e012365005f 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; |
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.