use of com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload in project Krothium-Launcher by DarkLBP.
the class YggdrasilMinecraftSessionService method fetchCustomTextures.
public Map<Type, MinecraftProfileTexture> fetchCustomTextures(GameProfile profile, boolean requireSecure) {
if (cache.containsKey(profile.getName())) {
System.out.println("Serving cached textures for: " + profile.getName() + " / " + profile.getId());
return cache.get(profile.getName());
} else {
try {
System.out.println("Serving textures for: " + profile.getName() + " / " + profile.getId());
JSONArray users = new JSONArray();
users.put(profile.getName());
byte[] data = users.toString().getBytes();
String profileID = null;
String response = Utils.sendPost(GET_PROFILESID, data, new HashMap<String, String>());
JSONArray rdata = new JSONArray(response);
if (rdata.length() == 1) {
JSONObject user = rdata.getJSONObject(0);
if (user.has("id")) {
profileID = user.getString("id");
System.out.println("Found user " + profile.getName() + " on Krothium server.");
}
} else {
System.out.println("No textures found on Krothium for " + profile.getName() + ". Searching in Mojang server...");
HashMap<String, String> params = new HashMap<>();
params.put("Content-Type", "application/json");
response = Utils.sendPost(GET_PROFILESID_MOJANG, data, params);
rdata = new JSONArray(response);
if (rdata.length() == 1) {
JSONObject user = rdata.getJSONObject(0);
if (user.has("id")) {
profileID = user.getString("id");
System.out.println("Found user " + profile.getName() + " on Mojang server.");
}
}
}
if (profileID != null) {
JSONObject profileData = new JSONObject(Utils.readURL("https://sessionserver.mojang.com/session/minecraft/profile/" + profileID + "?unsigned=" + !requireSecure));
if (profileData.has("properties")) {
JSONArray properties = profileData.getJSONArray("properties");
if (properties.length() == 1) {
JSONObject property = properties.getJSONObject(0);
if (property.has("name") && property.has("value")) {
if (property.getString("name").equals("textures") && !property.getString("value").isEmpty()) {
String textures = new String(Base64.decodeBase64(property.getString("value")), Charsets.UTF_8);
MinecraftTexturesPayload result = this.gson.fromJson(textures, MinecraftTexturesPayload.class);
cache.put(profile.getName(), result.getTextures());
System.out.println("Found textures for " + profile.getName() + ".");
return result.getTextures();
}
}
}
}
}
} catch (Exception ex) {
System.err.println("Failed to fetch data from profile " + profile.getId() + " with name " + profile.getName());
}
}
System.out.println("No textures found for " + profile.getName());
return new HashMap();
}
use of com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload in project Krothium-Launcher by DarkLBP.
the class YggdrasilMinecraftSessionService method getTextures.
public Map<Type, MinecraftProfileTexture> getTextures(GameProfile profile, boolean requireSecure) {
Property textureProperty = (Property) Iterables.getFirst(profile.getProperties().get("textures"), (Object) null);
if (textureProperty == null) {
return fetchCustomTextures(profile, requireSecure);
} else {
MinecraftTexturesPayload result;
try {
String json = new String(Base64.decodeBase64(textureProperty.getValue()), Charsets.UTF_8);
result = (MinecraftTexturesPayload) this.gson.fromJson(json, MinecraftTexturesPayload.class);
} catch (JsonParseException var7) {
LOGGER.error("Could not decode textures payload", var7);
return new HashMap();
}
if (result != null && result.getTextures() != null) {
Iterator var8 = result.getTextures().entrySet().iterator();
Map.Entry entry;
do {
if (!var8.hasNext()) {
return result.getTextures();
}
entry = (Map.Entry) var8.next();
} while (isWhitelistedDomain(((MinecraftProfileTexture) entry.getValue()).getUrl()));
LOGGER.error("Textures payload has been tampered with (non-whitelisted domain)");
return new HashMap();
} else {
return new HashMap();
}
}
}
Aggregations