From b5d2f47cf84701846eecc65679bffb6e05476a67 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 10 Feb 2019 18:20:52 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=BE=D1=80=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20SetProfileRequest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/websocket/WebSocketService.java | 6 ++--- .../json/auth/SetProfileResponse.java | 5 ++-- .../request/auth/SetProfileRequest.java | 25 ++++++++++++++---- .../request/SetProfileRequestEvent.java | 26 +++++++++++++++++++ 4 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/events/request/SetProfileRequestEvent.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java index 1fd291bc..b13e3ade 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java @@ -16,10 +16,7 @@ import ru.gravit.launchserver.socket.websocket.json.EchoResponse; import ru.gravit.launchserver.socket.websocket.json.JsonResponseAdapter; import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; -import ru.gravit.launchserver.socket.websocket.json.auth.AuthResponse; -import ru.gravit.launchserver.socket.websocket.json.auth.CheckServerResponse; -import ru.gravit.launchserver.socket.websocket.json.auth.JoinServerResponse; -import ru.gravit.launchserver.socket.websocket.json.auth.ProfilesResponse; +import ru.gravit.launchserver.socket.websocket.json.auth.*; import ru.gravit.launchserver.socket.websocket.json.update.LauncherResponse; import ru.gravit.launchserver.socket.websocket.json.update.UpdateListResponse; import ru.gravit.utils.helper.LogHelper; @@ -78,6 +75,7 @@ public void registerResponses() { registerResponse("launcher", LauncherResponse.class); registerResponse("updateList", UpdateListResponse.class); registerResponse("cmdExec", UpdateListResponse.class); + registerResponse("setProfile", SetProfileResponse.class); } public void sendObject(ChannelHandlerContext ctx, Object obj) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java index dfe4e156..c12b5053 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java @@ -2,6 +2,7 @@ import io.netty.channel.ChannelHandlerContext; import ru.gravit.launcher.events.request.ErrorRequestEvent; +import ru.gravit.launcher.events.request.SetProfileRequestEvent; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.socket.Client; @@ -32,8 +33,8 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client return; } client.profile = p; - service.sendObject(ctx, new WebSocketService.SuccessResult(getType())); - break; + service.sendObject(ctx, new SetProfileRequestEvent(p)); + return; } } service.sendObject(ctx, new ErrorRequestEvent("Profile not found")); 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 index 4dee1fd2..a0872d82 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/SetProfileRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/SetProfileRequest.java @@ -1,30 +1,45 @@ package ru.gravit.launcher.request.auth; import ru.gravit.launcher.LauncherConfig; +import ru.gravit.launcher.events.request.SetProfileRequestEvent; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.RequestType; +import ru.gravit.launcher.request.websockets.LegacyRequestBridge; +import ru.gravit.launcher.request.websockets.RequestInterface; 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 class SetProfileRequest extends Request implements RequestInterface { + private transient ClientProfile profile; + + public String client; public SetProfileRequest(LauncherConfig config, ClientProfile profile) { super(config); this.profile = profile; + this.client = profile.getTitle(); + } + @Override + public SetProfileRequestEvent requestWebSockets() throws Exception + { + return (SetProfileRequestEvent) LegacyRequestBridge.sendRequest(this); } - @Override public Integer getLegacyType() { return RequestType.SETPROFILE.getNumber(); } @Override - protected Boolean requestDo(HInput input, HOutput output) throws Exception { + protected SetProfileRequestEvent requestDo(HInput input, HOutput output) throws Exception { output.writeString(profile.getTitle(), SerializeLimits.MAX_CLIENT); readError(input); - return input.readBoolean(); + return new SetProfileRequestEvent(profile); + } + + @Override + public String getType() { + return "setProfile"; } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/SetProfileRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/SetProfileRequestEvent.java new file mode 100644 index 00000000..5a0ba168 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/SetProfileRequestEvent.java @@ -0,0 +1,26 @@ +package ru.gravit.launcher.events.request; + +import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launcher.request.ResultInterface; +import ru.gravit.utils.event.EventInterface; + +import java.util.UUID; + +public class SetProfileRequestEvent implements ResultInterface, EventInterface { + private static final UUID uuid = UUID.fromString("08c0de9e-4364-4152-9066-8354a3a48541"); + public ClientProfile newProfile; + + public SetProfileRequestEvent(ClientProfile newProfile) { + this.newProfile = newProfile; + } + + @Override + public String getType() { + return "setProfile"; + } + + @Override + public UUID getUUID() { + return uuid; + } +}