From 8d7db40909ff009f1a60d7a5d15ab885cc594131 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 20 Oct 2018 15:57:30 +0700 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D1=8F?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE=D1=84=D0=B8=D0=BB=D1=8C=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/response/Response.java | 6 +-- .../response/auth/SetProfileResponse.java | 38 +++++++++++++++++++ .../request/auth/SetProfileRequest.java | 30 +++++++++++++++ .../gravit/launcher/request/RequestType.java | 2 +- 4 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java create mode 100644 LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/SetProfileRequest.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 09c730b9..7e760bba 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java @@ -5,16 +5,13 @@ import java.util.concurrent.ConcurrentHashMap; import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launchserver.response.auth.AuthServerResponse; +import ru.gravit.launchserver.response.auth.*; import ru.gravit.utils.helper.LogHelper; import ru.gravit.launcher.request.RequestException; import ru.gravit.launcher.request.RequestType; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.response.auth.AuthResponse; -import ru.gravit.launchserver.response.auth.CheckServerResponse; -import ru.gravit.launchserver.response.auth.JoinServerResponse; import ru.gravit.launchserver.response.profile.BatchProfileByUsernameResponse; import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse; import ru.gravit.launchserver.response.profile.ProfileByUsernameResponse; @@ -55,6 +52,7 @@ public static void registerResponses() { registerResponse(RequestType.UPDATE.getNumber(), UpdateResponse::new); registerResponse(RequestType.PROFILES.getNumber(), ProfilesResponse::new); registerResponse(RequestType.SERVERAUTH.getNumber(), AuthServerResponse::new); + registerResponse(RequestType.SETPROFILE.getNumber(), SetProfileResponse::new); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java new file mode 100644 index 00000000..5631149e --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java @@ -0,0 +1,38 @@ +package ru.gravit.launchserver.response.auth; + +import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launcher.serialize.HInput; +import ru.gravit.launcher.serialize.HOutput; +import ru.gravit.launcher.serialize.SerializeLimits; +import ru.gravit.launcher.serialize.signed.SignedObjectHolder; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.auth.AuthException; +import ru.gravit.launchserver.response.Response; +import ru.gravit.launchserver.socket.Client; + +import java.util.Collection; + +public class SetProfileResponse extends Response { + public SetProfileResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { + super(server, session, input, output, ip); + } + + @Override + public void reply() throws Exception { + String client = input.readString(SerializeLimits.MAX_CLIENT); + Client clientData = server.sessionManager.getClient(session); + if(!clientData.isAuth) requestError("You not auth"); + Collection> profiles = server.getProfiles(); + for (SignedObjectHolder p : profiles) { + if (p.object.getTitle().equals(client)) { + if (!p.object.isWhitelistContains(clientData.username)) { + requestError(server.config.whitelistRejectString); + return; + } + clientData.profile = p.object; + output.writeBoolean(true); + break; + } + } + } +} diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/SetProfileRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/SetProfileRequest.java new file mode 100644 index 00000000..191b77b2 --- /dev/null +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/SetProfileRequest.java @@ -0,0 +1,30 @@ +package ru.gravit.launcher.request.auth; + +import ru.gravit.launcher.LauncherConfig; +import ru.gravit.launcher.profiles.ClientProfile; +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.launcher.serialize.SerializeLimits; + +public class SetProfileRequest extends Request { + private ClientProfile profile; + + public SetProfileRequest(LauncherConfig config, ClientProfile profile) { + super(config); + this.profile = profile; + } + + @Override + public Integer getType() { + return RequestType.SETPROFILE.getNumber(); + } + + @Override + protected Boolean requestDo(HInput input, HOutput output) throws Exception { + output.writeString(profile.getTitle(), SerializeLimits.MAX_CLIENT); + readError(input); + return input.readBoolean(); + } +} 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 e664b73b..ce465dd7 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 { LAUNCHER(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), + PROFILES(10),SERVERAUTH(11), SETPROFILE(12), CUSTOM(255); // Custom requests private static final EnumSerializer SERIALIZER = new EnumSerializer<>(RequestType.class);