Fix and improved custom payload handling (#3497)

This commit is contained in:
RK_01 2023-10-24 00:01:33 +00:00 committed by GitHub
parent 68a32ed2f0
commit 78c7f03923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 19 deletions

View File

@ -45,8 +45,8 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
public void register() {
map(Type.STRING); // Channel
handler(wrapper -> {
String channel = wrapper.get(Type.STRING, 0);
if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) {
String channel = Key.namespaced(wrapper.get(Type.STRING, 0));
if (channel.equals("minecraft:trader_list")) {
wrapper.passthrough(Type.INT); // Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);

View File

@ -22,6 +22,7 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_13_2to1_13_1.Protocol1_13_2To1_13_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.util.Key;
public class InventoryPackets {
@ -47,8 +48,8 @@ public class InventoryPackets {
public void register() {
map(Type.STRING); // Channel
handler(wrapper -> {
String channel = wrapper.get(Type.STRING, 0);
if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) {
String channel = Key.namespaced(wrapper.get(Type.STRING, 0));
if (channel.equals("minecraft:trader_list")) {
wrapper.passthrough(Type.INT); // Passthrough Window ID
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);

View File

@ -17,11 +17,7 @@
*/
package com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.DoubleTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.github.steveice10.opennbt.tag.builtin.*;
import com.google.common.collect.Sets;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@ -41,6 +37,8 @@ import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTr
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.rewriter.ItemRewriter;
import com.viaversion.viaversion.rewriter.RecipeRewriter;
import com.viaversion.viaversion.util.Key;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
@ -143,8 +141,8 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
public void register() {
map(Type.STRING); // Channel
handler(wrapper -> {
String channel = wrapper.get(Type.STRING, 0);
if (channel.equals("minecraft:trader_list") || channel.equals("trader_list")) {
String channel = Key.namespaced(wrapper.get(Type.STRING, 0));
if (channel.equals("minecraft:trader_list")) {
wrapper.setPacketType(ClientboundPackets1_14.TRADE_LIST);
wrapper.resetReader();
wrapper.read(Type.STRING); // Remove channel
@ -178,7 +176,8 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
wrapper.write(Type.VAR_INT, 0);
wrapper.write(Type.VAR_INT, 0);
wrapper.write(Type.BOOLEAN, false);
} else if (channel.equals("minecraft:book_open") || channel.equals("book_open")) {
wrapper.clearInputBuffer();
} else if (channel.equals("minecraft:book_open")) {
int hand = wrapper.read(Type.VAR_INT);
wrapper.clearPacket();
wrapper.setPacketType(ClientboundPackets1_14.OPEN_BOOK);
@ -286,4 +285,4 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
}
return item;
}
}
}

View File

@ -47,6 +47,8 @@ import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
import com.viaversion.viaversion.util.GsonUtil;
import com.viaversion.viaversion.util.Key;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -164,12 +166,13 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
public void register() {
handler(wrapper -> {
String channel = wrapper.passthrough(Type.STRING);
final String namespacedChannel = Key.namespaced(channel);
if (channel.length() > 32) {
if (!Via.getConfig().isSuppressConversionWarnings()) {
Via.getPlatform().getLogger().warning("Ignoring incoming plugin channel, as it is longer than 32 characters: " + channel);
}
wrapper.cancel();
} else if (channel.equals("minecraft:register") || channel.equals("minecraft:unregister")) {
} else if (namespacedChannel.equals("minecraft:register") || namespacedChannel.equals("minecraft:unregister")) {
String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0");
List<String> checkedChannels = new ArrayList<>(channels.length);
for (String registeredChannel : channels) {

View File

@ -50,9 +50,11 @@ import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.Configur
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.LastResourcePack;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.LastTags;
import com.viaversion.viaversion.rewriter.SoundRewriter;
import java.util.UUID;
import com.viaversion.viaversion.util.Key;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.UUID;
public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPackets1_19_4, ClientboundPackets1_20_2, ServerboundPackets1_19_4, ServerboundPackets1_20_2> {
public static final MappingData MAPPINGS = new MappingDataBase("1.20", "1.20.2");
@ -73,14 +75,14 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
soundRewriter.registerEntitySound(ClientboundPackets1_19_4.ENTITY_SOUND);
registerClientbound(ClientboundPackets1_19_4.PLUGIN_MESSAGE, wrapper -> {
final String channel = wrapper.passthrough(Type.STRING);
final String channel = Key.namespaced(wrapper.passthrough(Type.STRING));
if (channel.equals("minecraft:brand")) {
wrapper.passthrough(Type.STRING);
wrapper.clearInputBuffer();
}
});
registerServerbound(ServerboundPackets1_20_2.PLUGIN_MESSAGE, wrapper -> {
final String channel = wrapper.passthrough(Type.STRING);
final String channel = Key.namespaced(wrapper.passthrough(Type.STRING));
if (channel.equals("minecraft:brand")) {
wrapper.passthrough(Type.STRING);
wrapper.clearInputBuffer();

View File

@ -19,12 +19,12 @@ package com.viaversion.viaversion.protocols.protocol1_9to1_8.packets;
import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.PlayerMovementMapper;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
@ -268,7 +268,6 @@ public class PlayerPackets {
handler(wrapper -> {
String name = wrapper.get(Type.STRING, 0);
if (name.equalsIgnoreCase("MC|BOpen")) {
wrapper.clearInputBuffer();
wrapper.write(Type.VAR_INT, 0);
} else if (name.equalsIgnoreCase("MC|TrList")) {
wrapper.passthrough(Type.INT); // ID