mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] Client debug
This commit is contained in:
parent
65c6520001
commit
6ffbc5515f
4 changed files with 137 additions and 9 deletions
|
@ -53,10 +53,11 @@ public class LauncherEngine {
|
||||||
public RuntimeProvider runtimeProvider;
|
public RuntimeProvider runtimeProvider;
|
||||||
public ECPublicKey publicKey;
|
public ECPublicKey publicKey;
|
||||||
public ECPrivateKey privateKey;
|
public ECPrivateKey privateKey;
|
||||||
|
public Class<? extends RuntimeProvider> basicRuntimeProvider;
|
||||||
|
|
||||||
private LauncherEngine(boolean clientInstance) {
|
private LauncherEngine(boolean clientInstance, Class<? extends RuntimeProvider> basicRuntimeProvider) {
|
||||||
|
|
||||||
this.clientInstance = clientInstance;
|
this.clientInstance = clientInstance;
|
||||||
|
this.basicRuntimeProvider = basicRuntimeProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
//JVMHelper.getCertificates
|
//JVMHelper.getCertificates
|
||||||
|
@ -124,7 +125,7 @@ public static void main(String... args) throws Throwable {
|
||||||
Launcher.getConfig(); // init config
|
Launcher.getConfig(); // init config
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
new LauncherEngine(false).start(args);
|
newInstance(false).start(args);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
return;
|
return;
|
||||||
|
@ -157,7 +158,11 @@ public static RequestService initOffline() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LauncherEngine newInstance(boolean clientInstance) {
|
public static LauncherEngine newInstance(boolean clientInstance) {
|
||||||
return new LauncherEngine(clientInstance);
|
return new LauncherEngine(clientInstance, NoRuntimeProvider.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LauncherEngine newInstance(boolean clientInstance, Class<? extends RuntimeProvider> basicRuntimeProvider) {
|
||||||
|
return new LauncherEngine(clientInstance, basicRuntimeProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ECPublicKey getClientPublicKey() {
|
public ECPublicKey getClientPublicKey() {
|
||||||
|
@ -195,7 +200,7 @@ public void start(String... args) throws Throwable {
|
||||||
ClientPreGuiPhase event = new ClientPreGuiPhase(null);
|
ClientPreGuiPhase event = new ClientPreGuiPhase(null);
|
||||||
LauncherEngine.modulesManager.invokeEvent(event);
|
LauncherEngine.modulesManager.invokeEvent(event);
|
||||||
runtimeProvider = event.runtimeProvider;
|
runtimeProvider = event.runtimeProvider;
|
||||||
if (runtimeProvider == null) runtimeProvider = new NoRuntimeProvider();
|
if (runtimeProvider == null) runtimeProvider = basicRuntimeProvider.getConstructor().newInstance();
|
||||||
runtimeProvider.init(clientInstance);
|
runtimeProvider.init(clientInstance);
|
||||||
//runtimeProvider.preLoad();
|
//runtimeProvider.preLoad();
|
||||||
if (!Request.isAvailable()) {
|
if (!Request.isAvailable()) {
|
||||||
|
|
|
@ -0,0 +1,116 @@
|
||||||
|
package pro.gravit.launcher.debug;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.ClientPermissions;
|
||||||
|
import pro.gravit.launcher.Launcher;
|
||||||
|
import pro.gravit.launcher.LauncherEngine;
|
||||||
|
import pro.gravit.launcher.api.AuthService;
|
||||||
|
import pro.gravit.launcher.api.ClientService;
|
||||||
|
import pro.gravit.launcher.client.ClientParams;
|
||||||
|
import pro.gravit.launcher.events.request.AuthRequestEvent;
|
||||||
|
import pro.gravit.launcher.events.request.ProfilesRequestEvent;
|
||||||
|
import pro.gravit.launcher.gui.RuntimeProvider;
|
||||||
|
import pro.gravit.launcher.profiles.ClientProfile;
|
||||||
|
import pro.gravit.launcher.request.Request;
|
||||||
|
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||||
|
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
||||||
|
import pro.gravit.launcher.request.update.ProfilesRequest;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ClientRuntimeProvider implements RuntimeProvider {
|
||||||
|
@Override
|
||||||
|
public void run(String[] args) {
|
||||||
|
ArrayList<String> newArgs = new ArrayList<>(Arrays.asList(args));
|
||||||
|
try {
|
||||||
|
String username = System.getProperty("launcher.runtime.username", null);
|
||||||
|
String uuid = System.getProperty("launcher.runtime.uuid", null);
|
||||||
|
String login = System.getProperty("launcher.runtime.login", username);
|
||||||
|
String password = System.getProperty("launcher.runtime.password", "Player");
|
||||||
|
String authId = System.getProperty("launcher.runtime.auth.authid", "std");
|
||||||
|
String accessToken = System.getProperty("launcher.runtime.auth.accesstoken", null);
|
||||||
|
String refreshToken = System.getProperty("launcher.runtime.auth.refreshtoken", null);
|
||||||
|
String minecraftAccessToken = System.getProperty("launcher.runtime.auth.minecraftaccesstoken", "DEBUG");
|
||||||
|
long expire = Long.parseLong(System.getProperty("launcher.runtime.auth.expire", "0"));
|
||||||
|
String profileUUID = System.getProperty("launcher.runtime.profileuuid", null);
|
||||||
|
String mainClass = System.getProperty("launcher.runtime.mainclass", null);
|
||||||
|
ClientPermissions permissions = new ClientPermissions();
|
||||||
|
if(mainClass == null) {
|
||||||
|
throw new NullPointerException("Add `-Dlauncher.runtime.mainclass=YOUR_MAIN_CLASS` to jvmArgs");
|
||||||
|
}
|
||||||
|
if(accessToken != null) {
|
||||||
|
Request.setOAuth(authId, new AuthRequestEvent.OAuthRequestEvent(accessToken, refreshToken, expire));
|
||||||
|
Request.RequestRestoreReport report = Request.restore(true);
|
||||||
|
permissions = report.userInfo.permissions;
|
||||||
|
username = report.userInfo.playerProfile.username;
|
||||||
|
uuid = report.userInfo.playerProfile.uuid.toString();
|
||||||
|
if(report.userInfo.accessToken != null) {
|
||||||
|
minecraftAccessToken = report.userInfo.accessToken;
|
||||||
|
}
|
||||||
|
} else if(password != null) {
|
||||||
|
AuthRequest request = new AuthRequest(login, password, authId, AuthRequest.ConnectTypes.API);
|
||||||
|
AuthRequestEvent event = request.request();
|
||||||
|
Request.setOAuth(authId, event.oauth);
|
||||||
|
if(event.accessToken != null) {
|
||||||
|
minecraftAccessToken = event.accessToken;
|
||||||
|
}
|
||||||
|
username = event.playerProfile.username;
|
||||||
|
uuid = event.playerProfile.uuid.toString();
|
||||||
|
}
|
||||||
|
if(profileUUID != null) {
|
||||||
|
UUID profileUuid = UUID.fromString(profileUUID);
|
||||||
|
ProfilesRequest profiles = new ProfilesRequest();
|
||||||
|
ProfilesRequestEvent event = profiles.request();
|
||||||
|
for(ClientProfile profile : event.profiles) {
|
||||||
|
if(profile.getUUID().equals(profileUuid)) {
|
||||||
|
AuthService.profile = profile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(username == null) {
|
||||||
|
username = "Player";
|
||||||
|
}
|
||||||
|
if(uuid == null) {
|
||||||
|
uuid = "a7899336-e61c-4e51-b480-0c815b18aed8";
|
||||||
|
}
|
||||||
|
replaceOrCreateArgument(newArgs, "--username", username);
|
||||||
|
replaceOrCreateArgument(newArgs, "--uuid", uuid);
|
||||||
|
replaceOrCreateArgument(newArgs, "--accessToken", minecraftAccessToken);
|
||||||
|
AuthService.uuid = UUID.fromString(uuid);
|
||||||
|
AuthService.username = username;
|
||||||
|
AuthService.permissions = permissions;
|
||||||
|
Class<?> mainClazz = Class.forName(mainClass);
|
||||||
|
mainClazz.getMethod("main", String[].class).invoke(null, (Object) newArgs.toArray(new String[0]));
|
||||||
|
} catch (Throwable e) {
|
||||||
|
LogHelper.error(e);
|
||||||
|
LauncherEngine.exitLauncher(-15);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void replaceOrCreateArgument(ArrayList<String> args, String name, String value) {
|
||||||
|
int index = args.indexOf(name);
|
||||||
|
if(index < 0) {
|
||||||
|
args.add(name);
|
||||||
|
if(value != null) {
|
||||||
|
args.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(value != null) {
|
||||||
|
int valueIndex = index+1;
|
||||||
|
args.set(valueIndex, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preLoad() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(boolean clientInstance) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -69,7 +69,7 @@ public static void main(String[] args) throws Throwable {
|
||||||
}
|
}
|
||||||
Request.setRequestService(service);
|
Request.setRequestService(service);
|
||||||
LogHelper.debug("Initialization LauncherEngine");
|
LogHelper.debug("Initialization LauncherEngine");
|
||||||
LauncherEngine instance = LauncherEngine.newInstance(false);
|
LauncherEngine instance = LauncherEngine.newInstance(false, ClientRuntimeProvider.class);
|
||||||
instance.start(args);
|
instance.start(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import pro.gravit.launcher.LauncherNetworkAPI;
|
import pro.gravit.launcher.LauncherNetworkAPI;
|
||||||
import pro.gravit.launcher.events.request.AuthRequestEvent;
|
import pro.gravit.launcher.events.request.AuthRequestEvent;
|
||||||
|
import pro.gravit.launcher.events.request.CurrentUserRequestEvent;
|
||||||
import pro.gravit.launcher.events.request.RefreshTokenRequestEvent;
|
import pro.gravit.launcher.events.request.RefreshTokenRequestEvent;
|
||||||
import pro.gravit.launcher.events.request.RestoreRequestEvent;
|
import pro.gravit.launcher.events.request.RestoreRequestEvent;
|
||||||
import pro.gravit.launcher.request.auth.RefreshTokenRequest;
|
import pro.gravit.launcher.request.auth.RefreshTokenRequest;
|
||||||
|
@ -122,6 +123,10 @@ public static void reconnect() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RequestRestoreReport restore() throws Exception {
|
public static RequestRestoreReport restore() throws Exception {
|
||||||
|
return restore(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RequestRestoreReport restore(boolean needUserInfo) throws Exception {
|
||||||
boolean refreshed = false;
|
boolean refreshed = false;
|
||||||
RestoreRequest request;
|
RestoreRequest request;
|
||||||
if (oauth != null) {
|
if (oauth != null) {
|
||||||
|
@ -131,7 +136,7 @@ public static RequestRestoreReport restore() throws Exception {
|
||||||
setOAuth(authId, event.oauth);
|
setOAuth(authId, event.oauth);
|
||||||
refreshed = true;
|
refreshed = true;
|
||||||
}
|
}
|
||||||
request = new RestoreRequest(authId, oauth.accessToken, extendedTokens, false);
|
request = new RestoreRequest(authId, oauth.accessToken, extendedTokens, needUserInfo);
|
||||||
} else {
|
} else {
|
||||||
request = new RestoreRequest(authId, null, extendedTokens, false);
|
request = new RestoreRequest(authId, null, extendedTokens, false);
|
||||||
}
|
}
|
||||||
|
@ -159,7 +164,7 @@ public static RequestRestoreReport restore() throws Exception {
|
||||||
}
|
}
|
||||||
invalidTokens = event.invalidTokens;
|
invalidTokens = event.invalidTokens;
|
||||||
}
|
}
|
||||||
return new RequestRestoreReport(false, refreshed, invalidTokens);
|
return new RequestRestoreReport(false, refreshed, invalidTokens, event.userInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requestError(String message) throws RequestException {
|
public static void requestError(String message) throws RequestException {
|
||||||
|
@ -216,11 +221,13 @@ public static class RequestRestoreReport {
|
||||||
public final boolean legacySession;
|
public final boolean legacySession;
|
||||||
public final boolean refreshed;
|
public final boolean refreshed;
|
||||||
public final List<String> invalidExtendedTokens;
|
public final List<String> invalidExtendedTokens;
|
||||||
|
public final CurrentUserRequestEvent.UserInfo userInfo;
|
||||||
|
|
||||||
public RequestRestoreReport(boolean legacySession, boolean refreshed, List<String> invalidExtendedTokens) {
|
public RequestRestoreReport(boolean legacySession, boolean refreshed, List<String> invalidExtendedTokens, CurrentUserRequestEvent.UserInfo userInfo) {
|
||||||
this.legacySession = legacySession;
|
this.legacySession = legacySession;
|
||||||
this.refreshed = refreshed;
|
this.refreshed = refreshed;
|
||||||
this.invalidExtendedTokens = invalidExtendedTokens;
|
this.invalidExtendedTokens = invalidExtendedTokens;
|
||||||
|
this.userInfo = userInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue