Skip to content

Commit 2955642

Browse files
committed
[FEATURE] Improve https handling
1 parent 3744ca5 commit 2955642

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

components/launchserver/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,22 @@ public static void generateConfigIfNotExists(Path configFile, CommandHandler com
226226
logger.error("ProjectName null. Using MineCraft");
227227
newConfig.projectName = "MineCraft";
228228
}
229+
boolean usingHttps;
230+
if(address.startsWith("ws://")) {
231+
address = address.substring("ws://".length());
232+
usingHttps = false;
233+
} else if(address.startsWith("wss://")) {
234+
address = address.substring("wss://".length());
235+
usingHttps = true;
236+
} else if(address.startsWith("http://")) {
237+
address = address.substring("http://".length());
238+
usingHttps = false;
239+
} else if(address.startsWith("https://")) {
240+
address = address.substring("https://".length());
241+
usingHttps = true;
242+
} else {
243+
usingHttps = false;
244+
}
229245
String portString = System.getenv("LISTEN_PORT");
230246
if(portString == null) {
231247
portString = System.getProperty("launchserver.listenport", null);
@@ -245,10 +261,10 @@ public static void generateConfigIfNotExists(Path configFile, CommandHandler com
245261
port = 9274;
246262
logger.info("Address {} doesn't contains port (you want to use nginx?)", address);
247263
}
248-
newConfig.netty.address = "ws://" + address + "/api";
249-
newConfig.netty.downloadURL = "http://" + address + "/%dirname%/";
250-
newConfig.netty.launcherURL = "http://" + address + "/Launcher.jar";
251-
newConfig.netty.launcherEXEURL = "http://" + address + "/Launcher.exe";
264+
newConfig.netty.address = (usingHttps ? "wss://" : "ws://") + address + "/api";
265+
newConfig.netty.downloadURL = (usingHttps ? "https://" : "http://") + address + "/%dirname%/";
266+
newConfig.netty.launcherURL = (usingHttps ? "https://" : "http://") + address + "/Launcher.jar";
267+
newConfig.netty.launcherEXEURL = (usingHttps ? "https://" : "http://") + address + "/Launcher.exe";
252268
newConfig.netty.binds[0].port = port;
253269

254270
// Write LaunchServer config

0 commit comments

Comments
 (0)