|
95 | 95 | }
|
96 | 96 | }
|
97 | 97 |
|
98 |
| -@@ -88,30 +_,119 @@ |
| 98 | +@@ -88,30 +_,123 @@ |
99 | 99 | public void handlePong(ServerboundPongPacket packet) {
|
100 | 100 | }
|
101 | 101 |
|
|
105 | 105 | @Override
|
106 | 106 | public void handleCustomPayload(ServerboundCustomPayloadPacket packet) {
|
107 | 107 | - }
|
108 |
| -+ // CraftBukkit start |
109 |
| -+ // Paper start - Brand support |
| 108 | ++ // Paper start |
110 | 109 | + if (packet.payload() instanceof net.minecraft.network.protocol.common.custom.BrandPayload(String brand)) {
|
111 | 110 | + this.player.clientBrandName = brand;
|
112 | 111 | + }
|
113 |
| -+ // Paper end - Brand support |
| 112 | ++ |
114 | 113 | + if (!(packet.payload() instanceof final net.minecraft.network.protocol.common.custom.DiscardedPayload discardedPayload)) {
|
115 | 114 | + return;
|
116 | 115 | + }
|
| 116 | ++ |
117 | 117 | + PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
118 |
| -+ net.minecraft.resources.ResourceLocation identifier = packet.payload().type().id(); |
119 |
| -+ io.netty.buffer.ByteBuf payload = discardedPayload.data(); |
120 | 118 | +
|
121 |
| -+ if (identifier.equals(ServerCommonPacketListenerImpl.CUSTOM_REGISTER)) { |
122 |
| -+ try { |
123 |
| -+ String channels = payload.toString(com.google.common.base.Charsets.UTF_8); |
124 |
| -+ for (String channel : channels.split("\0")) { |
125 |
| -+ this.getCraftPlayer().addChannel(channel); |
| 119 | ++ final net.minecraft.resources.ResourceLocation identifier = packet.payload().type().id(); |
| 120 | ++ final byte[] data = discardedPayload.data(); |
| 121 | ++ try { |
| 122 | ++ final boolean registerChannel = ServerCommonPacketListenerImpl.CUSTOM_REGISTER.equals(identifier); |
| 123 | ++ if (registerChannel || ServerCommonPacketListenerImpl.CUSTOM_UNREGISTER.equals(identifier)) { |
| 124 | ++ // Strings separated by zeros instead of length prefixes |
| 125 | ++ int startIndex = 0; |
| 126 | ++ for (int i = 0; i < data.length; i++) { |
| 127 | ++ final byte b = data[i]; |
| 128 | ++ if (b != 0) { |
| 129 | ++ continue; |
| 130 | ++ } |
| 131 | ++ |
| 132 | ++ readChannelIdentifier(data, startIndex, i, registerChannel); |
| 133 | ++ startIndex = i + 1; |
126 | 134 | + }
|
127 |
| -+ } catch (Exception ex) { |
128 |
| -+ ServerGamePacketListenerImpl.LOGGER.error("Couldn't register custom payload", ex); |
129 |
| -+ this.disconnect(Component.literal("Invalid payload REGISTER!"), org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PAYLOAD); // Paper - kick event cause |
| 135 | ++ |
| 136 | ++ // Read the last one |
| 137 | ++ readChannelIdentifier(data, startIndex, data.length, registerChannel); |
| 138 | ++ return; |
130 | 139 | + }
|
131 |
| -+ } else if (identifier.equals(ServerCommonPacketListenerImpl.CUSTOM_UNREGISTER)) { |
132 |
| -+ try { |
133 |
| -+ String channels = payload.toString(com.google.common.base.Charsets.UTF_8); |
134 |
| -+ for (String channel : channels.split("\0")) { |
135 |
| -+ this.getCraftPlayer().removeChannel(channel); |
136 |
| -+ } |
137 |
| -+ } catch (Exception ex) { |
138 |
| -+ ServerGamePacketListenerImpl.LOGGER.error("Couldn't unregister custom payload", ex); |
139 |
| -+ this.disconnect(Component.literal("Invalid payload UNREGISTER!"), org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PAYLOAD); // Paper - kick event cause |
| 140 | ++ |
| 141 | ++ if (identifier.equals(MINECRAFT_BRAND)) { |
| 142 | ++ this.player.clientBrandName = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.wrappedBuffer(data)).readUtf(256); |
140 | 143 | + }
|
| 144 | ++ |
| 145 | ++ this.cserver.getMessenger().dispatchIncomingMessage(this.player.getBukkitEntity(), identifier.toString(), data); |
| 146 | ++ } catch (final Exception e) { |
| 147 | ++ ServerGamePacketListenerImpl.LOGGER.error("Couldn't handle custom payload on channel {}", identifier, e); |
| 148 | ++ this.disconnect(Component.literal("Invalid custom payload payload!"), org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PAYLOAD); // Paper - kick event cause |
| 149 | ++ } |
| 150 | ++ } |
| 151 | ++ |
| 152 | ++ private void readChannelIdentifier(final byte[] data, final int from, final int to, final boolean register) { |
| 153 | ++ final int length = to - from; |
| 154 | ++ if (length == 0) { |
| 155 | ++ return; |
| 156 | ++ } |
| 157 | ++ |
| 158 | ++ final String channel = new String(data, from, length, java.nio.charset.StandardCharsets.US_ASCII); |
| 159 | ++ if (register) { |
| 160 | ++ this.getCraftPlayer().addChannel(channel); |
141 | 161 | + } else {
|
142 |
| -+ try { |
143 |
| -+ byte[] data = new byte[payload.readableBytes()]; |
144 |
| -+ payload.readBytes(data); |
145 |
| -+ // Paper start - Brand support; Retain this incase upstream decides to 'break' the new mechanism in favour of backwards compat... |
146 |
| -+ if (identifier.equals(MINECRAFT_BRAND)) { |
147 |
| -+ try { |
148 |
| -+ this.player.clientBrandName = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.copiedBuffer(data)).readUtf(256); |
149 |
| -+ } catch (StringIndexOutOfBoundsException ex) { |
150 |
| -+ this.player.clientBrandName = "illegal"; |
151 |
| -+ } |
152 |
| -+ } |
153 |
| -+ // Paper end - Brand support |
154 |
| -+ this.cserver.getMessenger().dispatchIncomingMessage(this.player.getBukkitEntity(), identifier.toString(), data); |
155 |
| -+ } catch (Exception ex) { |
156 |
| -+ ServerGamePacketListenerImpl.LOGGER.error("Couldn't dispatch custom payload", ex); |
157 |
| -+ this.disconnect(Component.literal("Invalid custom payload!"), org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PAYLOAD); // Paper - kick event cause |
158 |
| -+ } |
| 162 | ++ this.getCraftPlayer().removeChannel(channel); |
159 | 163 | + }
|
160 | 164 | + }
|
161 | 165 | +
|
162 | 166 | + public final boolean isDisconnected() {
|
163 | 167 | + return (!this.player.joining && !this.connection.isConnected()) || this.processedDisconnect; // Paper - Fix duplication bugs
|
164 | 168 | + }
|
165 |
| -+ // CraftBukkit end |
| 169 | ++ // Paper end |
166 | 170 |
|
167 | 171 | @Override
|
168 | 172 | public void handleResourcePackResponse(ServerboundResourcePackPacket packet) {
|
|
0 commit comments