@Override public SortedSet<Integer> getSupportedVersions() { SortedSet<Integer> outputSet = new TreeSet<>(ProtocolRegistry.getSupportedVersions()); outputSet.removeAll(Via.getPlatform().getConf().getBlockedProtocols()); return outputSet; }
/** * 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; }
default void init(ViaRewindConfig config) { ViaRewind.init(this, config); ProtocolRegistry.registerProtocol(new Protocol1_8TO1_9(), Collections.singletonList(ProtocolVersion.v1_8.getId()), ProtocolVersion.v1_9.getId()); ProtocolRegistry.registerProtocol(new Protocol1_7_6_10TO1_8(), Collections.singletonList(ProtocolVersion.v1_7_6.getId()), ProtocolVersion.v1_8.getId()); ProtocolRegistry.registerProtocol(new Protocol1_7_0_5to1_7_6_10(), Collections.singletonList(ProtocolVersion.v1_7_1.getId()), ProtocolVersion.v1_7_6.getId()); }
public void onServerLoaded() { // Load Server Protocol try { ProtocolRegistry.SERVER_PROTOCOL = injector.getServerProtocolVersion(); } catch (Exception e) { getPlatform().getLogger().severe("ViaVersion failed to get the server protocol!"); e.printStackTrace(); } // Check if there are any pipes to this version if (ProtocolRegistry.SERVER_PROTOCOL != -1) { getPlatform().getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(ProtocolRegistry.SERVER_PROTOCOL)); if (!ProtocolRegistry.isWorkingPipe()) { getPlatform().getLogger().warning("ViaVersion does not have any compatible versions for this server version, please read our resource page carefully."); } } // Load Listeners / Tasks ProtocolRegistry.onServerLoaded(); // Load Platform loader.load(); // Refresh Versions ProtocolRegistry.refreshVersions(); }
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId); ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline(); user.clearStoredObjects(); pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId));
/** * Add a protocol to the current pipeline * This will call the {@link Protocol#init(UserConnection)} method. * * @param protocol The protocol to add to the end */ public void add(Protocol protocol) { if (protocolList != null) { protocolList.add(protocol); protocol.init(userConnection); // Move base Protocols to the end, so the login packets can be modified by other protocols List<Protocol> toMove = new ArrayList<>(); for (Protocol p : protocolList) { if (ProtocolRegistry.isBaseProtocol(p)) { toMove.add(p); } } protocolList.removeAll(toMove); protocolList.addAll(toMove); } else { throw new NullPointerException("Tried to add protocol to early"); } }
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId); ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline(); user.clearStoredObjects(); pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId));
@Override public SortedSet<Integer> getSupportedVersions() { SortedSet<Integer> outputSet = new TreeSet<>(ProtocolRegistry.getSupportedVersions()); outputSet.removeAll(Via.getPlatform().getConf().getBlockedProtocols()); return outputSet; }
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()); } }
/** * Initialize ViaBackwards */ default void init() { ViaBackwards.init(this); if (!isOutdated()) { ProtocolRegistry.registerProtocol(new Protocol1_9_4To1_10(), Collections.singletonList(ProtocolVersion.v1_9_3.getId()), ProtocolVersion.v1_10.getId()); ProtocolRegistry.registerProtocol(new Protocol1_10To1_11(), Collections.singletonList(ProtocolVersion.v1_10.getId()), ProtocolVersion.v1_11.getId()); ProtocolRegistry.registerProtocol(new Protocol1_11To1_11_1(), Collections.singletonList(ProtocolVersion.v1_11.getId()), ProtocolVersion.v1_11_1.getId()); ProtocolRegistry.registerProtocol(new Protocol1_11_1To1_12(), Collections.singletonList(ProtocolVersion.v1_11_1.getId()), ProtocolVersion.v1_12.getId()); ProtocolRegistry.registerProtocol(new Protocol1_12To1_12_1(), Collections.singletonList(ProtocolVersion.v1_12.getId()), ProtocolVersion.v1_12_1.getId()); ProtocolRegistry.registerProtocol(new Protocol1_12_1To1_12_2(), Collections.singletonList(ProtocolVersion.v1_12_1.getId()), ProtocolVersion.v1_12_2.getId()); } }
@Override public SortedSet<Integer> getSupportedVersions() { SortedSet<Integer> outputSet = new TreeSet<>(ProtocolRegistry.getSupportedVersions()); outputSet.removeAll(Via.getPlatform().getConf().getBlockedProtocols()); return outputSet; }
newCurrent.add(pair); newCurrent = getProtocolPath(newCurrent, entry.getKey(), serverVersion); if (newCurrent != null) {
@Override public SortedSet<Integer> getSupportedVersions() { SortedSet<Integer> outputSet = new TreeSet<>(ProtocolRegistry.getSupportedVersions()); outputSet.removeAll(Via.getPlatform().getConf().getBlockedProtocols()); return outputSet; }
@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(); } }
public void init() { if (System.getProperty("ViaVersion") != null) { // Reload? platform.onReload(); } // Check for updates if (platform.getConf().isCheckForUpdates()) UpdateUtil.sendUpdateMessage(); // Force class load ProtocolRegistry.getSupportedVersions(); // Inject try { injector.inject(); } catch (Exception e) { getPlatform().getLogger().severe("ViaVersion failed to inject:"); e.printStackTrace(); return; } // Mark as injected System.setProperty("ViaVersion", getPlatform().getPluginVersion()); // If successful platform.runSync(new Runnable() { @Override public void run() { onServerLoaded(); } }); }
@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(); } }
System.getProperty("os.name"), ProtocolRegistry.SERVER_PROTOCOL, ProtocolRegistry.getSupportedVersions(), Via.getPlatform().getPlatformName(), Via.getPlatform().getPlatformVersion(),