diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java index ca25cb89..4ee003eb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -22,6 +22,7 @@ public final class AuthProviderPair { public transient String name; public transient Set features; public String displayName; + public boolean visible = true; private transient boolean warnOAuthShow = false; public AuthProviderPair() { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java index c43e3210..cb8860cb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java @@ -46,6 +46,7 @@ public static void registerProviders() { providers.register("postgresql", PostgresSQLCoreProvider.class); providers.register("memory", MemoryAuthCoreProvider.class); providers.register("http", HttpAuthCoreProvider.class); + providers.register("merge", MergeAuthCoreProvider.class); registredProviders = true; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MergeAuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MergeAuthCoreProvider.java new file mode 100644 index 00000000..74498515 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MergeAuthCoreProvider.java @@ -0,0 +1,90 @@ +package pro.gravit.launchserver.auth.core; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.auth.AuthException; +import pro.gravit.launchserver.manangers.AuthManager; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.auth.AuthResponse; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class MergeAuthCoreProvider extends AuthCoreProvider { + private transient final Logger logger = LogManager.getLogger(MergeAuthCoreProvider.class); + public List list = new ArrayList<>(); + private transient List providers = new ArrayList<>(); + @Override + public User getUserByUsername(String username) { + for(var core : providers) { + var result = core.getUserByUsername(username); + if(result != null) { + return result; + } + } + return null; + } + + @Override + public User getUserByUUID(UUID uuid) { + for(var core : providers) { + var result = core.getUserByUUID(uuid); + if(result != null) { + return result; + } + } + return null; + } + + @Override + public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws OAuthAccessTokenExpired { + throw new OAuthAccessTokenExpired(); // Authorization not supported + } + + @Override + public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthResponse.AuthContext context) { + return null; + } + + @Override + public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext context, AuthRequest.AuthPasswordInterface password, boolean minecraftAccess) throws IOException { + throw new AuthException("Authorization not supported"); + } + + @Override + public User checkServer(Client client, String username, String serverID) throws IOException { + for(var core : providers) { + var result = core.checkServer(client, username, serverID); + if(result != null) { + return result; + } + } + return null; + } + + @Override + public boolean joinServer(Client client, String username, String accessToken, String serverID) throws IOException { + return false; // Authorization not supported + } + + @Override + public void init(LaunchServer server) { + for(var e : list) { + var pair = server.config.auth.get(e); + if(pair != null) { + providers.add(pair.core); + } else { + logger.warn("Provider {} not found", e); + } + } + } + + @Override + public void close() throws IOException { + // Providers closed automatically + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java index 00e7fdf0..6b517b3b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java @@ -83,8 +83,7 @@ private Path setConfig() { jre.setMinVersion(server.config.launch4j.minVersion); if (server.config.launch4j.setMaxVersion) jre.setMaxVersion(server.config.launch4j.maxVersion); - jre.setRuntimeBits(Jre.RUNTIME_BITS_64_AND_32); - jre.setJdkPreference(Jre.JDK_PREFERENCE_PREFER_JRE); + jre.setPath(System.getProperty("java.home")); config.setJre(jre); // Prepare version info (product) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java index 997240a3..a1f79553 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java @@ -40,11 +40,11 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - verifyArgs(args, 2); + verifyArgs(args, 1); //Version version = Version.byName(args[0]); String versionName = args[0]; + String dirName = IOHelper.verifyFileName(args[1] != null ? args[1] : "assets"); String type = args.length > 2 ? args[2] : "mojang"; - String dirName = IOHelper.verifyFileName(args[1]); Path assetDir = server.updatesDir.resolve(dirName); // Create asset dir diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java index 36fb964a..942be0c2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java @@ -41,18 +41,14 @@ public void invoke(String... args) throws IOException, CommandException { verifyArgs(args, 2); //Version version = Version.byName(args[0]); String versionName = args[0]; - String dirName = IOHelper.verifyFileName(args[1]); - Path clientDir = server.updatesDir.resolve(args[1]); + String dirName = IOHelper.verifyFileName(args[1] != null ? args[1] : args[0]); + Path clientDir = server.updatesDir.resolve(dirName); boolean isMirrorClientDownload = false; if (args.length > 2) { isMirrorClientDownload = args[2].equals("mirror"); } - // Create client dir - logger.info("Creating client dir: '{}'", dirName); - Files.createDirectory(clientDir); - // Download required client logger.info("Downloading client, it may take some time"); //HttpDownloader.downloadZip(server.mirrorManager.getDefaultMirror().getClientsURL(version.name), clientDir); @@ -60,7 +56,25 @@ public void invoke(String... args) throws IOException, CommandException { // Create profile file logger.info("Creaing profile file: '{}'", dirName); - ClientProfile client = null; + ClientProfile clientProfile = null; + if (isMirrorClientDownload) { + try { + JsonElement clientJson = server.mirrorManager.jsonRequest(null, "GET", "clients/%s.json", versionName); + clientProfile = Launcher.gsonManager.configGson.fromJson(clientJson, ClientProfile.class); + clientProfile.setTitle(dirName); + clientProfile.setDir(dirName); + clientProfile.setUUID(UUID.randomUUID()); + if (clientProfile.getServers() != null) { + ClientProfile.ServerProfile serverProfile = clientProfile.getDefaultServerProfile(); + if (serverProfile != null) { + serverProfile.name = dirName; + } + } + } catch (Exception e) { + logger.error("Filed download clientProfile from mirror: '{}' Generation through MakeProfileHelper", versionName); + isMirrorClientDownload = false; + } + } if (!isMirrorClientDownload) { try { String internalVersion = versionName; @@ -75,27 +89,14 @@ public void invoke(String... args) throws IOException, CommandException { for (MakeProfileHelper.MakeProfileOption option : options) { logger.debug("Detected option {}", option.getClass().getSimpleName()); } - client = MakeProfileHelper.makeProfile(version, dirName, options); + clientProfile = MakeProfileHelper.makeProfile(version, dirName, options); } catch (Throwable e) { isMirrorClientDownload = true; } } - if (isMirrorClientDownload) { - JsonElement clientJson = server.mirrorManager.jsonRequest(null, "GET", "clients/%s.json", versionName); - client = Launcher.gsonManager.configGson.fromJson(clientJson, ClientProfile.class); - client.setTitle(dirName); - client.setDir(dirName); - client.setUUID(UUID.randomUUID()); - if (client.getServers() != null) { - ClientProfile.ServerProfile serverProfile = client.getDefaultServerProfile(); - if (serverProfile != null) { - serverProfile.name = dirName; - } - } - } try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir, dirName, "json"))) { - Launcher.gsonManager.configGson.toJson(client, writer); + Launcher.gsonManager.configGson.toJson(clientProfile, writer); } // Finished diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java index c41ae7dc..424f0e3f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java @@ -23,10 +23,10 @@ public void execute(ChannelHandlerContext ctx, Client client) { var rca = pair.isSupport(AuthSupportRemoteClientAccess.class); if (rca != null) { list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName, - pair.core.getDetails(client), rca.getClientApiUrl(), rca.getClientApiFeatures())); + pair.visible, pair.core.getDetails(client), rca.getClientApiUrl(), rca.getClientApiFeatures())); } else { list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName, - pair.core.getDetails(client))); + pair.visible, pair.core.getDetails(client))); } } sendResult(new GetAvailabilityAuthRequestEvent(list)); diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 0294860b..793f151c 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -179,7 +179,7 @@ public static void applyBasicOfflineProcessors(OfflineRequestService service) { service.registerRequestProcessor(GetAvailabilityAuthRequest.class, (r) -> { List details = new ArrayList<>(); details.add(new AuthLoginOnlyDetails()); - GetAvailabilityAuthRequestEvent.AuthAvailability authAvailability = new GetAvailabilityAuthRequestEvent.AuthAvailability("offline", "Offline Mode", details); + GetAvailabilityAuthRequestEvent.AuthAvailability authAvailability = new GetAvailabilityAuthRequestEvent.AuthAvailability("offline", "Offline Mode", true, details); List list = new ArrayList<>(1); list.add(authAvailability); return new GetAvailabilityAuthRequestEvent(list); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java b/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java index 5cea3f32..57a86dbe 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java @@ -1,5 +1,6 @@ package pro.gravit.launcher.client; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import pro.gravit.launcher.profiles.ClientProfile; @@ -162,9 +163,13 @@ private Result modernPing(HInput input, HOutput output) throws IOException { } // Parse JSON response - JsonObject object = JsonParser.parseString(response).getAsJsonObject(); + JsonElement element = JsonParser.parseString(response); + if(element.isJsonPrimitive()) { + throw new IOException(element.getAsString()); + } + JsonObject object = element.getAsJsonObject(); if (object.has("error")) { - throw new IOException(object.get("error").getAsString()); + throw new IOException(object.get("error").getAsString()); // May be not needed? } JsonObject playersObject = object.get("players").getAsJsonObject(); int online = playersObject.get("online").getAsInt(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java index 3a81326c..b2709e04 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java @@ -45,18 +45,23 @@ public static class AuthAvailability { public String name; @LauncherNetworkAPI public String displayName; + + @LauncherNetworkAPI + public boolean visible; @LauncherNetworkAPI public String apiUrl; @LauncherNetworkAPI public List apiFeatures; - public AuthAvailability(String name, String displayName, List details) { + public AuthAvailability(String name, String displayName, boolean visible, List details) { this.name = name; this.displayName = displayName; + this.visible = visible; this.details = details; } - public AuthAvailability(String name, String displayName, List details, String apiUrl, List apiFeatures) { + public AuthAvailability(String name, String displayName, boolean visible, List details, String apiUrl, List apiFeatures) { + this.visible = visible; this.details = details; this.name = name; this.displayName = displayName; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java index c46a35f5..658edd0b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java @@ -27,6 +27,21 @@ public OptionalView(OptionalView view) { this.all = view.all; } + public OptionalView(ClientProfile profile, OptionalView old) { + this(profile); + for(OptionalFile oldFile : old.all) { + OptionalFile newFile = findByName(oldFile.name); + if(newFile == null) { + continue; + } + if(old.isEnabled(oldFile)) { + enable(newFile, old.installInfo.get(oldFile).isManual, (file, status) -> {}); + } else { + disable(newFile, (file, status) -> {}); + } + } + } + @SuppressWarnings("unchecked") public Set getActionsByClass(Class clazz) { Set results = new HashSet<>(); @@ -42,6 +57,19 @@ public Set getActionsByClass(Class clazz) { return results; } + public OptionalFile findByName(String name) { + for(OptionalFile file : all) { + if(name.equals(file.name)) { + return file; + } + } + return null; + } + + public boolean isEnabled(OptionalFile file) { + return enabled.contains(file); + } + public Set getEnabledActions() { Set results = new HashSet<>(); for (OptionalFile e : enabled) { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/HttpDownloader.java b/LauncherCore/src/main/java/pro/gravit/utils/HttpDownloader.java index 161d317b..6a606f8d 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/HttpDownloader.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/HttpDownloader.java @@ -56,6 +56,7 @@ public static void downloadFile(URL url, Path file, Consumer chanheTrac public static void downloadZip(URL url, Path dir) throws IOException { try (ZipInputStream input = IOHelper.newZipInput(url)) { + Files.createDirectory(dir); for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) { if (entry.isDirectory()) { Files.createDirectory(dir.resolve(IOHelper.toPath(entry.getName()))); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 34cf7597..d343dea1 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -6,7 +6,7 @@ public final class Version implements Comparable { public static final int MAJOR = 5; public static final int MINOR = 3; - public static final int PATCH = 5; + public static final int PATCH = 6; public static final int BUILD = 1; public static final Version.Type RELEASE = Type.STABLE; public final int major; diff --git a/ServerWrapper/build.gradle b/ServerWrapper/build.gradle index dc8c5dba..b481f010 100644 --- a/ServerWrapper/build.gradle +++ b/ServerWrapper/build.gradle @@ -64,7 +64,7 @@ pack project(':LauncherAPI') shadowJar { duplicatesStrategy = 'EXCLUDE' - classifier = null + archiveClassifier = null relocate 'io.netty', 'pro.gravit.repackage.io.netty' configurations = [project.configurations.pack] exclude 'module-info.class' diff --git a/build.gradle b/build.gradle index b44eadef..31d9b1c6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,11 @@ plugins { - id 'com.github.johnrengelman.shadow' version '5.2.0' apply false + id 'com.github.johnrengelman.shadow' version '7.1.2' apply false id 'maven-publish' id 'signing' id 'org.openjfx.javafxplugin' version '0.0.10' apply false } group = 'pro.gravit.launcher' -version = '5.3.5' +version = '5.3.6' apply from: 'props.gradle' diff --git a/modules b/modules index 614aea89..e16960e7 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 614aea895f2d3ccbcf311b8058ab7a5f1dcd8602 +Subproject commit e16960e7eef248a217071638f0e68b14cec09cb8 diff --git a/props.gradle b/props.gradle index 0a84797d..f74b6a75 100644 --- a/props.gradle +++ b/props.gradle @@ -1,20 +1,20 @@ project.ext { - verAsm = '9.3' - verNetty = '4.1.78.Final' - verOshiCore = '6.2.1' - verJunit = '5.8.2' + verAsm = '9.4' + verNetty = '4.1.87.Final' + verOshiCore = '6.4.0' + verJunit = '5.9.2' verGuavaC = '30.1.1-jre' verJansi = '2.4.0' - verJline = '3.21.0' + verJline = '3.22.0' verJwt = '0.11.5' verBcprov = '1.70' - verGson = '2.9.0' + verGson = '2.10.1' verBcpkix = '1.70' verSlf4j = '1.7.36' - verLog4j = '2.17.2' - verMySQLConn = '8.0.29' - verPostgreSQLConn = '42.4.0' - verProguard = '7.2.2' - verLaunch4j = '3.14' + verLog4j = '2.19.0' + verMySQLConn = '8.0.32' + verPostgreSQLConn = '42.5.1' + verProguard = '7.3.1' + verLaunch4j = '3.50' verHibernate = '5.5.6.Final' }