mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Реализация restoreSession
This commit is contained in:
parent
a0e2c28d81
commit
ae3e824c91
11 changed files with 124 additions and 0 deletions
|
@ -21,6 +21,10 @@ public class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocket
|
||||||
static {
|
static {
|
||||||
service.registerResponses();
|
service.registerResponses();
|
||||||
}
|
}
|
||||||
|
public void setClient(Client client)
|
||||||
|
{
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelActive(ChannelHandlerContext ctx) {
|
public void channelActive(ChannelHandlerContext ctx) {
|
||||||
|
|
|
@ -81,6 +81,7 @@ public void registerResponses() {
|
||||||
registerResponse("setProfile", SetProfileResponse.class);
|
registerResponse("setProfile", SetProfileResponse.class);
|
||||||
registerResponse("addLogListener", AddLogListenerResponse.class);
|
registerResponse("addLogListener", AddLogListenerResponse.class);
|
||||||
registerResponse("update", UpdateResponse.class);
|
registerResponse("update", UpdateResponse.class);
|
||||||
|
registerResponse("restoreSession", RestoreSessionResponse.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendObject(ChannelHandlerContext ctx, Object obj) {
|
public void sendObject(ChannelHandlerContext ctx, Object obj) {
|
||||||
|
|
|
@ -21,13 +21,17 @@
|
||||||
|
|
||||||
import javax.crypto.BadPaddingException;
|
import javax.crypto.BadPaddingException;
|
||||||
import javax.crypto.IllegalBlockSizeException;
|
import javax.crypto.IllegalBlockSizeException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class AuthResponse implements JsonResponseInterface {
|
public class AuthResponse implements JsonResponseInterface {
|
||||||
|
public transient static Random random = new SecureRandom();
|
||||||
public String login;
|
public String login;
|
||||||
public String client;
|
public String client;
|
||||||
public String customText;
|
public String customText;
|
||||||
|
public boolean getSession;
|
||||||
|
|
||||||
public String password;
|
public String password;
|
||||||
public byte[] encryptedPassword;
|
public byte[] encryptedPassword;
|
||||||
|
@ -110,6 +114,12 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
||||||
clientData.updateAuth();
|
clientData.updateAuth();
|
||||||
result.accessToken = aresult.accessToken;
|
result.accessToken = aresult.accessToken;
|
||||||
result.permissions = clientData.permissions;
|
result.permissions = clientData.permissions;
|
||||||
|
if(getSession)
|
||||||
|
{
|
||||||
|
clientData.session = random.nextLong();
|
||||||
|
LaunchServer.server.sessionManager.addClient(clientData);
|
||||||
|
result.session = clientData.session;
|
||||||
|
}
|
||||||
result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, aresult.username, client, clientData.auth.textureProvider);
|
result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, aresult.username, client, clientData.auth.textureProvider);
|
||||||
service.sendObject(ctx, result);
|
service.sendObject(ctx, result);
|
||||||
} catch (AuthException | HWIDException e) {
|
} catch (AuthException | HWIDException e) {
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package ru.gravit.launchserver.socket.websocket.json.auth;
|
||||||
|
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import ru.gravit.launcher.LauncherNetworkAPI;
|
||||||
|
import ru.gravit.launcher.events.request.ErrorRequestEvent;
|
||||||
|
import ru.gravit.launcher.events.request.RestoreSessionRequestEvent;
|
||||||
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.socket.Client;
|
||||||
|
import ru.gravit.launchserver.socket.websocket.WebSocketFrameHandler;
|
||||||
|
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||||
|
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||||
|
|
||||||
|
public class RestoreSessionResponse implements JsonResponseInterface {
|
||||||
|
@LauncherNetworkAPI
|
||||||
|
public long session;
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "restoreSession";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||||
|
Client rClient = LaunchServer.server.sessionManager.getClient(session);
|
||||||
|
if(rClient == null)
|
||||||
|
{
|
||||||
|
service.sendObject(ctx, new ErrorRequestEvent("Session invalid"));
|
||||||
|
}
|
||||||
|
WebSocketFrameHandler frameHandler = ctx.pipeline().get(WebSocketFrameHandler.class);
|
||||||
|
frameHandler.setClient(rClient);
|
||||||
|
service.sendObject(ctx, new RestoreSessionRequestEvent());
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@
|
||||||
import ru.gravit.launcher.profiles.ClientProfile;
|
import ru.gravit.launcher.profiles.ClientProfile;
|
||||||
import ru.gravit.launcher.profiles.PlayerProfile;
|
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||||
import ru.gravit.launcher.request.Request;
|
import ru.gravit.launcher.request.Request;
|
||||||
|
import ru.gravit.launcher.request.auth.RestoreSessionRequest;
|
||||||
import ru.gravit.launcher.request.update.LegacyLauncherRequest;
|
import ru.gravit.launcher.request.update.LegacyLauncherRequest;
|
||||||
import ru.gravit.launcher.serialize.HInput;
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
import ru.gravit.launcher.serialize.HOutput;
|
import ru.gravit.launcher.serialize.HOutput;
|
||||||
|
@ -466,6 +467,12 @@ public static void main(String... args) throws Throwable {
|
||||||
PublicURLClassLoader.systemclassloader = classLoader;
|
PublicURLClassLoader.systemclassloader = classLoader;
|
||||||
// Start client with WatchService monitoring
|
// Start client with WatchService monitoring
|
||||||
boolean digest = !profile.isUpdateFastCheck();
|
boolean digest = !profile.isUpdateFastCheck();
|
||||||
|
LogHelper.debug("Restore sessions");
|
||||||
|
if(Launcher.getConfig().isNettyEnabled)
|
||||||
|
{
|
||||||
|
RestoreSessionRequest request = new RestoreSessionRequest(Request.getSession());
|
||||||
|
request.request();
|
||||||
|
}
|
||||||
LogHelper.debug("Starting JVM and client WatchService");
|
LogHelper.debug("Starting JVM and client WatchService");
|
||||||
FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher();
|
FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher();
|
||||||
FileNameMatcher clientMatcher = profile.getClientUpdateMatcher();
|
FileNameMatcher clientMatcher = profile.getClientUpdateMatcher();
|
||||||
|
|
|
@ -102,6 +102,10 @@ public static HasherStore getDefaultHasherStore() {
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static void setAuthParams(AuthRequestEvent event) {
|
public static void setAuthParams(AuthRequestEvent event) {
|
||||||
|
if(event.session != 0)
|
||||||
|
{
|
||||||
|
Request.setSession(event.session);
|
||||||
|
}
|
||||||
LauncherGuardManager.guard.setProtectToken(event.protectToken);
|
LauncherGuardManager.guard.setProtectToken(event.protectToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ public final class AuthRequest extends Request<AuthRequestEvent> implements Requ
|
||||||
private final String auth_id;
|
private final String auth_id;
|
||||||
private final HWID hwid;
|
private final HWID hwid;
|
||||||
private final String customText;
|
private final String customText;
|
||||||
|
private final boolean getSession;
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hwid) {
|
public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hwid) {
|
||||||
|
@ -32,6 +33,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hw
|
||||||
this.hwid = hwid;
|
this.hwid = hwid;
|
||||||
customText = "";
|
customText = "";
|
||||||
auth_id = "";
|
auth_id = "";
|
||||||
|
getSession = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -42,6 +44,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hw
|
||||||
this.hwid = hwid;
|
this.hwid = hwid;
|
||||||
this.auth_id = auth_id;
|
this.auth_id = auth_id;
|
||||||
customText = "";
|
customText = "";
|
||||||
|
getSession = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -52,6 +55,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hw
|
||||||
this.hwid = hwid;
|
this.hwid = hwid;
|
||||||
this.auth_id = auth_id;
|
this.auth_id = auth_id;
|
||||||
this.customText = customText;
|
this.customText = customText;
|
||||||
|
getSession = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package ru.gravit.launcher.request.auth;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.LauncherNetworkAPI;
|
||||||
|
import ru.gravit.launcher.events.request.AuthRequestEvent;
|
||||||
|
import ru.gravit.launcher.events.request.RestoreSessionRequestEvent;
|
||||||
|
import ru.gravit.launcher.request.Request;
|
||||||
|
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 java.io.IOException;
|
||||||
|
|
||||||
|
public class RestoreSessionRequest extends Request<RestoreSessionRequestEvent> implements RequestInterface {
|
||||||
|
@LauncherNetworkAPI
|
||||||
|
public long session;
|
||||||
|
|
||||||
|
public RestoreSessionRequest(long session) {
|
||||||
|
this.session = session;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public RestoreSessionRequestEvent requestWebSockets() throws IOException, InterruptedException {
|
||||||
|
return (RestoreSessionRequestEvent) LegacyRequestBridge.sendRequest(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getLegacyType() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected RestoreSessionRequestEvent requestDo(HInput input, HOutput output) throws Exception {
|
||||||
|
return new RestoreSessionRequestEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "restoreSession";
|
||||||
|
}
|
||||||
|
}
|
|
@ -91,6 +91,7 @@ public void registerResults() {
|
||||||
registerResult("updateList", UpdateListRequestEvent.class);
|
registerResult("updateList", UpdateListRequestEvent.class);
|
||||||
registerResult("error", ErrorRequestEvent.class);
|
registerResult("error", ErrorRequestEvent.class);
|
||||||
registerResult("update", UpdateRequestEvent.class);
|
registerResult("update", UpdateRequestEvent.class);
|
||||||
|
registerResult("restoreSession", RestoreSessionRequestEvent.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerHandler(EventHandler eventHandler) {
|
public void registerHandler(EventHandler eventHandler) {
|
||||||
|
|
|
@ -24,6 +24,8 @@ public AuthRequestEvent() {
|
||||||
public String accessToken;
|
public String accessToken;
|
||||||
@LauncherNetworkAPI
|
@LauncherNetworkAPI
|
||||||
public String protectToken;
|
public String protectToken;
|
||||||
|
@LauncherNetworkAPI
|
||||||
|
public long session;
|
||||||
|
|
||||||
public AuthRequestEvent(PlayerProfile pp, String accessToken, ClientPermissions permissions) {
|
public AuthRequestEvent(PlayerProfile pp, String accessToken, ClientPermissions permissions) {
|
||||||
this.playerProfile = pp;
|
this.playerProfile = pp;
|
||||||
|
@ -38,6 +40,15 @@ public AuthRequestEvent(ClientPermissions permissions, PlayerProfile playerProfi
|
||||||
this.protectToken = protectToken;
|
this.protectToken = protectToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AuthRequestEvent(String error, ClientPermissions permissions, PlayerProfile playerProfile, String accessToken, String protectToken, long session) {
|
||||||
|
this.error = error;
|
||||||
|
this.permissions = permissions;
|
||||||
|
this.playerProfile = playerProfile;
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
this.protectToken = protectToken;
|
||||||
|
this.session = session;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID() {
|
public UUID getUUID() {
|
||||||
return uuid;
|
return uuid;
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package ru.gravit.launcher.events.request;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.request.ResultInterface;
|
||||||
|
|
||||||
|
public class RestoreSessionRequestEvent implements ResultInterface {
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "restoreSession";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue