aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0475-Brand-support.patch
blob: 9163787c48a4480ef3df1e389be1517895f5b97e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index a29b1bdac36b3fc10bc7a8c1be6602e3c31b1d7c..5a33dd6575a4453694736e39652c1da2486c98d7 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -296,6 +296,8 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
     private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit
     private static final int MAX_SIGN_LINE_LENGTH = Integer.getInteger("Paper.maxSignLength", 80); // Paper
 
+    private String clientBrandName = null; // Paper - Brand name
+
     public ServerGamePacketListenerImpl(MinecraftServer server, Connection connection, ServerPlayer player) {
         this.lastChatTimeStamp = new AtomicReference(Instant.EPOCH);
         this.lastSeenMessagesValidator = new LastSeenMessagesValidator();
@@ -3429,6 +3431,8 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
     private static final ResourceLocation CUSTOM_REGISTER = new ResourceLocation("register");
     private static final ResourceLocation CUSTOM_UNREGISTER = new ResourceLocation("unregister");
 
+    private static final ResourceLocation MINECRAFT_BRAND = new ResourceLocation("brand"); // Paper - Brand support
+
     @Override
     public void handleCustomPayload(ServerboundCustomPayloadPacket packet) {
         PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
@@ -3456,6 +3460,15 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
             try {
                 byte[] data = new byte[packet.data.readableBytes()];
                 packet.data.readBytes(data);
+                // Paper start - Brand support
+                if (packet.identifier.equals(MINECRAFT_BRAND)) {
+                    try {
+                        this.clientBrandName = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.copiedBuffer(data)).readUtf(256);
+                    } catch (StringIndexOutOfBoundsException ex) {
+                        this.clientBrandName = "illegal";
+                    }
+                }
+                // Paper end
                 this.cserver.getMessenger().dispatchIncomingMessage(this.player.getBukkitEntity(), packet.identifier.toString(), data);
             } catch (Exception ex) {
                 ServerGamePacketListenerImpl.LOGGER.error("Couldn\'t dispatch custom payload", ex);
@@ -3465,6 +3478,12 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
 
     }
 
+    // Paper start - brand support
+    public String getClientBrandName() {
+        return clientBrandName;
+    }
+    // Paper end
+
     public final boolean isDisconnected() {
         return (!this.player.joining && !this.connection.isConnected()) || this.processedDisconnect; // Paper
     }
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 593925b1f20f94d7cd25492e0a70b9558c8b63c6..7783ba0edd8fb3f102769eeb4d755f915c8f7820 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -2691,6 +2691,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
         // Paper end
     };
 
+    // Paper start - brand support
+    @Override
+    public String getClientBrandName() {
+        return getHandle().connection != null ? getHandle().connection.getClientBrandName() : null;
+    }
+    // Paper end
+
     public Player.Spigot spigot()
     {
         return this.spigot;