mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-04-06 18:20:26 +08:00
each authenticator has its own username now
This commit is contained in:
parent
b82243a9c0
commit
a62848d4fa
2
.gitignore
vendored
2
.gitignore
vendored
@ -22,6 +22,6 @@ hs_err_pid*
|
||||
|
||||
HMCLAPI/build/
|
||||
HMCL/build/
|
||||
HMCL/src/main/org/jackhuang/hellominecraft/launcher/servers/
|
||||
HMCLServer/
|
||||
HMCSM/build/
|
||||
MetroLookAndFeel/build/
|
||||
|
@ -48,13 +48,17 @@ public class DefaultPlugin implements IPlugin {
|
||||
public void onRegisterAuthenticators(Consumer<IAuthenticator> apply) {
|
||||
String clientToken = Settings.getInstance().getClientToken();
|
||||
OFFLINE_LOGIN = new OfflineAuthenticator(clientToken);
|
||||
OFFLINE_LOGIN.onLoadSettings(Settings.getInstance().getAuthenticatorConfig(OFFLINE_LOGIN.id()));
|
||||
YGGDRASIL_LOGIN = new YggdrasilAuthenticator(clientToken);
|
||||
YGGDRASIL_LOGIN.onLoadSettings(Settings.getInstance().getYggdrasilConfig());
|
||||
YGGDRASIL_LOGIN.onLoadSettings(Settings.getInstance().getAuthenticatorConfig(YGGDRASIL_LOGIN.id()));
|
||||
SKINME_LOGIN = new SkinmeAuthenticator(clientToken);
|
||||
SKINME_LOGIN.onLoadSettings(Settings.getInstance().getAuthenticatorConfig(SKINME_LOGIN.id()));
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(()
|
||||
-> Settings.getInstance().setYggdrasilConfig(YGGDRASIL_LOGIN.onSaveSettings())
|
||||
));
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
Settings.getInstance().setAuthenticatorConfig(OFFLINE_LOGIN.id(), OFFLINE_LOGIN.onSaveSettings());
|
||||
Settings.getInstance().setAuthenticatorConfig(YGGDRASIL_LOGIN.id(), YGGDRASIL_LOGIN.onSaveSettings());
|
||||
Settings.getInstance().setAuthenticatorConfig(SKINME_LOGIN.id(), SKINME_LOGIN.onSaveSettings());
|
||||
}));
|
||||
apply.accept(OFFLINE_LOGIN);
|
||||
apply.accept(YGGDRASIL_LOGIN);
|
||||
apply.accept(SKINME_LOGIN);
|
||||
@ -62,7 +66,7 @@ public class DefaultPlugin implements IPlugin {
|
||||
|
||||
@Override
|
||||
public void showUI() {
|
||||
MainFrame.showMainFrame(Settings.isFirstLoading());
|
||||
MainFrame.showMainFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,6 +36,7 @@ import org.jackhuang.hellominecraft.launcher.version.MinecraftLibrary;
|
||||
import org.jackhuang.hellominecraft.tasks.TaskWindow;
|
||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.utils.MessageBox;
|
||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -67,7 +68,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
|
||||
res.add((v.isCanceledWrapper() ? "" : "-mainClass=") + mainClass);
|
||||
|
||||
String arg = v.getSelectedMinecraftVersion().minecraftArguments;
|
||||
String[] splitted = org.jackhuang.hellominecraft.utils.StrUtils.tokenize(arg);
|
||||
String[] splitted = StrUtils.tokenize(arg);
|
||||
|
||||
if (!checkAssetsExist())
|
||||
if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) {
|
||||
|
@ -20,6 +20,7 @@ package org.jackhuang.hellominecraft.launcher.settings;
|
||||
import org.jackhuang.hellominecraft.launcher.utils.download.DownloadType;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
@ -40,8 +41,6 @@ public final class Config {
|
||||
private String last;
|
||||
@SerializedName("bgpath")
|
||||
private String bgpath;
|
||||
@SerializedName("username")
|
||||
private String username;
|
||||
@SerializedName("clientToken")
|
||||
private final String clientToken;
|
||||
private String proxyHost, proxyPort, proxyUserName, proxyPassword;
|
||||
@ -116,15 +115,6 @@ public final class Config {
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
public String getClientToken() {
|
||||
return clientToken;
|
||||
}
|
||||
@ -163,12 +153,12 @@ public final class Config {
|
||||
return configurations;
|
||||
}
|
||||
|
||||
public Map getYggdrasilConfig() {
|
||||
return yggdrasil;
|
||||
public Map getAuthenticatorConfig(String authId) {
|
||||
return auth.get(authId);
|
||||
}
|
||||
|
||||
public void setYggdrasilConfig(Map yggdrasil) {
|
||||
this.yggdrasil = yggdrasil;
|
||||
public void setAuthenticatorConfig(String authId, Map map) {
|
||||
auth.put(authId, map);
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
@ -178,17 +168,17 @@ public final class Config {
|
||||
private int downloadtype;
|
||||
@SerializedName("configurations")
|
||||
private TreeMap<String, Profile> configurations;
|
||||
@SerializedName("yggdrasil")
|
||||
private Map yggdrasil;
|
||||
@SerializedName("auth")
|
||||
private Map<String, Map> auth;
|
||||
|
||||
public Config() {
|
||||
clientToken = UUID.randomUUID().toString();
|
||||
username = "";
|
||||
logintype = downloadtype = 0;
|
||||
enableShadow = false;
|
||||
enableAnimation = true;
|
||||
theme = 4;
|
||||
decorated = OS.os() == OS.LINUX;
|
||||
auth = new HashMap<>();
|
||||
}
|
||||
|
||||
public DownloadType getDownloadSource() {
|
||||
|
@ -32,7 +32,6 @@ import org.jackhuang.hellominecraft.utils.CollectionUtils;
|
||||
import org.jackhuang.hellominecraft.utils.system.FileUtils;
|
||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||
import org.jackhuang.hellominecraft.utils.MessageBox;
|
||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||
import org.jackhuang.hellominecraft.utils.UpdateChecker;
|
||||
import org.jackhuang.hellominecraft.utils.VersionNumber;
|
||||
import org.jackhuang.hellominecraft.utils.system.Java;
|
||||
@ -48,7 +47,6 @@ public final class Settings {
|
||||
|
||||
public static final File SETTINGS_FILE = new File(IOUtils.currentDir(), "hmcl.json");
|
||||
|
||||
private static boolean isFirstLoading;
|
||||
private static final Config SETTINGS;
|
||||
public static final UpdateChecker UPDATE_CHECKER = new UpdateChecker(new VersionNumber(Main.VERSION_FIRST, Main.VERSION_SECOND, Main.VERSION_THIRD),
|
||||
"hmcl");
|
||||
@ -58,10 +56,6 @@ public final class Settings {
|
||||
return SETTINGS;
|
||||
}
|
||||
|
||||
public static boolean isFirstLoading() {
|
||||
return isFirstLoading;
|
||||
}
|
||||
|
||||
static {
|
||||
SETTINGS = initSettings();
|
||||
if (!getProfiles().containsKey(DEFAULT_PROFILE))
|
||||
@ -82,7 +76,7 @@ public final class Settings {
|
||||
|
||||
private static Config initSettings() {
|
||||
Config c = new Config();
|
||||
if (SETTINGS_FILE.exists()) {
|
||||
if (SETTINGS_FILE.exists())
|
||||
try {
|
||||
String str = FileUtils.readFileToString(SETTINGS_FILE);
|
||||
if (str == null || str.trim().equals(""))
|
||||
@ -100,11 +94,8 @@ public final class Settings {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
isFirstLoading = StrUtils.isBlank(c.getUsername());
|
||||
} else {
|
||||
else
|
||||
HMCLog.log("No settings file here, may be first loading.");
|
||||
isFirstLoading = true;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,11 @@ public final class BestLogin extends IAuthenticator {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "best";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "BestLogin";
|
||||
|
@ -18,7 +18,9 @@
|
||||
package org.jackhuang.hellominecraft.launcher.utils.auth;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
|
||||
|
||||
/**
|
||||
@ -34,7 +36,7 @@ public abstract class IAuthenticator {
|
||||
PluginManager.NOW_PLUGIN.onRegisterAuthenticators(LOGINS::add);
|
||||
}
|
||||
|
||||
protected String clientToken;
|
||||
protected String clientToken, username;
|
||||
|
||||
public IAuthenticator(String clientToken) {
|
||||
this.clientToken = clientToken;
|
||||
@ -52,6 +54,8 @@ public abstract class IAuthenticator {
|
||||
*/
|
||||
public abstract UserProfileProvider login(LoginInfo info) throws AuthenticationException;
|
||||
|
||||
public abstract String id();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the name of login method.
|
||||
@ -78,4 +82,24 @@ public abstract class IAuthenticator {
|
||||
public abstract UserProfileProvider loginBySettings() throws AuthenticationException;
|
||||
|
||||
public abstract void logout();
|
||||
|
||||
public Map onSaveSettings() {
|
||||
HashMap m = new HashMap();
|
||||
m.put("IAuthenticator_UserName", username);
|
||||
return m;
|
||||
}
|
||||
|
||||
public void onLoadSettings(Map m) {
|
||||
if (m == null)
|
||||
return;
|
||||
username = (String) m.get("IAuthenticator_UserName");
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String s) {
|
||||
username = s;
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,11 @@ public final class OfflineAuthenticator extends IAuthenticator {
|
||||
return DigestUtils.md5Hex(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "offline";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return C.i18n("login.methods.offline");
|
||||
|
@ -104,6 +104,11 @@ public final class SkinmeAuthenticator extends IAuthenticator {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "skinme";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Skinme";
|
||||
|
@ -92,16 +92,26 @@ public final class YggdrasilAuthenticator extends IAuthenticator {
|
||||
return ua.isLoggedIn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return "yggdrasil";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return C.i18n("login.methods.yggdrasil");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map onSaveSettings() {
|
||||
return ua.saveForStorage();
|
||||
Map m = ua.saveForStorage();
|
||||
m.putAll(super.onSaveSettings());
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadSettings(Map settings) {
|
||||
super.onLoadSettings(settings);
|
||||
if (settings == null)
|
||||
return;
|
||||
ua.loadFromStorage(settings);
|
||||
|
@ -1241,7 +1241,7 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
||||
// <editor-fold defaultstate="collapsed" desc="Mods">
|
||||
private boolean reloadingMods = false;
|
||||
|
||||
private void reloadMods() {
|
||||
private synchronized void reloadMods() {
|
||||
if (reloadingMods)
|
||||
return;
|
||||
reloadingMods = true;
|
||||
@ -1343,6 +1343,6 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget
|
||||
private javax.swing.JTextField txtWidth;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
private javax.swing.JPanel pnlGameDownloads;
|
||||
private final javax.swing.JPanel pnlGameDownloads;
|
||||
// </editor-fold>
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ import org.jackhuang.hellominecraft.launcher.settings.Settings;
|
||||
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
|
||||
import org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils;
|
||||
import org.jackhuang.hellominecraft.lookandfeel.Theme;
|
||||
import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||
import org.jackhuang.hellominecraft.utils.Utils;
|
||||
import org.jackhuang.hellominecraft.views.DropShadowBorder;
|
||||
import org.jackhuang.hellominecraft.views.TintablePanel;
|
||||
@ -388,10 +389,10 @@ public final class MainFrame extends DraggableFrame {
|
||||
windowTitle.setForeground(Color.white);
|
||||
}
|
||||
|
||||
public static void showMainFrame(boolean firstLoad) {
|
||||
if (firstLoad)
|
||||
SwingUtilities.invokeLater(() -> MainFrame.INSTANCE.showMessage(C.i18n("ui.message.first_load")));
|
||||
public static void showMainFrame() {
|
||||
IAuthenticator l = Settings.getInstance().getAuthenticator();
|
||||
if (StrUtils.isBlank(l.getUsername()))
|
||||
SwingUtilities.invokeLater(() -> MainFrame.INSTANCE.showMessage(C.i18n("ui.message.first_load")));
|
||||
if (l.hasPassword() && !l.isLoggedIn())
|
||||
SwingUtilities.invokeLater(() -> MainFrame.INSTANCE.showMessage(C.i18n("ui.message.enter_password")));
|
||||
INSTANCE.setVisible(true);
|
||||
|
@ -297,7 +297,8 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
}//GEN-LAST:event_txtPlayerNameFocusGained
|
||||
|
||||
private void txtPlayerNameFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtPlayerNameFocusLost
|
||||
Settings.getInstance().setUsername(txtPlayerName.getText());
|
||||
IAuthenticator l = Settings.getInstance().getAuthenticator();
|
||||
l.setUsername(txtPlayerName.getText());
|
||||
}//GEN-LAST:event_txtPlayerNameFocusLost
|
||||
|
||||
private void cboLoginModeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboLoginModeItemStateChanged
|
||||
@ -350,8 +351,8 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
|
||||
private void txtPlayerNameKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPlayerNameKeyPressed
|
||||
if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
Settings.getInstance().setUsername(txtPlayerName.getText());
|
||||
IAuthenticator l = Settings.getInstance().getAuthenticator();
|
||||
l.setUsername(txtPlayerName.getText());
|
||||
if (!l.hasPassword())
|
||||
runGame();
|
||||
else if (!l.isLoggedIn())
|
||||
@ -400,7 +401,7 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
return;
|
||||
}
|
||||
final IAuthenticator l = IAuthenticator.LOGINS.get(index);
|
||||
final LoginInfo li = new LoginInfo(Settings.getInstance().getUsername(), l.isLoggedIn() || !l.hasPassword() ? null : new String(txtPassword.getPassword()));
|
||||
final LoginInfo li = new LoginInfo(l.getUsername(), l.isLoggedIn() || !l.hasPassword() ? null : new String(txtPassword.getPassword()));
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -458,9 +459,10 @@ public class MainPagePanel extends AnimatedPanel implements Event<String> {
|
||||
cl.last(pnlPassword);
|
||||
else
|
||||
cl.first(pnlPassword);
|
||||
String username = Settings.getInstance().getUsername();
|
||||
if (StrUtils.isNotBlank(username))
|
||||
txtPlayerName.setText(username);
|
||||
String username = l.getUsername();
|
||||
if (username == null)
|
||||
username = "";
|
||||
txtPlayerName.setText(username);
|
||||
}
|
||||
|
||||
void loadFromSettings() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user