Updated ViaBedrock usage

This commit is contained in:
RaphiMC 2023-05-31 22:12:27 +02:00
parent fae244e5e5
commit 0613132cb1
No known key found for this signature in database
GPG key ID: 0F6BB0657A03AC94
5 changed files with 42 additions and 16 deletions

View file

@ -106,7 +106,7 @@ dependencies {
include "net.lenni0451:Reflect:1.2.0"
include "net.lenni0451:LambdaEvents:2.0.3"
include "net.raphimc.netminecraft:all:2.3.3"
include("net.raphimc:MinecraftAuth:2.1.3") {
include("net.raphimc:MinecraftAuth:2.1.4-SNAPSHOT") {
exclude group: "com.google.code.gson", module: "gson"
exclude group: "org.slf4j", module: "slf4j-api"
}

View file

@ -117,7 +117,9 @@ public class ExternalInterface {
} else if (Options.MC_ACCOUNT instanceof BedrockAccount && proxyConnection.getServerVersion().equals(VersionEnum.bedrockLatest)) {
final BedrockAccount bedrockAccount = (BedrockAccount) Options.MC_ACCOUNT;
final StepMCChain.MCChain mcChain = bedrockAccount.getMcChain();
user.put(new AuthChainData(user, mcChain.mojangJwt(), mcChain.identityJwt(), mcChain.publicKey(), mcChain.privateKey()));
final UUID deviceId = mcChain.prevResult().initialXblSession().prevResult2().id();
final String playFabId = bedrockAccount.getPlayFabToken().playFabId();
user.put(new AuthChainData(user, mcChain.mojangJwt(), mcChain.identityJwt(), mcChain.publicKey(), mcChain.privateKey(), deviceId, playFabId));
}
}

View file

@ -52,6 +52,8 @@ public class SaveManager {
final JsonObject saveObject = GSON.fromJson(reader, JsonObject.class);
reader.close();
SaveMigrator.migrate(saveObject);
RStream
.of(this)
.fields()
@ -66,8 +68,6 @@ public class SaveManager {
Logger.LOGGER.error("Failed to load save " + save.getName(), e);
}
});
SaveMigrator.migrate(this, saveObject);
} catch (Throwable e) {
Logger.LOGGER.error("Failed to load saves from file", e);
}

View file

@ -17,22 +17,26 @@
*/
package net.raphimc.viaproxy.saves;
import com.google.gson.JsonElement;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.raphimc.mcauth.MinecraftAuth;
import net.raphimc.viaproxy.saves.impl.accounts.BedrockAccount;
import net.raphimc.viaproxy.util.logging.Logger;
public class SaveMigrator {
public static void migrate(final SaveManager saveManager, final JsonObject jsonObject) {
public static void migrate(final JsonObject jsonObject) {
try {
if (jsonObject.has("accounts")) {
for (JsonElement element : jsonObject.getAsJsonArray("accounts")) {
final JsonObject object = element.getAsJsonObject();
if (object.has("is_offline_mode_account") && object.get("is_offline_mode_account").getAsBoolean()) {
saveManager.accountsSave.addAccount(object.get("name").getAsString());
} else {
saveManager.accountsSave.addAccount(MinecraftAuth.JAVA_DEVICE_CODE_LOGIN.fromJson(object));
if (jsonObject.has("new_accounts")) {
final JsonArray accountsArray = jsonObject.getAsJsonArray("new_accounts");
for (int i = 0; i < accountsArray.size(); i++) {
final JsonObject object = accountsArray.get(i).getAsJsonObject();
final String type = object.get("account_type").getAsString();
if (BedrockAccount.class.getName().equals(type) && !object.has("mc_chain")) {
final JsonObject newObject = new JsonObject();
object.remove("account_type");
newObject.add("mc_chain", object);
newObject.addProperty("account_type", type);
accountsArray.set(i, newObject);
}
}
}

View file

@ -20,6 +20,7 @@ package net.raphimc.viaproxy.saves.impl.accounts;
import com.google.gson.JsonObject;
import net.raphimc.mcauth.MinecraftAuth;
import net.raphimc.mcauth.step.bedrock.StepMCChain;
import net.raphimc.mcauth.step.bedrock.playfab.StepPlayFabToken;
import org.apache.http.impl.client.CloseableHttpClient;
import java.util.UUID;
@ -27,9 +28,13 @@ import java.util.UUID;
public class BedrockAccount extends Account {
private StepMCChain.MCChain mcChain;
private StepPlayFabToken.PlayFabToken playFabToken;
public BedrockAccount(final JsonObject jsonObject) throws Throwable {
this.mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.fromJson(jsonObject);
this.mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.fromJson(jsonObject.getAsJsonObject("mc_chain"));
if (jsonObject.has("play_fab_token")) {
this.playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.fromJson(jsonObject.getAsJsonObject("play_fab_token"));
}
}
public BedrockAccount(final StepMCChain.MCChain mcChain) {
@ -38,7 +43,10 @@ public class BedrockAccount extends Account {
@Override
public JsonObject toJson() {
return this.mcChain.toJson();
final JsonObject jsonObject = new JsonObject();
jsonObject.add("mc_chain", this.mcChain.toJson());
jsonObject.add("play_fab_token", this.playFabToken.toJson());
return jsonObject;
}
@Override
@ -55,6 +63,10 @@ public class BedrockAccount extends Account {
return this.mcChain;
}
public StepPlayFabToken.PlayFabToken getPlayFabToken() {
return this.playFabToken;
}
@Override
public String getDisplayString() {
return this.getName() + " (Bedrock)";
@ -63,6 +75,14 @@ public class BedrockAccount extends Account {
@Override
public void refresh(CloseableHttpClient httpClient) throws Exception {
this.mcChain = MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.refresh(httpClient, this.mcChain);
try {
if (this.playFabToken == null) {
throw new NullPointerException();
}
this.playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.refresh(httpClient, this.playFabToken);
} catch (Throwable e) {
this.playFabToken = MinecraftAuth.BEDROCK_PLAY_FAB_TOKEN.getFromInput(httpClient, this.mcChain.prevResult().fullXblSession());
}
}
}