From d008dc7217a4e0f42e213b8ca612ed15096fc6dc Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 10 Jul 2019 20:02:46 +0700 Subject: [PATCH] =?UTF-8?q?[FIX]=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC?= =?UTF-8?q?=D0=B0=20=D1=81=20reconnectCallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launcher/server/ServerWrapper.java | 42 ++++++++----------- .../server/setup/ServerWrapperSetup.java | 4 +- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index b32ac0d6..8c7bba1c 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -157,21 +157,19 @@ public void run(String... args) throws Throwable { else mainClass = Class.forName(classname); MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)); modulesManager.postInitModules(); - if (config.websocket.enabled) { - Request.service.reconnectCallback = () -> - { - LogHelper.debug("WebSocket connect closed. Try reconnect"); - try { - Request.service.open(); - LogHelper.debug("Connect to %s", config.websocket.address); - } catch (Exception e) { - LogHelper.error(e); - throw new RequestException(String.format("Connect error: %s", e.getMessage() != null ? e.getMessage() : "null")); - } - auth(); - }; - } - LogHelper.info("ServerWrapper: Project %s, LaunchServer address: %s. Title: %s", config.projectname, config.websocket.address, config.title); + Request.service.reconnectCallback = () -> + { + LogHelper.debug("WebSocket connect closed. Try reconnect"); + try { + Request.service.open(); + LogHelper.debug("Connect to %s", config.address); + } catch (Exception e) { + LogHelper.error(e); + throw new RequestException(String.format("Connect error: %s", e.getMessage() != null ? e.getMessage() : "null")); + } + auth(); + }; + LogHelper.info("ServerWrapper: Project %s, LaunchServer address: %s. Title: %s", config.projectname, config.address, config.title); LogHelper.info("Minecraft Version (for profile): %s", wrapper.profile == null ? "unknown" : wrapper.profile.getVersion().name); LogHelper.info("Start Minecraft Server"); LogHelper.debug("Invoke main method %s", mainClass.getName()); @@ -192,11 +190,9 @@ public void updateLauncherConfig() { LauncherConfig cfg = null; try { - cfg = new LauncherConfig(config.websocket.address, SecurityHelper.toPublicRSAKey(IOHelper.read(publicKeyFile)), new HashMap<>(), config.projectname); - if (config.websocket != null && config.websocket.enabled) { - cfg.isNettyEnabled = true; - cfg.address = config.websocket.address; - } + cfg = new LauncherConfig(config.address, SecurityHelper.toPublicRSAKey(IOHelper.read(publicKeyFile)), new HashMap<>(), config.projectname); + cfg.isNettyEnabled = true; + cfg.address = config.address; } catch (InvalidKeySpecException | IOException e) { LogHelper.error(e); } @@ -228,8 +224,7 @@ public Config getDefaultConfig() { newConfig.reconnectCount = 10; newConfig.reconnectSleep = 1000; newConfig.websocket = new WebSocketConf(); - newConfig.websocket.address = "ws://localhost:9274/api"; - newConfig.websocket.enabled = false; + newConfig.address = "ws://localhost:9274/api"; newConfig.env = LauncherConfig.LauncherEnvironment.STD; return newConfig; } @@ -242,6 +237,7 @@ public void setConfig(Config config) { public static final class Config { public String title; public String projectname; + public String address; public WebSocketConf websocket; public int reconnectCount; public int reconnectSleep; @@ -261,8 +257,6 @@ public static final class Config { } public static final class WebSocketConf { - public boolean enabled; - public String address; } public ClientProfile profile; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java index ad6c0174..6a63ffae 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java @@ -41,10 +41,10 @@ public void run() throws IOException { } } LogHelper.info("Found MainClass %s", mainClassName); - System.out.println("Print launchserver websocket host:"); + System.out.println("Print launchserver websocket host( ws://host:port/api ):"); String address = commands.commandHandler.readLine(); wrapper.config.mainclass = mainClassName; - wrapper.config.websocket.address = address; + wrapper.config.address = address; if (!Files.exists(ServerWrapper.publicKeyFile)) { LogHelper.error("public.key not found"); for (int i = 0; i < 10; ++i) {