Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@

import com.mojang.authlib.Environment;
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
import de.florianreuth.waybackauthlib.InvalidCredentialsException;
import de.florianreuth.waybackauthlib.WaybackAuthLib;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.systems.accounts.Account;
import meteordevelopment.meteorclient.systems.accounts.AccountType;
import meteordevelopment.meteorclient.systems.accounts.TokenAccount;
import meteordevelopment.meteorclient.utils.misc.NbtException;
import meteordevelopment.meteorclient.utils.network.Http;
import com.mojang.util.UndashedUuid;
import net.minecraft.client.User;
import net.minecraft.nbt.CompoundTag;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;
import java.util.UUID;

import static meteordevelopment.meteorclient.MeteorClient.mc;

public class TheAlteningAccount extends Account<TheAlteningAccount> implements TokenAccount {
private static final Environment ENVIRONMENT = new Environment("http://sessionserver.thealtening.com", "http://authserver.thealtening.com", "https://api.mojang.com", "The Altening");
private static final YggdrasilAuthenticationService SERVICE = new YggdrasilAuthenticationService(mc.getProxy(), ENVIRONMENT);
private String token;
private @Nullable WaybackAuthLib auth;
private String accessToken;

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

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

try {
auth.logIn();

cache.username = auth.getCurrentProfile().name();
cache.uuid = auth.getCurrentProfile().id().toString();
AuthResponse res = authenticate();
if (res == null || res.accessToken == null || res.selectedProfile == null) {
MeteorClient.LOG.error("Invalid TheAltening credentials.");
return false;
}

accessToken = res.accessToken;
cache.username = res.selectedProfile.name;
cache.uuid = res.selectedProfile.id;
cache.loadHead();

return true;
} catch (InvalidCredentialsException _) {
MeteorClient.LOG.error("Invalid TheAltening credentials.");
return false;
} catch (Exception _) {
MeteorClient.LOG.error("Failed to fetch info for TheAltening account!");
return false;
Expand All @@ -56,25 +56,22 @@ public boolean fetchInfo() {

@Override
public boolean login() {
if (auth == null) return false;
if (accessToken == null || cache.username.isEmpty() || cache.uuid.isEmpty()) return false;
applyLoginEnvironment(SERVICE);

try {
setSession(new User(auth.getCurrentProfile().name(), auth.getCurrentProfile().id(), auth.getAccessToken(), Optional.empty(), Optional.empty()));
setSession(new User(cache.username, UndashedUuid.fromStringLenient(cache.uuid), accessToken, Optional.empty(), Optional.empty()));
return true;
} catch (Exception _) {
MeteorClient.LOG.error("Failed to login with TheAltening.");
return false;
}
}

private WaybackAuthLib getAuth() {
WaybackAuthLib auth = new WaybackAuthLib(ENVIRONMENT.servicesHost());

auth.setUsername(name);
auth.setPassword("Meteor on Crack!");

return auth;
private AuthResponse authenticate() {
return Http.post(ENVIRONMENT.servicesHost() + "/authenticate")
.bodyJson(new AuthRequest("MINECRAFT", token, "Meteor on Crack!", UUID.randomUUID().toString(), true))
.sendJson(AuthResponse.class);
}

@Override
Expand Down Expand Up @@ -105,4 +102,16 @@ public TheAlteningAccount fromTag(CompoundTag tag) {

return this;
}

private record AuthRequest(String agent, String username, String password, String clientToken, boolean requestUser) {}

private static class AuthResponse {
public String accessToken;
public AuthProfile selectedProfile;
}

private static class AuthProfile {
public String id;
public String name;
}
}