From 7f4fe566de59db7fb14de337b81a7620d1677857 Mon Sep 17 00:00:00 2001 From: Gravita Date: Fri, 9 Dec 2022 20:19:22 +0700 Subject: [PATCH 1/5] [FIX] ClassCastException --- .../gravit/launchserver/auth/core/AbstractSQLCoreProvider.java | 2 +- .../pro/gravit/launchserver/auth/core/MySQLCoreProvider.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java index 66b5f4b4..914b67e0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java @@ -238,7 +238,7 @@ public void close() throws IOException { getSQLConfig().close(); } - private SQLUser constructUser(ResultSet set) throws SQLException { + protected SQLUser constructUser(ResultSet set) throws SQLException { return set.next() ? new SQLUser(UUID.fromString(set.getString(uuidColumn)), set.getString(usernameColumn), set.getString(accessTokenColumn), set.getString(serverIDColumn), set.getString(passwordColumn), requestPermissions(set.getString(uuidColumn))) : null; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java index 427efcbb..dc9c6467 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java @@ -63,7 +63,8 @@ public void init(LaunchServer server) { sqlUpdateUsers = String.format("UPDATE %s SET `%s` = ? WHERE `%s` = ?", table, hardwareIdColumn, uuidColumn); } - private MySQLUser constructUser(ResultSet set) throws SQLException { + @Override + protected MySQLUser constructUser(ResultSet set) throws SQLException { return set.next() ? new MySQLUser(UUID.fromString(set.getString(uuidColumn)), set.getString(usernameColumn), set.getString(accessTokenColumn), set.getString(serverIDColumn), set.getString(passwordColumn), requestPermissions(set.getString(uuidColumn)), set.getLong(hardwareIdColumn)) : null; } From 0d1b32fc1cb4544986253ee118cce5a347c8e611 Mon Sep 17 00:00:00 2001 From: Gravita Date: Fri, 9 Dec 2022 20:55:58 +0700 Subject: [PATCH 2/5] [FIX] Save config with postgresql --- .../pro/gravit/launchserver/auth/PostgreSQLSourceConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/PostgreSQLSourceConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/PostgreSQLSourceConfig.java index bb4c6e4a..16731436 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/PostgreSQLSourceConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/PostgreSQLSourceConfig.java @@ -28,8 +28,8 @@ public final class PostgreSQLSourceConfig implements AutoCloseable, SQLSourceCon private String database; // Cache - private DataSource source; - private boolean hikari; + private transient DataSource source; + private transient boolean hikari; @Override public synchronized void close() { From 553cdf5250fd15491f9691800eabe7140bc5e4a5 Mon Sep 17 00:00:00 2001 From: Gravita Date: Fri, 9 Dec 2022 21:17:07 +0700 Subject: [PATCH 3/5] [FEATURE] Safe config write --- .../gravit/launchserver/LaunchServerStarter.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index cab9413e..d4208a21 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -28,10 +28,7 @@ import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.Writer; +import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.security.Security; @@ -148,9 +145,11 @@ public LaunchServerRuntimeConfig readRuntimeConfig() throws IOException { @Override public void writeConfig(LaunchServerConfig config) throws IOException { - try (Writer writer = IOHelper.newWriter(configFile)) { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + try (Writer writer = IOHelper.newWriter(output)) { if (Launcher.gsonManager.configGson != null) { Launcher.gsonManager.configGson.toJson(config, writer); + IOHelper.write(configFile, output.toByteArray()); } else { logger.error("Error writing LaunchServer runtime config file. Gson is null"); } @@ -159,9 +158,11 @@ public void writeConfig(LaunchServerConfig config) throws IOException { @Override public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOException { - try (Writer writer = IOHelper.newWriter(runtimeConfigFile)) { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + try (Writer writer = IOHelper.newWriter(output)) { if (Launcher.gsonManager.configGson != null) { Launcher.gsonManager.configGson.toJson(config, writer); + IOHelper.write(runtimeConfigFile, output.toByteArray()); } else { logger.error("Error writing LaunchServer runtime config file. Gson is null"); } From ae994ebb4f9fbb6c48aa447e060460e21f3f1e35 Mon Sep 17 00:00:00 2001 From: Gravita Date: Fri, 9 Dec 2022 21:23:18 +0700 Subject: [PATCH 4/5] [FIX] More safe save config and 5.3.3 --- .../pro/gravit/launchserver/LaunchServerStarter.java | 12 +++++++++--- .../src/main/java/pro/gravit/utils/Version.java | 2 +- build.gradle | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index d4208a21..59890706 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -149,11 +149,14 @@ public void writeConfig(LaunchServerConfig config) throws IOException { try (Writer writer = IOHelper.newWriter(output)) { if (Launcher.gsonManager.configGson != null) { Launcher.gsonManager.configGson.toJson(config, writer); - IOHelper.write(configFile, output.toByteArray()); } else { - logger.error("Error writing LaunchServer runtime config file. Gson is null"); + logger.error("Error writing LaunchServer config file. Gson is null"); } } + byte[] bytes = output.toByteArray(); + if(bytes.length > 0) { + IOHelper.write(configFile, bytes); + } } @Override @@ -162,11 +165,14 @@ public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOExcept try (Writer writer = IOHelper.newWriter(output)) { if (Launcher.gsonManager.configGson != null) { Launcher.gsonManager.configGson.toJson(config, writer); - IOHelper.write(runtimeConfigFile, output.toByteArray()); } else { logger.error("Error writing LaunchServer runtime config file. Gson is null"); } } + byte[] bytes = output.toByteArray(); + if(bytes.length > 0) { + IOHelper.write(runtimeConfigFile, bytes); + } } }; LaunchServer.LaunchServerDirectories directories = new LaunchServer.LaunchServerDirectories(); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 34cf2ce5..99062749 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 = 2; + public static final int PATCH = 3; public static final int BUILD = 1; public static final Version.Type RELEASE = Type.STABLE; public final int major; diff --git a/build.gradle b/build.gradle index 1b8f9b54..5156e367 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.0.10' apply false } group = 'pro.gravit.launcher' -version = '5.3.2' +version = '5.3.3' apply from: 'props.gradle' From 7dcc5aef3fb351b3d0fb2f999ece64e41c8346e9 Mon Sep 17 00:00:00 2001 From: Gravita Date: Fri, 9 Dec 2022 21:46:05 +0700 Subject: [PATCH 5/5] [FIX] More details in error when reading launcher module config file --- .../launchserver/launchermodules/LauncherModuleLoader.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java b/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java index b57bbd04..7b20a2d9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java @@ -150,6 +150,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO } else { try (Reader reader = IOHelper.newReader(configPath)) { targetConfig = Launcher.gsonManager.configGson.fromJson(reader, clazz); + } catch (Exception e) { + logger.error("Error when reading config {} in module {}: {}", configPath, file, e); + return super.visitFile(file, attrs); } } if (entity.propertyMap == null) entity.propertyMap = new HashMap<>();