From 70e142e4c41acfa0b952e247ab6fb7742cc5bc79 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 22 Jun 2020 17:02:25 +0200 Subject: [PATCH] Fix 1.16 Bungee compat Moved the version hack outside of the BaseProtocol class into separate impls with properly checking the sent version --- .../api/protocol/ProtocolRegistry.java | 4 ++- .../protocols/base/BaseProtocol1_16.java | 14 ++++++++++ .../protocols/base/BaseProtocol1_7.java | 28 ++++++++----------- 3 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_16.java diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java index 4553bd6d2..635f86c1d 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java @@ -9,6 +9,7 @@ import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.protocols.base.BaseProtocol; +import us.myles.ViaVersion.protocols.base.BaseProtocol1_16; import us.myles.ViaVersion.protocols.base.BaseProtocol1_7; import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_11_1to1_11.Protocol1_11_1To1_11; @@ -72,7 +73,8 @@ public class ProtocolRegistry { // Base Protocol registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE)); - registerBaseProtocol(new BaseProtocol1_7(), Range.all()); + registerBaseProtocol(new BaseProtocol1_7(), Range.lessThan(ProtocolVersion.v1_16.getId())); + registerBaseProtocol(new BaseProtocol1_16(), Range.atLeast(ProtocolVersion.v1_16.getId())); registerProtocol(new Protocol1_9To1_8(), ProtocolVersion.v1_9, ProtocolVersion.v1_8); registerProtocol(new Protocol1_9_1To1_9(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9.getId()); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_16.java b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_16.java new file mode 100644 index 000000000..7b9a73c28 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_16.java @@ -0,0 +1,14 @@ +package us.myles.ViaVersion.protocols.base; + +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.type.Type; + +import java.util.UUID; + +public class BaseProtocol1_16 extends BaseProtocol1_7 { + + @Override + protected UUID passthroughLoginUUID(final PacketWrapper wrapper) throws Exception { + return wrapper.passthrough(Type.UUID_INT_ARRAY); + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java index 0cbf7b93a..1b49faaf4 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol1_7.java @@ -11,7 +11,6 @@ import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; -import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.api.protocol.SimpleProtocol; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; @@ -116,20 +115,8 @@ public class BaseProtocol1_7 extends SimpleProtocol { ProtocolInfo info = wrapper.user().getProtocolInfo(); info.setState(State.PLAY); - if (info.getServerProtocolVersion() >= ProtocolVersion.v1_16.getId()) { - // 1.16+ uses int arrays - UUID uuid = wrapper.passthrough(Type.UUID_INT_ARRAY); - info.setUuid(uuid); - } else { - // Save other info - String stringUUID = wrapper.passthrough(Type.STRING); - if (stringUUID.length() == 32) { // Trimmed UUIDs are 32 characters - // Trimmed - stringUUID = addDashes(stringUUID); - } - UUID uuid = UUID.fromString(stringUUID); - info.setUuid(uuid); - } + UUID uuid = passthroughLoginUUID(wrapper); + info.setUuid(uuid); String username = wrapper.passthrough(Type.STRING); info.setUsername(username); @@ -137,7 +124,7 @@ public class BaseProtocol1_7 extends SimpleProtocol { Via.getManager().handleLoginSuccess(wrapper.user()); if (info.getPipeline().pipes().size() == 2 - && info.getPipeline().pipes().get(1).getClass() == BaseProtocol1_7.class + && info.getPipeline().pipes().get(1).getClass().isAssignableFrom(BaseProtocol1_7.class) && info.getPipeline().pipes().get(0).getClass() == BaseProtocol.class) // Only base protocol wrapper.user().setActive(false); @@ -198,4 +185,13 @@ public class BaseProtocol1_7 extends SimpleProtocol { idBuff.insert(8, '-'); return idBuff.toString(); } + + protected UUID passthroughLoginUUID(PacketWrapper wrapper) throws Exception { + String uuidString = wrapper.passthrough(Type.STRING); + if (uuidString.length() == 32) { // Trimmed UUIDs are 32 characters + // Trimmed + uuidString = addDashes(uuidString); + } + return UUID.fromString(uuidString); + } }