Skip to content

Commit

Permalink
Fix duplicate code execution between fetchInfo() && login()
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTas authored and Wide-Cat committed Oct 25, 2024
1 parent 0f22604 commit 2d96d9c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,34 @@
import meteordevelopment.meteorclient.systems.accounts.AccountType;
import meteordevelopment.meteorclient.systems.accounts.MicrosoftLogin;
import net.minecraft.client.session.Session;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class MicrosoftAccount extends Account<MicrosoftAccount> {
private @Nullable String token;
public MicrosoftAccount(String refreshToken) {
super(AccountType.Microsoft, refreshToken);
}

@Override
public boolean fetchInfo() {
return auth() != null;
token = auth();
return token != null;
}

@Override
public boolean login() {
super.login();

String token = auth();
if (token == null) return false;

super.login();
cache.loadHead();

setSession(new Session(cache.username, UndashedUuid.fromStringLenient(cache.uuid), token, Optional.empty(), Optional.empty(), Session.AccountType.MSA));
return true;
}

private String auth() {
private @Nullable String auth() {
MicrosoftLogin.LoginData data = MicrosoftLogin.login(name);
if (!data.isGood()) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import meteordevelopment.meteorclient.utils.misc.NbtException;
import net.minecraft.client.session.Session;
import net.minecraft.nbt.NbtCompound;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

Expand All @@ -27,6 +28,7 @@ public class TheAlteningAccount extends Account<TheAlteningAccount> implements T
private static final Environment ENVIRONMENT = new Environment("http://sessionserver.thealtening.com", "http://authserver.thealtening.com", "The Altening");
private static final YggdrasilAuthenticationService SERVICE = new YggdrasilAuthenticationService(((MinecraftClientAccessor) mc).getProxy(), ENVIRONMENT);
private String token;
private @Nullable WaybackAuthLib auth;

public TheAlteningAccount(String token) {
super(AccountType.TheAltening, token);
Expand All @@ -35,37 +37,33 @@ public TheAlteningAccount(String token) {

@Override
public boolean fetchInfo() {
WaybackAuthLib auth = getAuth();
auth = getAuth();

try {
auth.logIn();

cache.username = auth.getCurrentProfile().getName();
cache.uuid = auth.getCurrentProfile().getId().toString();
cache.loadHead();

return true;
} catch (InvalidCredentialsException e) {
MeteorClient.LOG.error("Invalid TheAltening credentials.");
return false;
} catch (Exception e) {
MeteorClient.LOG.error("Failed to fetch info for TheAltening account!");
return false;
}
}

@Override
public boolean login() {
if (auth == null) return false;
applyLoginEnvironment(SERVICE, YggdrasilMinecraftSessionServiceAccessor.createYggdrasilMinecraftSessionService(SERVICE.getServicesKeySet(), SERVICE.getProxy(), ENVIRONMENT));

WaybackAuthLib auth = getAuth();

try {
auth.logIn();
setSession(new Session(auth.getCurrentProfile().getName(), auth.getCurrentProfile().getId(), auth.getAccessToken(), Optional.empty(), Optional.empty(), Session.AccountType.MOJANG));

cache.username = auth.getCurrentProfile().getName();
cache.loadHead();

return true;
} catch (InvalidCredentialsException e) {
MeteorClient.LOG.error("Invalid TheAltening credentials.");
return false;
} catch (Exception e) {
MeteorClient.LOG.error("Failed to login with TheAltening.");
return false;
Expand Down

0 comments on commit 2d96d9c

Please sign in to comment.