ignore non-identifier format on plugin messages

This commit is contained in:
creeper123123321 2019-03-18 15:11:35 -03:00
parent 47819180c4
commit 4e28a10aaa
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
3 changed files with 39 additions and 28 deletions

View File

@ -1,6 +1,5 @@
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.event.ServerConnectEvent;
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.Method;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
public class BungeeServerHandler implements Listener {
private static Method getHandshake;
@ -152,23 +154,28 @@ public class BungeeServerHandler implements Listener {
String channel = plMsg.getTag();
int id1_13 = ProtocolVersion.v1_13.getId();
if (previousServerProtocol != -1) {
String oldChannel = channel;
if (previousServerProtocol < id1_13 && protocolId >= id1_13) {
channel = InventoryPackets.getNewPluginChannelId(channel);
if (channel == null) {
throw new RuntimeException(oldChannel + " found in relayMessages");
}
if (channel.equals("minecraft:register")) {
String[] channels = new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0");
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));
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) {
channel = InventoryPackets.getOldPluginChannelId(channel);
if (channel == null) {
throw new RuntimeException(oldChannel + " found in relayMessages");
}
if (channel.equals("REGISTER")) {
String[] channels = new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0");
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));
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));
}
}
}

View File

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

View File

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