mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2025-01-12 20:00:57 +01:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
a0e1732bb9
@ -24,7 +24,6 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import net.raphimc.mcauth.step.bedrock.StepMCChain;
|
import net.raphimc.mcauth.step.bedrock.StepMCChain;
|
||||||
import net.raphimc.mcauth.step.java.StepPlayerCertificates;
|
import net.raphimc.mcauth.step.java.StepPlayerCertificates;
|
||||||
import net.raphimc.mcauth.util.MicrosoftConstants;
|
|
||||||
import net.raphimc.netminecraft.packet.PacketTypes;
|
import net.raphimc.netminecraft.packet.PacketTypes;
|
||||||
import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket1_19_3;
|
import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket1_19_3;
|
||||||
import net.raphimc.netminecraft.packet.impl.login.C2SLoginKeyPacket1_19;
|
import net.raphimc.netminecraft.packet.impl.login.C2SLoginKeyPacket1_19;
|
||||||
@ -41,7 +40,6 @@ import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
|||||||
import net.raphimc.viaproxy.saves.impl.accounts.BedrockAccount;
|
import net.raphimc.viaproxy.saves.impl.accounts.BedrockAccount;
|
||||||
import net.raphimc.viaproxy.saves.impl.accounts.MicrosoftAccount;
|
import net.raphimc.viaproxy.saves.impl.accounts.MicrosoftAccount;
|
||||||
import net.raphimc.viaproxy.util.logging.Logger;
|
import net.raphimc.viaproxy.util.logging.Logger;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
|
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
@ -59,12 +57,7 @@ public class ExternalInterface {
|
|||||||
Logger.u_info("auth", proxyConnection.getC2P().remoteAddress(), proxyConnection.getGameProfile(), "Filling player data");
|
Logger.u_info("auth", proxyConnection.getC2P().remoteAddress(), proxyConnection.getGameProfile(), "Filling player data");
|
||||||
try {
|
try {
|
||||||
if (Options.MC_ACCOUNT != null) {
|
if (Options.MC_ACCOUNT != null) {
|
||||||
synchronized (ViaProxy.saveManager.accountsSave) {
|
ViaProxy.saveManager.accountsSave.ensureRefreshed(Options.MC_ACCOUNT);
|
||||||
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
|
|
||||||
Options.MC_ACCOUNT.refresh(httpClient);
|
|
||||||
}
|
|
||||||
ViaProxy.saveManager.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
proxyConnection.setGameProfile(Options.MC_ACCOUNT.getGameProfile());
|
proxyConnection.setGameProfile(Options.MC_ACCOUNT.getGameProfile());
|
||||||
final UserConnection user = proxyConnection.getUserConnection();
|
final UserConnection user = proxyConnection.getUserConnection();
|
||||||
@ -127,8 +120,7 @@ public class ExternalInterface {
|
|||||||
try {
|
try {
|
||||||
AuthLibServices.SESSION_SERVICE.joinServer(Options.MC_ACCOUNT.getGameProfile(), microsoftAccount.getMcProfile().prevResult().prevResult().access_token(), serverIdHash);
|
AuthLibServices.SESSION_SERVICE.joinServer(Options.MC_ACCOUNT.getGameProfile(), microsoftAccount.getMcProfile().prevResult().prevResult().access_token(), serverIdHash);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
proxyConnection.kickClient("§cFailed to authenticate with Mojang servers! Please try again in a couple of seconds.");
|
||||||
proxyConnection.kickClient("§cFailed to authenticate with Mojang servers! Please try again later.");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
proxyConnection.kickClient("§cThis server is in online mode and requires a valid authentication mode.");
|
proxyConnection.kickClient("§cThis server is in online mode and requires a valid authentication mode.");
|
||||||
|
@ -20,9 +20,12 @@ package net.raphimc.viaproxy.saves.impl;
|
|||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import net.raphimc.mcauth.util.MicrosoftConstants;
|
||||||
|
import net.raphimc.viaproxy.ViaProxy;
|
||||||
import net.raphimc.viaproxy.saves.AbstractSave;
|
import net.raphimc.viaproxy.saves.AbstractSave;
|
||||||
import net.raphimc.viaproxy.saves.impl.accounts.Account;
|
import net.raphimc.viaproxy.saves.impl.accounts.Account;
|
||||||
import net.raphimc.viaproxy.saves.impl.accounts.OfflineAccount;
|
import net.raphimc.viaproxy.saves.impl.accounts.OfflineAccount;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -49,7 +52,7 @@ public class NewAccountsSave extends AbstractSave {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonElement save() throws Throwable {
|
public JsonElement save() {
|
||||||
final JsonArray array = new JsonArray();
|
final JsonArray array = new JsonArray();
|
||||||
for (Account account : this.accounts) {
|
for (Account account : this.accounts) {
|
||||||
final JsonObject jsonObject = account.toJson();
|
final JsonObject jsonObject = account.toJson();
|
||||||
@ -79,6 +82,16 @@ public class NewAccountsSave extends AbstractSave {
|
|||||||
this.accounts.remove(account);
|
this.accounts.remove(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ensureRefreshed(final Account account) throws Throwable {
|
||||||
|
synchronized (this) {
|
||||||
|
try (final CloseableHttpClient httpClient = MicrosoftConstants.createHttpClient()) {
|
||||||
|
if (account.refresh(httpClient)) {
|
||||||
|
ViaProxy.saveManager.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public List<Account> getAccounts() {
|
public List<Account> getAccounts() {
|
||||||
return Collections.unmodifiableList(this.accounts);
|
return Collections.unmodifiableList(this.accounts);
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,12 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public abstract class Account {
|
public abstract class Account {
|
||||||
|
|
||||||
|
private long lastRefresh = 0L;
|
||||||
|
|
||||||
public Account() {
|
public Account() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract JsonObject toJson() throws Throwable;
|
public abstract JsonObject toJson();
|
||||||
|
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
|
|
||||||
@ -40,6 +42,12 @@ public abstract class Account {
|
|||||||
|
|
||||||
public abstract String getDisplayString();
|
public abstract String getDisplayString();
|
||||||
|
|
||||||
public abstract void refresh(final CloseableHttpClient httpClient) throws Throwable;
|
public boolean refresh(final CloseableHttpClient httpClient) throws Exception {
|
||||||
|
if (System.currentTimeMillis() - this.lastRefresh < 10_000L) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.lastRefresh = System.currentTimeMillis();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public class BedrockAccount extends Account {
|
|||||||
private StepMCChain.MCChain mcChain;
|
private StepMCChain.MCChain mcChain;
|
||||||
private StepPlayFabToken.PlayFabToken playFabToken;
|
private StepPlayFabToken.PlayFabToken playFabToken;
|
||||||
|
|
||||||
public BedrockAccount(final JsonObject jsonObject) throws Throwable {
|
public BedrockAccount(final JsonObject jsonObject) throws Exception {
|
||||||
this.mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.fromJson(jsonObject.getAsJsonObject("mc_chain"));
|
this.mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.fromJson(jsonObject.getAsJsonObject("mc_chain"));
|
||||||
if (jsonObject.has("play_fab_token")) {
|
if (jsonObject.has("play_fab_token")) {
|
||||||
try {
|
try {
|
||||||
@ -80,7 +80,9 @@ public class BedrockAccount extends Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh(CloseableHttpClient httpClient) throws Exception {
|
public boolean refresh(CloseableHttpClient httpClient) throws Exception {
|
||||||
|
if (!super.refresh(httpClient)) return false;
|
||||||
|
|
||||||
this.mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.refresh(httpClient, this.mcChain);
|
this.mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.refresh(httpClient, this.mcChain);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -92,6 +94,8 @@ public class BedrockAccount extends Account {
|
|||||||
this.playFabToken = null;
|
this.playFabToken = null;
|
||||||
this.playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.getFromInput(httpClient, this.mcChain.prevResult().fullXblSession());
|
this.playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.getFromInput(httpClient, this.mcChain.prevResult().fullXblSession());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,9 @@ public class MicrosoftAccount extends Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh(CloseableHttpClient httpClient) throws Exception {
|
public boolean refresh(CloseableHttpClient httpClient) throws Exception {
|
||||||
|
if (!super.refresh(httpClient)) return false;
|
||||||
|
|
||||||
this.mcProfile = MinecraftAuth.JAVA_DEVICE_CODE_LOGIN.refresh(httpClient, this.mcProfile);
|
this.mcProfile = MinecraftAuth.JAVA_DEVICE_CODE_LOGIN.refresh(httpClient, this.mcProfile);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -92,6 +94,8 @@ public class MicrosoftAccount extends Account {
|
|||||||
this.playerCertificates = null;
|
this.playerCertificates = null;
|
||||||
this.playerCertificates = MinecraftAuth.JAVA_PLAYER_CERTIFICATES.getFromInput(httpClient, this.mcProfile.prevResult().prevResult());
|
this.playerCertificates = MinecraftAuth.JAVA_PLAYER_CERTIFICATES.getFromInput(httpClient, this.mcProfile.prevResult().prevResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,8 @@ public class OfflineAccount extends Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh(CloseableHttpClient httpClient) {
|
public boolean refresh(CloseableHttpClient httpClient) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user