mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-29 15:37:59 +01:00
Ensure skin servers have a valid address (or gateway in the case of legacy)
This commit is contained in:
parent
9a629587ab
commit
b12567b033
7 changed files with 43 additions and 32 deletions
|
@ -242,6 +242,8 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSkinServer(SkinServer skinServer) {
|
public void addSkinServer(SkinServer skinServer) {
|
||||||
|
skinServer.validate();
|
||||||
|
|
||||||
skinServers.add(skinServer);
|
skinServers.add(skinServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,11 @@ import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
import org.apache.logging.log4j.util.Strings;
|
||||||
|
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.exceptions.AuthenticationException;
|
import com.mojang.authlib.exceptions.AuthenticationException;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
@ -20,6 +25,12 @@ import net.minecraft.util.Session;
|
||||||
|
|
||||||
public abstract class AbstractSkinServer implements SkinServer {
|
public abstract class AbstractSkinServer implements SkinServer {
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
protected final String address;
|
||||||
|
|
||||||
|
public AbstractSkinServer(String address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Optional<MinecraftTexturesPayload> loadProfileData(GameProfile profile) {
|
public final Optional<MinecraftTexturesPayload> loadProfileData(GameProfile profile) {
|
||||||
|
@ -40,8 +51,21 @@ public abstract class AbstractSkinServer implements SkinServer {
|
||||||
}, HDSkinManager.skinUploadExecutor);
|
}, HDSkinManager.skinUploadExecutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() throws JsonParseException {
|
||||||
|
if (Strings.isBlank(address)) {
|
||||||
|
throw new JsonParseException("Address was not specified.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract MinecraftTexturesPayload getProfileData(GameProfile profile);
|
protected abstract MinecraftTexturesPayload getProfileData(GameProfile profile);
|
||||||
|
|
||||||
protected abstract SkinUploadResponse doUpload(Session session, URI image, Type type, Map<String, String> metadata) throws AuthenticationException, IOException;
|
protected abstract SkinUploadResponse doUpload(Session session, URI image, Type type, Map<String, String> metadata) throws AuthenticationException, IOException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new ToStringBuilder(this, IndentedToStringStyle.INSTANCE)
|
||||||
|
.append("address", address)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import org.apache.http.HttpStatus;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableMap.Builder;
|
import com.google.common.collect.ImmutableMap.Builder;
|
||||||
import com.google.gson.annotations.Expose;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.exceptions.AuthenticationException;
|
import com.mojang.authlib.exceptions.AuthenticationException;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||||
|
@ -23,11 +22,8 @@ public class BethlehemSkinServer extends AbstractSkinServer {
|
||||||
|
|
||||||
private static final String SERVER_ID = "7853dfddc358333843ad55a2c7485c4aa0380a51";
|
private static final String SERVER_ID = "7853dfddc358333843ad55a2c7485c4aa0380a51";
|
||||||
|
|
||||||
@Expose
|
public BethlehemSkinServer(String address) {
|
||||||
private final String address;
|
super(address);
|
||||||
|
|
||||||
private BethlehemSkinServer(String address) {
|
|
||||||
this.address = address;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.voxelmodpack.hdskins.skins;
|
package com.voxelmodpack.hdskins.skins;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableMap.Builder;
|
import com.google.common.collect.ImmutableMap.Builder;
|
||||||
import com.google.gson.annotations.Expose;
|
import com.google.gson.annotations.Expose;
|
||||||
|
@ -16,10 +15,10 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.apache.logging.log4j.util.Strings;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -32,23 +31,16 @@ public class LegacySkinServer extends AbstractSkinServer {
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger();
|
private static final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
@Expose
|
|
||||||
private final String address;
|
|
||||||
|
|
||||||
@Expose
|
@Expose
|
||||||
private final String gateway;
|
private final String gateway;
|
||||||
|
|
||||||
public LegacySkinServer(String address, @Nullable String gateway) {
|
public LegacySkinServer(String address, @Nullable String gateway) {
|
||||||
this.address = address;
|
super(address);
|
||||||
this.gateway = gateway;
|
this.gateway = Strings.isBlank(gateway) ? address : gateway;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Type, MinecraftProfileTexture> getPreviewTextures(GameProfile profile) {
|
public Map<Type, MinecraftProfileTexture> getPreviewTextures(GameProfile profile) {
|
||||||
if (Strings.isNullOrEmpty(gateway)) {
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<Type, MinecraftProfileTexture> map = new EnumMap<>(Type.class);
|
Map<Type, MinecraftProfileTexture> map = new EnumMap<>(Type.class);
|
||||||
|
|
||||||
for (Type type : Type.values()) {
|
for (Type type : Type.values()) {
|
||||||
|
@ -105,8 +97,10 @@ public class LegacySkinServer extends AbstractSkinServer {
|
||||||
response = response.substring(7);
|
response = response.substring(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response.equalsIgnoreCase("OK") && !response.endsWith("OK"))
|
if (!response.equalsIgnoreCase("OK") && !response.endsWith("OK")) {
|
||||||
throw new IOException(response);
|
throw new IOException(response);
|
||||||
|
}
|
||||||
|
|
||||||
return new SkinUploadResponse(response);
|
return new SkinUploadResponse(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.voxelmodpack.hdskins.skins;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.exceptions.AuthenticationException;
|
import com.mojang.authlib.exceptions.AuthenticationException;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
@ -39,6 +40,8 @@ public interface SkinServer extends Exposable {
|
||||||
|
|
||||||
CompletableFuture<SkinUploadResponse> uploadSkin(Session session, @Nullable URI image, MinecraftProfileTexture.Type type, Map<String, String> metadata);
|
CompletableFuture<SkinUploadResponse> uploadSkin(Session session, @Nullable URI image, MinecraftProfileTexture.Type type, Map<String, String> metadata);
|
||||||
|
|
||||||
|
void validate() throws JsonParseException;
|
||||||
|
|
||||||
public static void verifyServerConnection(Session session, String serverId) throws AuthenticationException {
|
public static void verifyServerConnection(Session session, String serverId) throws AuthenticationException {
|
||||||
MinecraftSessionService service = Minecraft.getMinecraft().getSessionService();
|
MinecraftSessionService service = Minecraft.getMinecraft().getSessionService();
|
||||||
service.joinServer(session.getProfile(), session.getToken(), serverId);
|
service.joinServer(session.getProfile(), session.getToken(), serverId);
|
||||||
|
|
|
@ -32,6 +32,10 @@ public class SkinServerSerializer implements JsonSerializer<SkinServer>, JsonDes
|
||||||
public SkinServer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
public SkinServer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
String type = json.getAsJsonObject().get("type").getAsString();
|
String type = json.getAsJsonObject().get("type").getAsString();
|
||||||
|
|
||||||
return context.deserialize(json, HDSkinManager.INSTANCE.getSkinServerClass(type));
|
SkinServer server = context.deserialize(json, HDSkinManager.INSTANCE.getSkinServerClass(type));
|
||||||
|
|
||||||
|
server.validate();
|
||||||
|
|
||||||
|
return server;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.voxelmodpack.hdskins.skins;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.annotations.Expose;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.exceptions.AuthenticationException;
|
import com.mojang.authlib.exceptions.AuthenticationException;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
@ -14,7 +13,6 @@ import javax.annotation.Nullable;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.Session;
|
import net.minecraft.util.Session;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
|
||||||
import org.apache.http.HttpHeaders;
|
import org.apache.http.HttpHeaders;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
|
@ -42,13 +40,10 @@ import java.util.UUID;
|
||||||
@ServerType("valhalla")
|
@ServerType("valhalla")
|
||||||
public class ValhallaSkinServer extends AbstractSkinServer {
|
public class ValhallaSkinServer extends AbstractSkinServer {
|
||||||
|
|
||||||
@Expose
|
|
||||||
private final String address;
|
|
||||||
|
|
||||||
private transient String accessToken;
|
private transient String accessToken;
|
||||||
|
|
||||||
public ValhallaSkinServer(String address) {
|
public ValhallaSkinServer(String address) {
|
||||||
this.address = address;
|
super(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -222,13 +217,6 @@ public class ValhallaSkinServer extends AbstractSkinServer {
|
||||||
return URI.create(String.format("%s/auth/response", address));
|
return URI.create(String.format("%s/auth/response", address));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return new ToStringBuilder(this, IndentedToStringStyle.INSTANCE)
|
|
||||||
.append("address", address)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
private static class AuthHandshake {
|
private static class AuthHandshake {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue