mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-13 05:46:59 -04:00
AuthlibInjectorAccount中存储AuthlibInjectorServer对象而不是url
This commit is contained in:
parent
5f40d01fb4
commit
76a259c107
@ -31,8 +31,6 @@ import org.jackhuang.hmcl.auth.yggdrasil.MojangYggdrasilProvider;
|
|||||||
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
|
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
|
||||||
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccountFactory;
|
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccountFactory;
|
||||||
import org.jackhuang.hmcl.task.FileDownloadTask;
|
import org.jackhuang.hmcl.task.FileDownloadTask;
|
||||||
import org.jackhuang.hmcl.task.Task;
|
|
||||||
import org.jackhuang.hmcl.task.TaskResult;
|
|
||||||
import org.jackhuang.hmcl.util.Constants;
|
import org.jackhuang.hmcl.util.Constants;
|
||||||
import org.jackhuang.hmcl.util.FileUtils;
|
import org.jackhuang.hmcl.util.FileUtils;
|
||||||
import org.jackhuang.hmcl.util.NetworkUtils;
|
import org.jackhuang.hmcl.util.NetworkUtils;
|
||||||
@ -107,11 +105,6 @@ public final class Accounts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static TaskResult<String> getAuthlibInjectorServerNameAsync(AuthlibInjectorAccount account) {
|
|
||||||
return Task.ofResult("serverName", () -> Accounts.getAuthlibInjectorServerName(account.getServerBaseURL()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AuthlibInjectorServer getOrCreateAuthlibInjectorServer(String url) {
|
private static AuthlibInjectorServer getOrCreateAuthlibInjectorServer(String url) {
|
||||||
return Settings.SETTINGS.authlibInjectorServers.stream()
|
return Settings.SETTINGS.authlibInjectorServers.stream()
|
||||||
.filter(server -> url.equals(server.getUrl()))
|
.filter(server -> url.equals(server.getUrl()))
|
||||||
|
@ -54,7 +54,6 @@ import java.util.logging.Level;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
import static java.util.stream.Collectors.toSet;
|
|
||||||
import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating;
|
import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating;
|
||||||
import static org.jackhuang.hmcl.util.Lang.tryCast;
|
import static org.jackhuang.hmcl.util.Lang.tryCast;
|
||||||
import static org.jackhuang.hmcl.util.Logging.LOG;
|
import static org.jackhuang.hmcl.util.Logging.LOG;
|
||||||
@ -309,22 +308,15 @@ public class Settings {
|
|||||||
* AUTHLIB INJECTORS *
|
* AUTHLIB INJECTORS *
|
||||||
****************************************/
|
****************************************/
|
||||||
|
|
||||||
private Set<String> getAuthlibInjectorServerUrls() {
|
|
||||||
return SETTINGS.authlibInjectorServers.stream()
|
|
||||||
.map(AuthlibInjectorServer::getUrl)
|
|
||||||
.collect(toSet());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After an {@link AuthlibInjectorServer} is removed, the associated accounts should also be removed.
|
* After an {@link AuthlibInjectorServer} is removed, the associated accounts should also be removed.
|
||||||
* This method performs a check and removes the dangling accounts.
|
* This method performs a check and removes the dangling accounts.
|
||||||
* Don't call this before {@link #migrateAuthlibInjectorServers()} is called, otherwise old data would be lost.
|
* Don't call this before {@link #migrateAuthlibInjectorServers()} is called, otherwise old data would be lost.
|
||||||
*/
|
*/
|
||||||
private void removeDanglingAuthlibInjectorAccounts() {
|
private void removeDanglingAuthlibInjectorAccounts() {
|
||||||
Set<String> currentServerUrls = getAuthlibInjectorServerUrls();
|
|
||||||
accounts.values().stream()
|
accounts.values().stream()
|
||||||
.filter(AuthlibInjectorAccount.class::isInstance)
|
.filter(AuthlibInjectorAccount.class::isInstance)
|
||||||
.filter(it -> !currentServerUrls.contains(((AuthlibInjectorAccount) it).getServerBaseURL()))
|
.filter(it -> !SETTINGS.authlibInjectorServers.contains(((AuthlibInjectorAccount) it).getServer()))
|
||||||
.collect(toList())
|
.collect(toList())
|
||||||
.forEach(this::deleteAccount);
|
.forEach(this::deleteAccount);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorAccount;
|
|||||||
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
|
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
|
||||||
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
|
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount;
|
||||||
import org.jackhuang.hmcl.game.AccountHelper;
|
import org.jackhuang.hmcl.game.AccountHelper;
|
||||||
import org.jackhuang.hmcl.setting.Accounts;
|
|
||||||
import org.jackhuang.hmcl.setting.Settings;
|
import org.jackhuang.hmcl.setting.Settings;
|
||||||
import org.jackhuang.hmcl.setting.Theme;
|
import org.jackhuang.hmcl.setting.Theme;
|
||||||
import org.jackhuang.hmcl.task.Schedulers;
|
import org.jackhuang.hmcl.task.Schedulers;
|
||||||
@ -80,8 +79,7 @@ public class AccountPage extends StackPane implements DecoratorPage {
|
|||||||
|
|
||||||
FXUtils.setLimitWidth(this, 300);
|
FXUtils.setLimitWidth(this, 300);
|
||||||
if (account instanceof AuthlibInjectorAccount) {
|
if (account instanceof AuthlibInjectorAccount) {
|
||||||
Accounts.getAuthlibInjectorServerNameAsync((AuthlibInjectorAccount) account)
|
lblServer.setText(((AuthlibInjectorAccount) account).getServer().getName());
|
||||||
.subscribe(Schedulers.javafx(), variables -> lblServer.setText(variables.get("serverName")));
|
|
||||||
FXUtils.setLimitHeight(this, 182);
|
FXUtils.setLimitHeight(this, 182);
|
||||||
} else {
|
} else {
|
||||||
componentList.removeChildren(paneServer);
|
componentList.removeChildren(paneServer);
|
||||||
|
@ -186,9 +186,9 @@ public final class LeftPaneController {
|
|||||||
} else
|
} else
|
||||||
item.setImage(AccountHelper.getDefaultSkin(account.getUUID(), 4), AccountHelper.getViewport(4));
|
item.setImage(AccountHelper.getDefaultSkin(account.getUUID(), 4), AccountHelper.getViewport(4));
|
||||||
|
|
||||||
if (account instanceof AuthlibInjectorAccount)
|
if (account instanceof AuthlibInjectorAccount) {
|
||||||
Accounts.getAuthlibInjectorServerNameAsync((AuthlibInjectorAccount) account)
|
FXUtils.installTooltip(ripplerContainer, 500, 5000, 0, new Tooltip(((AuthlibInjectorAccount) account).getServer().getName()));
|
||||||
.subscribe(Schedulers.javafx(), variables -> FXUtils.installTooltip(ripplerContainer, 500, 5000, 0, new Tooltip(variables.get("serverName"))));
|
}
|
||||||
|
|
||||||
if (selectedAccount == account)
|
if (selectedAccount == account)
|
||||||
ripplerContainer.setSelected(true);
|
ripplerContainer.setSelected(true);
|
||||||
|
@ -37,14 +37,14 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
public class AuthlibInjectorAccount extends YggdrasilAccount {
|
public class AuthlibInjectorAccount extends YggdrasilAccount {
|
||||||
private final String serverBaseURL;
|
private final AuthlibInjectorServer server;
|
||||||
private final ExceptionalSupplier<String, ?> injectorJarPath;
|
private final ExceptionalSupplier<String, ?> injectorJarPath;
|
||||||
|
|
||||||
protected AuthlibInjectorAccount(YggdrasilService service, String serverBaseURL, ExceptionalSupplier<String, ?> injectorJarPath, String username, UUID characterUUID, YggdrasilSession session) {
|
protected AuthlibInjectorAccount(YggdrasilService service, AuthlibInjectorServer server, ExceptionalSupplier<String, ?> injectorJarPath, String username, UUID characterUUID, YggdrasilSession session) {
|
||||||
super(service, username, characterUUID, session);
|
super(service, username, characterUUID, session);
|
||||||
|
|
||||||
this.injectorJarPath = injectorJarPath;
|
this.injectorJarPath = injectorJarPath;
|
||||||
this.serverBaseURL = serverBaseURL;
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,7 +59,7 @@ public class AuthlibInjectorAccount extends YggdrasilAccount {
|
|||||||
|
|
||||||
private AuthInfo inject(ExceptionalSupplier<AuthInfo, AuthenticationException> supplier) throws AuthenticationException {
|
private AuthInfo inject(ExceptionalSupplier<AuthInfo, AuthenticationException> supplier) throws AuthenticationException {
|
||||||
// Authlib Injector recommends launchers to pre-fetch the server basic information before launched the game to save time.
|
// Authlib Injector recommends launchers to pre-fetch the server basic information before launched the game to save time.
|
||||||
GetTask getTask = new GetTask(NetworkUtils.toURL(serverBaseURL));
|
GetTask getTask = new GetTask(NetworkUtils.toURL(server.getUrl()));
|
||||||
AtomicBoolean flag = new AtomicBoolean(true);
|
AtomicBoolean flag = new AtomicBoolean(true);
|
||||||
Thread thread = Lang.thread(() -> flag.set(getTask.test()));
|
Thread thread = Lang.thread(() -> flag.set(getTask.test()));
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ public class AuthlibInjectorAccount extends YggdrasilAccount {
|
|||||||
try {
|
try {
|
||||||
thread.join();
|
thread.join();
|
||||||
|
|
||||||
Arguments arguments = new Arguments().addJVMArguments("-javaagent:" + injectorJarPath.get() + "=" + serverBaseURL);
|
Arguments arguments = new Arguments().addJVMArguments("-javaagent:" + injectorJarPath.get() + "=" + server.getUrl());
|
||||||
|
|
||||||
if (flag.get())
|
if (flag.get())
|
||||||
arguments = arguments.addJVMArguments("-Dorg.to2mbn.authlibinjector.config.prefetched=" + new String(Base64.getEncoder().encode(getTask.getResult().getBytes()), UTF_8));
|
arguments = arguments.addJVMArguments("-Dorg.to2mbn.authlibinjector.config.prefetched=" + new String(Base64.getEncoder().encode(getTask.getResult().getBytes()), UTF_8));
|
||||||
@ -81,12 +81,12 @@ public class AuthlibInjectorAccount extends YggdrasilAccount {
|
|||||||
@Override
|
@Override
|
||||||
public Map<Object, Object> toStorage() {
|
public Map<Object, Object> toStorage() {
|
||||||
Map<Object, Object> map = super.toStorage();
|
Map<Object, Object> map = super.toStorage();
|
||||||
map.put("serverBaseURL", serverBaseURL);
|
map.put("serverBaseURL", server.getUrl());
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServerBaseURL() {
|
public AuthlibInjectorServer getServer() {
|
||||||
return serverBaseURL;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class AuthlibInjectorAccountFactory extends AccountFactory<AuthlibInjecto
|
|||||||
AuthlibInjectorServer server = serverLookup.apply((String) apiRoot);
|
AuthlibInjectorServer server = serverLookup.apply((String) apiRoot);
|
||||||
|
|
||||||
AuthlibInjectorAccount account = new AuthlibInjectorAccount(new YggdrasilService(new AuthlibInjectorProvider(server.getUrl()), proxy),
|
AuthlibInjectorAccount account = new AuthlibInjectorAccount(new YggdrasilService(new AuthlibInjectorProvider(server.getUrl()), proxy),
|
||||||
server.getUrl(), injectorJarPathSupplier, username, null, null);
|
server, injectorJarPathSupplier, username, null, null);
|
||||||
account.logInWithPassword(password, selector);
|
account.logInWithPassword(password, selector);
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
@ -60,6 +60,6 @@ public class AuthlibInjectorAccountFactory extends AccountFactory<AuthlibInjecto
|
|||||||
AuthlibInjectorServer server = serverLookup.apply(apiRoot);
|
AuthlibInjectorServer server = serverLookup.apply(apiRoot);
|
||||||
|
|
||||||
return new AuthlibInjectorAccount(new YggdrasilService(new AuthlibInjectorProvider(server.getUrl()), proxy),
|
return new AuthlibInjectorAccount(new YggdrasilService(new AuthlibInjectorProvider(server.getUrl()), proxy),
|
||||||
server.getUrl(), injectorJarPathSupplier, username, session.getSelectedProfile().getId(), session);
|
server, injectorJarPathSupplier, username, session.getSelectedProfile().getId(), session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user