3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01: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());
for (Object message : (List) relayMessages) {
PluginMessage plMsg = (PluginMessage) message;
String channel = plMsg.getTag();
int id1_13 = ProtocolVersion.v1_13.getVersion(); int id1_13 = ProtocolVersion.v1_13.getVersion();
if (previousServerProtocol != -1) { boolean toNewId = previousServerProtocol < id1_13 && protocolId >= id1_13;
boolean toOldId = previousServerProtocol >= id1_13 && protocolId < id1_13;
if (previousServerProtocol != -1 && (toNewId || toOldId)) {
Collection<String> registeredChannels = (Collection<String>) getRegisteredChannels.invoke(e.getPlayer().getPendingConnection());
if (!registeredChannels.isEmpty()) {
Collection<String> newChannels = new HashSet<>();
for (Iterator<String> iterator = registeredChannels.iterator(); iterator.hasNext(); ) {
String channel = iterator.next();
String oldChannel = channel; String oldChannel = channel;
if (previousServerProtocol < id1_13 && protocolId >= id1_13) { if (toNewId) {
channel = InventoryPackets.getNewPluginChannelId(channel); channel = InventoryPackets.getNewPluginChannelId(channel);
if (channel == null) { } else {
throw new RuntimeException(oldChannel + " found in relayMessages");
}
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) {
channel = InventoryPackets.getOldPluginChannelId(channel); channel = InventoryPackets.getOldPluginChannelId(channel);
}
if (channel == null) { if (channel == null) {
throw new RuntimeException(oldChannel + " found in relayMessages"); iterator.remove();
continue;
} }
if (channel.equals("REGISTER")) { if (!oldChannel.equals(channel)) {
plMsg.setData(Arrays.stream(new String(plMsg.getData(), StandardCharsets.UTF_8).split("\0")) iterator.remove();
.map(InventoryPackets::getOldPluginChannelId) newChannels.add(channel);
.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);