3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-10-03 08:41:05 +02:00

Update BungeeCord support (#2731)

fixes #2730
Dieser Commit ist enthalten in:
_tomcraft 2021-11-14 09:44:33 +01:00 committet von GitHub
Ursprung 6bc7f911c3
Commit dfc77b6f84
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -49,16 +49,13 @@ 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.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class BungeeServerHandler implements Listener { public class BungeeServerHandler implements Listener {
private static Method getHandshake; private static Method getHandshake;
private static Method getRelayMessages; private static Method getRegisteredChannels;
private static Method getBrandMessage;
private static Method setProtocol; private static Method setProtocol;
private static Method getEntityMap = null; private static Method getEntityMap = null;
private static Method setVersion = null; private static Method setVersion = null;
@ -68,7 +65,8 @@ public class BungeeServerHandler implements Listener {
static { static {
try { try {
getHandshake = Class.forName("net.md_5.bungee.connection.InitialHandler").getDeclaredMethod("getHandshake"); getHandshake = Class.forName("net.md_5.bungee.connection.InitialHandler").getDeclaredMethod("getHandshake");
getRelayMessages = Class.forName("net.md_5.bungee.connection.InitialHandler").getDeclaredMethod("getRelayMessages"); getRegisteredChannels = Class.forName("net.md_5.bungee.connection.InitialHandler").getDeclaredMethod("getRegisteredChannels");
getBrandMessage = Class.forName("net.md_5.bungee.connection.InitialHandler").getDeclaredMethod("getBrandMessage");
setProtocol = Class.forName("net.md_5.bungee.protocol.packet.Handshake").getDeclaredMethod("setProtocolVersion", int.class); setProtocol = Class.forName("net.md_5.bungee.protocol.packet.Handshake").getDeclaredMethod("setProtocolVersion", int.class);
getEntityMap = Class.forName("net.md_5.bungee.entitymap.EntityMap").getDeclaredMethod("getEntityMap", int.class); getEntityMap = Class.forName("net.md_5.bungee.entitymap.EntityMap").getDeclaredMethod("getEntityMap", int.class);
setVersion = Class.forName("net.md_5.bungee.netty.ChannelWrapper").getDeclaredMethod("setVersion", int.class); setVersion = Class.forName("net.md_5.bungee.netty.ChannelWrapper").getDeclaredMethod("setVersion", int.class);
@ -203,38 +201,44 @@ public class BungeeServerHandler implements Listener {
pipeline.add(Via.getManager().getProtocolManager().getBaseProtocol(protocolId)); pipeline.add(Via.getManager().getProtocolManager().getBaseProtocol(protocolId));
// Workaround 1.13 server change // Workaround 1.13 server change
Object relayMessages = getRelayMessages.invoke(e.getPlayer().getPendingConnection()); int id1_13 = ProtocolVersion.v1_13.getVersion();
for (Object message : (List) relayMessages) { boolean toNewId = previousServerProtocol < id1_13 && protocolId >= id1_13;
PluginMessage plMsg = (PluginMessage) message; boolean toOldId = previousServerProtocol >= id1_13 && protocolId < id1_13;
String channel = plMsg.getTag(); if (previousServerProtocol != -1 && (toNewId || toOldId)) {
int id1_13 = ProtocolVersion.v1_13.getVersion(); Collection<String> registeredChannels = (Collection<String>) getRegisteredChannels.invoke(e.getPlayer().getPendingConnection());
if (previousServerProtocol != -1) { if (!registeredChannels.isEmpty()) {
String oldChannel = channel; Collection<String> newChannels = new HashSet<>();
if (previousServerProtocol < id1_13 && protocolId >= id1_13) { for (Iterator<String> iterator = registeredChannels.iterator(); iterator.hasNext(); ) {
channel = InventoryPackets.getNewPluginChannelId(channel); String channel = iterator.next();
String oldChannel = channel;
if (toNewId) {
channel = InventoryPackets.getNewPluginChannelId(channel);
} else {
channel = InventoryPackets.getOldPluginChannelId(channel);
}
if (channel == null) { if (channel == null) {
throw new RuntimeException(oldChannel + " found in relayMessages"); iterator.remove();
continue;
} }
if (channel.equals("minecraft:register")) { if (!oldChannel.equals(channel)) {
plMsg.setData(Arrays.stream(new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0")) iterator.remove();
.map(InventoryPackets::getNewPluginChannelId) newChannels.add(channel);
.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")) {
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));
} }
} }
registeredChannels.addAll(newChannels);
}
PluginMessage brandMessage = (PluginMessage) getBrandMessage.invoke(e.getPlayer().getPendingConnection());
if (brandMessage != null) {
String channel = brandMessage.getTag();
if (toNewId) {
channel = InventoryPackets.getNewPluginChannelId(channel);
} else {
channel = InventoryPackets.getOldPluginChannelId(channel);
}
if (channel != null) {
brandMessage.setTag(channel);
}
} }
plMsg.setTag(channel);
} }
user.put(storage); user.put(storage);