diff --git a/LaunchServer/source/command/hash/DownloadAssetCommand.java b/LaunchServer/source/command/hash/DownloadAssetCommand.java index 5396f94..9cce3f8 100644 --- a/LaunchServer/source/command/hash/DownloadAssetCommand.java +++ b/LaunchServer/source/command/hash/DownloadAssetCommand.java @@ -58,7 +58,6 @@ public void invoke(String... args) throws Throwable { verifyArgs(args, 2); - Version version = Version.byName(args[0]); String dirName = IOHelper.verifyFileName(args[1]); Path assetDir = server.updatesDir.resolve(dirName); @@ -69,7 +68,7 @@ // Download required asset ASSET_URL_MASK = server.config.mirror + "assets/%s.zip"; LogHelper.subInfo("Downloading asset, it may take some time"); - unpack(new URL(String.format(ASSET_URL_MASK, IOHelper.urlEncode(version.name))), assetDir); + unpack(new URL(String.format(ASSET_URL_MASK, IOHelper.urlEncode(args[0]))), assetDir); // Finished server.syncUpdatesDir(Collections.singleton(dirName)); diff --git a/LaunchServer/source/command/hash/DownloadClientCommand.java b/LaunchServer/source/command/hash/DownloadClientCommand.java index d5b5d07..dec6c93 100644 --- a/LaunchServer/source/command/hash/DownloadClientCommand.java +++ b/LaunchServer/source/command/hash/DownloadClientCommand.java @@ -42,7 +42,6 @@ public void invoke(String... args) throws Throwable { verifyArgs(args, 2); - Version version = Version.byName(args[0]); String dirName = IOHelper.verifyFileName(args[1]); Path clientDir = server.updatesDir.resolve(args[1]); @@ -54,12 +53,12 @@ LogHelper.subInfo("Downloading client, it may take some time"); CLIENT_URL_MASK = server.config.mirror + "clients/%s.zip"; DownloadAssetCommand.unpack(new URL(String.format(CLIENT_URL_MASK, - IOHelper.urlEncode(version.name))), clientDir); + IOHelper.urlEncode(args[0]))), clientDir); // Create profile file LogHelper.subInfo("Creaing profile file: '%s'", dirName); ClientProfile client; - String profilePath = String.format("launchserver/defaults/profile%s.cfg", version.name); + String profilePath = String.format("launchserver/defaults/profile%s.cfg", args[0]); try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL(profilePath))) { client = new ClientProfile(TextConfigReader.read(reader, false)); diff --git a/Launcher/source/client/ClientLauncher.java b/Launcher/source/client/ClientLauncher.java index 3f69597..9f28f5a 100644 --- a/Launcher/source/client/ClientLauncher.java +++ b/Launcher/source/client/ClientLauncher.java @@ -122,8 +122,8 @@ // Add classpath and main class Collections.addAll(args, profile.object.getJvmArgs()); - Version v = profile.object.getVersion(); - if (v.compareTo(Version.MC1132) >= 0 && JVMHelper.OS_TYPE == OS.MACOSX) + String v = profile.object.getVersion(); + if (Version.compare(v, "1.13") >= 0 && JVMHelper.OS_TYPE == OS.MACOSX) Collections.addAll(args, "-XstartOnFirstThread"); Collections.addAll(args, "-classpath", IOHelper.getCodeSource(ClientLauncher.class).toString(), ClientLauncher.class.getName()); args.add(paramsFile.toString()); // Add params file path to args @@ -246,18 +246,21 @@ PlayerProfile pp = params.pp; // Add version-dependent args - Version version = profile.getVersion(); + String version = profile.getVersion(); Collections.addAll(args, "--username", pp.username); - if (version.compareTo(Version.MC172) >= 0) + if (Version.compare(version, "1.7.2") >= 0) { Collections.addAll(args, "--uuid", toHash(pp.uuid)); Collections.addAll(args, "--accessToken", params.accessToken); - // Add 1.7.10+ args (user properties, asset index) - if (version.compareTo(Version.MC1710) >= 0) + // Add 1.7.3+ args (user properties, asset index) + if (Version.compare(version, "1.7.3") >= 0) { // Add user properties - Collections.addAll(args, "--userType", "mojang"); + if (Version.compare(version, "1.7.4") >= 0) + { + Collections.addAll(args, "--userType", "mojang"); + } JsonObject properties = Json.object(); if (pp.skin != null) { @@ -281,11 +284,11 @@ } // Add version and dirs args - Collections.addAll(args, "--version", profile.getVersion().name); + Collections.addAll(args, "--version", profile.getVersion()); Collections.addAll(args, "--gameDir", params.clientDir.toString()); Collections.addAll(args, "--assetsDir", params.assetDir.toString()); Collections.addAll(args, "--resourcePackDir", params.clientDir.resolve(RESOURCEPACKS_DIR).toString()); - if (version.compareTo(Version.MC194) >= 0) + if (Version.compare(version, "1.9.0") >= 0) { // Just to show it in debug screen Collections.addAll(args, "--versionType", "KJ-Launcher v" + Launcher.VERSION); } @@ -315,7 +318,7 @@ args.add(params.accessToken); // Add args for tweaker - Collections.addAll(args, "--version", profile.getVersion().name); + Collections.addAll(args, "--version", profile.getVersion()); Collections.addAll(args, "--gameDir", params.clientDir.toString()); Collections.addAll(args, "--assetsDir", params.assetDir.toString()); } @@ -327,7 +330,7 @@ // Add client args Collection args = new LinkedList<>(); - if (profile.getVersion().compareTo(Version.MC164) >= 0) + if (Version.compare(profile.getVersion(), "1.6.0") >= 0) { addClientArgs(args, profile, params); } diff --git a/Launcher/source/client/ClientProfile.java b/Launcher/source/client/ClientProfile.java index 73194a1..e1e78ae 100644 --- a/Launcher/source/client/ClientProfile.java +++ b/Launcher/source/client/ClientProfile.java @@ -12,8 +12,6 @@ import java.io.IOException; import java.net.InetSocketAddress; -import java.util.HashMap; -import java.util.Map; @SuppressWarnings("ComparableImplementedButEqualsNotOverridden") public final class ClientProfile extends ConfigObject implements Comparable @@ -92,15 +90,12 @@ } @LauncherAPI - public String getAssetIndex() - { - return assetIndex.getValue(); - } + public String getAssetIndex() { return assetIndex.getValue(); } @LauncherAPI public FileNameMatcher getAssetUpdateMatcher() { - return getVersion().compareTo(Version.MC1710) >= 0 ? ASSET_MATCHER : null; + return Version.compare(getVersion(), "1.7.3") >= 0 ? ASSET_MATCHER : null; } @LauncherAPI @@ -173,16 +168,7 @@ } @LauncherAPI - public Version getVersion() - { - return Version.byName(version.getValue()); - } - - @LauncherAPI - public void setVersion(Version version) - { - this.version.setValue(version.name); - } + public String getVersion() { return version.getValue(); } @LauncherAPI public boolean isUpdateFastCheck() @@ -194,8 +180,8 @@ public void verify() { // Version - getVersion(); - IOHelper.verifyFileName(getAssetIndex()); + VerifyHelper.verify(getVersion(), VerifyHelper.NOT_EMPTY, "Game version can't be empty"); + IOHelper.verifyFileName(getAssetIndex()); // А в смысле, там же версия, какой нахуй FileName? // Client VerifyHelper.verify(getTitle(), VerifyHelper.NOT_EMPTY, "Profile title can't be empty"); @@ -214,126 +200,20 @@ VerifyHelper.verify(getTitle(), VerifyHelper.NOT_EMPTY, "Main class can't be empty"); } - @LauncherAPI - public enum Version - { - // На всякий случай протоколы: - // https://minecraft.gamepedia.com/Protocol_version - // Официальные версии с аргументами и т.д.: - // https://launchermeta.mojang.com/mc/game/version_manifest.json - - // 1.4.x - MC147("1.4.7", 51), - - // 1.5.x - MC152("1.5.2", 61), - - // 1.6.x - MC164("1.6.4", 78), - - // 1.7.x - MC17("1.7", 3), - MC171("1.7.1", 3), - MC172("1.7.2", 4), - MC173("1.7.3", 4), - MC174("1.7.4", 4), - MC175("1.7.5", 4), - MC176("1.7.6", 5), - MC177("1.7.7", 5), - MC178("1.7.8", 5), - MC179("1.7.9", 5), - MC1710("1.7.10", 5), - - // 1.8.x - MC18("1.8", 47), - MC181("1.8.1", 47), - MC182("1.8.2", 47), - MC183("1.8.3", 47), - MC184("1.8.4", 47), - MC185("1.8.5", 47), - MC186("1.8.6", 47), - MC187("1.8.7", 47), - MC188("1.8.8", 47), - MC189("1.8.9", 47), - - // 1.9.x - MC19("1.9", 107), - MC191("1.9.1", 108), - MC192("1.9.2", 109), - MC193("1.9.3", 110), - MC194("1.9.4", 110), - - // 1.10.x - MC110("1.10", 210), - MC1101("1.10.1", 210), - MC1102("1.10.2", 210), - - // 1.11.x - MC111("1.11", 315), - MC1111("1.11.1", 316), - MC1112("1.11.2", 316), - - // 1.12.x - MC112("1.12", 335), - MC1121("1.12.1", 338), - MC1122("1.12.2", 340), - - // 1.13.x - MC113("1.13", 393), - MC1131("1.13.1", 401), - MC1132("1.13.2", 404), - - // 1.14.x - MC114("1.14", 477), - MC1141("1.14.1", 480), - MC1142("1.14.2", 485), - MC1143("1.14.3", 490), - MC1144("1.14.4", 498), - - // 1.15.x - MC115("1.15", 573), - MC1151("1.15.1", 575), - MC1152("1.15.2", 578), - - // 1.16.x - MC1160("1.16", 735), - MC1161("1.16.1", 736), - MC1162("1.16.2", 751), - MC1163("1.16.3", 753), - MC1164("1.16.4", 754); - // MC1165("1.16.5", 755); // Вангую - - // Попожа тут будет рефактор на json, не дело это добавлять каждый раз... - private static final Map VERSIONS; - - static - { - Version[] versionsValues = values(); - VERSIONS = new HashMap<>(versionsValues.length); - for (Version version : versionsValues) - { - VERSIONS.put(version.name, version); + // Можно конечно угореть и парсить версии с https://launchermeta.mojang.com/mc/game/version_manifest.json + // Но имеет ли это смысл? Даже такой простенький обработчик будет спокойно справляться с сравнением релизных версий + public static class Version { + public static int compare(String originVersion, String comparedVersion) { + String[] originVersionParts = originVersion.split("\\."); + String[] comparedVersionParts = comparedVersion.split("\\."); + int length = Math.max(originVersionParts.length, comparedVersionParts.length); + for(int i = 0; i < length; i++) { + int originVersionPart = i < originVersionParts.length ? Integer.parseInt(originVersionParts[i]) : 0; + int comparedVersionPart = i < comparedVersionParts.length ? Integer.parseInt(comparedVersionParts[i]) : 0; + if(originVersionPart < comparedVersionPart) return -1; + if(originVersionPart > comparedVersionPart) return 1; } - } - - public final String name; - public final int protocol; - - Version(String name, int protocol) - { - this.name = name; - this.protocol = protocol; - } - - public static Version byName(String name) - { - return VerifyHelper.getMapValue(VERSIONS, name, String.format("Unknown client version: '%s'", name)); - } - - @Override - public String toString() - { - return "Minecraft " + name; + return 0; } } } diff --git a/Launcher/source/client/ServerPinger.java b/Launcher/source/client/ServerPinger.java index 0eb27de..14e2d9b 100644 --- a/Launcher/source/client/ServerPinger.java +++ b/Launcher/source/client/ServerPinger.java @@ -29,7 +29,7 @@ // Instance private final InetSocketAddress address; - private final Version version; + private final String version; // Cache private final Object cacheLock = new Object(); @@ -38,7 +38,7 @@ private long cacheUntil = Long.MIN_VALUE; @LauncherAPI - public ServerPinger(InetSocketAddress address, Version version) + public ServerPinger(InetSocketAddress address, String version) { this.address = Objects.requireNonNull(address, "address"); this.version = Objects.requireNonNull(version, "version"); @@ -100,7 +100,7 @@ try (HInput input = new HInput(socket.getInputStream()); HOutput output = new HOutput(socket.getOutputStream())) { - return version.compareTo(Version.MC172) >= 0 ? modernPing(input, output) : legacyPing(input, output, version.compareTo(Version.MC164) >= 0); + return Version.compare(version, "1.7") >= 0 ? modernPing(input, output) : legacyPing(input, output, Version.compare(version, "1.6") >= 0); } } } @@ -120,7 +120,7 @@ { try (HOutput packetOutput = new HOutput(packetArray)) { - packetOutput.writeUnsignedByte(version.protocol); // Protocol version + packetOutput.writeUnsignedByte(78); // Protocol version // Для пинга можно указывать любой (здесь с 1.6.4) writeUTF16String(packetOutput, address.getHostString()); // Server address packetOutput.writeInt(address.getPort()); // Server port } @@ -156,12 +156,12 @@ throw new IOException("Magic string mismatch: " + magic); } int protocol = Integer.parseInt(splitted[1]); - if (protocol != version.protocol) + if (protocol != 78) // Смотри строку 123 { throw new IOException("Protocol mismatch: " + protocol); } String clientVersion = splitted[2]; - if (!clientVersion.equals(version.name)) + if (!clientVersion.equals(version)) { throw new IOException(String.format("Version mismatch: '%s'", clientVersion)); } @@ -183,7 +183,7 @@ try (HOutput packetOutput = new HOutput(packetArray)) { packetOutput.writeVarInt(0x0); // Handshake packet ID - packetOutput.writeVarInt(version.protocol); // Protocol version + packetOutput.writeVarInt(-1); // Protocol version // Опять же для пинга версия протокола не важна packetOutput.writeString(address.getHostString(), 0); // Server address packetOutput.writeShort((short) address.getPort()); // Server port packetOutput.writeVarInt(0x1); // Next state - status diff --git a/build.sh b/build.sh index 62e2e4c..7ee6717 100644 --- a/build.sh +++ b/build.sh @@ -20,4 +20,4 @@ jar -uf LaunchServer.jar Launcher.pack.gz buildnumber pack200 -E9 -Htrue -mlatest -Upass -r LaunchServer.jar jarsigner -keystore build/keeperjerry.jks -storepass PSP1448 -sigfile LAUNCHER LaunchServer.jar keeperjerry -rm Launcher.pack.gz +rm Launcher.pack.gz \ No newline at end of file diff --git a/buildnumber b/buildnumber index 2040f28..1796522 100644 --- a/buildnumber +++ b/buildnumber @@ -1 +1 @@ -495, 09.12.2020 \ No newline at end of file +515, 09.02.2021 \ No newline at end of file