mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2024-12-25 17:08:23 +01:00
Don't refresh all accounts on startup
This commit is contained in:
parent
bf9aba1f8c
commit
68d4a4b72d
@ -45,7 +45,6 @@ import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyChannelInitializer;
|
||||
import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyHandler;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
import net.raphimc.viaproxy.saves.SaveManager;
|
||||
import net.raphimc.viaproxy.tasks.AccountRefreshTask;
|
||||
import net.raphimc.viaproxy.tasks.LoaderTask;
|
||||
import net.raphimc.viaproxy.tasks.UpdateCheckTask;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyUI;
|
||||
@ -124,18 +123,15 @@ public class ViaProxy {
|
||||
PluginManager.EVENT_MANAGER.register(EventListener.class);
|
||||
|
||||
Thread loaderThread = new Thread(new LoaderTask(), "ViaLoader");
|
||||
Thread accountRefreshThread = new Thread(new AccountRefreshTask(saveManager), "AccountRefresh");
|
||||
Thread updateCheckThread = new Thread(new UpdateCheckTask(hasUI), "UpdateCheck");
|
||||
|
||||
if (hasUI) {
|
||||
loaderThread.start();
|
||||
accountRefreshThread.start();
|
||||
SwingUtilities.invokeLater(() -> ui = new ViaProxyUI());
|
||||
if (System.getProperty("skipUpdateCheck") == null) {
|
||||
updateCheckThread.start();
|
||||
}
|
||||
loaderThread.join();
|
||||
accountRefreshThread.join();
|
||||
while (ui == null) {
|
||||
Logger.LOGGER.info("Waiting for UI to be initialized...");
|
||||
Thread.sleep(1000);
|
||||
|
@ -59,17 +59,19 @@ public class ExternalInterface {
|
||||
Logger.u_info("auth", proxyConnection.getC2P().remoteAddress(), proxyConnection.getGameProfile(), "Filling player data");
|
||||
try {
|
||||
if (Options.MC_ACCOUNT != null) {
|
||||
synchronized (ViaProxy.saveManager.accountsSave) {
|
||||
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
|
||||
Options.MC_ACCOUNT.refresh(httpClient);
|
||||
}
|
||||
ViaProxy.saveManager.save();
|
||||
}
|
||||
|
||||
proxyConnection.setGameProfile(Options.MC_ACCOUNT.getGameProfile());
|
||||
final UserConnection user = proxyConnection.getUserConnection();
|
||||
|
||||
if (Options.CHAT_SIGNING && proxyConnection.getServerVersion().isNewerThanOrEqualTo(VersionEnum.r1_19) && Options.MC_ACCOUNT instanceof MicrosoftAccount) {
|
||||
final MicrosoftAccount microsoftAccount = (MicrosoftAccount) Options.MC_ACCOUNT;
|
||||
synchronized (ViaProxy.saveManager.accountsSave) {
|
||||
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
|
||||
microsoftAccount.refreshRuntimeData(httpClient);
|
||||
}
|
||||
ViaProxy.saveManager.accountsSave.save();
|
||||
}
|
||||
|
||||
final StepPlayerCertificates.PlayerCertificates playerCertificates = microsoftAccount.getPlayerCertificates();
|
||||
final Instant expiresAt = Instant.ofEpochMilli(playerCertificates.expireTimeMs());
|
||||
final long expiresAtMillis = playerCertificates.expireTimeMs();
|
||||
@ -90,12 +92,6 @@ public class ExternalInterface {
|
||||
user.put(new ChatSession1_19_3(user, uuid, privateKey, new ProfileKey(expiresAtMillis, publicKeyBytes, keySignature)));
|
||||
} else if (proxyConnection.getServerVersion().equals(VersionEnum.bedrockLatest) && Options.MC_ACCOUNT instanceof BedrockAccount) {
|
||||
final BedrockAccount bedrockAccount = (BedrockAccount) Options.MC_ACCOUNT;
|
||||
synchronized (ViaProxy.saveManager.accountsSave) {
|
||||
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
|
||||
bedrockAccount.refreshRuntimeData(httpClient);
|
||||
}
|
||||
ViaProxy.saveManager.accountsSave.save();
|
||||
}
|
||||
final StepMCChain.MCChain mcChain = bedrockAccount.getMcChain();
|
||||
|
||||
final UUID deviceId = mcChain.prevResult().initialXblSession().prevResult2().id();
|
||||
@ -107,7 +103,7 @@ public class ExternalInterface {
|
||||
PluginManager.EVENT_MANAGER.call(new FillPlayerDataEvent(proxyConnection));
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Failed to fill player data", e);
|
||||
proxyConnection.kickClient("§cFailed to fill player data. This might be caused by outdated account tokens. Please restart ViaProxy and try again.");
|
||||
proxyConnection.kickClient("§cFailed to fill player data. This might be caused by outdated account tokens or rate limits. Wait a couple of seconds and try again. If the problem persists, remove and re-add your account.");
|
||||
}
|
||||
|
||||
proxyConnection.getLoginHelloPacket().name = proxyConnection.getGameProfile().getName();
|
||||
@ -131,6 +127,7 @@ public class ExternalInterface {
|
||||
try {
|
||||
AuthLibServices.SESSION_SERVICE.joinServer(Options.MC_ACCOUNT.getGameProfile(), microsoftAccount.getMcProfile().prevResult().prevResult().access_token(), serverIdHash);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
proxyConnection.kickClient("§cFailed to authenticate with Mojang servers! Please try again later.");
|
||||
}
|
||||
} else {
|
||||
@ -150,7 +147,7 @@ public class ExternalInterface {
|
||||
} catch (TimeoutException e) {
|
||||
proxyConnection.kickClient("§cAuthentication cancelled! You need to install OpenAuthMod in order to join this server.");
|
||||
}
|
||||
} else if (Options.CHAT_SIGNING && Options.MC_ACCOUNT instanceof MicrosoftAccount) {
|
||||
} else if (Options.CHAT_SIGNING) {
|
||||
final UserConnection user = proxyConnection.getUserConnection();
|
||||
if (user.has(ChatSession1_19_0.class)) {
|
||||
final long salt = ThreadLocalRandom.current().nextLong();
|
||||
|
@ -20,12 +20,9 @@ package net.raphimc.viaproxy.saves.impl;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.raphimc.mcauth.util.MicrosoftConstants;
|
||||
import net.raphimc.viaproxy.saves.AbstractSave;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.Account;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.OfflineAccount;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -82,17 +79,6 @@ public class NewAccountsSave extends AbstractSave {
|
||||
this.accounts.remove(account);
|
||||
}
|
||||
|
||||
public void refreshAccounts() {
|
||||
for (Account account : new ArrayList<>(this.accounts)) {
|
||||
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
|
||||
account.refresh(httpClient);
|
||||
} catch (Throwable e) {
|
||||
this.accounts.remove(account);
|
||||
Logger.LOGGER.error("Failed to refresh account " + account.getName() + ", removing it from the list.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Account> getAccounts() {
|
||||
return Collections.unmodifiableList(this.accounts);
|
||||
}
|
||||
|
@ -42,6 +42,4 @@ public abstract class Account {
|
||||
|
||||
public abstract void refresh(final CloseableHttpClient httpClient) throws Throwable;
|
||||
|
||||
public abstract void refreshRuntimeData(final CloseableHttpClient httpClient) throws Throwable;
|
||||
|
||||
}
|
||||
|
@ -82,11 +82,7 @@ public class BedrockAccount extends Account {
|
||||
@Override
|
||||
public void refresh(CloseableHttpClient httpClient) throws Exception {
|
||||
this.mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.refresh(httpClient, this.mcChain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshRuntimeData(CloseableHttpClient httpClient) throws Throwable {
|
||||
this.refresh(httpClient);
|
||||
try {
|
||||
if (this.playFabToken == null) {
|
||||
throw new NullPointerException();
|
||||
|
@ -82,10 +82,7 @@ public class MicrosoftAccount extends Account {
|
||||
@Override
|
||||
public void refresh(CloseableHttpClient httpClient) throws Exception {
|
||||
this.mcProfile = MinecraftAuth.JAVA_DEVICE_CODE_LOGIN.refresh(httpClient, this.mcProfile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshRuntimeData(CloseableHttpClient httpClient) throws Throwable {
|
||||
try {
|
||||
if (this.playerCertificates == null) {
|
||||
throw new NullPointerException();
|
||||
|
@ -65,8 +65,4 @@ public class OfflineAccount extends Account {
|
||||
public void refresh(CloseableHttpClient httpClient) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshRuntimeData(CloseableHttpClient httpClient) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2023 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.viaproxy.tasks;
|
||||
|
||||
import net.raphimc.viaproxy.saves.SaveManager;
|
||||
|
||||
public class AccountRefreshTask implements Runnable {
|
||||
|
||||
private final SaveManager saveManager;
|
||||
|
||||
public AccountRefreshTask(final SaveManager saveManager) {
|
||||
this.saveManager = saveManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.saveManager.accountsSave.refreshAccounts();
|
||||
this.saveManager.save();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user