[FEATURE] Портирован SetProfileRequest

This commit is contained in:
Gravit 2019-02-10 18:20:52 +07:00
parent 956cef2cd6
commit b5d2f47cf8
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 51 additions and 11 deletions

View file

@ -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) {

View file

@ -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"));

View file

@ -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<Boolean> {
private ClientProfile profile;
public class SetProfileRequest extends Request<SetProfileRequestEvent> 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";
}
}

View file

@ -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;
}
}