From bcedb95eec40a0f42903850df43de0f0e6ee1e2a Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 20 Feb 2019 16:55:21 +0700 Subject: [PATCH] [FEATURE] UpdateResponse --- .../socket/websocket/WebSocketService.java | 2 ++ .../websocket/json/update/UpdateResponse.java | 36 +++++++++++++++++++ .../websockets/ClientWebSocketService.java | 1 + .../events/request/UpdateRequestEvent.java | 16 +++++++++ 4 files changed, 55 insertions(+) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateResponse.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateRequestEvent.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 ffebe4cc..e9b5db5e 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 @@ -21,6 +21,7 @@ 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.launchserver.socket.websocket.json.update.UpdateResponse; import ru.gravit.utils.helper.LogHelper; import java.lang.reflect.Type; @@ -79,6 +80,7 @@ public void registerResponses() { registerResponse("cmdExec", ExecCommandResponse.class); registerResponse("setProfile", SetProfileResponse.class); registerResponse("addLogListener", AddLogListenerResponse.class); + registerResponse("update", UpdateResponse.class); } public void sendObject(ChannelHandlerContext ctx, Object obj) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateResponse.java new file mode 100644 index 00000000..6c0502c6 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateResponse.java @@ -0,0 +1,36 @@ +package ru.gravit.launchserver.socket.websocket.json.update; + +import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.events.request.ErrorRequestEvent; +import ru.gravit.launcher.events.request.UpdateRequestEvent; +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; + +public class UpdateResponse implements JsonResponseInterface { + public String dir; + @Override + public String getType() { + return "update"; + } + + @Override + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + if (!client.isAuth || client.type != Client.Type.USER || client.profile == null) { + service.sendObject(ctx,new ErrorRequestEvent("Assess denied")); + return; + } + if (!client.permissions.canAdmin) { + for (ClientProfile p : LaunchServer.server.getProfiles()) { + if (!client.profile.getTitle().equals(p.getTitle())) continue; + if (!p.isWhitelistContains(client.username)) { + service.sendObject(ctx,new ErrorRequestEvent("You don't download this folder")); + return; + } + } + } + service.sendObject(ctx,new UpdateRequestEvent(LaunchServer.server.updatesDirMap.get(dir).object)); + } +} diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java index 98629b59..513c1803 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -88,6 +88,7 @@ public void registerResults() { registerResult("setProfile", SetProfileRequestEvent.class); registerResult("updateList", UpdateListRequestEvent.class); registerResult("error", ErrorRequestEvent.class); + registerResult("update", UpdateRequestEvent.class); } public void registerHandler(EventHandler eventHandler) diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateRequestEvent.java new file mode 100644 index 00000000..122db396 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateRequestEvent.java @@ -0,0 +1,16 @@ +package ru.gravit.launcher.events.request; + +import ru.gravit.launcher.hasher.HashedDir; +import ru.gravit.launcher.request.ResultInterface; + +public class UpdateRequestEvent implements ResultInterface { + public HashedDir hdir; + @Override + public String getType() { + return "update"; + } + + public UpdateRequestEvent(HashedDir hdir) { + this.hdir = hdir; + } +}