[FIX] No refresh in client

This commit is contained in:
Gravita 2023-11-21 13:40:21 +07:00
parent fe374c1f9e
commit 54bfc6de9c
4 changed files with 17 additions and 11 deletions

View file

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

View file

@ -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<String, String> getExpiredExtendedTokens() {
@ -178,16 +178,22 @@ private synchronized static Map<String, String> 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);

View file

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

View file

@ -6,9 +6,9 @@ public final class Version implements Comparable<Version> {
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;