From 0ff6ea427a2fd863bf7873f4ddea3c5720175f3c Mon Sep 17 00:00:00 2001 From: naufal Date: Tue, 19 Apr 2022 11:49:08 +0700 Subject: [PATCH] feat: added configuration for change upload port feat: added configuration for use non SSL --- src/main/java/emu/grasscutter/Config.java | 3 ++ .../server/dispatch/DispatchServer.java | 42 +++++++++++-------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/main/java/emu/grasscutter/Config.java b/src/main/java/emu/grasscutter/Config.java index b7a971122..0a3ff1a4a 100644 --- a/src/main/java/emu/grasscutter/Config.java +++ b/src/main/java/emu/grasscutter/Config.java @@ -6,12 +6,15 @@ public final class Config { public int DispatchServerPort = 443; public String DispatchServerKeystorePath = "./keystore.p12"; public String DispatchServerKeystorePassword = ""; + public Boolean UseSSL = true; public String GameServerName = "Test"; public String GameServerIp = "127.0.0.1"; public String GameServerPublicIp = ""; public int GameServerPort = 22102; + public int UploadLogPort = 80; + public String DatabaseUrl = "mongodb://localhost:27017"; public String DatabaseCollection = "grasscutter"; diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java index b014e904d..da90caa42 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java @@ -139,22 +139,28 @@ public final class DispatchServer { } public void start() throws Exception { - HttpsServer server = HttpsServer.create(getAddress(), 0); - SSLContext sslContext = SSLContext.getInstance("TLS"); - - try (FileInputStream fis = new FileInputStream(Grasscutter.getConfig().DispatchServerKeystorePath)) { - char[] keystorePassword = Grasscutter.getConfig().DispatchServerKeystorePassword.toCharArray(); - KeyStore ks = KeyStore.getInstance("PKCS12"); - ks.load(fis, keystorePassword); - KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); - kmf.init(ks, keystorePassword); - - sslContext.init(kmf.getKeyManagers(), null, null); - - server.setHttpsConfigurator(new HttpsConfigurator(sslContext)); - } catch (Exception e) { - Grasscutter.getLogger().error("No SSL cert found!"); - return; + HttpServer server; + if(Grasscutter.getConfig().UseSSL) { + HttpsServer httpsServer; + httpsServer = HttpsServer.create(getAddress(), 0); + SSLContext sslContext = SSLContext.getInstance("TLS"); + try (FileInputStream fis = new FileInputStream(Grasscutter.getConfig().DispatchServerKeystorePath)) { + char[] keystorePassword = Grasscutter.getConfig().DispatchServerKeystorePassword.toCharArray(); + KeyStore ks = KeyStore.getInstance("PKCS12"); + ks.load(fis, keystorePassword); + KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); + kmf.init(ks, keystorePassword); + + sslContext.init(kmf.getKeyManagers(), null, null); + + httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); + server = httpsServer; + } catch (Exception e) { + Grasscutter.getLogger().error("No SSL cert found!"); + return; + } + } else { + server = HttpServer.create(getAddress(), 0); } server.createContext("/", t -> { @@ -396,7 +402,7 @@ public final class DispatchServer { overseaLogServer.start(); Grasscutter.getLogger().info("Log server (overseauspider) started on port " + 8888); - HttpServer uploadLogServer = HttpServer.create(new InetSocketAddress(Grasscutter.getConfig().DispatchServerIp, 80), 0); + HttpServer uploadLogServer = HttpServer.create(new InetSocketAddress(Grasscutter.getConfig().DispatchServerIp, Grasscutter.getConfig().UploadLogPort), 0); uploadLogServer.createContext( // log-upload-os.mihoyo.com "/crash/dataUpload", new DispatchHttpJsonHandler("{\"code\":0}") @@ -413,7 +419,7 @@ public final class DispatchServer { os.close(); }); uploadLogServer.start(); - Grasscutter.getLogger().info("Log server (log-upload-os) started on port " + 80); + Grasscutter.getLogger().info("Log server (log-upload-os) started on port " + Grasscutter.getConfig().UploadLogPort); } private Map parseQueryString(String qs) {