diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 4a188c6ff..7e69afee1 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-1.13-pre4 + 1.4.0-1.13-pre5 4.0.0 diff --git a/bungee/pom.xml b/bungee/pom.xml index 83313574b..a688fc319 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-1.13-pre4 + 1.4.0-1.13-pre5 4.0.0 diff --git a/common/pom.xml b/common/pom.xml index 66f2e8329..e49621fde 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-1.13-pre4 + 1.4.0-1.13-pre5 4.0.0 diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolPipeline.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolPipeline.java index 9da7a58f8..6d91ce1d0 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolPipeline.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolPipeline.java @@ -74,8 +74,6 @@ public class ProtocolPipeline extends Protocol { // Apply protocols packetWrapper.apply(direction, state, 0, protocols); - int transformedId = packetWrapper.getId(); - super.transform(direction, state, packetWrapper); if (Via.getManager().isDebug()) { @@ -88,10 +86,7 @@ public class ProtocolPipeline extends Protocol { // For 1.8/1.9 server version, eventually we'll probably get an API for this... if (serverProtocol >= ProtocolVersion.v1_8.getId() && - serverProtocol <= ProtocolVersion.v1_9_3.getId() - || clientProtocol >= ProtocolVersion.v1_8.getId() && - clientProtocol <= ProtocolVersion.v1_9_3.getId()) { - + serverProtocol <= ProtocolVersion.v1_9_3.getId()) { PacketType type; if (serverProtocol <= ProtocolVersion.v1_8.getId()) { if (direction == Direction.INCOMING) { @@ -99,16 +94,8 @@ public class ProtocolPipeline extends Protocol { } else { type = PacketType.findOldPacket(state, direction, originalID); } - } else if (serverProtocol <= ProtocolVersion.v1_9_3.getId()) { - type = PacketType.findNewPacket(state, direction, originalID); - } else if (clientProtocol <= ProtocolVersion.v1_8.getId()) { - if (direction == Direction.INCOMING) { - type = PacketType.findNewPacket(state, direction, transformedId); - } else { - type = PacketType.findOldPacket(state, direction, transformedId); - } } else { - type = PacketType.findNewPacket(state, direction, transformedId); + type = PacketType.findNewPacket(state, direction, originalID); } if (type != null) { // Filter :) This would be not hard coded too, sorry :( diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java index 62b63a804..04d089dd5 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java @@ -62,7 +62,7 @@ public class ProtocolVersion { register(v1_12 = new ProtocolVersion(335, "1.12")); register(v1_12_1 = new ProtocolVersion(338, "1.12.1")); register(v1_12_2 = new ProtocolVersion(340, "1.12.2")); - register(v1_13 = new ProtocolVersion(386, "1.13-pre4")); + register(v1_13 = new ProtocolVersion(387, "1.13-pre5")); register(unknown = new ProtocolVersion(-1, "UNKNOWN")); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java index 2bc87bbb4..dfc510f8d 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java @@ -16,7 +16,6 @@ import us.myles.ViaVersion.api.platform.providers.ViaProviders; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; -import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; @@ -29,6 +28,7 @@ import java.util.List; import java.util.UUID; import java.util.logging.Level; +// TODO Make it work on 1.13 servers public class BaseProtocol extends Protocol { @Override @@ -108,51 +108,50 @@ public class BaseProtocol extends Protocol { registerOutgoing(State.STATUS, 0x01, 0x01); // Status Pong Packet + registerOutgoing(State.LOGIN, 0x00, 0x00); // Login Disconnect Packet + registerOutgoing(State.LOGIN, 0x01, 0x01); // Encryption Request Packet - // Login Disconnect Packet (1.12.2) - // Plugin Message (1.13) - registerOutgoing(State.LOGIN, 0x00, 0x00); - - // Encryption Request Packet (1.12.2) - // Login Disconnect Packet (1.13) - registerOutgoing(State.LOGIN, 0x01, 0x01); - - // Login Success Packet (1.12.2) - // Encryption Request Packet (1.13) + // Login Success Packet registerOutgoing(State.LOGIN, 0x02, 0x02, new PacketRemapper() { @Override public void registerMap() { + map(Type.STRING); // 0 - UUID as String + map(Type.STRING); // 1 - Player Username handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - int protocol = wrapper.user().get(ProtocolInfo.class).getServerProtocolVersion(); - if (protocol < ProtocolVersion.v1_13.getId()) - handleLoginSuccess(wrapper); + ProtocolInfo info = wrapper.user().get(ProtocolInfo.class); + info.setState(State.PLAY); + // Save other info + String stringUUID = wrapper.get(Type.STRING, 0); + if (stringUUID.length() == 32) { // Trimmed UUIDs are 32 characters + // Trimmed + stringUUID = addDashes(stringUUID); + } + UUID uuid = UUID.fromString(stringUUID); + info.setUuid(uuid); + info.setUsername(wrapper.get(Type.STRING, 1)); + // Add to ported clients + Via.getManager().addPortedClient(wrapper.user()); + + if (info.getPipeline().pipes().size() == 1 && info.getPipeline().pipes().get(0).getClass() == BaseProtocol.class) // Only base protocol + wrapper.user().setActive(false); + + if (Via.getManager().isDebug()) { + // Print out the route to console + Via.getPlatform().getLogger().log(Level.INFO, "{0} logged in with protocol {1}, Route: {2}", + new Object[]{ + wrapper.get(Type.STRING, 1), + info.getProtocolVersion(), + Joiner.on(", ").join(info.getPipeline().pipes(), ", ") + }); + } } }); } }); - // Login Set Compression Packet (1.12.2) - // Login Success Packet (1.13) - registerOutgoing(State.LOGIN, 0x03, 0x03, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int protocol = wrapper.user().get(ProtocolInfo.class).getServerProtocolVersion(); - if (protocol >= ProtocolVersion.v1_13.getId()) - handleLoginSuccess(wrapper); - } - }); - } - }); - - // Login Set Compression Packet (1.13) - registerOutgoing(State.LOGIN, 0x04, 0x04); - - + registerOutgoing(State.LOGIN, 0x03, 0x03); // Login Set Compression Packet /* Incoming Packets */ // Handshake Packet @@ -209,90 +208,35 @@ public class BaseProtocol extends Protocol { registerIncoming(State.STATUS, 0x00, 0x00); // Status Request Packet registerIncoming(State.STATUS, 0x01, 0x01); // Status Ping Packet - // Login Start Packet (1.12.2) - // Plugin Message (1.13) + // Login Start Packet registerIncoming(State.LOGIN, 0x00, 0x00, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @Override public void handle(final PacketWrapper wrapper) throws Exception { - int protocol = wrapper.user().get(ProtocolInfo.class).getServerProtocolVersion(); - if (protocol < ProtocolVersion.v1_13.getId()) - handleLoginStart(wrapper); + int protocol = wrapper.user().get(ProtocolInfo.class).getProtocolVersion(); + if (Via.getConfig().getBlockedProtocols().contains(protocol)) { + if (!wrapper.user().getChannel().isOpen()) return; + + PacketWrapper disconnectPacket = new PacketWrapper(0x00, null, wrapper.user()); // Disconnect Packet + Protocol1_9TO1_8.FIX_JSON.write(disconnectPacket, ChatColor.translateAlternateColorCodes('&', Via.getConfig().getBlockedDisconnectMsg())); + wrapper.cancel(); // cancel current + + // Send and close + ChannelFuture future = disconnectPacket.sendFuture(BaseProtocol.class); + future.addListener(new GenericFutureListener>() { + @Override + public void operationComplete(Future future) throws Exception { + wrapper.user().getChannel().close(); + } + }); + } } }); } - }); - - // Encryption Response Packet (1.12.2) - // Login Start Packet (1.13) - registerIncoming(State.LOGIN, 0x01, 0x01, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int protocol = wrapper.user().get(ProtocolInfo.class).getServerProtocolVersion(); - if (protocol >= ProtocolVersion.v1_13.getId()) - handleLoginStart(wrapper); - } - }); - } - }); - - // Encryption Response Packet (1.13) - registerIncoming(State.LOGIN, 0x02, 0x02); - } - - private void handleLoginStart(final PacketWrapper wrapper) throws Exception { - int protocol = wrapper.user().get(ProtocolInfo.class).getProtocolVersion(); - if (Via.getConfig().getBlockedProtocols().contains(protocol)) { - if (!wrapper.user().getChannel().isOpen()) return; - - PacketWrapper disconnectPacket = new PacketWrapper(0x00, null, wrapper.user()); // Disconnect Packet - Protocol1_9TO1_8.FIX_JSON.write(disconnectPacket, ChatColor.translateAlternateColorCodes('&', Via.getConfig().getBlockedDisconnectMsg())); - wrapper.cancel(); // cancel current - - // Send and close - ChannelFuture future = disconnectPacket.sendFuture(BaseProtocol.class); - future.addListener(new GenericFutureListener>() { - @Override - public void operationComplete(Future future) throws Exception { - wrapper.user().getChannel().close(); - } - }); - } - } - - private void handleLoginSuccess(final PacketWrapper wrapper) throws Exception { - ProtocolInfo info = wrapper.user().get(ProtocolInfo.class); - info.setState(State.PLAY); - // 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); - String username = wrapper.passthrough(Type.STRING); - info.setUsername(username); - // Add to ported clients - Via.getManager().addPortedClient(wrapper.user()); - - if (info.getPipeline().pipes().size() == 1 && info.getPipeline().pipes().get(0).getClass() == BaseProtocol.class) // Only base protocol - wrapper.user().setActive(false); - - if (Via.getManager().isDebug()) { - // Print out the route to console - Via.getPlatform().getLogger().log(Level.INFO, "{0} logged in with protocol {1}, Route: {2}", - new Object[]{ - username, - info.getProtocolVersion(), - Joiner.on(", ").join(info.getPipeline().pipes(), ", ") - }); - } + }); // Login Start Packet + registerIncoming(State.LOGIN, 0x01, 0x01); // Encryption Response Packet } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java index 57a4842bd..7942820c4 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/InventoryPackets.java @@ -1,6 +1,7 @@ package us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets; import com.github.steveice10.opennbt.tag.builtin.*; +import com.google.common.base.Joiner; import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.minecraft.item.Item; @@ -14,7 +15,9 @@ import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.MappingData; import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.SoundSource; import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.SpawnEggRewriter; -import java.util.Map; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; public class InventoryPackets { private static String NBT_TAG_NAME; @@ -125,20 +128,29 @@ public class InventoryPackets { wrapper.passthrough(Type.INT); // Number of tools uses wrapper.passthrough(Type.INT); // Maximum number of trade uses } - } else if (channel.equalsIgnoreCase("MC|Brand")) { - channel = "minecraft:brand"; - } else if (channel.equalsIgnoreCase("MC|BOpen")) { - channel = "minecraft:book_open"; - } else if (channel.equalsIgnoreCase("MC|DebugPath")) { - channel = "minecraft:debug/paths"; - } else if (channel.equalsIgnoreCase("MC|DebugNeighborsUpdate")) { - channel = "minecraft:debug/neighbors_update"; } else { - wrapper.cancel(); // TODO REGISTER channel removed? + String originalChannel = channel; + channel = getNewPluginChannelId(channel).orNull(); + if (channel == null) { + System.out.println("Plugin message cancelled " + originalChannel); // TODO remove this debug + wrapper.cancel(); + return; + } else if (channel.equals("minecraft:register") || channel.equals("minecraft:unregister")) { + String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0"); + List rewrittenChannels = new ArrayList<>(); + for (int i = 0; i < channels.length; i++) { + String rewritten = getNewPluginChannelId(channels[i]).orNull(); + if (rewritten != null) + rewrittenChannels.add(rewritten); + else + System.out.println("Ignoring plugin channel in REGISTER: " + channels[i]); + } + wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8)); + } } - // TODO message channel to new packets rewriting wrapper.set(Type.STRING, 0, channel); } + // TODO Fix trading GUI }); } }); @@ -208,6 +220,7 @@ public class InventoryPackets { } // TODO CLEANUP / SMARTER REWRITE SYSTEM + // TODO Rewrite identifiers public static void toClient(Item item) { if (item == null) return; @@ -430,4 +443,22 @@ public class InventoryPackets { || id == 442 // shield || id == 443; // elytra } + + public static Optional getNewPluginChannelId(String old) { + if (old.equalsIgnoreCase("MC|TrList")) + return Optional.of("minecraft:trader_list"); + if (old.equalsIgnoreCase("MC|Brand")) + return Optional.of("minecraft:brand"); + if (old.equalsIgnoreCase("MC|BOpen")) + return Optional.of("minecraft:book_open"); + if (old.equalsIgnoreCase("MC|DebugPath")) + return Optional.of("minecraft:debug/paths"); + if (old.equalsIgnoreCase("MC|DebugNeighborsUpdate")) + return Optional.of("minecraft:debug/neighbors_update"); + if (old.equalsIgnoreCase("REGISTER")) + return Optional.of("minecraft:register"); + if (old.equalsIgnoreCase("UNREGISTER")) + return Optional.of("minecraft:unregister"); + return Optional.absent(); + } } diff --git a/jar/pom.xml b/jar/pom.xml index a44d0eddb..d045c8a25 100644 --- a/jar/pom.xml +++ b/jar/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-1.13-pre4 + 1.4.0-1.13-pre5 4.0.0 viaversion-jar diff --git a/pom.xml b/pom.xml index 598e1e652..619c0c28b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ us.myles viaversion-parent - 1.4.0-1.13-pre4 + 1.4.0-1.13-pre5 pom viaversion-parent diff --git a/sponge-legacy/pom.xml b/sponge-legacy/pom.xml index 9b657e239..e5bef46cd 100644 --- a/sponge-legacy/pom.xml +++ b/sponge-legacy/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-1.13-pre4 + 1.4.0-1.13-pre5 4.0.0 diff --git a/sponge/pom.xml b/sponge/pom.xml index 76bebcd12..24d140ee7 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -5,7 +5,7 @@ viaversion-parent us.myles - 1.4.0-1.13-pre4 + 1.4.0-1.13-pre5 4.0.0