1.13-pre5 + revert some changes

This commit is contained in:
creeper123123321 2018-07-02 11:36:03 -03:00
parent 7fda025c0d
commit e3f71c26e7
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
11 changed files with 105 additions and 143 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-1.13-pre4</version>
<version>1.4.0-1.13-pre5</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-1.13-pre4</version>
<version>1.4.0-1.13-pre5</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-1.13-pre4</version>
<version>1.4.0-1.13-pre5</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -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 :(

View File

@ -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"));
}

View File

@ -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<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> 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<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> 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

View File

@ -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<String> 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<String> 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();
}
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-1.13-pre4</version>
<version>1.4.0-1.13-pre5</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>viaversion-jar</name>

View File

@ -6,7 +6,7 @@
<groupId>us.myles</groupId>
<artifactId>viaversion-parent</artifactId>
<version>1.4.0-1.13-pre4</version>
<version>1.4.0-1.13-pre5</version>
<packaging>pom</packaging>
<name>viaversion-parent</name>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-1.13-pre4</version>
<version>1.4.0-1.13-pre5</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-1.13-pre4</version>
<version>1.4.0-1.13-pre5</version>
</parent>
<modelVersion>4.0.0</modelVersion>