From 751048ab3ed325abf84330446ce34f4866368858 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 21:44:38 +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=20SetProfileResponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../websocket/json/auth/ProfilesResponse.java | 1 + .../json/auth/SetProfileResponse.java | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java index f08f71c1..29c9581b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java @@ -20,6 +20,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client if(!client.isAuth) { service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied")); + return; } service.sendObject(ctx, new Result((List) LaunchServer.server.getProfiles())); } 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 new file mode 100644 index 00000000..83e41ee2 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java @@ -0,0 +1,39 @@ +package ru.gravit.launchserver.socket.websocket.json.auth; + +import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.socket.Client; +import ru.gravit.launchserver.socket.websocket.WebSocketService; +import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; + +import java.util.Collection; + +public class SetProfileResponse implements JsonResponseInterface { + @Override + public String getType() { + return "setProfile"; + } + + @Override + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + if(!client.isAuth) + { + service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied")); + return; + } + Collection profiles = LaunchServer.server.getProfiles(); + for (ClientProfile p : profiles) { + if (p.getTitle().equals(client)) { + if (!p.isWhitelistContains(client.username)) { + service.sendObject(ctx, new WebSocketService.ErrorResult(LaunchServer.server.config.whitelistRejectString)); + return; + } + client.profile = p; + service.sendObject(ctx, new WebSocketService.SuccessResult(getType())); + break; + } + } + service.sendObject(ctx, new WebSocketService.ErrorResult("Profile not found")); + } +}