Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 16:12:42 +01:00
Replace more raw versions with ProtocolVersion
Dieser Commit ist enthalten in:
Ursprung
e449599ae7
Commit
dcc0642af9
@ -94,34 +94,36 @@ public interface ProtocolInfo {
|
|||||||
void setServerState(State serverState);
|
void setServerState(State serverState);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the user's release protocol version, or -1 if not set.
|
* Returns the user's protocol version, or null if not set.
|
||||||
* This is set during the {@link State#HANDSHAKE} state.
|
* This is set during the {@link State#HANDSHAKE} state.
|
||||||
*
|
*
|
||||||
* @return release protocol version, or -1 if not set
|
* @return protocol version, may be unknown
|
||||||
* @see ProtocolVersion
|
* @see ProtocolVersion#isKnown()
|
||||||
*/
|
*/
|
||||||
|
ProtocolVersion protocolVersion();
|
||||||
|
|
||||||
|
void setProtocolVersion(ProtocolVersion protocolVersion);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the server protocol version the user is connected to.
|
||||||
|
* This is set during the {@link State#HANDSHAKE} state.
|
||||||
|
*
|
||||||
|
* @return the server protocol version the user is connected to, may be unknown
|
||||||
|
* @see ProtocolVersion#isKnown()
|
||||||
|
*/
|
||||||
|
ProtocolVersion serverProtocolVersion();
|
||||||
|
|
||||||
|
void setServerProtocolVersion(ProtocolVersion protocolVersion);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
default int getProtocolVersion() {
|
default int getProtocolVersion() {
|
||||||
return protocolVersion() != null ? protocolVersion().getVersion() : -1;
|
return protocolVersion() != null ? protocolVersion().getVersion() : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Deprecated
|
||||||
* Returns the user's protocol version, or null if not set.
|
default int getServerProtocolVersion() {
|
||||||
*
|
return serverProtocolVersion() != null ? serverProtocolVersion().getVersion() : -1;
|
||||||
* @return protocol version if set
|
}
|
||||||
*/
|
|
||||||
@Nullable ProtocolVersion protocolVersion();
|
|
||||||
|
|
||||||
void setProtocolVersion(int protocolVersion);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the server protocol version the user is connected to, or -1 if not set.
|
|
||||||
* This is set during the {@link State#HANDSHAKE} state.
|
|
||||||
*
|
|
||||||
* @return server protocol version, or -1 if not set
|
|
||||||
*/
|
|
||||||
int getServerProtocolVersion();
|
|
||||||
|
|
||||||
void setServerProtocolVersion(int serverProtocolVersion);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the username associated with this connection.
|
* Returns the username associated with this connection.
|
||||||
|
@ -23,8 +23,9 @@
|
|||||||
package com.viaversion.viaversion.api.platform;
|
package com.viaversion.viaversion.api.platform;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSortedSets;
|
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
public interface ViaInjector {
|
public interface ViaInjector {
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ public interface ViaInjector {
|
|||||||
* @throws Exception if there is an error with getting this info, e.g. not binded
|
* @throws Exception if there is an error with getting this info, e.g. not binded
|
||||||
* @see ViaPlatform#isProxy()
|
* @see ViaPlatform#isProxy()
|
||||||
*/
|
*/
|
||||||
int getServerProtocolVersion() throws Exception;
|
ProtocolVersion getServerProtocolVersion() throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the supported server protocol versions.
|
* Returns the supported server protocol versions.
|
||||||
@ -69,8 +70,10 @@ public interface ViaInjector {
|
|||||||
* @throws Exception if there is an error with getting this info, e.g. not binded
|
* @throws Exception if there is an error with getting this info, e.g. not binded
|
||||||
* @see ViaPlatform#isProxy()
|
* @see ViaPlatform#isProxy()
|
||||||
*/
|
*/
|
||||||
default IntSortedSet getServerProtocolVersions() throws Exception {
|
default SortedSet<ProtocolVersion> getServerProtocolVersions() throws Exception {
|
||||||
return IntSortedSets.singleton(getServerProtocolVersion());
|
final SortedSet<ProtocolVersion> versions = new ObjectLinkedOpenHashSet<>();
|
||||||
|
versions.add(getServerProtocolVersion());
|
||||||
|
return versions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,8 +28,10 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.EnumMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
@ -37,7 +39,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
||||||
|
|
||||||
// These need to be at the top of the class to be initialized first
|
// These need to be at the top of the class to be initialized first
|
||||||
private static final Int2ObjectMap<ProtocolVersion> VERSIONS = new Int2ObjectOpenHashMap<>();
|
private static final Map<VersionType, Int2ObjectMap<ProtocolVersion>> VERSIONS = new EnumMap<>(VersionType.class);
|
||||||
private static final List<ProtocolVersion> VERSION_LIST = new ArrayList<>();
|
private static final List<ProtocolVersion> VERSION_LIST = new ArrayList<>();
|
||||||
|
|
||||||
public static final ProtocolVersion v1_7_1 = register(4, "1.7.2-1.7.5", new VersionRange("1.7", 2, 5));
|
public static final ProtocolVersion v1_7_1 = register(4, "1.7.2-1.7.5", new VersionRange("1.7", 2, 5));
|
||||||
@ -106,9 +108,11 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
|||||||
*/
|
*/
|
||||||
public static void register(ProtocolVersion protocolVersion) {
|
public static void register(ProtocolVersion protocolVersion) {
|
||||||
VERSION_LIST.add(protocolVersion);
|
VERSION_LIST.add(protocolVersion);
|
||||||
VERSIONS.put(protocolVersion.getVersion(), protocolVersion);
|
|
||||||
|
final Int2ObjectMap<ProtocolVersion> versions = VERSIONS.computeIfAbsent(protocolVersion.versionType, $ -> new Int2ObjectOpenHashMap<>());
|
||||||
|
versions.put(protocolVersion.version, protocolVersion);
|
||||||
if (protocolVersion.isSnapshot()) {
|
if (protocolVersion.isSnapshot()) {
|
||||||
VERSIONS.put(protocolVersion.getFullSnapshotVersion(), protocolVersion);
|
versions.put(protocolVersion.getFullSnapshotVersion(), protocolVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,24 +122,36 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
|||||||
* @param version protocol version
|
* @param version protocol version
|
||||||
* @return true if this protocol version has been registered
|
* @return true if this protocol version has been registered
|
||||||
*/
|
*/
|
||||||
|
public static boolean isRegistered(final VersionType versionType, final int version) {
|
||||||
|
final Int2ObjectMap<ProtocolVersion> versions = VERSIONS.get(versionType);
|
||||||
|
return versions != null && versions.containsKey(version);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isRegistered(int version) {
|
public static boolean isRegistered(int version) {
|
||||||
return VERSIONS.containsKey(version);
|
return isRegistered(VersionType.RELEASE, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a ProtocolVersion instance, even if this protocol version
|
* Returns a ProtocolVersion instance, even if this protocol version
|
||||||
* has not been registered. See {@link #isRegistered(int)} berorehand or {@link #isKnown()}.
|
* has not been registered. See {@link #isRegistered(VersionType, int)} berorehand or {@link #isKnown()}.
|
||||||
*
|
*
|
||||||
* @param version protocol version
|
* @param versionType protocol version type
|
||||||
|
* @param version protocol version
|
||||||
* @return registered or unknown ProtocolVersion
|
* @return registered or unknown ProtocolVersion
|
||||||
*/
|
*/
|
||||||
public static @NonNull ProtocolVersion getProtocol(final int version) {
|
public static @NonNull ProtocolVersion getProtocol(final VersionType versionType, final int version) {
|
||||||
final ProtocolVersion protocolVersion = VERSIONS.get(version);
|
final Int2ObjectMap<ProtocolVersion> versions = VERSIONS.get(versionType);
|
||||||
if (protocolVersion != null) {
|
if (versions != null) {
|
||||||
return protocolVersion;
|
final ProtocolVersion protocolVersion = versions.get(version);
|
||||||
} else {
|
if (protocolVersion != null) {
|
||||||
return new ProtocolVersion(VersionType.SPECIAL, version, -1, "Unknown (" + version + ")", null);
|
return protocolVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return new ProtocolVersion(VersionType.SPECIAL, version, -1, "Unknown (" + version + ")", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NonNull ProtocolVersion getProtocol(final int version) {
|
||||||
|
return getProtocol(VersionType.RELEASE, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -168,7 +184,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
|||||||
* @return registered protocol version if present, else null
|
* @return registered protocol version if present, else null
|
||||||
*/
|
*/
|
||||||
public static @Nullable ProtocolVersion getClosest(String protocol) {
|
public static @Nullable ProtocolVersion getClosest(String protocol) {
|
||||||
for (ProtocolVersion version : VERSIONS.values()) {
|
for (ProtocolVersion version : VERSION_LIST) {
|
||||||
String name = version.getName();
|
String name = version.getName();
|
||||||
if (name.equals(protocol) || version.isRange() && version.getIncludedVersions().contains(protocol)) {
|
if (name.equals(protocol) || version.isRange() && version.getIncludedVersions().contains(protocol)) {
|
||||||
return version;
|
return version;
|
||||||
|
@ -22,39 +22,27 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.api.protocol.version;
|
package com.viaversion.viaversion.api.protocol.version;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
public interface ServerProtocolVersion {
|
public interface ServerProtocolVersion {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the lowest supported protocol version by this server.
|
* Returns the lowest supported protocol version by this server.
|
||||||
* This and {@link #highestSupportedVersion()} should only differ on proxy servers supporting multiple versions.
|
* This and {@link #highestSupportedProtocolVersion()} should only differ on proxy servers supporting multiple versions.
|
||||||
*
|
*
|
||||||
* @return lowest supported protocol version
|
* @return lowest supported protocol version
|
||||||
*/
|
*/
|
||||||
int lowestSupportedVersion();
|
ProtocolVersion lowestSupportedProtocolVersion();
|
||||||
|
|
||||||
/**
|
|
||||||
* @see #highestSupportedVersion()
|
|
||||||
*/
|
|
||||||
default ProtocolVersion lowestSupportedProtocolVersion() {
|
|
||||||
return ProtocolVersion.getProtocol(lowestSupportedVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the highest supported protocol version by this server.
|
* Returns the highest supported protocol version by this server.
|
||||||
* This and {@link #lowestSupportedVersion()} should only differ on proxy servers supporting multiple versions.
|
* This and {@link #lowestSupportedProtocolVersion()} should only differ on proxy servers supporting multiple versions.
|
||||||
*
|
*
|
||||||
* @return highest supported protocol version
|
* @return highest supported protocol version
|
||||||
*/
|
*/
|
||||||
int highestSupportedVersion();
|
ProtocolVersion highestSupportedProtocolVersion();
|
||||||
|
|
||||||
/**
|
|
||||||
* @see #lowestSupportedVersion()
|
|
||||||
*/
|
|
||||||
default ProtocolVersion highestSupportedProtocolVersion() {
|
|
||||||
return ProtocolVersion.getProtocol(highestSupportedVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a sorted set of all supported protocol version by this server.
|
* Returns a sorted set of all supported protocol version by this server.
|
||||||
@ -62,7 +50,7 @@ public interface ServerProtocolVersion {
|
|||||||
*
|
*
|
||||||
* @return sorted set of supported protocol versions
|
* @return sorted set of supported protocol versions
|
||||||
*/
|
*/
|
||||||
IntSortedSet supportedVersions();
|
SortedSet<ProtocolVersion> supportedProtocolVersions();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the actual protocol version has not yet been identified.
|
* Returns true if the actual protocol version has not yet been identified.
|
||||||
@ -71,6 +59,22 @@ public interface ServerProtocolVersion {
|
|||||||
* @return true if set, false if unknown (yet)
|
* @return true if set, false if unknown (yet)
|
||||||
*/
|
*/
|
||||||
default boolean isKnown() {
|
default boolean isKnown() {
|
||||||
return lowestSupportedVersion() != -1 && highestSupportedVersion() != -1;
|
return lowestSupportedProtocolVersion().isKnown() && highestSupportedProtocolVersion().isKnown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
default int lowestSupportedVersion() {
|
||||||
|
return lowestSupportedProtocolVersion().getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
default int highestSupportedVersion() {
|
||||||
|
return highestSupportedProtocolVersion().getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
default IntSortedSet supportedVersions() {
|
||||||
|
return supportedProtocolVersions().stream().mapToInt(ProtocolVersion::getVersion)
|
||||||
|
.collect(IntLinkedOpenHashSet::new, IntSortedSet::add, IntSortedSet::addAll);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,5 +35,5 @@ public interface VersionProvider extends Provider {
|
|||||||
* @param connection connection
|
* @param connection connection
|
||||||
* @return closest server protocol version to the user's protocol version
|
* @return closest server protocol version to the user's protocol version
|
||||||
*/
|
*/
|
||||||
int getClosestServerProtocol(UserConnection connection) throws Exception;
|
ProtocolVersion getClosestServerProtocol(UserConnection connection) throws Exception;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ fun ShadowJar.configureRelocations() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun ShadowJar.configureExcludes() {
|
fun ShadowJar.configureExcludes() {
|
||||||
// FastUtil - we only want object and int maps
|
// FastUtil - we only want object, int, and reference maps
|
||||||
// Object types
|
// Object types
|
||||||
exclude("it/unimi/dsi/fastutil/*/*Reference*")
|
exclude("it/unimi/dsi/fastutil/*/*Reference*")
|
||||||
exclude("it/unimi/dsi/fastutil/*/*Boolean*")
|
exclude("it/unimi/dsi/fastutil/*/*Boolean*")
|
||||||
|
@ -43,7 +43,7 @@ public class BukkitViaAPI extends ViaAPIBase<Player> {
|
|||||||
public int getPlayerVersion(UUID uuid) {
|
public int getPlayerVersion(UUID uuid) {
|
||||||
UserConnection connection = Via.getManager().getConnectionManager().getConnectedClient(uuid);
|
UserConnection connection = Via.getManager().getConnectionManager().getConnectedClient(uuid);
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
return connection.getProtocolInfo().getProtocolVersion();
|
return connection.getProtocolInfo().protocolVersion().getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isProtocolSupport()) {
|
if (isProtocolSupport()) {
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package com.viaversion.viaversion.bukkit.platform;
|
package com.viaversion.viaversion.bukkit.platform;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||||
import com.viaversion.viaversion.bukkit.handlers.BukkitChannelInitializer;
|
import com.viaversion.viaversion.bukkit.handlers.BukkitChannelInitializer;
|
||||||
import com.viaversion.viaversion.bukkit.util.NMSUtil;
|
import com.viaversion.viaversion.bukkit.util.NMSUtil;
|
||||||
import com.viaversion.viaversion.platform.LegacyViaInjector;
|
import com.viaversion.viaversion.platform.LegacyViaInjector;
|
||||||
@ -61,13 +62,13 @@ public class BukkitViaInjector extends LegacyViaInjector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getServerProtocolVersion() throws ReflectiveOperationException {
|
public ProtocolVersion getServerProtocolVersion() throws ReflectiveOperationException {
|
||||||
if (PaperViaInjector.PAPER_PROTOCOL_METHOD) {
|
if (PaperViaInjector.PAPER_PROTOCOL_METHOD) {
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
return Bukkit.getUnsafe().getProtocolVersion();
|
return ProtocolVersion.getProtocol(Bukkit.getUnsafe().getProtocolVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
return HAS_WORLD_VERSION_PROTOCOL_VERSION ? cursedProtocolDetection() : veryCursedProtocolDetection();
|
return ProtocolVersion.getProtocol(HAS_WORLD_VERSION_PROTOCOL_VERSION ? cursedProtocolDetection() : veryCursedProtocolDetection());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int cursedProtocolDetection() throws ReflectiveOperationException {
|
private int cursedProtocolDetection() throws ReflectiveOperationException {
|
||||||
|
@ -37,8 +37,8 @@ public final class BukkitAckSequenceProvider extends AckSequenceProvider {
|
|||||||
final SequenceStorage sequenceStorage = connection.get(SequenceStorage.class);
|
final SequenceStorage sequenceStorage = connection.get(SequenceStorage.class);
|
||||||
final int previousSequence = sequenceStorage.setSequenceId(sequence);
|
final int previousSequence = sequenceStorage.setSequenceId(sequence);
|
||||||
if (previousSequence == -1) {
|
if (previousSequence == -1) {
|
||||||
final int serverProtocolVersion = connection.getProtocolInfo().getServerProtocolVersion();
|
final ProtocolVersion serverProtocolVersion = connection.getProtocolInfo().serverProtocolVersion();
|
||||||
final long delay = serverProtocolVersion > ProtocolVersion.v1_8.getVersion() && serverProtocolVersion < ProtocolVersion.v1_14.getVersion() ? 2 : 1;
|
final long delay = serverProtocolVersion.higherThan(ProtocolVersion.v1_8) && serverProtocolVersion.lowerThan(ProtocolVersion.v1_14) ? 2 : 1;
|
||||||
|
|
||||||
if (plugin.isEnabled()) {
|
if (plugin.isEnabled()) {
|
||||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new AckSequenceTask(connection, sequenceStorage), delay);
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new AckSequenceTask(connection, sequenceStorage), delay);
|
||||||
|
@ -100,7 +100,7 @@ public class BungeeServerHandler implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int serverProtocolVersion = Via.proxyPlatform().protocolDetectorService().serverProtocolVersion(event.getTarget().getName());
|
int serverProtocolVersion = Via.proxyPlatform().protocolDetectorService().serverProtocolVersion(event.getTarget().getName());
|
||||||
int clientProtocolVersion = user.getProtocolInfo().getProtocolVersion();
|
int clientProtocolVersion = user.getProtocolInfo().protocolVersion().getVersion();
|
||||||
List<ProtocolPathEntry> protocols = Via.getManager().getProtocolManager().getProtocolPath(clientProtocolVersion, serverProtocolVersion);
|
List<ProtocolPathEntry> protocols = Via.getManager().getProtocolManager().getProtocolPath(clientProtocolVersion, serverProtocolVersion);
|
||||||
|
|
||||||
// Check if ViaVersion can support that version
|
// Check if ViaVersion can support that version
|
||||||
@ -172,8 +172,8 @@ public class BungeeServerHandler implements Listener {
|
|||||||
|
|
||||||
String serverName = server.getInfo().getName();
|
String serverName = server.getInfo().getName();
|
||||||
storage.setCurrentServer(serverName);
|
storage.setCurrentServer(serverName);
|
||||||
int serverProtocolVersion = Via.proxyPlatform().protocolDetectorService().serverProtocolVersion(serverName);
|
ProtocolVersion serverProtocolVersion = ProtocolVersion.getProtocol(Via.proxyPlatform().protocolDetectorService().serverProtocolVersion(serverName));
|
||||||
if (serverProtocolVersion <= ProtocolVersion.v1_8.getVersion() && storage.getBossbar() != null) { // 1.8 doesn't have BossBar packet
|
if (serverProtocolVersion.lowerThanOrEquals(ProtocolVersion.v1_8) && storage.getBossbar() != null) { // 1.8 doesn't have BossBar packet
|
||||||
// This ensures we can encode it properly as only the 1.9 protocol is currently implemented.
|
// This ensures we can encode it properly as only the 1.9 protocol is currently implemented.
|
||||||
if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
|
if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
|
||||||
for (UUID uuid : storage.getBossbar()) {
|
for (UUID uuid : storage.getBossbar()) {
|
||||||
@ -187,16 +187,17 @@ public class BungeeServerHandler implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProtocolInfo info = user.getProtocolInfo();
|
ProtocolInfo info = user.getProtocolInfo();
|
||||||
int previousServerProtocol = info.getServerProtocolVersion();
|
ProtocolVersion previousServerProtocol = info.serverProtocolVersion();
|
||||||
|
|
||||||
// Refresh the pipes
|
// Refresh the pipes
|
||||||
List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), serverProtocolVersion);
|
List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager()
|
||||||
|
.getProtocolPath(info.protocolVersion().getVersion(), serverProtocolVersion.getVersion());
|
||||||
ProtocolPipeline pipeline = user.getProtocolInfo().getPipeline();
|
ProtocolPipeline pipeline = user.getProtocolInfo().getPipeline();
|
||||||
user.clearStoredObjects(true);
|
user.clearStoredObjects(true);
|
||||||
pipeline.cleanPipes();
|
pipeline.cleanPipes();
|
||||||
if (protocolPath == null) {
|
if (protocolPath == null) {
|
||||||
// TODO Check Bungee Supported Protocols? *shrugs*
|
// TODO Check Bungee Supported Protocols? *shrugs*
|
||||||
serverProtocolVersion = info.getProtocolVersion();
|
serverProtocolVersion = info.protocolVersion();
|
||||||
} else {
|
} else {
|
||||||
List<Protocol> protocols = new ArrayList<>(protocolPath.size());
|
List<Protocol> protocols = new ArrayList<>(protocolPath.size());
|
||||||
for (ProtocolPathEntry entry : protocolPath) {
|
for (ProtocolPathEntry entry : protocolPath) {
|
||||||
@ -207,13 +208,12 @@ public class BungeeServerHandler implements Listener {
|
|||||||
|
|
||||||
info.setServerProtocolVersion(serverProtocolVersion);
|
info.setServerProtocolVersion(serverProtocolVersion);
|
||||||
// Add version-specific base Protocol
|
// Add version-specific base Protocol
|
||||||
pipeline.add(Via.getManager().getProtocolManager().getBaseProtocol(serverProtocolVersion));
|
pipeline.add(Via.getManager().getProtocolManager().getBaseProtocol(serverProtocolVersion.getVersion()));
|
||||||
|
|
||||||
// Workaround 1.13 server change
|
// Workaround 1.13 server change
|
||||||
int id1_13 = ProtocolVersion.v1_13.getVersion();
|
boolean toNewId = previousServerProtocol.lowerThan(ProtocolVersion.v1_13) && serverProtocolVersion.higherThanOrEquals(ProtocolVersion.v1_13);
|
||||||
boolean toNewId = previousServerProtocol < id1_13 && serverProtocolVersion >= id1_13;
|
boolean toOldId = previousServerProtocol.higherThanOrEquals(ProtocolVersion.v1_13) && serverProtocolVersion.lowerThan(ProtocolVersion.v1_13);
|
||||||
boolean toOldId = previousServerProtocol >= id1_13 && serverProtocolVersion < id1_13;
|
if (previousServerProtocol.isKnown() && (toNewId || toOldId)) {
|
||||||
if (previousServerProtocol != -1 && (toNewId || toOldId)) {
|
|
||||||
Collection<String> registeredChannels = (Collection<String>) getRegisteredChannels.invoke(event.getPlayer().getPendingConnection());
|
Collection<String> registeredChannels = (Collection<String>) getRegisteredChannels.invoke(event.getPlayer().getPendingConnection());
|
||||||
if (!registeredChannels.isEmpty()) {
|
if (!registeredChannels.isEmpty()) {
|
||||||
Collection<String> newChannels = new HashSet<>();
|
Collection<String> newChannels = new HashSet<>();
|
||||||
|
@ -21,18 +21,19 @@ import com.google.gson.JsonArray;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.platform.ViaInjector;
|
import com.viaversion.viaversion.api.platform.ViaInjector;
|
||||||
|
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||||
import com.viaversion.viaversion.bungee.handlers.BungeeChannelInitializer;
|
import com.viaversion.viaversion.bungee.handlers.BungeeChannelInitializer;
|
||||||
import com.viaversion.viaversion.util.ReflectionUtil;
|
import com.viaversion.viaversion.util.ReflectionUtil;
|
||||||
import com.viaversion.viaversion.util.SetWrapper;
|
import com.viaversion.viaversion.util.SetWrapper;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.SortedSet;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
|
||||||
public class BungeeViaInjector implements ViaInjector {
|
public class BungeeViaInjector implements ViaInjector {
|
||||||
@ -111,13 +112,17 @@ public class BungeeViaInjector implements ViaInjector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getServerProtocolVersion() throws Exception {
|
public ProtocolVersion getServerProtocolVersion() throws Exception {
|
||||||
return getBungeeSupportedVersions().get(0);
|
return ProtocolVersion.getProtocol(getBungeeSupportedVersions().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntSortedSet getServerProtocolVersions() throws Exception {
|
public SortedSet<ProtocolVersion> getServerProtocolVersions() throws Exception {
|
||||||
return new IntLinkedOpenHashSet(getBungeeSupportedVersions());
|
final SortedSet<ProtocolVersion> versions = new ObjectLinkedOpenHashSet<>();
|
||||||
|
for (final Integer version : getBungeeSupportedVersions()) {
|
||||||
|
versions.add(ProtocolVersion.getProtocol(version));
|
||||||
|
}
|
||||||
|
return versions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -26,6 +26,7 @@ import com.viaversion.viaversion.protocols.base.BaseVersionProvider;
|
|||||||
import com.viaversion.viaversion.util.ReflectionUtil;
|
import com.viaversion.viaversion.util.ReflectionUtil;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
@ -33,7 +34,7 @@ import net.md_5.bungee.protocol.ProtocolConstants;
|
|||||||
public class BungeeVersionProvider extends BaseVersionProvider {
|
public class BungeeVersionProvider extends BaseVersionProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getClosestServerProtocol(UserConnection user) throws Exception {
|
public ProtocolVersion getClosestServerProtocol(UserConnection user) throws Exception {
|
||||||
// TODO Have one constant list forever until restart? (Might limit plugins if they change this)
|
// TODO Have one constant list forever until restart? (Might limit plugins if they change this)
|
||||||
List<Integer> list = ReflectionUtil.getStatic(ProtocolConstants.class, "SUPPORTED_VERSION_IDS", List.class);
|
List<Integer> list = ReflectionUtil.getStatic(ProtocolConstants.class, "SUPPORTED_VERSION_IDS", List.class);
|
||||||
List<Integer> sorted = new ArrayList<>(list);
|
List<Integer> sorted = new ArrayList<>(list);
|
||||||
@ -42,13 +43,14 @@ public class BungeeVersionProvider extends BaseVersionProvider {
|
|||||||
ProtocolInfo info = user.getProtocolInfo();
|
ProtocolInfo info = user.getProtocolInfo();
|
||||||
|
|
||||||
// Bungee supports it
|
// Bungee supports it
|
||||||
if (sorted.contains(info.getProtocolVersion())) {
|
final ProtocolVersion clientProtocolVersion = info.protocolVersion();
|
||||||
return info.getProtocolVersion();
|
if (new HashSet<>(sorted).contains(clientProtocolVersion.getVersion())) {
|
||||||
|
return clientProtocolVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Older than bungee supports, get the lowest version
|
// Older than bungee supports, get the lowest version
|
||||||
if (info.getProtocolVersion() < sorted.get(0)) {
|
if (clientProtocolVersion.getVersion() < sorted.get(0)) {
|
||||||
return getLowestSupportedVersion();
|
return ProtocolVersion.getProtocol(getLowestSupportedVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through all protocols to get the closest protocol id that bungee supports (and that viaversion does too)
|
// Loop through all protocols to get the closest protocol id that bungee supports (and that viaversion does too)
|
||||||
@ -56,13 +58,13 @@ public class BungeeVersionProvider extends BaseVersionProvider {
|
|||||||
// TODO: This needs a better fix, i.e checking ProtocolRegistry to see if it would work.
|
// TODO: This needs a better fix, i.e checking ProtocolRegistry to see if it would work.
|
||||||
// This is more of a workaround for snapshot support by bungee.
|
// This is more of a workaround for snapshot support by bungee.
|
||||||
for (Integer protocol : Lists.reverse(sorted)) {
|
for (Integer protocol : Lists.reverse(sorted)) {
|
||||||
if (info.getProtocolVersion() > protocol && ProtocolVersion.isRegistered(protocol)) {
|
if (clientProtocolVersion.getVersion() > protocol && ProtocolVersion.isRegistered(protocol)) {
|
||||||
return protocol;
|
return ProtocolVersion.getProtocol(protocol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Via.getPlatform().getLogger().severe("Panic, no protocol id found for " + info.getProtocolVersion());
|
Via.getPlatform().getLogger().severe("Panic, no protocol id found for " + clientProtocolVersion);
|
||||||
return info.getProtocolVersion();
|
return clientProtocolVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getLowestSupportedVersion() {
|
public static int getLowestSupportedVersion() {
|
||||||
|
@ -42,7 +42,7 @@ public abstract class ViaAPIBase<T> implements ViaAPI<T> {
|
|||||||
@Override
|
@Override
|
||||||
public int getPlayerVersion(UUID uuid) {
|
public int getPlayerVersion(UUID uuid) {
|
||||||
UserConnection connection = Via.getManager().getConnectionManager().getConnectedClient(uuid);
|
UserConnection connection = Via.getManager().getConnectionManager().getConnectedClient(uuid);
|
||||||
return connection != null ? connection.getProtocolInfo().getProtocolVersion() : -1;
|
return connection != null ? connection.getProtocolInfo().protocolVersion().getVersion() : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,6 +49,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.SortedSet;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -131,12 +132,12 @@ public class ViaManagerImpl implements ViaManager {
|
|||||||
if (protocolVersion.isKnown()) {
|
if (protocolVersion.isKnown()) {
|
||||||
if (platform.isProxy()) {
|
if (platform.isProxy()) {
|
||||||
platform.getLogger().info("ViaVersion detected lowest supported version by the proxy: " + protocolVersion.lowestSupportedProtocolVersion());
|
platform.getLogger().info("ViaVersion detected lowest supported version by the proxy: " + protocolVersion.lowestSupportedProtocolVersion());
|
||||||
platform.getLogger().info("Highest supported version by the proxy: " + ProtocolVersion.getProtocol(protocolVersion.highestSupportedVersion()));
|
platform.getLogger().info("Highest supported version by the proxy: " + protocolVersion.highestSupportedProtocolVersion());
|
||||||
if (debugHandler.enabled()) {
|
if (debugHandler.enabled()) {
|
||||||
platform.getLogger().info("Supported version range: " + Arrays.toString(protocolVersion.supportedVersions().toArray(new int[0])));
|
platform.getLogger().info("Supported version range: " + Arrays.toString(protocolVersion.supportedProtocolVersions().toArray(new ProtocolVersion[0])));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
platform.getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(protocolVersion.highestSupportedVersion()));
|
platform.getLogger().info("ViaVersion detected server version: " + protocolVersion.highestSupportedProtocolVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!protocolManager.isWorkingPipe()) {
|
if (!protocolManager.isWorkingPipe()) {
|
||||||
@ -185,13 +186,13 @@ public class ViaManagerImpl implements ViaManager {
|
|||||||
|
|
||||||
private void loadServerProtocol() {
|
private void loadServerProtocol() {
|
||||||
try {
|
try {
|
||||||
ProtocolVersion serverProtocolVersion = ProtocolVersion.getProtocol(injector.getServerProtocolVersion());
|
ProtocolVersion serverProtocolVersion = injector.getServerProtocolVersion();
|
||||||
ServerProtocolVersion versionInfo;
|
ServerProtocolVersion versionInfo;
|
||||||
if (platform.isProxy()) {
|
if (platform.isProxy()) {
|
||||||
IntSortedSet supportedVersions = injector.getServerProtocolVersions();
|
SortedSet<ProtocolVersion> supportedVersions = injector.getServerProtocolVersions();
|
||||||
versionInfo = new ServerProtocolVersionRange(supportedVersions.firstInt(), supportedVersions.lastInt(), supportedVersions);
|
versionInfo = new ServerProtocolVersionRange(supportedVersions.first(), supportedVersions.last(), supportedVersions);
|
||||||
} else {
|
} else {
|
||||||
versionInfo = new ServerProtocolVersionSingleton(serverProtocolVersion.getVersion());
|
versionInfo = new ServerProtocolVersionSingleton(serverProtocolVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
protocolManager.setServerProtocol(versionInfo);
|
protocolManager.setServerProtocol(versionInfo);
|
||||||
|
@ -29,8 +29,8 @@ public class ProtocolInfoImpl implements ProtocolInfo {
|
|||||||
private final UserConnection connection;
|
private final UserConnection connection;
|
||||||
private State clientState = State.HANDSHAKE;
|
private State clientState = State.HANDSHAKE;
|
||||||
private State serverState = State.HANDSHAKE;
|
private State serverState = State.HANDSHAKE;
|
||||||
private int serverProtocolVersion = -1;
|
private ProtocolVersion serverProtocolVersion = ProtocolVersion.unknown;
|
||||||
private ProtocolVersion protocolVersion;
|
private ProtocolVersion protocolVersion = ProtocolVersion.unknown;
|
||||||
private String username;
|
private String username;
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
private ProtocolPipeline pipeline;
|
private ProtocolPipeline pipeline;
|
||||||
@ -71,19 +71,18 @@ public class ProtocolInfoImpl implements ProtocolInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setProtocolVersion(int protocolVersion) {
|
public void setProtocolVersion(ProtocolVersion protocolVersion) {
|
||||||
this.protocolVersion = ProtocolVersion.getProtocol(protocolVersion);
|
this.protocolVersion = protocolVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getServerProtocolVersion() {
|
public ProtocolVersion serverProtocolVersion() {
|
||||||
return serverProtocolVersion;
|
return serverProtocolVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setServerProtocolVersion(int serverProtocolVersion) {
|
public void setServerProtocolVersion(ProtocolVersion serverProtocolVersion) {
|
||||||
ProtocolVersion protocol = ProtocolVersion.getProtocol(serverProtocolVersion);
|
this.serverProtocolVersion = serverProtocolVersion;
|
||||||
this.serverProtocolVersion = protocol.getVersion();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -124,12 +123,12 @@ public class ProtocolInfoImpl implements ProtocolInfo {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ProtocolInfo{" +
|
return "ProtocolInfo{" +
|
||||||
"clientState=" + clientState +
|
"clientState=" + clientState +
|
||||||
", serverState=" + serverState +
|
", serverState=" + serverState +
|
||||||
", protocolVersion=" + protocolVersion +
|
", protocolVersion=" + protocolVersion +
|
||||||
", serverProtocolVersion=" + serverProtocolVersion +
|
", serverProtocolVersion=" + serverProtocolVersion +
|
||||||
", username='" + username + '\'' +
|
", username='" + username + '\'' +
|
||||||
", uuid=" + uuid +
|
", uuid=" + uuid +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
|||||||
private ThreadPoolExecutor mappingLoaderExecutor;
|
private ThreadPoolExecutor mappingLoaderExecutor;
|
||||||
private boolean mappingsLoaded;
|
private boolean mappingsLoaded;
|
||||||
|
|
||||||
private ServerProtocolVersion serverProtocolVersion = new ServerProtocolVersionSingleton(-1);
|
private ServerProtocolVersion serverProtocolVersion = new ServerProtocolVersionSingleton(ProtocolVersion.unknown);
|
||||||
private int maxPathDeltaIncrease; // Only allow lowering path entries by default
|
private int maxPathDeltaIncrease; // Only allow lowering path entries by default
|
||||||
private int maxProtocolPathSize = 50;
|
private int maxProtocolPathSize = 50;
|
||||||
|
|
||||||
@ -381,8 +381,8 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isWorkingPipe() {
|
public boolean isWorkingPipe() {
|
||||||
for (Int2ObjectMap<Protocol> map : registryMap.values()) {
|
for (Int2ObjectMap<Protocol> map : registryMap.values()) {
|
||||||
for (int protocolVersion : serverProtocolVersion.supportedVersions()) {
|
for (ProtocolVersion protocolVersion : serverProtocolVersion.supportedProtocolVersions()) {
|
||||||
if (map.containsKey(protocolVersion)) {
|
if (map.containsKey(protocolVersion.getVersion())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
|
|||||||
AbstractSimpleProtocol.toNiceHex(originalID),
|
AbstractSimpleProtocol.toNiceHex(originalID),
|
||||||
packetWrapper.getId(),
|
packetWrapper.getId(),
|
||||||
AbstractSimpleProtocol.toNiceHex(packetWrapper.getId()),
|
AbstractSimpleProtocol.toNiceHex(packetWrapper.getId()),
|
||||||
Integer.toString(userConnection.getProtocolInfo().getProtocolVersion()),
|
userConnection.getProtocolInfo().protocolVersion().getName(),
|
||||||
packetWrapper
|
packetWrapper
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -17,32 +17,33 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocol;
|
package com.viaversion.viaversion.protocol;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||||
import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion;
|
import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
public class ServerProtocolVersionRange implements ServerProtocolVersion {
|
public class ServerProtocolVersionRange implements ServerProtocolVersion {
|
||||||
private final int lowestSupportedVersion;
|
private final ProtocolVersion lowestSupportedVersion;
|
||||||
private final int highestSupportedVersion;
|
private final ProtocolVersion highestSupportedVersion;
|
||||||
private final IntSortedSet supportedVersions;
|
private final SortedSet<ProtocolVersion> supportedVersions;
|
||||||
|
|
||||||
public ServerProtocolVersionRange(int lowestSupportedVersion, int highestSupportedVersion, IntSortedSet supportedVersions) {
|
public ServerProtocolVersionRange(ProtocolVersion lowestSupportedVersion, ProtocolVersion highestSupportedVersion, SortedSet<ProtocolVersion> supportedVersions) {
|
||||||
this.lowestSupportedVersion = lowestSupportedVersion;
|
this.lowestSupportedVersion = lowestSupportedVersion;
|
||||||
this.highestSupportedVersion = highestSupportedVersion;
|
this.highestSupportedVersion = highestSupportedVersion;
|
||||||
this.supportedVersions = supportedVersions;
|
this.supportedVersions = supportedVersions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int lowestSupportedVersion() {
|
public ProtocolVersion lowestSupportedProtocolVersion() {
|
||||||
return lowestSupportedVersion;
|
return lowestSupportedVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int highestSupportedVersion() {
|
public ProtocolVersion highestSupportedProtocolVersion() {
|
||||||
return highestSupportedVersion;
|
return highestSupportedVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntSortedSet supportedVersions() {
|
public SortedSet<ProtocolVersion> supportedProtocolVersions() {
|
||||||
return supportedVersions;
|
return supportedVersions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,29 +17,32 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocol;
|
package com.viaversion.viaversion.protocol;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||||
import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion;
|
import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSortedSets;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
public class ServerProtocolVersionSingleton implements ServerProtocolVersion {
|
public class ServerProtocolVersionSingleton implements ServerProtocolVersion {
|
||||||
private final int protocolVersion;
|
private final ProtocolVersion protocolVersion;
|
||||||
|
|
||||||
public ServerProtocolVersionSingleton(int protocolVersion) {
|
public ServerProtocolVersionSingleton(ProtocolVersion protocolVersion) {
|
||||||
this.protocolVersion = protocolVersion;
|
this.protocolVersion = protocolVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int lowestSupportedVersion() {
|
public ProtocolVersion lowestSupportedProtocolVersion() {
|
||||||
return protocolVersion;
|
return protocolVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int highestSupportedVersion() {
|
public ProtocolVersion highestSupportedProtocolVersion() {
|
||||||
return protocolVersion;
|
return protocolVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntSortedSet supportedVersions() {
|
public SortedSet<ProtocolVersion> supportedProtocolVersions() {
|
||||||
return IntSortedSets.singleton(protocolVersion);
|
final SortedSet<ProtocolVersion> set = new ObjectLinkedOpenHashSet<>();
|
||||||
|
set.add(protocolVersion);
|
||||||
|
return set;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
public class VersionedPacketTransformerImpl<C extends ClientboundPacketType, S extends ServerboundPacketType> implements VersionedPacketTransformer<C, S> {
|
public class VersionedPacketTransformerImpl<C extends ClientboundPacketType, S extends ServerboundPacketType> implements VersionedPacketTransformer<C, S> {
|
||||||
|
|
||||||
private final int inputProtocolVersion;
|
private final int inputProtocolVersion; // TODO Use ProtocolVersion
|
||||||
private final Class<C> clientboundPacketsClass;
|
private final Class<C> clientboundPacketsClass;
|
||||||
private final Class<S> serverboundPacketsClass;
|
private final Class<S> serverboundPacketsClass;
|
||||||
|
|
||||||
@ -142,8 +142,8 @@ public class VersionedPacketTransformerImpl<C extends ClientboundPacketType, S e
|
|||||||
PacketType packetType = packet.getPacketType();
|
PacketType packetType = packet.getPacketType();
|
||||||
UserConnection connection = packet.user();
|
UserConnection connection = packet.user();
|
||||||
boolean clientbound = packetType.direction() == Direction.CLIENTBOUND;
|
boolean clientbound = packetType.direction() == Direction.CLIENTBOUND;
|
||||||
int serverProtocolVersion = clientbound ? this.inputProtocolVersion : connection.getProtocolInfo().getServerProtocolVersion();
|
int serverProtocolVersion = clientbound ? this.inputProtocolVersion : connection.getProtocolInfo().serverProtocolVersion().getVersion();
|
||||||
int clientProtocolVersion = clientbound ? connection.getProtocolInfo().getProtocolVersion() : this.inputProtocolVersion;
|
int clientProtocolVersion = clientbound ? connection.getProtocolInfo().protocolVersion().getVersion() : this.inputProtocolVersion;
|
||||||
|
|
||||||
// Construct protocol pipeline
|
// Construct protocol pipeline
|
||||||
List<ProtocolPathEntry> path = Via.getManager().getProtocolManager().getProtocolPath(clientProtocolVersion, serverProtocolVersion);
|
List<ProtocolPathEntry> path = Via.getManager().getProtocolManager().getProtocolPath(clientProtocolVersion, serverProtocolVersion);
|
||||||
|
@ -57,7 +57,7 @@ public class BaseProtocol extends AbstractProtocol<BaseClientboundPacket, BaseCl
|
|||||||
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(protocolVersion);
|
info.setProtocolVersion(ProtocolVersion.getProtocol(protocolVersion));
|
||||||
// Ensure the server has a version provider
|
// Ensure the server has a version provider
|
||||||
VersionProvider versionProvider = Via.getManager().getProviders().get(VersionProvider.class);
|
VersionProvider versionProvider = Via.getManager().getProviders().get(VersionProvider.class);
|
||||||
if (versionProvider == null) {
|
if (versionProvider == null) {
|
||||||
@ -66,13 +66,14 @@ public class BaseProtocol extends AbstractProtocol<BaseClientboundPacket, BaseCl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Choose the pipe
|
// Choose the pipe
|
||||||
int serverProtocol = versionProvider.getClosestServerProtocol(wrapper.user());
|
ProtocolVersion serverProtocol = versionProvider.getClosestServerProtocol(wrapper.user());
|
||||||
info.setServerProtocolVersion(serverProtocol);
|
info.setServerProtocolVersion(serverProtocol);
|
||||||
List<ProtocolPathEntry> protocolPath = null;
|
List<ProtocolPathEntry> protocolPath = 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() >= serverProtocol || Via.getPlatform().isOldClientsAllowed()) {
|
if (info.protocolVersion().higherThanOrEquals(serverProtocol) || Via.getPlatform().isOldClientsAllowed()) {
|
||||||
protocolPath = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), serverProtocol);
|
protocolPath = Via.getManager().getProtocolManager()
|
||||||
|
.getProtocolPath(info.protocolVersion().getVersion(), serverProtocol.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtocolPipeline pipeline = wrapper.user().getProtocolInfo().getPipeline();
|
ProtocolPipeline pipeline = wrapper.user().getProtocolInfo().getPipeline();
|
||||||
@ -89,15 +90,14 @@ public class BaseProtocol extends AbstractProtocol<BaseClientboundPacket, BaseCl
|
|||||||
pipeline.add(protocols);
|
pipeline.add(protocols);
|
||||||
|
|
||||||
// Set the original snapshot version if present
|
// Set the original snapshot version if present
|
||||||
ProtocolVersion protocol = ProtocolVersion.getProtocol(serverProtocol);
|
wrapper.set(Type.VAR_INT, 0, serverProtocol.getOriginalVersion());
|
||||||
wrapper.set(Type.VAR_INT, 0, protocol.getOriginalVersion());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Base Protocol
|
// Add Base Protocol
|
||||||
pipeline.add(Via.getManager().getProtocolManager().getBaseProtocol(serverProtocol));
|
pipeline.add(Via.getManager().getProtocolManager().getBaseProtocol(serverProtocol.getVersion()));
|
||||||
|
|
||||||
if (Via.getManager().isDebug()) {
|
if (Via.getManager().isDebug()) {
|
||||||
Via.getPlatform().getLogger().info("User connected with protocol: " + info.getProtocolVersion() + " and serverProtocol: " + info.getServerProtocolVersion());
|
Via.getPlatform().getLogger().info("User connected with protocol: " + info.protocolVersion() + " and serverProtocol: " + info.serverProtocolVersion());
|
||||||
Via.getPlatform().getLogger().info("Protocol pipeline: " + pipeline.pipes());
|
Via.getPlatform().getLogger().info("Protocol pipeline: " + pipeline.pipes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ public class BaseProtocol extends AbstractProtocol<BaseClientboundPacket, BaseCl
|
|||||||
} else if (state == TRANSFER_INTENT) {
|
} else if (state == TRANSFER_INTENT) {
|
||||||
info.setState(State.LOGIN);
|
info.setState(State.LOGIN);
|
||||||
|
|
||||||
if (serverProtocol < ProtocolVersion.v1_20_5.getVersion()) {
|
if (serverProtocol.lowerThan(ProtocolVersion.v1_20_5)) {
|
||||||
wrapper.set(Type.VAR_INT, 1, LOGIN_INTENT);
|
wrapper.set(Type.VAR_INT, 1, LOGIN_INTENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ public class BaseProtocol1_7 extends AbstractProtocol<BaseClientboundPacket, Bas
|
|||||||
|
|
||||||
if (!Via.getAPI().getServerVersion().isKnown()) { // Set the Server protocol if the detection on startup failed
|
if (!Via.getAPI().getServerVersion().isKnown()) { // Set the Server protocol if the detection on startup failed
|
||||||
ProtocolManagerImpl protocolManager = (ProtocolManagerImpl) Via.getManager().getProtocolManager();
|
ProtocolManagerImpl protocolManager = (ProtocolManagerImpl) Via.getManager().getProtocolManager();
|
||||||
protocolManager.setServerProtocol(new ServerProtocolVersionSingleton(ProtocolVersion.getProtocol(protocolVersion).getVersion()));
|
protocolManager.setServerProtocol(new ServerProtocolVersionSingleton(ProtocolVersion.getProtocol(protocolVersion)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the server has a version provider
|
// Ensure the server has a version provider
|
||||||
@ -96,23 +96,23 @@ public class BaseProtocol1_7 extends AbstractProtocol<BaseClientboundPacket, Bas
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int closestServerProtocol = versionProvider.getClosestServerProtocol(wrapper.user());
|
ProtocolVersion closestServerProtocol = versionProvider.getClosestServerProtocol(wrapper.user());
|
||||||
List<ProtocolPathEntry> protocols = null;
|
List<ProtocolPathEntry> protocols = null;
|
||||||
if (info.getProtocolVersion() >= closestServerProtocol || Via.getPlatform().isOldClientsAllowed()) {
|
if (info.protocolVersion().higherThanOrEquals(closestServerProtocol) || Via.getPlatform().isOldClientsAllowed()) {
|
||||||
protocols = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), closestServerProtocol);
|
protocols = Via.getManager().getProtocolManager()
|
||||||
|
.getProtocolPath(info.protocolVersion().getVersion(), closestServerProtocol.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (protocols != null) {
|
if (protocols != null) {
|
||||||
if (protocolVersion == closestServerProtocol || protocolVersion == 0) { // Fix ServerListPlus
|
if (protocolVersion == closestServerProtocol.getVersion() || protocolVersion == 0) { // Fix ServerListPlus
|
||||||
ProtocolVersion prot = ProtocolVersion.getProtocol(info.getProtocolVersion());
|
version.addProperty("protocol", info.protocolVersion().getOriginalVersion());
|
||||||
version.addProperty("protocol", prot.getOriginalVersion());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// not compatible :(, *plays very sad violin*
|
// not compatible :(, *plays very sad violin*
|
||||||
wrapper.user().setActive(false);
|
wrapper.user().setActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Via.getConfig().blockedProtocolVersions().contains(info.getProtocolVersion())) {
|
if (Via.getConfig().blockedProtocolVersions().contains(info.protocolVersion().getVersion())) {
|
||||||
version.addProperty("protocol", -1); // Show blocked versions as outdated
|
version.addProperty("protocol", -1); // Show blocked versions as outdated
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ public class BaseProtocol1_7 extends AbstractProtocol<BaseClientboundPacket, Bas
|
|||||||
Via.getPlatform().getLogger().log(Level.INFO, "{0} logged in with protocol {1}, Route: {2}",
|
Via.getPlatform().getLogger().log(Level.INFO, "{0} logged in with protocol {1}, Route: {2}",
|
||||||
new Object[]{
|
new Object[]{
|
||||||
username,
|
username,
|
||||||
info.getProtocolVersion(),
|
info.protocolVersion().getName(),
|
||||||
Joiner.on(", ").join(info.getPipeline().pipes(), ", ")
|
Joiner.on(", ").join(info.getPipeline().pipes(), ", ")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ public class BaseProtocol1_7 extends AbstractProtocol<BaseClientboundPacket, Bas
|
|||||||
|
|
||||||
// Login Start Packet
|
// Login Start Packet
|
||||||
registerServerbound(ServerboundLoginPackets.HELLO, wrapper -> {
|
registerServerbound(ServerboundLoginPackets.HELLO, wrapper -> {
|
||||||
int protocol = wrapper.user().getProtocolInfo().getProtocolVersion();
|
int protocol = wrapper.user().getProtocolInfo().protocolVersion().getVersion();
|
||||||
if (Via.getConfig().blockedProtocolVersions().contains(protocol)) {
|
if (Via.getConfig().blockedProtocolVersions().contains(protocol)) {
|
||||||
if (!wrapper.user().getChannel().isOpen()) return;
|
if (!wrapper.user().getChannel().isOpen()) return;
|
||||||
if (!wrapper.user().shouldApplyBlockProtocol()) return;
|
if (!wrapper.user().shouldApplyBlockProtocol()) return;
|
||||||
|
@ -19,12 +19,13 @@ package com.viaversion.viaversion.protocols.base;
|
|||||||
|
|
||||||
import com.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
|
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||||
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
|
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
|
||||||
|
|
||||||
public class BaseVersionProvider implements VersionProvider {
|
public class BaseVersionProvider implements VersionProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getClosestServerProtocol(UserConnection connection) throws Exception {
|
public ProtocolVersion getClosestServerProtocol(UserConnection connection) throws Exception {
|
||||||
return Via.getAPI().getServerVersion().lowestSupportedVersion();
|
return Via.getAPI().getServerVersion().lowestSupportedProtocolVersion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ public class Protocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9
|
|||||||
clientChunks.setEnvironment(dimensionId);
|
clientChunks.setEnvironment(dimensionId);
|
||||||
|
|
||||||
// Reset recipes
|
// Reset recipes
|
||||||
if (user.getProtocolInfo().getProtocolVersion() >= ProtocolVersion.v1_13.getVersion()) {
|
if (user.getProtocolInfo().protocolVersion().higherThanOrEquals(ProtocolVersion.v1_13)) {
|
||||||
wrapper.create(ClientboundPackets1_13.DECLARE_RECIPES, packetWrapper -> packetWrapper.write(Type.VAR_INT, 0))
|
wrapper.create(ClientboundPackets1_13.DECLARE_RECIPES, packetWrapper -> packetWrapper.write(Type.VAR_INT, 0))
|
||||||
.scheduleSend(Protocol1_13To1_12_2.class);
|
.scheduleSend(Protocol1_13To1_12_2.class);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler {
|
|||||||
|
|
||||||
protected byte getStates(UserConnection user, Position position, int blockState) {
|
protected byte getStates(UserConnection user, Position position, int blockState) {
|
||||||
byte states = 0;
|
byte states = 0;
|
||||||
boolean pre1_12 = user.getProtocolInfo().getServerProtocolVersion() < ProtocolVersion.v1_12.getVersion();
|
boolean pre1_12 = user.getProtocolInfo().serverProtocolVersion().lowerThan(ProtocolVersion.v1_12);
|
||||||
if (connects(BlockFace.EAST, getBlockData(user, position.getRelative(BlockFace.EAST)), pre1_12)) states |= 1;
|
if (connects(BlockFace.EAST, getBlockData(user, position.getRelative(BlockFace.EAST)), pre1_12)) states |= 1;
|
||||||
if (connects(BlockFace.NORTH, getBlockData(user, position.getRelative(BlockFace.NORTH)), pre1_12)) states |= 2;
|
if (connects(BlockFace.NORTH, getBlockData(user, position.getRelative(BlockFace.NORTH)), pre1_12)) states |= 2;
|
||||||
if (connects(BlockFace.SOUTH, getBlockData(user, position.getRelative(BlockFace.SOUTH)), pre1_12)) states |= 4;
|
if (connects(BlockFace.SOUTH, getBlockData(user, position.getRelative(BlockFace.SOUTH)), pre1_12)) states |= 4;
|
||||||
|
@ -20,6 +20,7 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnection
|
|||||||
import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.minecraft.Position;
|
import com.viaversion.viaversion.api.minecraft.Position;
|
||||||
|
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ public class GlassConnectionHandler extends AbstractFenceConnectionHandler {
|
|||||||
if (states != 0) return states;
|
if (states != 0) return states;
|
||||||
|
|
||||||
ProtocolInfo protocolInfo = user.getProtocolInfo();
|
ProtocolInfo protocolInfo = user.getProtocolInfo();
|
||||||
return protocolInfo.getServerProtocolVersion() <= 47
|
return protocolInfo.serverProtocolVersion().lowerThanOrEquals(ProtocolVersion.v1_8)
|
||||||
&& protocolInfo.getServerProtocolVersion() != -1 ? 0xF : states;
|
&& protocolInfo.serverProtocolVersion().isKnown() ? 0xF : states;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
|
|||||||
lastTags.sendLastTags(connection);
|
lastTags.sendLastTags(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastResourcePack != null && connection.getProtocolInfo().getProtocolVersion() == ProtocolVersion.v1_20_2.getVersion()) {
|
if (lastResourcePack != null && connection.getProtocolInfo().protocolVersion() == ProtocolVersion.v1_20_2) {
|
||||||
// The client for some reason drops the resource pack when reentering the configuration state
|
// The client for some reason drops the resource pack when reentering the configuration state
|
||||||
final PacketWrapper resourcePackPacket = PacketWrapper.create(ClientboundConfigurationPackets1_20_2.RESOURCE_PACK, connection);
|
final PacketWrapper resourcePackPacket = PacketWrapper.create(ClientboundConfigurationPackets1_20_2.RESOURCE_PACK, connection);
|
||||||
resourcePackPacket.write(Type.STRING, lastResourcePack.url());
|
resourcePackPacket.write(Type.STRING, lastResourcePack.url());
|
||||||
|
@ -137,7 +137,7 @@ public final class DumpUtil {
|
|||||||
playerSample.add("versions", versions);
|
playerSample.add("versions", versions);
|
||||||
final Map<ProtocolVersion, Integer> playerVersions = new TreeMap<>(ProtocolVersion::compareTo);
|
final Map<ProtocolVersion, Integer> playerVersions = new TreeMap<>(ProtocolVersion::compareTo);
|
||||||
for (final UserConnection connection : Via.getManager().getConnectionManager().getConnections()) {
|
for (final UserConnection connection : Via.getManager().getConnectionManager().getConnections()) {
|
||||||
final ProtocolVersion protocolVersion = ProtocolVersion.getProtocol(connection.getProtocolInfo().getProtocolVersion());
|
final ProtocolVersion protocolVersion = connection.getProtocolInfo().protocolVersion();
|
||||||
playerVersions.compute(protocolVersion, (v, num) -> num != null ? num + 1 : 1);
|
playerVersions.compute(protocolVersion, (v, num) -> num != null ? num + 1 : 1);
|
||||||
}
|
}
|
||||||
for (final Map.Entry<ProtocolVersion, Integer> entry : playerVersions.entrySet()) {
|
for (final Map.Entry<ProtocolVersion, Integer> entry : playerVersions.entrySet()) {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.sponge.platform;
|
package com.viaversion.viaversion.sponge.platform;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||||
import com.viaversion.viaversion.platform.LegacyViaInjector;
|
import com.viaversion.viaversion.platform.LegacyViaInjector;
|
||||||
import com.viaversion.viaversion.platform.WrappedChannelInitializer;
|
import com.viaversion.viaversion.platform.WrappedChannelInitializer;
|
||||||
import com.viaversion.viaversion.sponge.handlers.SpongeChannelInitializer;
|
import com.viaversion.viaversion.sponge.handlers.SpongeChannelInitializer;
|
||||||
@ -30,14 +31,14 @@ import org.spongepowered.api.Sponge;
|
|||||||
public class SpongeViaInjector extends LegacyViaInjector {
|
public class SpongeViaInjector extends LegacyViaInjector {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getServerProtocolVersion() throws ReflectiveOperationException {
|
public ProtocolVersion getServerProtocolVersion() throws ReflectiveOperationException {
|
||||||
MinecraftVersion version = Sponge.platform().minecraftVersion();
|
MinecraftVersion version = Sponge.platform().minecraftVersion();
|
||||||
|
|
||||||
// 'protocolVersion' method was exposed to the API in a 1.19.4 build and 'getProtocol' no longer exists in the impl.
|
// 'protocolVersion' method was exposed to the API in a 1.19.4 build and 'getProtocol' no longer exists in the impl.
|
||||||
try {
|
try {
|
||||||
return (int) version.getClass().getDeclaredMethod("getProtocol").invoke(version);
|
return ProtocolVersion.getProtocol((int) version.getClass().getDeclaredMethod("getProtocol").invoke(version));
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
return (int) version.getClass().getDeclaredMethod("protocolVersion").invoke(version);
|
return ProtocolVersion.getProtocol((int) version.getClass().getDeclaredMethod("protocolVersion").invoke(version));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,13 +25,12 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
|||||||
import com.viaversion.viaversion.util.ReflectionUtil;
|
import com.viaversion.viaversion.util.ReflectionUtil;
|
||||||
import com.viaversion.viaversion.velocity.handlers.VelocityChannelInitializer;
|
import com.viaversion.viaversion.velocity.handlers.VelocityChannelInitializer;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.SortedSet;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
|
||||||
public class VelocityViaInjector implements ViaInjector {
|
public class VelocityViaInjector implements ViaInjector {
|
||||||
public static final Method GET_PLAYER_INFO_FORWARDING_MODE = getPlayerInfoForwardingModeMethod();
|
public static final Method GET_PLAYER_INFO_FORWARDING_MODE = getPlayerInfoForwardingModeMethod();
|
||||||
|
|
||||||
@ -78,18 +77,18 @@ public class VelocityViaInjector implements ViaInjector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getServerProtocolVersion() throws Exception {
|
public ProtocolVersion getServerProtocolVersion() {
|
||||||
return getLowestSupportedProtocolVersion();
|
return ProtocolVersion.getProtocol(getLowestSupportedProtocolVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntSortedSet getServerProtocolVersions() throws Exception {
|
public SortedSet<ProtocolVersion> getServerProtocolVersions() {
|
||||||
int lowestSupportedProtocolVersion = getLowestSupportedProtocolVersion();
|
int lowestSupportedProtocolVersion = getLowestSupportedProtocolVersion();
|
||||||
|
|
||||||
IntSortedSet set = new IntLinkedOpenHashSet();
|
SortedSet<ProtocolVersion> set = new ObjectLinkedOpenHashSet<>();
|
||||||
for (com.velocitypowered.api.network.ProtocolVersion version : com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS) {
|
for (com.velocitypowered.api.network.ProtocolVersion version : com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS) {
|
||||||
if (version.getProtocol() >= lowestSupportedProtocolVersion) {
|
if (version.getProtocol() >= lowestSupportedProtocolVersion) {
|
||||||
set.add(version.getProtocol());
|
set.add(ProtocolVersion.getProtocol(version.getProtocol()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return set;
|
return set;
|
||||||
|
@ -43,19 +43,20 @@ public class VelocityVersionProvider extends BaseVersionProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getClosestServerProtocol(UserConnection user) throws Exception {
|
public ProtocolVersion getClosestServerProtocol(UserConnection user) throws Exception {
|
||||||
return user.isClientSide() ? getBackProtocol(user) : getFrontProtocol(user);
|
return user.isClientSide() ? getBackProtocol(user) : getFrontProtocol(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getBackProtocol(UserConnection user) throws Exception {
|
private ProtocolVersion getBackProtocol(UserConnection user) throws Exception {
|
||||||
//TODO use newly added Velocity netty event
|
//TODO use newly added Velocity netty event
|
||||||
ChannelHandler mcHandler = user.getChannel().pipeline().get("handler");
|
ChannelHandler mcHandler = user.getChannel().pipeline().get("handler");
|
||||||
ServerConnection serverConnection = (ServerConnection) GET_ASSOCIATION.invoke(mcHandler);
|
ServerConnection serverConnection = (ServerConnection) GET_ASSOCIATION.invoke(mcHandler);
|
||||||
return Via.proxyPlatform().protocolDetectorService().serverProtocolVersion(serverConnection.getServerInfo().getName());
|
final int protocolVersion = Via.proxyPlatform().protocolDetectorService().serverProtocolVersion(serverConnection.getServerInfo().getName());
|
||||||
|
return ProtocolVersion.getProtocol(protocolVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getFrontProtocol(UserConnection user) throws Exception {
|
private ProtocolVersion getFrontProtocol(UserConnection user) throws Exception {
|
||||||
int playerVersion = user.getProtocolInfo().getProtocolVersion();
|
ProtocolVersion playerVersion = user.getProtocolInfo().protocolVersion();
|
||||||
|
|
||||||
IntStream versions = com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS.stream()
|
IntStream versions = com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS.stream()
|
||||||
.mapToInt(com.velocitypowered.api.network.ProtocolVersion::getProtocol);
|
.mapToInt(com.velocitypowered.api.network.ProtocolVersion::getProtocol);
|
||||||
@ -68,14 +69,14 @@ public class VelocityVersionProvider extends BaseVersionProvider {
|
|||||||
}
|
}
|
||||||
int[] compatibleProtocols = versions.toArray();
|
int[] compatibleProtocols = versions.toArray();
|
||||||
|
|
||||||
if (Arrays.binarySearch(compatibleProtocols, playerVersion) >= 0) {
|
if (Arrays.binarySearch(compatibleProtocols, playerVersion.getVersion()) >= 0) {
|
||||||
// Velocity supports it
|
// Velocity supports it
|
||||||
return playerVersion;
|
return playerVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerVersion < compatibleProtocols[0]) {
|
if (playerVersion.getVersion() < compatibleProtocols[0]) {
|
||||||
// Older than Velocity supports, get the lowest version
|
// Older than Velocity supports, get the lowest version
|
||||||
return compatibleProtocols[0];
|
return ProtocolVersion.getProtocol(compatibleProtocols[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through all protocols to get the closest protocol id that Velocity supports (and that Via does too)
|
// Loop through all protocols to get the closest protocol id that Velocity supports (and that Via does too)
|
||||||
@ -84,8 +85,8 @@ public class VelocityVersionProvider extends BaseVersionProvider {
|
|||||||
// This is more of a workaround for snapshot support
|
// This is more of a workaround for snapshot support
|
||||||
for (int i = compatibleProtocols.length - 1; i >= 0; i--) {
|
for (int i = compatibleProtocols.length - 1; i >= 0; i--) {
|
||||||
int protocol = compatibleProtocols[i];
|
int protocol = compatibleProtocols[i];
|
||||||
if (playerVersion > protocol && ProtocolVersion.isRegistered(protocol)) {
|
if (playerVersion.getVersion() > protocol && ProtocolVersion.isRegistered(protocol)) {
|
||||||
return protocol;
|
return ProtocolVersion.getProtocol(protocol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ public final class ProtocolDetectorService extends AbstractProtocolDetectorServi
|
|||||||
@Override
|
@Override
|
||||||
protected int lowestSupportedProtocolVersion() {
|
protected int lowestSupportedProtocolVersion() {
|
||||||
try {
|
try {
|
||||||
return ProtocolVersion.getProtocol(Via.getManager().getInjector().getServerProtocolVersion()).getVersion();
|
return Via.getManager().getInjector().getServerProtocolVersion().getVersion();
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return ProtocolVersion.v1_8.getVersion();
|
return ProtocolVersion.v1_8.getVersion();
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren