Prepare hackery for 1.16.4

This commit is contained in:
KennyTV 2020-10-07 12:32:52 +02:00
parent 03ba058a9b
commit 6371b77b94
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
18 changed files with 113 additions and 48 deletions

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>3.2.0-SNAPSHOT</version> <version>3.2.0-1.16.4-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>3.2.0-SNAPSHOT</version> <version>3.2.0-1.16.4-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>3.2.0-SNAPSHOT</version> <version>3.2.0-1.16.4-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>3.2.0-SNAPSHOT</version> <version>3.2.0-1.16.4-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -83,7 +83,7 @@ public class ViaManager {
public void onServerLoaded() { public void onServerLoaded() {
// Load Server Protocol // Load Server Protocol
try { try {
ProtocolRegistry.SERVER_PROTOCOL = injector.getServerProtocolVersion(); ProtocolRegistry.SERVER_PROTOCOL = ProtocolVersion.getProtocol(injector.getServerProtocolVersion()).getId();
} catch (Exception e) { } catch (Exception e) {
platform.getLogger().severe("ViaVersion failed to get the server protocol!"); platform.getLogger().severe("ViaVersion failed to get the server protocol!");
e.printStackTrace(); e.printStackTrace();

View File

@ -32,6 +32,7 @@ import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
import us.myles.ViaVersion.protocols.protocol1_16_1to1_16.Protocol1_16_1To1_16; import us.myles.ViaVersion.protocols.protocol1_16_1to1_16.Protocol1_16_1To1_16;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1; import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import us.myles.ViaVersion.protocols.protocol1_16_3to1_16_2.Protocol1_16_3To1_16_2; import us.myles.ViaVersion.protocols.protocol1_16_3to1_16_2.Protocol1_16_3To1_16_2;
import us.myles.ViaVersion.protocols.protocol1_16_4to1_16_3.Protocol1_16_4To1_16_3;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4;
import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1To1_9; import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1To1_9;
@ -116,6 +117,7 @@ public class ProtocolRegistry {
registerProtocol(new Protocol1_16_1To1_16(), ProtocolVersion.v1_16_1, ProtocolVersion.v1_16); registerProtocol(new Protocol1_16_1To1_16(), ProtocolVersion.v1_16_1, ProtocolVersion.v1_16);
registerProtocol(new Protocol1_16_2To1_16_1(), ProtocolVersion.v1_16_2, ProtocolVersion.v1_16_1); registerProtocol(new Protocol1_16_2To1_16_1(), ProtocolVersion.v1_16_2, ProtocolVersion.v1_16_1);
registerProtocol(new Protocol1_16_3To1_16_2(), ProtocolVersion.v1_16_3, ProtocolVersion.v1_16_2); registerProtocol(new Protocol1_16_3To1_16_2(), ProtocolVersion.v1_16_3, ProtocolVersion.v1_16_2);
registerProtocol(new Protocol1_16_4To1_16_3(), ProtocolVersion.v1_16_4, ProtocolVersion.v1_16_3);
} }
public static void init() { public static void init() {

View File

@ -1,11 +1,15 @@
package us.myles.ViaVersion.api.protocol; package us.myles.ViaVersion.api.protocol;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ProtocolVersion { public class ProtocolVersion {
private static final Map<Integer, ProtocolVersion> versions = new HashMap<>(); private static final Int2ObjectMap<ProtocolVersion> versions = new Int2ObjectOpenHashMap<>();
private static final List<ProtocolVersion> versionList = new ArrayList<>(); private static final List<ProtocolVersion> versionList = new ArrayList<>();
public static final ProtocolVersion v1_4_6; public static final ProtocolVersion v1_4_6;
@ -43,11 +47,9 @@ public class ProtocolVersion {
public static final ProtocolVersion v1_16_1; public static final ProtocolVersion v1_16_1;
public static final ProtocolVersion v1_16_2; public static final ProtocolVersion v1_16_2;
public static final ProtocolVersion v1_16_3; public static final ProtocolVersion v1_16_3;
public static final ProtocolVersion v1_16_4;
public static final ProtocolVersion unknown; public static final ProtocolVersion unknown;
private final int id;
private final String name;
static { static {
// Before netty rewrite // Before netty rewrite
register(v1_4_6 = new ProtocolVersion(51, "1.4.6")); register(v1_4_6 = new ProtocolVersion(51, "1.4.6"));
@ -87,18 +89,17 @@ public class ProtocolVersion {
register(v1_16_1 = new ProtocolVersion(736, "1.16.1")); register(v1_16_1 = new ProtocolVersion(736, "1.16.1"));
register(v1_16_2 = new ProtocolVersion(751, "1.16.2")); register(v1_16_2 = new ProtocolVersion(751, "1.16.2"));
register(v1_16_3 = new ProtocolVersion(753, "1.16.3")); register(v1_16_3 = new ProtocolVersion(753, "1.16.3"));
register(v1_16_4 = new ProtocolVersion(754, 1, "1.16.4"));
register(unknown = new ProtocolVersion(-1, "UNKNOWN")); register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
} }
public ProtocolVersion(int id, String name) {
this.id = id;
this.name = name;
}
public static void register(ProtocolVersion protocol) { public static void register(ProtocolVersion protocol) {
Preconditions.checkNotNull(protocol); Preconditions.checkNotNull(protocol);
versions.put(protocol.getId(), protocol); versions.put(protocol.id, protocol);
if (protocol.isSnapshot()) {
versions.put(protocol.getFullSnapshotId(), protocol);
}
versionList.add(protocol); versionList.add(protocol);
} }
@ -125,30 +126,67 @@ public class ProtocolVersion {
public static ProtocolVersion getClosest(String protocol) { public static ProtocolVersion getClosest(String protocol) {
for (ProtocolVersion version : versions.values()) { for (ProtocolVersion version : versions.values()) {
if (version.getName().equals(protocol)) String name = version.name;
if (name.equals(protocol) || name.equals(protocol + ".x")) {
return version; return version;
if (version.getName().equals(protocol + ".x")) }
return version;
String[] parts = version.getName().split("-"); if (version.isRange()) {
for (String part : parts) { String[] parts = name.split("-");
if (part.equalsIgnoreCase(protocol)) { for (String part : parts) {
return version; if (part.equalsIgnoreCase(protocol) || part.equals(protocol + ".x")) {
return version;
}
} }
if (part.equals(protocol + ".x"))
return version;
} }
} }
return null; return null;
} }
private final int id;
private final int snapshotId;
private final String name;
public ProtocolVersion(int id, String name) {
this(id, -1, name);
}
public ProtocolVersion(int id, int snapshotId, String name) {
this.id = id;
this.snapshotId = snapshotId;
this.name = name;
}
public int getId() { public int getId() {
return id; return id;
} }
/**
* @return snapshot protocol version without the snapshot indicator bit, -1 if not a snapshot
*/
public int getSnapshotId() {
return snapshotId;
}
/**
* @return snapshot protocol version with the hight bit indicating its snapshot status, -1 if not a snapshot
*/
public int getFullSnapshotId() {
return id == -1 ? -1 : (1 << 30) | snapshotId; // Bit indicating snapshot versions
}
public String getName() { public String getName() {
return name; return name;
} }
public boolean isSnapshot() {
return snapshotId != -1;
}
public boolean isRange() {
return name.indexOf('-') != -1;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
@ -165,6 +203,6 @@ public class ProtocolVersion {
@Override @Override
public String toString() { public String toString() {
return String.format("%s(%d)", this.getName(), this.getId()); return String.format("%s(%d)", this.name, this.id);
} }
} }

View File

@ -27,26 +27,27 @@ public class BaseProtocol extends SimpleProtocol {
@Override @Override
public void registerMap() { public void registerMap() {
handler(wrapper -> { handler(wrapper -> {
int protVer = wrapper.passthrough(Type.VAR_INT); int protocolVersion = wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.STRING); // Server Address wrapper.passthrough(Type.STRING); // Server Address
wrapper.passthrough(Type.UNSIGNED_SHORT); // Server Port wrapper.passthrough(Type.UNSIGNED_SHORT); // Server Port
int state = wrapper.passthrough(Type.VAR_INT); int state = wrapper.passthrough(Type.VAR_INT);
ProtocolInfo info = wrapper.user().getProtocolInfo(); ProtocolInfo info = wrapper.user().getProtocolInfo();
info.setProtocolVersion(protVer); info.setProtocolVersion(protocolVersion);
// Ensure the server has a version provider // Ensure the server has a version provider
if (Via.getManager().getProviders().get(VersionProvider.class) == null) { if (Via.getManager().getProviders().get(VersionProvider.class) == null) {
wrapper.user().setActive(false); wrapper.user().setActive(false);
return; return;
} }
// Choose the pipe // Choose the pipe
int protocol = Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(wrapper.user()); int serverProtocol = Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(wrapper.user());
info.setServerProtocolVersion(protocol); info.setServerProtocolVersion(serverProtocol);
List<Pair<Integer, Protocol>> protocols = null; List<Pair<Integer, Protocol>> protocols = null;
// Only allow newer clients or (1.9.2 on 1.9.4 server if the server supports it) // Only allow newer clients or (1.9.2 on 1.9.4 server if the server supports it)
if (info.getProtocolVersion() >= protocol || Via.getPlatform().isOldClientsAllowed()) { if (info.getProtocolVersion() >= serverProtocol || Via.getPlatform().isOldClientsAllowed()) {
protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocol); protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), serverProtocol);
} }
ProtocolPipeline pipeline = wrapper.user().getProtocolInfo().getPipeline(); ProtocolPipeline pipeline = wrapper.user().getProtocolInfo().getPipeline();
@ -56,11 +57,11 @@ public class BaseProtocol extends SimpleProtocol {
// Ensure mapping data has already been loaded // Ensure mapping data has already been loaded
ProtocolRegistry.completeMappingDataLoading(prot.getValue().getClass()); ProtocolRegistry.completeMappingDataLoading(prot.getValue().getClass());
} }
wrapper.set(Type.VAR_INT, 0, protocol); wrapper.set(Type.VAR_INT, 0, serverProtocol);
} }
// Add Base Protocol // Add Base Protocol
pipeline.add(ProtocolRegistry.getBaseProtocol(protocol)); pipeline.add(ProtocolRegistry.getBaseProtocol(serverProtocol));
// Change state // Change state
if (state == 1) { if (state == 1) {

View File

@ -11,6 +11,7 @@ import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry; 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.protocol.SimpleProtocol;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
@ -60,16 +61,21 @@ public class BaseProtocol1_7 extends SimpleProtocol {
version = new JsonObject(); version = new JsonObject();
json.getAsJsonObject().add("version", version); json.getAsJsonObject().add("version", version);
} }
if (Via.getConfig().isSendSupportedVersions()) //Send supported versions
version.add("supportedVersions", GsonUtil.getGson().toJsonTree(Via.getAPI().getSupportedVersions()));
if (ProtocolRegistry.SERVER_PROTOCOL == -1) // Set the Server protocol if the detection on startup failed if (Via.getConfig().isSendSupportedVersions()) { // Send supported versions
ProtocolRegistry.SERVER_PROTOCOL = protocolVersion; version.add("supportedVersions", GsonUtil.getGson().toJsonTree(Via.getAPI().getSupportedVersions()));
}
if (ProtocolRegistry.SERVER_PROTOCOL == -1) { // Set the Server protocol if the detection on startup failed
ProtocolRegistry.SERVER_PROTOCOL = ProtocolVersion.getProtocol(protocolVersion).getId();
}
// Ensure the server has a version provider // Ensure the server has a version provider
if (Via.getManager().getProviders().get(VersionProvider.class) == null) { if (Via.getManager().getProviders().get(VersionProvider.class) == null) {
wrapper.user().setActive(false); wrapper.user().setActive(false);
return; return;
} }
int protocol = Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(wrapper.user()); int protocol = Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(wrapper.user());
List<Pair<Integer, Protocol>> protocols = null; List<Pair<Integer, Protocol>> protocols = null;
@ -88,8 +94,9 @@ public class BaseProtocol1_7 extends SimpleProtocol {
wrapper.user().setActive(false); wrapper.user().setActive(false);
} }
if (Via.getConfig().getBlockedProtocols().contains(info.getProtocolVersion())) if (Via.getConfig().getBlockedProtocols().contains(info.getProtocolVersion())) {
version.addProperty("protocol", -1); // Show blocked versions as outdated version.addProperty("protocol", -1); // Show blocked versions as outdated
}
wrapper.set(Type.STRING, 0, GsonUtil.getGson().toJson(json)); // Update value wrapper.set(Type.STRING, 0, GsonUtil.getGson().toJson(json)); // Update value
} catch (JsonParseException e) { } catch (JsonParseException e) {

View File

@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.base;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import java.util.UUID; import java.util.UUID;
@ -32,7 +33,9 @@ public class ProtocolInfo extends StoredObject {
} }
public void setProtocolVersion(int protocolVersion) { public void setProtocolVersion(int protocolVersion) {
this.protocolVersion = protocolVersion; // Map snapshot versions to the higher/orderer release version
ProtocolVersion protocol = ProtocolVersion.getProtocol(protocolVersion);
this.protocolVersion = protocol.getId();
} }
public int getServerProtocolVersion() { public int getServerProtocolVersion() {
@ -40,7 +43,8 @@ public class ProtocolInfo extends StoredObject {
} }
public void setServerProtocolVersion(int serverProtocolVersion) { public void setServerProtocolVersion(int serverProtocolVersion) {
this.serverProtocolVersion = serverProtocolVersion; ProtocolVersion protocol = ProtocolVersion.getProtocol(serverProtocolVersion);
this.serverProtocolVersion = protocol.getId();
} }
public String getUsername() { public String getUsername() {

View File

@ -0,0 +1,13 @@
package us.myles.ViaVersion.protocols.protocol1_16_4to1_16_3;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
public class Protocol1_16_4To1_16_3 extends Protocol<ClientboundPackets1_16_2, ClientboundPackets1_16_2, ServerboundPackets1_16_2, ServerboundPackets1_16_2> {
@Override
protected void registerPackets() {
}
}

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>3.2.0-SNAPSHOT</version> <version>3.2.0-1.16.4-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>3.2.0-SNAPSHOT</version> <version>3.2.0-1.16.4-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<name>viaversion-jar</name> <name>viaversion-jar</name>

View File

@ -6,7 +6,7 @@
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<version>3.2.0-SNAPSHOT</version> <version>3.2.0-1.16.4-pre1</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>viaversion-parent</name> <name>viaversion-parent</name>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>3.2.0-SNAPSHOT</version> <version>3.2.0-1.16.4-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>3.2.0-SNAPSHOT</version> <version>3.2.0-1.16.4-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>3.2.0-SNAPSHOT</version> <version>3.2.0-1.16.4-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -37,7 +37,7 @@ public class ProtocolDetectorService implements Runnable {
} }
// Step 4: Use bungee lowest supported... *cries* // Step 4: Use bungee lowest supported... *cries*
try { try {
return Via.getManager().getInjector().getServerProtocolVersion(); return ProtocolVersion.getProtocol(Via.getManager().getInjector().getServerProtocolVersion()).getId();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return ProtocolVersion.v1_8.getId(); return ProtocolVersion.v1_8.getId();