From 9e2a154c5065cf5a8cf0d44ad0a297f4e3faf512 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 6 Nov 2018 18:57:19 +0700 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BF=D1=80=D0=BE=D1=81=20ChangeSe?= =?UTF-8?q?rver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/response/Response.java | 1 + .../response/auth/ChangeServerResponse.java | 28 ++++++++++++ .../request/auth/ChangeServerRequest.java | 44 +++++++++++++++++++ .../ru/gravit/launcher/LauncherConfig.java | 2 +- .../gravit/launcher/request/RequestType.java | 2 +- 5 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/ChangeServerResponse.java create mode 100644 LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/ChangeServerRequest.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java index b490abda..51fe4f9a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java @@ -50,6 +50,7 @@ public static void registerResponses() { registerResponse(RequestType.PROFILES.getNumber(), ProfilesResponse::new); registerResponse(RequestType.SERVERAUTH.getNumber(), AuthServerResponse::new); registerResponse(RequestType.SETPROFILE.getNumber(), SetProfileResponse::new); + registerResponse(RequestType.CHANGESERVER.getNumber(),ChangeServerResponse::new); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/ChangeServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/ChangeServerResponse.java new file mode 100644 index 00000000..a28dc556 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/ChangeServerResponse.java @@ -0,0 +1,28 @@ +package ru.gravit.launchserver.response.auth; + +import ru.gravit.launcher.serialize.HInput; +import ru.gravit.launcher.serialize.HOutput; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.response.Response; + +public class ChangeServerResponse extends Response { + public static boolean needChange = false; + public static String address; + public static int port; + + public ChangeServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { + super(server, session, input, output, ip); + } + + @Override + public void reply() throws Exception { + writeNoError(output); + output.writeBoolean(needChange); + //if true + if(needChange) + { + output.writeString(address,255); + output.writeInt(port); + } + } +} diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/ChangeServerRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/ChangeServerRequest.java new file mode 100644 index 00000000..d25385ed --- /dev/null +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/ChangeServerRequest.java @@ -0,0 +1,44 @@ +package ru.gravit.launcher.request.auth; + +import jdk.nashorn.internal.ir.RuntimeNode; +import ru.gravit.launcher.Launcher; +import ru.gravit.launcher.request.Request; +import ru.gravit.launcher.request.RequestType; +import ru.gravit.launcher.serialize.HInput; +import ru.gravit.launcher.serialize.HOutput; +import ru.gravit.utils.helper.IOHelper; + +import java.net.InetSocketAddress; + +public class ChangeServerRequest extends Request { + @Override + public Integer getType() { + return RequestType.CHANGESERVER.getNumber(); + } + public boolean change(Result result) + { + if(!result.needChange) return false; + Launcher.getConfig().address = InetSocketAddress.createUnresolved( result.address, result.port); + return true; + } + @Override + protected Result requestDo(HInput input, HOutput output) throws Exception { + readError(input); + Result result = new Result(); + result.needChange = input.readBoolean(); + if(result.needChange) + { + result.address = input.readString(255); + result.port = input.readInt(); + } + if(result.needChange) change(result); + return result; + } + + public class Result + { + public boolean needChange; + public String address; + public int port; + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java index 54286338..7e781b44 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java @@ -31,7 +31,7 @@ public static AutogenConfig getAutogenConfig() { // Instance @LauncherAPI - public final InetSocketAddress address; + public InetSocketAddress address; @LauncherAPI public final String projectname; public final int clientPort; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/request/RequestType.java b/libLauncher/src/main/java/ru/gravit/launcher/request/RequestType.java index ccedb14f..1960410f 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/request/RequestType.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/request/RequestType.java @@ -11,7 +11,7 @@ public enum RequestType implements EnumSerializer.Itf { LEGACYLAUNCHER(1), UPDATE(2), UPDATE_LIST(3), // Update requests AUTH(4), JOIN_SERVER(5), CHECK_SERVER(6), // Auth requests PROFILE_BY_USERNAME(7), PROFILE_BY_UUID(8), BATCH_PROFILE_BY_USERNAME(9), // Profile requests - PROFILES(10),SERVERAUTH(11), SETPROFILE(12),LAUNCHER(13), + PROFILES(10),SERVERAUTH(11), SETPROFILE(12),LAUNCHER(13),CHANGESERVER(14), CUSTOM(255); // Custom requests private static final EnumSerializer SERIALIZER = new EnumSerializer<>(RequestType.class);