From 54bfc6de9cd08b0580523747836283123410b327 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Tue, 21 Nov 2023 13:40:21 +0700 Subject: [PATCH] [FIX] No refresh in client --- .../launcher/debug/ClientRuntimeProvider.java | 2 +- .../pro/gravit/launcher/request/Request.java | 20 ++++++++++++------- .../client/ClientLauncherEntryPoint.java | 2 +- .../main/java/pro/gravit/utils/Version.java | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/debug/ClientRuntimeProvider.java b/Launcher/src/main/java/pro/gravit/launcher/debug/ClientRuntimeProvider.java index 82bd51e2..f9a1a682 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/debug/ClientRuntimeProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/debug/ClientRuntimeProvider.java @@ -57,7 +57,7 @@ public void run(String[] args) { if(uuid == null) { if(accessToken != null) { Request.setOAuth(authId, new AuthRequestEvent.OAuthRequestEvent(accessToken, refreshToken, expire)); - Request.RequestRestoreReport report = Request.restore(true, false); + Request.RequestRestoreReport report = Request.restore(true, false, true); permissions = report.userInfo.permissions; username = report.userInfo.playerProfile.username; uuid = report.userInfo.playerProfile.uuid.toString(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java index 9500de2f..f2b8a418 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java @@ -159,7 +159,7 @@ public static void reconnect() throws Exception { } public static RequestRestoreReport restore() throws Exception { - return restore(false, false); + return restore(false, false, false); } private synchronized static Map getExpiredExtendedTokens() { @@ -178,16 +178,22 @@ private synchronized static Map getExpiredExtendedTokens() { return makeNewTokens(set); } - public static synchronized RequestRestoreReport restore(boolean needUserInfo, boolean refreshOnly) throws Exception { + public static synchronized RequestRestoreReport restore(boolean needUserInfo, boolean refreshOnly, boolean noRefresh) throws Exception { boolean refreshed = false; RestoreRequest request; if (oauth != null) { - if (isTokenExpired() || oauth.accessToken == null) { - RefreshTokenRequest refreshRequest = new RefreshTokenRequest(authId, oauth.refreshToken); - RefreshTokenRequestEvent event = refreshRequest.request(); - setOAuth(authId, event.oauth); - refreshed = true; + if(isTokenExpired() || oauth.accessToken == null) { + if(noRefresh) { + oauth = null; + } else { + RefreshTokenRequest refreshRequest = new RefreshTokenRequest(authId, oauth.refreshToken); + RefreshTokenRequestEvent event = refreshRequest.request(); + setOAuth(authId, event.oauth); + refreshed = true; + } } + } + if (oauth != null) { request = new RestoreRequest(authId, oauth.accessToken, refreshOnly ? getExpiredExtendedTokens() : getStringExtendedTokens(), needUserInfo); } else { request = new RestoreRequest(authId, null, refreshOnly ? getExpiredExtendedTokens() : getStringExtendedTokens(), false); diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index 70c7c739..64f292fe 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -124,7 +124,7 @@ private static void realMain(String[] args) throws Throwable { service = StdWebSocketService.initWebSockets(Launcher.getConfig().address).get(); Request.setRequestService(service); LogHelper.debug("Restore sessions"); - Request.restore(); + Request.restore(false, false, true); service.registerEventHandler(new BasicLauncherEventHandler()); ((StdWebSocketService) service).reconnectCallback = () -> { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 69a95013..272fc6be 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -6,9 +6,9 @@ public final class Version implements Comparable { public static final int MAJOR = 5; public static final int MINOR = 5; - public static final int PATCH = 2; + public static final int PATCH = 3; public static final int BUILD = 1; - public static final Version.Type RELEASE = Type.STABLE; + public static final Version.Type RELEASE = Type.DEV; public final int major; public final int minor; public final int patch;