/** * Calculate a path from a client version to server version * * @param clientVersion The input client version * @param serverVersion The desired output server version * @return The path it generated, null if it failed. */ public static List<Pair<Integer, Protocol>> getProtocolPath(int clientVersion, int serverVersion) { Pair<Integer, Integer> protocolKey = new Pair<>(clientVersion, serverVersion); // Check cache List<Pair<Integer, Protocol>> protocolList = pathCache.get(protocolKey); if (protocolList != null) { return protocolList; } // Generate path List<Pair<Integer, Protocol>> outputPath = getProtocolPath(new ArrayList<Pair<Integer, Protocol>>(), clientVersion, serverVersion); // If it found a path, cache it. if (outputPath != null) { pathCache.put(protocolKey, outputPath); } return outputPath; }
public static void refreshVersions() { supportedVersions.clear(); supportedVersions.add(ProtocolRegistry.SERVER_PROTOCOL); for (ProtocolVersion versions : ProtocolVersion.getProtocols()) { List<Pair<Integer, Protocol>> paths = getProtocolPath(versions.getId(), ProtocolRegistry.SERVER_PROTOCOL); if (paths == null) continue; supportedVersions.add(versions.getId()); for (Pair<Integer, Protocol> path : paths) supportedVersions.add(path.getKey()); } }
newCurrent.add(pair); newCurrent = getProtocolPath(newCurrent, entry.getKey(), serverVersion); if (newCurrent != null) {
@EventHandler public void onServerConnect(ServerConnectEvent e) { UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); if (user == null) return; if (!user.has(BungeeStorage.class)) { user.put(new BungeeStorage(user, e.getPlayer())); } int protocolId = ProtocolDetectorService.getProtocolId(e.getTarget().getName()); List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.get(ProtocolInfo.class).getProtocolVersion(), protocolId); // Check if ViaVersion can support that version try { //Object pendingConnection = getPendingConnection.invoke(e.getPlayer()); Object handshake = getHandshake.invoke(e.getPlayer().getPendingConnection()); setProtocol.invoke(handshake, protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId); } catch (InvocationTargetException | IllegalAccessException e1) { e1.printStackTrace(); } }
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId); ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline(); user.clearStoredObjects();
@Subscribe public void preServerConnect(ServerPreConnectEvent e) { try { UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); if (user == null) return; if (!user.has(VelocityStorage.class)) { user.put(new VelocityStorage(user, e.getPlayer())); } int protocolId = ProtocolDetectorService.getProtocolId(e.getOriginalServer().getServerInfo().getName()); List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.get(ProtocolInfo.class).getProtocolVersion(), protocolId); // Check if ViaVersion can support that version Object connection = getMinecraftConnection.invoke(e.getPlayer()); setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId)); } catch (IllegalAccessException | InvocationTargetException e1) { e1.printStackTrace(); } }
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId); ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline(); user.clearStoredObjects();