[FIX] Исправлена роблема с reconnectCallback

This commit is contained in:
Gravit 2019-07-10 20:02:46 +07:00
parent 27b54cccba
commit d008dc7217
2 changed files with 20 additions and 26 deletions

View file

@ -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;

View file

@ -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) {