mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] UpdateResponse
This commit is contained in:
parent
e0c6386d23
commit
bcedb95eec
4 changed files with 55 additions and 0 deletions
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue