diff --git a/BuildScripts/version.gradle b/BuildScripts/version.gradle index 4158785..5126820 100644 --- a/BuildScripts/version.gradle +++ b/BuildScripts/version.gradle @@ -30,6 +30,7 @@ String getShortVersion() { } ext { + getBuildNum = this.&getBuildNum getCSLVersion = this.&getCSLVersion getShortVersion = this.&getShortVersion } \ No newline at end of file diff --git a/Common/source/customskinloader/CustomSkinLoader.java b/Common/source/customskinloader/CustomSkinLoader.java index d588534..ee37cbc 100644 --- a/Common/source/customskinloader/CustomSkinLoader.java +++ b/Common/source/customskinloader/CustomSkinLoader.java @@ -2,18 +2,20 @@ package customskinloader; import java.io.File; import java.util.Map; -import java.util.concurrent.*; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import com.google.common.collect.Maps; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; -import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; - import customskinloader.config.Config; import customskinloader.config.SkinSiteProfile; -import customskinloader.loader.*; +import customskinloader.loader.ProfileLoader; import customskinloader.profile.DynamicSkullManager; import customskinloader.profile.ModelManager0; import customskinloader.profile.ProfileCache; @@ -28,22 +30,11 @@ import customskinloader.utils.MinecraftUtil; public class CustomSkinLoader { public static final String CustomSkinLoader_VERSION="@MOD_VERSION@"; public static final String CustomSkinLoader_FULL_VERSION="@MOD_FULL_VERSION@"; + public static final int CustomSkinLoader_BUILD_NUMBER=Integer.parseInt("@MOD_BUILD_NUMBER@"); public static final File DATA_DIR=new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader"), LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"), CONFIG_FILE=new File(DATA_DIR,"CustomSkinLoader.json"); - public static final SkinSiteProfile[] DEFAULT_LOAD_LIST={ - SkinSiteProfile.createMojangAPI("Mojang"), - SkinSiteProfile.createCustomSkinAPI("LittleSkin","https://littlesk.in/csl/"), - SkinSiteProfile.createCustomSkinAPI("BlessingSkin","http://skin.prinzeugen.net/"), - //OneSkin has been removed temporarily - //SkinSiteProfile.createCustomSkinAPI("OneSkin","http://fleey.cn/skin/skin_user/skin_json.php/"), - //Minecrack could not load skin correctly - //SkinSiteProfile.creatLegacy("Minecrack","http://minecrack.fr.nf/mc/skinsminecrackd/{USERNAME}.png","http://minecrack.fr.nf/mc/cloaksminecrackd/{USERNAME}.png",null), - SkinSiteProfile.createElyByAPI("ElyBy"), - SkinSiteProfile.createUniSkinAPI("SkinMe","http://www.skinme.cc/uniskin/"), - SkinSiteProfile.createLegacy("LocalSkin","LocalSkin/skins/{USERNAME}.png","LocalSkin/capes/{USERNAME}.png","LocalSkin/elytras/{USERNAME}.png"), - SkinSiteProfile.createGlitchlessAPI("GlitchlessGames","https://games.glitchless.ru/api/minecraft/users/profiles/textures/?nickname=")}; public static final Gson GSON=new GsonBuilder().setPrettyPrinting().create(); public static final Logger logger=initLogger(); @@ -66,9 +57,9 @@ public class CustomSkinLoader { config.threadPoolSize, config.threadPoolSize, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue<>(333), customFactory, new ThreadPoolExecutor.DiscardOldestPolicy() ); - + //For User Skin - public static Map loadProfile(GameProfile gameProfile){ + public static Map loadProfile(GameProfile gameProfile){ String username=gameProfile.getName(); String credential=MinecraftUtil.getCredential(gameProfile); //Fix: http://hopper.minecraft.net/crashes/minecraft/MCX-2773713 @@ -166,7 +157,7 @@ public class CustomSkinLoader { } //For Skull - public static Map loadProfileFromCache(final GameProfile gameProfile) { + public static Map loadProfileFromCache(final GameProfile gameProfile) { String username=gameProfile.getName(); String credential=MinecraftUtil.getCredential(gameProfile); diff --git a/Common/source/customskinloader/config/Config.java b/Common/source/customskinloader/config/Config.java index 1b9ed06..a8c2161 100644 --- a/Common/source/customskinloader/config/Config.java +++ b/Common/source/customskinloader/config/Config.java @@ -3,22 +3,23 @@ package customskinloader.config; import java.io.File; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; - -import customskinloader.utils.Version; -import org.apache.commons.io.FileUtils; +import java.util.Objects; import customskinloader.CustomSkinLoader; import customskinloader.loader.ProfileLoader; +import customskinloader.plugin.PluginLoader; import customskinloader.utils.HttpRequestUtil; import customskinloader.utils.HttpTextureUtil; import customskinloader.utils.HttpUtil0; +import customskinloader.utils.Version; +import org.apache.commons.io.FileUtils; @SuppressWarnings("ResultOfMethodCallIgnored") public class Config { //Program public String version; + public int buildNumber; public List loadlist; //Function @@ -41,9 +42,9 @@ public class Config { public boolean forceDisableCache = false; //Init config - public Config(SkinSiteProfile[] loadlist){ + public Config(List loadlist){ this.version=CustomSkinLoader.CustomSkinLoader_VERSION; - this.loadlist=Arrays.asList(loadlist); + this.loadlist=loadlist; } public static Config loadConfig0() { @@ -78,9 +79,12 @@ public class Config { //Check config version Version configVersion = Version.of(config.version); - if (configVersion.compareTo(CustomSkinLoader.CustomSkinLoader_VERSION) < 0) { - CustomSkinLoader.logger.info("Config File is out of date: " + config.version); + if (CustomSkinLoader.CustomSkinLoader_BUILD_NUMBER == 0 // Custom builds + || configVersion.compareTo(CustomSkinLoader.CustomSkinLoader_VERSION) < 0 + || config.buildNumber < CustomSkinLoader.CustomSkinLoader_BUILD_NUMBER) { + CustomSkinLoader.logger.info("Config File is out of date: " + config.version + ", build number: " + config.buildNumber); config.version = CustomSkinLoader.CustomSkinLoader_VERSION; + config.buildNumber = CustomSkinLoader.CustomSkinLoader_BUILD_NUMBER; //Update some config if (configVersion.compareTo("14.10") < 0)//Lower than 14.10 @@ -92,11 +96,9 @@ public class Config { for (Field field : config.getClass().getDeclaredFields()) { try { Object value = field.get(config); - if (value instanceof String || value instanceof Integer || value instanceof Boolean) - CustomSkinLoader.logger.info(field.getName() + " : " + value); + CustomSkinLoader.logger.info(field.getName() + " : " + value); } catch (Exception ignored) { } } - CustomSkinLoader.logger.info("loadList : " + (config.loadlist == null ? 0 : config.loadlist.size())); return config; } @@ -180,12 +182,26 @@ public class Config { } } + // The config file does not exist or was broken. private static Config initConfig() { - Config config=new Config(CustomSkinLoader.DEFAULT_LOAD_LIST); + List loadlist = new ArrayList(); + PluginLoader.PLUGINS.forEach((name, plugin) -> { + SkinSiteProfile ssp = new SkinSiteProfile(); + ssp.name = name; + plugin.updateSkinSiteProfile(ssp); + loadlist.add(ssp); + }); + Config config=new Config(loadlist); writeConfig(config,false); return config; } private static void writeConfig(Config config,boolean update){ + if (update && config.loadlist != null) { // Update loadlist, complete missing elements + PluginLoader.PLUGINS.forEach((name, plugin) -> config.loadlist.stream() + .filter(ssp -> Objects.equals(ssp.name, name)) + .forEach(plugin::updateSkinSiteProfile)); + } + String json=CustomSkinLoader.GSON.toJson(config); if(CustomSkinLoader.CONFIG_FILE.exists()) CustomSkinLoader.CONFIG_FILE.delete(); diff --git a/Common/source/customskinloader/config/SkinSiteProfile.java b/Common/source/customskinloader/config/SkinSiteProfile.java index e24ac87..17faa90 100644 --- a/Common/source/customskinloader/config/SkinSiteProfile.java +++ b/Common/source/customskinloader/config/SkinSiteProfile.java @@ -1,5 +1,7 @@ package customskinloader.config; +import java.lang.reflect.Field; + public class SkinSiteProfile { //Common public String name; @@ -20,61 +22,23 @@ public class SkinSiteProfile { public String cape; public String elytra; - public static SkinSiteProfile createMojangAPI(String name) { - SkinSiteProfile ssp = new SkinSiteProfile(); - ssp.name = name; - ssp.type = "MojangAPI"; - return ssp; - } - - public static SkinSiteProfile createCustomSkinAPI(String name, String root) { - SkinSiteProfile ssp = new SkinSiteProfile(); - ssp.name = name; - ssp.type = "CustomSkinAPI"; - ssp.root = root; - return ssp; - } - - public static SkinSiteProfile creatCustomSkinAPIPlus(String name, String root) { - SkinSiteProfile ssp = new SkinSiteProfile(); - ssp.name = name; - ssp.type = "CustomSkinAPIPlus"; - ssp.root = root; - return ssp; - } - - public static SkinSiteProfile createGlitchlessAPI(String name, String root) { - SkinSiteProfile ssp = new SkinSiteProfile(); - ssp.name = name; - ssp.type = "GlitchlessAPI"; - ssp.root = root; - return ssp; - } - - public static SkinSiteProfile createUniSkinAPI(String name, String root) { - SkinSiteProfile ssp = new SkinSiteProfile(); - ssp.name = name; - ssp.type = "UniSkinAPI"; - ssp.root = root; - return ssp; - } - - public static SkinSiteProfile createLegacy(String name, String skin, String cape, String elytra) { - SkinSiteProfile ssp = new SkinSiteProfile(); - ssp.name = name; - ssp.type = "Legacy"; - ssp.checkPNG = false; - ssp.skin = skin; - ssp.model = "auto"; - ssp.cape = cape; - ssp.elytra = elytra; - return ssp; - } - - public static SkinSiteProfile createElyByAPI(String name) { - SkinSiteProfile ssp = new SkinSiteProfile(); - ssp.name = name; - ssp.type = "ElyByAPI"; - return ssp; + @Override + public String toString() { + StringBuilder sb = new StringBuilder("{ "); + Field[] fields = SkinSiteProfile.class.getDeclaredFields(); + boolean first = true; + for (Field field : fields) { + try { + Object value = field.get(this); + if (value == null) continue; + if (first) { + first = false; + } else { + sb.append(", "); + } + sb.append("\"").append(field.getName()).append("\": \"").append(value).append("\""); + } catch (Exception ignored) { } + } + return sb.append(" }").toString(); } } diff --git a/Common/source/customskinloader/loader/JsonAPILoader.java b/Common/source/customskinloader/loader/JsonAPILoader.java index 4f30f56..a7b473d 100644 --- a/Common/source/customskinloader/loader/JsonAPILoader.java +++ b/Common/source/customskinloader/loader/JsonAPILoader.java @@ -3,23 +3,21 @@ package customskinloader.loader; import java.io.File; import java.io.FileInputStream; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; - import com.mojang.authlib.GameProfile; - import customskinloader.CustomSkinLoader; import customskinloader.config.SkinSiteProfile; -import customskinloader.loader.jsonapi.*; +import customskinloader.plugin.ICustomSkinLoaderPlugin; import customskinloader.profile.UserProfile; import customskinloader.utils.HttpRequestUtil; import customskinloader.utils.HttpUtil0; -import customskinloader.utils.HttpRequestUtil.HttpRequest; -import customskinloader.utils.HttpRequestUtil.HttpResponce; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; -public class JsonAPILoader implements ProfileLoader.IProfileLoader { +public class JsonAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader { public interface IJsonAPI { + String getLoaderName(); + String getRoot(); String toJsonUrl(String root, String username); String getPayload(SkinSiteProfile ssp); UserProfile toUserProfile(String root, String json, boolean local); @@ -29,32 +27,41 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader { public int errno; public String msg; } - public enum Type{ - CustomSkinAPI(new CustomSkinAPI()), - CustomSkinAPIPlus(new CustomSkinAPIPlus()), - UniSkinAPI(new UniSkinAPI()), - ElyByAPI(new ElyByAPI()), - GlitchlessAPI(new GlitchlessAPI()); - public IJsonAPI jsonAPI; - Type(IJsonAPI jsonAPI){ - this.jsonAPI=jsonAPI; - } - } - private Type type; - public JsonAPILoader(Type type){ - this.type=type; + private final IJsonAPI jsonAPI; + public JsonAPILoader(IJsonAPI jsonAPI){ + this.jsonAPI = jsonAPI; } + + // === ICustomSkinLoaderPlugin === + + @Override + public ProfileLoader.IProfileLoader getProfileLoader() { + return this; + } + + @Override + public String getLoaderName() { + return this.jsonAPI.getLoaderName(); + } + + @Override + public void updateSkinSiteProfile(SkinSiteProfile ssp) { + ssp.type = this.getName(); + ssp.root = this.jsonAPI.getRoot(); + } + + // === IProfileLoader === @Override public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { String username=gameProfile.getName(); - if(StringUtils.isEmpty(ssp.root) && type!=Type.ElyByAPI){ + if (StringUtils.isEmpty(ssp.root)) { CustomSkinLoader.logger.info("Root not defined."); return null; } boolean local = HttpUtil0.isLocal(ssp.root); - String jsonUrl=type.jsonAPI.toJsonUrl(ssp.root, username); + String jsonUrl = this.jsonAPI.toJsonUrl(ssp.root, username); String json; if(local){ File jsonFile = new File(CustomSkinLoader.DATA_DIR, jsonUrl); @@ -64,7 +71,7 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader { } json=IOUtils.toString(new FileInputStream(jsonFile), "UTF-8"); }else{ - HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(jsonUrl).setCacheTime(90).setUserAgent(ssp.userAgent).setPayload(type.jsonAPI.getPayload(ssp))); + HttpRequestUtil.HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(jsonUrl).setCacheTime(90).setUserAgent(ssp.userAgent).setPayload(this.jsonAPI.getPayload(ssp))); json=responce.content; } if(json==null||json.equals("")){ @@ -78,7 +85,7 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader { return null; } - UserProfile p=type.jsonAPI.toUserProfile(ssp.root, json, local); + UserProfile p=this.jsonAPI.toUserProfile(ssp.root, json, local); if(p==null||p.isEmpty()){ CustomSkinLoader.logger.info("Both skin and cape not found."); return null; @@ -92,7 +99,7 @@ public class JsonAPILoader implements ProfileLoader.IProfileLoader { } @Override public String getName() { - return type.jsonAPI.getName(); + return this.jsonAPI.getName(); } @SuppressWarnings("ResultOfMethodCallIgnored") @Override diff --git a/Common/source/customskinloader/loader/LegacyLoader.java b/Common/source/customskinloader/loader/LegacyLoader.java index e26c21f..09eebda 100644 --- a/Common/source/customskinloader/loader/LegacyLoader.java +++ b/Common/source/customskinloader/loader/LegacyLoader.java @@ -1,25 +1,61 @@ package customskinloader.loader; import java.io.File; - -import com.mojang.util.UUIDTypeAdapter; -import org.apache.commons.lang3.StringUtils; +import javax.annotation.Nonnull; import com.mojang.authlib.GameProfile; - +import com.mojang.util.UUIDTypeAdapter; import customskinloader.CustomSkinLoader; import customskinloader.config.SkinSiteProfile; +import customskinloader.plugin.ICustomSkinLoaderPlugin; import customskinloader.profile.ModelManager0; import customskinloader.profile.UserProfile; import customskinloader.utils.HttpRequestUtil; -import customskinloader.utils.HttpRequestUtil.HttpRequest; -import customskinloader.utils.HttpRequestUtil.HttpResponce; import customskinloader.utils.HttpTextureUtil; import customskinloader.utils.HttpUtil0; +import org.apache.commons.lang3.StringUtils; -import javax.annotation.Nonnull; +public abstract class LegacyLoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader { + + // === ICustomSkinLoaderPlugin === + + @Override + public ProfileLoader.IProfileLoader getProfileLoader() { + return this; + } + + @Override + public void updateSkinSiteProfile(SkinSiteProfile ssp) { + ssp.type = this.getName(); + if (ssp.checkPNG == null) ssp.checkPNG = false; + if (ssp.model == null) ssp.model = "auto"; + if (ssp.skin == null || !HttpUtil0.isLocal(this.getSkinRoot())) ssp.skin = this.getSkinRoot(); + if (ssp.cape == null || !HttpUtil0.isLocal(this.getCapeRoot())) ssp.cape = this.getCapeRoot(); + if (ssp.elytra == null || !HttpUtil0.isLocal(this.getElytraRoot())) ssp.elytra = this.getElytraRoot(); + } + + public abstract String getSkinRoot(); + public abstract String getCapeRoot(); + public abstract String getElytraRoot(); + + public static class LocalSkin extends LegacyLoader { + @Override public String getLoaderName() { return "LocalSkin"; } + @Override public String getSkinRoot() { return "LocalSkin/skins/{USERNAME}.png"; } + @Override public String getCapeRoot() { return "LocalSkin/capes/{USERNAME}.png"; } + @Override public String getElytraRoot() { return "LocalSkin/elytras/{USERNAME}.png"; } + } + + /* Minecrack could not load skin correctly + public static class Minecrack extends LegacyLoader { + @Override public String getLoaderName() { return "Minecrack"; } + @Override public String getSkinRoot() { return "http://minecrack.fr.nf/mc/skinsminecrackd/{USERNAME}.png"; } + @Override public String getCapeRoot() { return "http://minecrack.fr.nf/mc/cloaksminecrackd/{USERNAME}.png"; } + @Override public String getElytraRoot() { return null; } + } + */ + + // === IProfileLoader === -public class LegacyLoader implements ProfileLoader.IProfileLoader { public static final String USERNAME_PLACEHOLDER = "{USERNAME}"; public static final String UUID_PLACEHOLDER = "{UUID}"; @@ -34,7 +70,7 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader { if (skinFile.exists() && skinFile.isFile()) profile.skinUrl = HttpTextureUtil.getLocalLegacyFakeUrl(skin, HttpTextureUtil.getHash(skin, skinFile.length(), skinFile.lastModified())); } else { - HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequest(skin).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG != null && ssp.checkPNG).setLoadContent(false).setCacheTime(90)); + HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(skin).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG != null && ssp.checkPNG).setLoadContent(false).setCacheTime(90)); if (responce.success) profile.skinUrl = HttpTextureUtil.getLegacyFakeUrl(skin); } @@ -47,7 +83,7 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader { if (capeFile.exists() && capeFile.isFile()) profile.capeUrl = HttpTextureUtil.getLocalLegacyFakeUrl(cape, HttpTextureUtil.getHash(cape, capeFile.length(), capeFile.lastModified())); } else { - HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequest(cape).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG != null && ssp.checkPNG).setLoadContent(false).setCacheTime(90)); + HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(cape).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG != null && ssp.checkPNG).setLoadContent(false).setCacheTime(90)); if (responce.success) profile.capeUrl = HttpTextureUtil.getLegacyFakeUrl(cape); } @@ -59,7 +95,7 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader { if (elytraFile.exists() && elytraFile.isFile()) profile.elytraUrl = HttpTextureUtil.getLocalLegacyFakeUrl(elytra, HttpTextureUtil.getHash(elytra, elytraFile.length(), elytraFile.lastModified())); } else { - HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequest(elytra).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG != null && ssp.checkPNG).setLoadContent(false).setCacheTime(90)); + HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(elytra).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG != null && ssp.checkPNG).setLoadContent(false).setCacheTime(90)); if (responce.success) profile.elytraUrl = HttpTextureUtil.getLegacyFakeUrl(elytra); } diff --git a/Common/source/customskinloader/loader/MojangAPILoader.java b/Common/source/customskinloader/loader/MojangAPILoader.java index 6dce47d..284b9cf 100644 --- a/Common/source/customskinloader/loader/MojangAPILoader.java +++ b/Common/source/customskinloader/loader/MojangAPILoader.java @@ -4,12 +4,8 @@ import java.util.Collections; import java.util.Map; import java.util.UUID; -import com.google.common.collect.Maps; -import org.apache.commons.codec.Charsets; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.lang3.StringUtils; - import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mojang.authlib.GameProfile; @@ -19,16 +15,42 @@ import com.mojang.authlib.properties.PropertyMap; import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse; import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload; import com.mojang.util.UUIDTypeAdapter; - import customskinloader.CustomSkinLoader; import customskinloader.config.SkinSiteProfile; +import customskinloader.plugin.ICustomSkinLoaderPlugin; import customskinloader.profile.ModelManager0; import customskinloader.profile.UserProfile; import customskinloader.utils.HttpRequestUtil; -import customskinloader.utils.HttpRequestUtil.HttpRequest; -import customskinloader.utils.HttpRequestUtil.HttpResponce; +import org.apache.commons.codec.Charsets; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang3.StringUtils; -public class MojangAPILoader implements ProfileLoader.IProfileLoader { +public abstract class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader { + + // === ICustomSkinLoaderPlugin === + + @Override + public ProfileLoader.IProfileLoader getProfileLoader() { + return this; + } + + @Override + public void updateSkinSiteProfile(SkinSiteProfile ssp) { + ssp.type = this.getName(); + ssp.apiRoot = this.getAPIRoot(); + ssp.sessionRoot = this.getSessionRoot(); + } + + public abstract String getAPIRoot(); + public abstract String getSessionRoot(); + + public static class Mojang extends MojangAPILoader { + @Override public String getLoaderName() { return "Mojang"; } + @Override public String getAPIRoot() { return "https://api.mojang.com/"; } + @Override public String getSessionRoot() { return "https://sessionserver.mojang.com/"; } + } + + // === IProfileLoader === @Override public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception { @@ -58,8 +80,8 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader { //Doc (https://wiki.vg/Mojang_API#Playernames_-.3E_UUIDs) Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create(); - HttpResponce responce = HttpRequestUtil.makeHttpRequest( - new HttpRequest(apiRoot + "profiles/minecraft") + HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest( + new HttpRequestUtil.HttpRequest(apiRoot + "profiles/minecraft") .setCacheTime(600).setPayload(gson.toJson(Collections.singletonList(username))) ); if (StringUtils.isEmpty(responce.content)) @@ -78,8 +100,8 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader { //UUID -> Profile public static GameProfile fillGameProfile(String sessionRoot, GameProfile profile) { //Doc (http://wiki.vg/Mojang_API#UUID_-.3E_Profile_.2B_Skin.2FCape) - HttpResponce responce = HttpRequestUtil.makeHttpRequest( - new HttpRequest(sessionRoot + "session/minecraft/profile/" + HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest( + new HttpRequestUtil.HttpRequest(sessionRoot + "session/minecraft/profile/" + UUIDTypeAdapter.fromUUID(profile.getId())).setCacheTime(90)); if (StringUtils.isEmpty(responce.content)) return profile; diff --git a/Common/source/customskinloader/loader/ProfileLoader.java b/Common/source/customskinloader/loader/ProfileLoader.java index d9be744..5f64832 100644 --- a/Common/source/customskinloader/loader/ProfileLoader.java +++ b/Common/source/customskinloader/loader/ProfileLoader.java @@ -3,30 +3,25 @@ package customskinloader.loader; import java.util.HashMap; import com.mojang.authlib.GameProfile; - +import customskinloader.CustomSkinLoader; import customskinloader.config.SkinSiteProfile; +import customskinloader.plugin.ICustomSkinLoaderPlugin; import customskinloader.plugin.PluginLoader; import customskinloader.profile.UserProfile; public class ProfileLoader { - private static final IProfileLoader[] DEFAULT_LOADERS={ - new MojangAPILoader(), - new JsonAPILoader(JsonAPILoader.Type.CustomSkinAPI), - new JsonAPILoader(JsonAPILoader.Type.CustomSkinAPIPlus), - new JsonAPILoader(JsonAPILoader.Type.UniSkinAPI), - new JsonAPILoader(JsonAPILoader.Type.ElyByAPI), - new JsonAPILoader(JsonAPILoader.Type.GlitchlessAPI), - new LegacyLoader()}; - public static final HashMap LOADERS=initLoaders(); private static HashMap initLoaders() { - HashMap loaders=new HashMap(); - for(IProfileLoader loader:DEFAULT_LOADERS){ - loaders.put(loader.getName().toLowerCase(), loader); + HashMap profileLoaders = new HashMap(); + for (ICustomSkinLoaderPlugin plugin : PluginLoader.PLUGINS.values()) { + ProfileLoader.IProfileLoader profileLoader = plugin.getProfileLoader(); + if (profileLoader != null) { + profileLoaders.put(profileLoader.getName().toLowerCase(), profileLoader); + CustomSkinLoader.logger.info("Add a profile loader: " + profileLoader.getName()); + } } - loaders.putAll(PluginLoader.loadPlugins()); - return loaders; + return profileLoaders; } public interface IProfileLoader { diff --git a/Common/source/customskinloader/loader/jsonapi/CustomSkinAPI.java b/Common/source/customskinloader/loader/jsonapi/CustomSkinAPI.java index dba0f45..04a5ca0 100644 --- a/Common/source/customskinloader/loader/jsonapi/CustomSkinAPI.java +++ b/Common/source/customskinloader/loader/jsonapi/CustomSkinAPI.java @@ -3,17 +3,33 @@ package customskinloader.loader.jsonapi; import java.util.LinkedHashMap; import java.util.Map; -import org.apache.commons.lang3.StringUtils; - import customskinloader.CustomSkinLoader; import customskinloader.config.SkinSiteProfile; -import customskinloader.loader.JsonAPILoader.IJsonAPI; +import customskinloader.loader.JsonAPILoader; import customskinloader.profile.ModelManager0; -import customskinloader.profile.ModelManager0.Model; import customskinloader.profile.UserProfile; import customskinloader.utils.HttpTextureUtil; +import org.apache.commons.lang3.StringUtils; + +public abstract class CustomSkinAPI implements JsonAPILoader.IJsonAPI { + + public static class LittleSkin extends CustomSkinAPI { + @Override public String getLoaderName() { return "LittleSkin"; } + @Override public String getRoot() { return "https://littlesk.in/csl/"; } + } + + public static class BlessingSkin extends CustomSkinAPI { + @Override public String getLoaderName() { return "BlessingSkin"; } + @Override public String getRoot() { return "http://skin.prinzeugen.net/"; } + } + + /* OneSkin has been removed temporarily + public static class OneSkin extends CustomSkinAPI { + @Override public String getLoaderName() { return "OneSkin"; } + @Override public String getRoot() { return "http://fleey.cn/skin/skin_user/skin_json.php/"; } + } + */ -public class CustomSkinAPI implements IJsonAPI { private static final String TEXTURES="textures/"; private static final String SUFFIX=".json"; @@ -53,7 +69,7 @@ public class CustomSkinAPI implements IJsonAPI { boolean hasSkin=false; for(String model:textures.keySet()){ - Model enumModel=ModelManager0.getEnumModel(model); + ModelManager0.Model enumModel=ModelManager0.getEnumModel(model); if(enumModel==null||StringUtils.isEmpty(textures.get(model))) continue; if(ModelManager0.isSkin(enumModel)) @@ -69,7 +85,7 @@ public class CustomSkinAPI implements IJsonAPI { return p; } - private class CustomSkinAPIProfile{ + private static class CustomSkinAPIProfile{ public String username; public LinkedHashMap textures; diff --git a/Common/source/customskinloader/loader/jsonapi/CustomSkinAPIPlus.java b/Common/source/customskinloader/loader/jsonapi/CustomSkinAPIPlus.java index 2265ce1..9a27d2c 100644 --- a/Common/source/customskinloader/loader/jsonapi/CustomSkinAPIPlus.java +++ b/Common/source/customskinloader/loader/jsonapi/CustomSkinAPIPlus.java @@ -3,18 +3,13 @@ package customskinloader.loader.jsonapi; import java.io.File; import java.util.UUID; -import org.apache.commons.io.FileUtils; - import com.google.gson.Gson; - import customskinloader.CustomSkinLoader; import customskinloader.config.SkinSiteProfile; -import customskinloader.loader.JsonAPILoader; -import customskinloader.loader.JsonAPILoader.IJsonAPI; -import customskinloader.profile.UserProfile; import customskinloader.utils.MinecraftUtil; +import org.apache.commons.io.FileUtils; -public class CustomSkinAPIPlus implements IJsonAPI { +public abstract class CustomSkinAPIPlus extends CustomSkinAPI { private static String clientID=null; public CustomSkinAPIPlus(){ @@ -35,21 +30,12 @@ public class CustomSkinAPIPlus implements IJsonAPI { } } } - @Override - public String toJsonUrl(String root, String username) { - return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toJsonUrl(root, username); - } @Override public String getPayload(SkinSiteProfile ssp) { return new Gson().toJson(new CustomSkinAPIPlusPayload()); } - @Override - public UserProfile toUserProfile(String root, String json, boolean local) { - return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toUserProfile(root, json, local); - } - @Override public String getName() { return "CustomSKinAPIPlus"; diff --git a/Common/source/customskinloader/loader/jsonapi/ElyByAPI.java b/Common/source/customskinloader/loader/jsonapi/ElyByAPI.java index 033c2b1..a42ba0e 100644 --- a/Common/source/customskinloader/loader/jsonapi/ElyByAPI.java +++ b/Common/source/customskinloader/loader/jsonapi/ElyByAPI.java @@ -1,40 +1,30 @@ package customskinloader.loader.jsonapi; +import java.util.Map; + import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.mojang.authlib.minecraft.MinecraftProfileTexture; -import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import customskinloader.config.SkinSiteProfile; import customskinloader.loader.JsonAPILoader; import customskinloader.profile.ModelManager0; import customskinloader.profile.UserProfile; -import customskinloader.utils.MinecraftUtil; -import java.net.URI; -import java.util.Map; +public abstract class ElyByAPI implements JsonAPILoader.IJsonAPI { + + public static class ElyBy extends ElyByAPI { + @Override public String getLoaderName() { return "ElyBy"; } + @Override public String getRoot() { return "http://skinsystem.ely.by/textures/"; } + } -public class ElyByAPI implements JsonAPILoader.IJsonAPI { @Override public String toJsonUrl(String root, String username) { - return "http://skinsystem.ely.by/textures/" + username + "?version=2&minecraft_version=" + MinecraftUtil.getMinecraftMainVersion(); + return root + username; } @Override public UserProfile toUserProfile(String root, String json, boolean local) { - Map result = new Gson().fromJson(json, new TypeToken>() { - }.getType()); - if (!result.containsKey(Type.SKIN)) - return null; - - //Check URL - try { - URI uri = new URI(result.get(Type.SKIN).getUrl()); - if (!uri.getHost().endsWith("ely.by")) - return null; - } catch (Exception e) { - return null; - } - + Map result = new Gson().fromJson(json, new TypeToken>() { }.getType()); return ModelManager0.toUserProfile(result); } diff --git a/Common/source/customskinloader/loader/jsonapi/GlitchlessAPI.java b/Common/source/customskinloader/loader/jsonapi/GlitchlessAPI.java index c2b747d..9f2fc50 100644 --- a/Common/source/customskinloader/loader/jsonapi/GlitchlessAPI.java +++ b/Common/source/customskinloader/loader/jsonapi/GlitchlessAPI.java @@ -1,5 +1,7 @@ package customskinloader.loader.jsonapi; +import java.util.Map; + import com.google.gson.Gson; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import customskinloader.config.SkinSiteProfile; @@ -7,9 +9,13 @@ import customskinloader.loader.JsonAPILoader; import customskinloader.profile.ModelManager0; import customskinloader.profile.UserProfile; -import java.util.Map; +public abstract class GlitchlessAPI implements JsonAPILoader.IJsonAPI { + + public static class GlitchlessGames extends GlitchlessAPI { + @Override public String getLoaderName() { return "GlitchlessGames"; } + @Override public String getRoot() { return "https://games.glitchless.ru/api/minecraft/users/profiles/textures/?nickname="; } + } -public class GlitchlessAPI implements JsonAPILoader.IJsonAPI { @Override public String toJsonUrl(String root, String username) { return root + username; diff --git a/Common/source/customskinloader/loader/jsonapi/UniSkinAPI.java b/Common/source/customskinloader/loader/jsonapi/UniSkinAPI.java index 0dc7b4f..533fc86 100644 --- a/Common/source/customskinloader/loader/jsonapi/UniSkinAPI.java +++ b/Common/source/customskinloader/loader/jsonapi/UniSkinAPI.java @@ -3,17 +3,21 @@ package customskinloader.loader.jsonapi; import java.util.List; import java.util.Map; -import org.apache.commons.lang3.StringUtils; - import customskinloader.CustomSkinLoader; import customskinloader.config.SkinSiteProfile; -import customskinloader.loader.JsonAPILoader.IJsonAPI; +import customskinloader.loader.JsonAPILoader; import customskinloader.profile.ModelManager0; import customskinloader.profile.UserProfile; -import customskinloader.profile.ModelManager0.Model; import customskinloader.utils.HttpTextureUtil; +import org.apache.commons.lang3.StringUtils; + +public abstract class UniSkinAPI implements JsonAPILoader.IJsonAPI { + + public static class SkinMe extends UniSkinAPI { + @Override public String getLoaderName() { return "SkinMe"; } + @Override public String getRoot() { return "http://www.skinme.cc/uniskin/"; } + } -public class UniSkinAPI implements IJsonAPI { private static final String TEXTURES="textures/"; private static final String SUFFIX=".json"; @@ -40,7 +44,7 @@ public class UniSkinAPI implements IJsonAPI { boolean hasSkin=false; for(String model:profile.model_preference){ - Model enumModel=ModelManager0.getEnumModel(model); + ModelManager0.Model enumModel=ModelManager0.getEnumModel(model); if(enumModel==null||StringUtils.isEmpty(profile.skins.get(model))) continue; if(ModelManager0.isSkin(enumModel)) diff --git a/Common/source/customskinloader/plugin/ICustomSkinLoaderPlugin.java b/Common/source/customskinloader/plugin/ICustomSkinLoaderPlugin.java index f30bb4f..9426430 100644 --- a/Common/source/customskinloader/plugin/ICustomSkinLoaderPlugin.java +++ b/Common/source/customskinloader/plugin/ICustomSkinLoaderPlugin.java @@ -1,7 +1,12 @@ package customskinloader.plugin; +import customskinloader.config.SkinSiteProfile; import customskinloader.loader.ProfileLoader; public interface ICustomSkinLoaderPlugin { ProfileLoader.IProfileLoader getProfileLoader(); + + String getLoaderName(); + + void updateSkinSiteProfile(SkinSiteProfile ssp); } diff --git a/Common/source/customskinloader/plugin/PluginLoader.java b/Common/source/customskinloader/plugin/PluginLoader.java index c04700d..f646907 100644 --- a/Common/source/customskinloader/plugin/PluginLoader.java +++ b/Common/source/customskinloader/plugin/PluginLoader.java @@ -5,16 +5,33 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.ServiceLoader; +import customskinloader.CustomSkinLoader; +import customskinloader.loader.JsonAPILoader; +import customskinloader.loader.LegacyLoader; +import customskinloader.loader.MojangAPILoader; +import customskinloader.loader.jsonapi.CustomSkinAPI; +import customskinloader.loader.jsonapi.ElyByAPI; +import customskinloader.loader.jsonapi.GlitchlessAPI; +import customskinloader.loader.jsonapi.UniSkinAPI; import org.apache.commons.io.FileUtils; -import customskinloader.CustomSkinLoader; -import customskinloader.loader.ProfileLoader; - public class PluginLoader { - public static HashMap loadPlugins() { + // This controls the default loading order. + public static final ICustomSkinLoaderPlugin[] DEFAULT_PLUGINS = new ICustomSkinLoaderPlugin[] { + new MojangAPILoader.Mojang(), + new JsonAPILoader(new CustomSkinAPI.LittleSkin()), + new JsonAPILoader(new CustomSkinAPI.BlessingSkin()), + new JsonAPILoader(new ElyByAPI.ElyBy()), + new JsonAPILoader(new UniSkinAPI.SkinMe()), + new LegacyLoader.LocalSkin(), + new JsonAPILoader(new GlitchlessAPI.GlitchlessGames()) + }; + public static final LinkedHashMap PLUGINS = loadPlugins(); + + private static LinkedHashMap loadPlugins() { File pluginsDir = new File(CustomSkinLoader.DATA_DIR, "Plugins"); ArrayList urls = new ArrayList(); if (!pluginsDir.isDirectory()) { @@ -27,13 +44,19 @@ public class PluginLoader { } catch (MalformedURLException ignored) {} } } + LinkedHashMap plugins = new LinkedHashMap<>(); + addPlugin(plugins, DEFAULT_PLUGINS); + ServiceLoader sl = ServiceLoader.load(ICustomSkinLoaderPlugin.class, new URLClassLoader(urls.toArray(new URL[0]), PluginLoader.class.getClassLoader())); - HashMap profileLoaders = new HashMap(); - for (ICustomSkinLoaderPlugin cslPlugin : sl) { - ProfileLoader.IProfileLoader profileLoader = cslPlugin.getProfileLoader(); - profileLoaders.put(profileLoader.getName().toLowerCase(), profileLoader); - CustomSkinLoader.logger.info("Add profile loader: " + profileLoader.getName()); + for (ICustomSkinLoaderPlugin plugin : sl) { + plugins.put(plugin.getLoaderName(), plugin); + } + return plugins; + } + + public static void addPlugin(LinkedHashMap pluginMap, ICustomSkinLoaderPlugin... plugins) { + for (ICustomSkinLoaderPlugin plugin : plugins) { + pluginMap.put(plugin.getLoaderName(), plugin); } - return profileLoaders; } } diff --git a/Common/source/customskinloader/utils/HttpUtil0.java b/Common/source/customskinloader/utils/HttpUtil0.java index 2386fc5..b3a4aef 100644 --- a/Common/source/customskinloader/utils/HttpUtil0.java +++ b/Common/source/customskinloader/utils/HttpUtil0.java @@ -5,14 +5,19 @@ import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; import java.security.cert.X509Certificate; - -import javax.net.ssl.*; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; import org.apache.commons.lang3.StringUtils; public class HttpUtil0 { public static boolean isLocal(String url){ - return url != null && !url.startsWith("http"); + return url != null && !url.startsWith("http://") && !url.startsWith("https://"); } //From: http://blog.csdn.net/xiyushiyi/article/details/46685387 diff --git a/build.gradle b/build.gradle index 2121c9a..688fb17 100644 --- a/build.gradle +++ b/build.gradle @@ -57,6 +57,7 @@ subprojects { replace '@MOD_VERSION@', rootProject.ext.config.version replace '@MOD_FULL_VERSION@', project.version + replace '@MOD_BUILD_NUMBER@', getBuildNum() replaceIn 'CustomSkinLoader.java' }