3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 00:00:28 +01:00

Merge pull request #1219 from creeper123123321/master

ignore non-identifier format on plugin messages
Dieser Commit ist enthalten in:
Myles 2019-03-18 21:37:21 +00:00 committet von GitHub
Commit b0c2d6f71c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 39 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.bungee.handlers; package us.myles.ViaVersion.bungee.handlers;
import com.google.common.base.Joiner;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ServerConnectEvent; import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.event.ServerConnectedEvent; import net.md_5.bungee.api.event.ServerConnectedEvent;
@ -29,8 +28,11 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
public class BungeeServerHandler implements Listener { public class BungeeServerHandler implements Listener {
private static Method getHandshake; private static Method getHandshake;
@ -152,23 +154,28 @@ public class BungeeServerHandler implements Listener {
String channel = plMsg.getTag(); String channel = plMsg.getTag();
int id1_13 = ProtocolVersion.v1_13.getId(); int id1_13 = ProtocolVersion.v1_13.getId();
if (previousServerProtocol != -1) { if (previousServerProtocol != -1) {
String oldChannel = channel;
if (previousServerProtocol < id1_13 && protocolId >= id1_13) { if (previousServerProtocol < id1_13 && protocolId >= id1_13) {
channel = InventoryPackets.getNewPluginChannelId(channel); channel = InventoryPackets.getNewPluginChannelId(channel);
if (channel.equals("minecraft:register")) { if (channel == null) {
String[] channels = new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0"); throw new RuntimeException(oldChannel + " found in relayMessages");
for (int i = 0; i < channels.length; i++) {
channels[i] = InventoryPackets.getNewPluginChannelId(channels[i]);
} }
plMsg.setData(Joiner.on('\0').join(channels).getBytes(StandardCharsets.UTF_8)); if (channel.equals("minecraft:register")) {
plMsg.setData(Arrays.stream(new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0"))
.map(InventoryPackets::getNewPluginChannelId)
.filter(Objects::nonNull)
.collect(Collectors.joining("\0")).getBytes(StandardCharsets.UTF_8));
} }
} else if (previousServerProtocol >= id1_13 && protocolId < id1_13) { } else if (previousServerProtocol >= id1_13 && protocolId < id1_13) {
channel = InventoryPackets.getOldPluginChannelId(channel); channel = InventoryPackets.getOldPluginChannelId(channel);
if (channel.equals("REGISTER")) { if (channel == null) {
String[] channels = new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0"); throw new RuntimeException(oldChannel + " found in relayMessages");
for (int i = 0; i < channels.length; i++) {
channels[i] = InventoryPackets.getOldPluginChannelId(channels[i]);
} }
plMsg.setData(Joiner.on('\0').join(channels).getBytes(StandardCharsets.UTF_8)); if (channel.equals("REGISTER")) {
plMsg.setData(Arrays.stream(new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0"))
.map(InventoryPackets::getOldPluginChannelId)
.filter(Objects::nonNull)
.collect(Collectors.joining("\0")).getBytes(StandardCharsets.UTF_8));
} }
} }
} }

Datei anzeigen

@ -4,7 +4,6 @@ import com.github.steveice10.opennbt.conversion.ConverterRegistry;
import com.github.steveice10.opennbt.tag.builtin.*; import com.github.steveice10.opennbt.tag.builtin.*;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.io.BaseEncoding;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
@ -159,8 +158,12 @@ public class InventoryPackets {
wrapper.passthrough(Type.INT); // Maximum number of trade uses wrapper.passthrough(Type.INT); // Maximum number of trade uses
} }
} else { } else {
String old = channel;
channel = getNewPluginChannelId(channel); channel = getNewPluginChannelId(channel);
if (channel == null) { if (channel == null) {
if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Ignoring outgoing plugin message with channel: " + old);
}
wrapper.cancel(); wrapper.cancel();
return; return;
} else if (channel.equals("minecraft:register") || channel.equals("minecraft:unregister")) { } else if (channel.equals("minecraft:register") || channel.equals("minecraft:unregister")) {
@ -171,7 +174,7 @@ public class InventoryPackets {
if (rewritten != null) { if (rewritten != null) {
rewrittenChannels.add(rewritten); rewrittenChannels.add(rewritten);
} else if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { } else if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Ignoring plugin channel in REGISTER: " + channels[i]); Via.getPlatform().getLogger().warning("Ignoring plugin channel in outgoing REGISTER: " + channels[i]);
} }
} }
wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8)); wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8));
@ -238,8 +241,12 @@ public class InventoryPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
String channel = wrapper.get(Type.STRING, 0); String channel = wrapper.get(Type.STRING, 0);
String old = channel;
channel = getOldPluginChannelId(channel); channel = getOldPluginChannelId(channel);
if (channel == null) { if (channel == null) {
if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Ignoring incoming plugin message with channel: " + old);
}
wrapper.cancel(); wrapper.cancel();
return; return;
} else if (channel.equals("REGISTER") || channel.equals("UNREGISTER")) { } else if (channel.equals("REGISTER") || channel.equals("UNREGISTER")) {
@ -250,7 +257,7 @@ public class InventoryPackets {
if (rewritten != null) { if (rewritten != null) {
rewrittenChannels.add(rewritten); rewrittenChannels.add(rewritten);
} else if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) { } else if (!Via.getConfig().isSuppress1_13ConversionErrors() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Ignoring plugin channel in REGISTER: " + channels[i]); Via.getPlatform().getLogger().warning("Ignoring plugin channel in incoming REGISTER: " + channels[i]);
} }
} }
wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8)); wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8));
@ -488,9 +495,7 @@ public class InventoryPackets {
return "wdl:request"; return "wdl:request";
default: default:
return old.matches("([0-9a-z_-]*:)?[0-9a-z_/.-]*") // Identifier regex return old.matches("([0-9a-z_-]*:)?[0-9a-z_/.-]*") // Identifier regex
? old ? old : null;
: "viaversion:legacy/" + BaseEncoding.base32().lowerCase().withPadChar('-').encode(
old.getBytes(StandardCharsets.UTF_8));
} }
} }
@ -710,14 +715,8 @@ public class InventoryPackets {
case "wdl:request": case "wdl:request":
return "WDL|REQUEST"; return "WDL|REQUEST";
default: default:
return newId.startsWith("viaversion:legacy/") // Our format :) return newId.matches("([0-9a-z_-]*:)?[0-9a-z_/.-]*") // Identifier regex
? new String(BaseEncoding.base32().lowerCase().withPadChar('-').decode( ? newId : null;
newId.substring(18)), StandardCharsets.UTF_8)
: newId.startsWith("legacy:")
? newId.substring(7) // Rewrite BungeeCord's format. It will only prevent kicks, plugins will still be broken because of case-sensitivity *plays sad violin*
: newId.startsWith("bungeecord:legacy/")
? newId.substring(18)
: newId;
} }
} }

Datei anzeigen

@ -155,15 +155,20 @@ public class VelocityServerHandler {
if (previousServerProtocol < id1_13 && protocolId >= id1_13) { if (previousServerProtocol < id1_13 && protocolId >= id1_13) {
ArrayList<String> newChannels = new ArrayList<>(); ArrayList<String> newChannels = new ArrayList<>();
for (String oldChannel : knownChannels) { for (String oldChannel : knownChannels) {
newChannels.add(InventoryPackets.getNewPluginChannelId(oldChannel)); String transformed = InventoryPackets.getNewPluginChannelId(oldChannel);
if (transformed != null) {
newChannels.add(transformed);
}
} }
knownChannels.clear(); knownChannels.clear();
knownChannels.addAll(newChannels); knownChannels.addAll(newChannels);
} else if (previousServerProtocol >= id1_13 && protocolId < id1_13) { } else if (previousServerProtocol >= id1_13 && protocolId < id1_13) {
ArrayList<String> newChannels = new ArrayList<>(); ArrayList<String> newChannels = new ArrayList<>();
for (String oldChannel : knownChannels) { for (String oldChannel : knownChannels) {
newChannels.add(InventoryPackets.getOldPluginChannelId(oldChannel)); String transformed = InventoryPackets.getOldPluginChannelId(oldChannel);
if (transformed != null) {
newChannels.add(transformed);
}
} }
knownChannels.clear(); knownChannels.clear();
knownChannels.addAll(newChannels); knownChannels.addAll(newChannels);