Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Catch errors in <= 1.20 custom payload reading (#3770)
Dieser Commit ist enthalten in:
Ursprung
3ee4c8ed63
Commit
b113a82710
@ -22,11 +22,13 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.protocol.remapper;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public abstract class PacketHandlers implements PacketHandler {
|
||||
private final List<PacketHandler> packetHandlers = new ArrayList<>();
|
||||
@ -128,6 +130,24 @@ public abstract class PacketHandlers implements PacketHandler {
|
||||
packetHandlers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a packet handler which will suppress any exceptions thrown by the handler.
|
||||
*
|
||||
* @param handler packet handler
|
||||
*/
|
||||
public void handlerSoftFail(PacketHandler handler) {
|
||||
packetHandlers.add(h -> {
|
||||
try {
|
||||
handler.handle(h);
|
||||
} catch (Exception e) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, "Failed to handle packet", e);
|
||||
}
|
||||
h.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a value.
|
||||
*
|
||||
|
@ -46,7 +46,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
|
||||
public void register() {
|
||||
map(Type.STRING); // 0 - Channel
|
||||
|
||||
handler(wrapper -> {
|
||||
handlerSoftFail(wrapper -> {
|
||||
if (wrapper.get(Type.STRING, 0).equals("MC|TrList")) {
|
||||
wrapper.passthrough(Type.INT); // Passthrough Window ID
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING); // Channel
|
||||
handler(wrapper -> {
|
||||
handlerSoftFail(wrapper -> {
|
||||
String channel = Key.namespaced(wrapper.get(Type.STRING, 0));
|
||||
if (channel.equals("minecraft:trader_list")) {
|
||||
wrapper.passthrough(Type.INT); // Passthrough Window ID
|
||||
|
@ -47,7 +47,7 @@ public class InventoryPackets {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING); // Channel
|
||||
handler(wrapper -> {
|
||||
handlerSoftFail(wrapper -> {
|
||||
String channel = Key.namespaced(wrapper.get(Type.STRING, 0));
|
||||
if (channel.equals("minecraft:trader_list")) {
|
||||
wrapper.passthrough(Type.INT); // Passthrough Window ID
|
||||
|
@ -100,7 +100,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
||||
public void register() {
|
||||
map(Type.STRING); // 0 - Channel
|
||||
|
||||
handler(wrapper -> {
|
||||
handlerSoftFail(wrapper -> {
|
||||
String channel = wrapper.get(Type.STRING, 0);
|
||||
// Handle stopsound change
|
||||
if (channel.equals("MC|StopSound")) {
|
||||
@ -223,7 +223,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING); // Channel
|
||||
handler(wrapper -> {
|
||||
handlerSoftFail(wrapper -> {
|
||||
String channel = wrapper.get(Type.STRING, 0);
|
||||
String old = channel;
|
||||
channel = getOldPluginChannelId(channel);
|
||||
|
@ -142,7 +142,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING); // Channel
|
||||
handler(wrapper -> {
|
||||
handlerSoftFail(wrapper -> {
|
||||
String channel = Key.namespaced(wrapper.get(Type.STRING, 0));
|
||||
if (channel.equals("minecraft:trader_list")) {
|
||||
wrapper.setPacketType(ClientboundPackets1_14.TRADE_LIST);
|
||||
|
@ -163,8 +163,9 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
registerServerbound(ServerboundPackets1_16.PLUGIN_MESSAGE, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
String channel = wrapper.passthrough(Type.STRING);
|
||||
map(Type.STRING); // Channel
|
||||
handlerSoftFail(wrapper -> {
|
||||
final String channel = wrapper.get(Type.STRING, 0);
|
||||
final String namespacedChannel = Key.namespaced(channel);
|
||||
if (channel.length() > 32) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings()) {
|
||||
|
@ -30,6 +30,7 @@ import com.viaversion.viaversion.api.protocol.packet.Direction;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.api.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.ItemRewriter;
|
||||
@ -52,8 +53,8 @@ import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.LastReso
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.LastTags;
|
||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import java.util.UUID;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPackets1_19_4, ClientboundPackets1_20_2, ServerboundPackets1_19_4, ServerboundPackets1_20_2> {
|
||||
@ -75,8 +76,21 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
|
||||
soundRewriter.register1_19_3Sound(ClientboundPackets1_19_4.SOUND);
|
||||
soundRewriter.register1_19_3Sound(ClientboundPackets1_19_4.ENTITY_SOUND);
|
||||
|
||||
registerClientbound(ClientboundPackets1_19_4.PLUGIN_MESSAGE, this::sanitizeCustomPayload);
|
||||
registerServerbound(ServerboundPackets1_20_2.PLUGIN_MESSAGE, this::sanitizeCustomPayload);
|
||||
final PacketHandlers sanitizeCustomPayload = new PacketHandlers() {
|
||||
@Override
|
||||
protected void register() {
|
||||
map(Type.STRING); // Channel
|
||||
handlerSoftFail(wrapper -> {
|
||||
final String channel = Key.namespaced(wrapper.get(Type.STRING, 0));
|
||||
if (channel.equals("minecraft:brand")) {
|
||||
wrapper.passthrough(Type.STRING);
|
||||
wrapper.clearInputBuffer();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
registerClientbound(ClientboundPackets1_19_4.PLUGIN_MESSAGE, sanitizeCustomPayload);
|
||||
registerServerbound(ServerboundPackets1_20_2.PLUGIN_MESSAGE, sanitizeCustomPayload);
|
||||
|
||||
registerClientbound(ClientboundPackets1_19_4.RESOURCE_PACK, wrapper -> {
|
||||
final String url = wrapper.passthrough(Type.STRING);
|
||||
@ -315,14 +329,6 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
|
||||
};
|
||||
}
|
||||
|
||||
private void sanitizeCustomPayload(final PacketWrapper wrapper) throws Exception {
|
||||
final String channel = Key.namespaced(wrapper.passthrough(Type.STRING));
|
||||
if (channel.equals("minecraft:brand")) {
|
||||
wrapper.passthrough(Type.STRING);
|
||||
wrapper.clearInputBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingData getMappingData() {
|
||||
return MAPPINGS;
|
||||
|
@ -264,7 +264,7 @@ public class PlayerPackets {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING); // 0 - Channel Name
|
||||
handler(wrapper -> {
|
||||
handlerSoftFail(wrapper -> {
|
||||
String name = wrapper.get(Type.STRING, 0);
|
||||
if (name.equals("MC|BOpen")) {
|
||||
wrapper.write(Type.VAR_INT, 0);
|
||||
@ -405,7 +405,7 @@ public class PlayerPackets {
|
||||
@Override
|
||||
public void register() {
|
||||
map(Type.STRING); // 0 - Channel Name
|
||||
handler(wrapper -> {
|
||||
handlerSoftFail(wrapper -> {
|
||||
String name = wrapper.get(Type.STRING, 0);
|
||||
if (name.equals("MC|BSign")) {
|
||||
Item item = wrapper.passthrough(Type.ITEM1_8);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren