diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index fd5ef96f..a2a04688 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,9 +1,6 @@ name: push on: push: - create: - tags: - - v* jobs: launcher: name: Launcher @@ -55,7 +52,7 @@ jobs: - name: Create release id: create_release uses: actions/create-release@v1 - if: github.event_name == 'create' + if: github.event.ref == 'refs/tags/*' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: @@ -65,13 +62,13 @@ jobs: prerelease: false - name: Pack release - if: github.event_name == 'create' + if: github.event.ref == 'refs/tags/*' run: | cd artifacts/ zip -r -9 ../Release.zip * - name: Upload release - if: github.event_name == 'create' + if: github.event.ref == 'refs/tags/*' uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index b74d8de7..724d8a31 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -293,6 +293,15 @@ public void invoke(String... args) throws Exception { } }; commands.put("reload", reload); + SubCommand save = new SubCommand() { + @Override + public void invoke(String... args) throws Exception { + launchServerConfigManager.writeConfig(config); + launchServerConfigManager.writeRuntimeConfig(runtime); + LogHelper.info("LaunchServerConfig saved"); + } + }; + commands.put("save", save); return commands; } @@ -319,7 +328,8 @@ public void buildLauncherBinaries() throws IOException { } public void close() throws Exception { - + LogHelper.info("Close server socket"); + nettyServerSocketHandler.close(); // Close handlers & providers config.close(ReloadType.FULL); modulesManager.invokeEvent(new ClosePhase()); @@ -368,8 +378,14 @@ public void run() { } if (config.netty != null) rebindNettyServerSocket(); - modulesManager.fullInitializedLaunchServer(this); - modulesManager.invokeEvent(new LaunchServerFullInitEvent(this)); + try { + modulesManager.fullInitializedLaunchServer(this); + modulesManager.invokeEvent(new LaunchServerFullInitEvent(this)); + LogHelper.info("LaunchServer started"); + } catch (Throwable e) { + LogHelper.error(e); + JVMHelper.RUNTIME.exit(-1); + } } public void syncLauncherBinaries() throws IOException { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 0c2079d9..a8e858b4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -61,7 +61,13 @@ public static void main(String[] args) throws Exception { Path privateKeyFile = dir.resolve("private.key"); ECPublicKey publicKey; ECPrivateKey privateKey; - Security.addProvider(new BouncyCastleProvider()); + try { + Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider"); + Security.addProvider(new BouncyCastleProvider()); + } catch (ClassNotFoundException ex) { + LogHelper.error("Library BouncyCastle not found! Is directory 'libraries' empty?"); + return; + } CertificateManager certificateManager = new CertificateManager(); try { certificateManager.readTrustStore(dir.resolve("truststore")); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/session/MemorySessionStorage.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/session/MemorySessionStorage.java index 620b0faa..0dc45db7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/session/MemorySessionStorage.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/session/MemorySessionStorage.java @@ -17,7 +17,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Stream; -public class MemorySessionStorage extends SessionStorage implements NeedGarbageCollection { +public class MemorySessionStorage extends SessionStorage implements NeedGarbageCollection, AutoCloseable { private transient final Map clientSet = new ConcurrentHashMap<>(128); private transient final Map> uuidIndex = new ConcurrentHashMap<>(32); @@ -90,10 +90,6 @@ public boolean deleteSessionsByUserUUID(UUID userUUID) { public void clear() { clientSet.clear(); uuidIndex.clear(); - if(autoDump) { - garbageCollection(); - dumpSessionsData(); - } } public void dumpSessionsData() { @@ -161,6 +157,14 @@ public void garbageCollection() { to_delete.clear(); } + @Override + public void close() throws Exception { + if(autoDump) { + garbageCollection(); + dumpSessionsData(); + } + } + private static class Entry { public byte[] data; public UUID sessionUuid; @@ -174,8 +178,8 @@ public Entry(byte[] data, UUID sessionUuid) { } private static class DumpedData { - private transient final Map clientSet; - private transient final Map> uuidIndex; + private final Map clientSet; + private final Map> uuidIndex; private DumpedData(Map clientSet, Map> uuidIndex) { this.clientSet = clientSet; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index 671a4ba9..107153c5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -235,6 +235,13 @@ public void close(LaunchServer.ReloadType type) { } if(sessions != null) { server.unregisterObject("sessions", sessions); + if (sessions instanceof AutoCloseable) { + try { + ((AutoCloseable) sessions).close(); + } catch (Exception e) { + LogHelper.error(e); + } + } } if (dao != null) { server.unregisterObject("dao", dao); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java index 6042d2d2..a68169df 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java @@ -24,6 +24,7 @@ import pro.gravit.utils.helper.LogHelper; import java.net.InetSocketAddress; +import java.util.concurrent.TimeUnit; public class LauncherNettyServer implements AutoCloseable { private static final String WEBSOCKET_PATH = "/api"; @@ -77,7 +78,9 @@ public ChannelFuture bind(InetSocketAddress address) { @Override public void close() { - workerGroup.shutdownGracefully(); - bossGroup.shutdownGracefully(); + workerGroup.shutdownGracefully(2, 5, TimeUnit.SECONDS); + bossGroup.shutdownGracefully(2, 5, TimeUnit.SECONDS); + //workerGroup.shutdownGracefully(); + //bossGroup.shutdownGracefully(); } } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java b/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java index 12699f34..97689567 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java @@ -31,6 +31,7 @@ public class AsyncDownloader { public final Callback callback; @LauncherInject("launcher.certificatePinning") private static boolean isCertificatePinning; + private static volatile SSLSocketFactory sslSocketFactory; public AsyncDownloader(Callback callback) { this.callback = callback; @@ -71,9 +72,11 @@ public void downloadFile(URL url, Path target) throws IOException { } public SSLSocketFactory makeSSLSocketFactory() throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, KeyManagementException { + if(sslSocketFactory != null) return sslSocketFactory; SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, CertificatePinningTrustManager.getTrustManager().getTrustManagers(), new SecureRandom()); - return sslContext.getSocketFactory(); + sslSocketFactory = sslContext.getSocketFactory(); + return sslSocketFactory; } public void downloadListInOneThread(List files, String baseURL, Path targetDir) throws URISyntaxException, IOException { diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/CertificatePinningTrustManager.java b/LauncherCore/src/main/java/pro/gravit/launcher/CertificatePinningTrustManager.java index 0c9838f7..a8183fbc 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/CertificatePinningTrustManager.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/CertificatePinningTrustManager.java @@ -21,6 +21,7 @@ public final class CertificatePinningTrustManager { @LauncherInject("launchercore.certificates") private static List secureConfigCertificates; private static X509Certificate[] certs = null; + private volatile static TrustManagerFactory INSTANCE; private static X509Certificate[] getInternalCertificates() { CertificateFactory certFactory = null; try { @@ -45,6 +46,7 @@ public static X509Certificate[] getCertificates() { } public static TrustManagerFactory getTrustManager() throws KeyStoreException, NoSuchAlgorithmException, IOException, CertificateException { + if(INSTANCE != null) return INSTANCE; if(certs == null) certs = getInternalCertificates(); TrustManagerFactory factory = TrustManagerFactory.getInstance("X.509"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); @@ -57,6 +59,7 @@ public static TrustManagerFactory getTrustManager() throws KeyStoreException, No i++; } factory.init(keystore); + INSTANCE = factory; return factory; } } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 3e643fc5..1686b8bc 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -7,8 +7,8 @@ public final class Version { public static final int MAJOR = 5; public static final int MINOR = 1; public static final int PATCH = 10; - public static final int BUILD = 1; - public static final Version.Type RELEASE = Type.DEV; + public static final int BUILD = 2; + public static final Version.Type RELEASE = Type.STABLE; public final int major; public final int minor; public final int patch; diff --git a/build.gradle b/build.gradle index 9eafacce..b53c73e8 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.0.8' apply false } group = 'pro.gravit.launcher' -version = '5.1.10-SNAPSHOT' +version = '5.1.10' apply from: 'props.gradle'