2016-02-27 15:22:35 +08:00
|
|
|
package customskinloader.loader;
|
|
|
|
|
|
2016-07-31 22:00:46 +08:00
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
2016-02-27 15:22:35 +08:00
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
2016-07-31 22:00:46 +08:00
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
|
2016-02-27 15:22:35 +08:00
|
|
|
import com.google.gson.Gson;
|
2016-07-31 22:00:46 +08:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2016-02-27 15:22:35 +08:00
|
|
|
|
|
|
|
|
import customskinloader.CustomSkinLoader;
|
|
|
|
|
import customskinloader.config.SkinSiteProfile;
|
2016-07-31 22:00:46 +08:00
|
|
|
import customskinloader.profile.ModelManager0;
|
|
|
|
|
import customskinloader.profile.UserProfile;
|
|
|
|
|
import customskinloader.utils.HttpTextureUtil;
|
2016-02-27 16:37:05 +08:00
|
|
|
import customskinloader.utils.HttpUtil0;
|
2016-02-27 15:22:35 +08:00
|
|
|
|
|
|
|
|
public class UniSkinAPILoader implements IProfileLoader {
|
|
|
|
|
public static final String TEXTURES="textures/";
|
|
|
|
|
@Override
|
2016-07-31 22:00:46 +08:00
|
|
|
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
|
|
|
|
String username=gameProfile.getName();
|
2016-02-27 15:22:35 +08:00
|
|
|
if(ssp.root==null||ssp.root.equals("")){
|
2016-07-31 22:00:46 +08:00
|
|
|
CustomSkinLoader.logger.info("Root not defined.");
|
2016-02-27 15:22:35 +08:00
|
|
|
return null;
|
|
|
|
|
}
|
2016-07-04 14:10:44 +08:00
|
|
|
String json=HttpUtil0.readHttp(ssp.root+username+".json",ssp.userAgent);
|
2016-02-27 15:22:35 +08:00
|
|
|
if(json==null||json.equals("")){
|
|
|
|
|
CustomSkinLoader.logger.info("Profile not found.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2016-07-31 22:00:46 +08:00
|
|
|
UserProfile p=toUserProfile(ssp.root,json,false);
|
|
|
|
|
if(p==null||p.isEmpty()){
|
|
|
|
|
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
|
|
|
|
return null;
|
|
|
|
|
}else{
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Json profile for UniSkinAPI
|
|
|
|
|
* Source Code: https://github.com/RecursiveG/UniSkinMod/blob/master/src/main/java/org/devinprogress/uniskinmod/UniSkinApiProfile.java#L18-L22
|
|
|
|
|
* @author RecursiveG
|
|
|
|
|
*/
|
|
|
|
|
private class UniSkinAPI{
|
|
|
|
|
public String player_name;
|
|
|
|
|
public long last_update;
|
|
|
|
|
public List<String> model_preference;
|
|
|
|
|
public Map<String,String> skins;
|
|
|
|
|
public String cape;
|
|
|
|
|
|
|
|
|
|
public int errno;
|
|
|
|
|
public String msg;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public UserProfile loadLocalProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
|
|
|
|
String username=gameProfile.getName();
|
|
|
|
|
if(ssp.root==null||ssp.root.equals("")){
|
|
|
|
|
CustomSkinLoader.logger.info("Root not defined.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
File jsonFile=new File(CustomSkinLoader.DATA_DIR,ssp.root+username+".json");
|
|
|
|
|
if(!jsonFile.exists()){
|
|
|
|
|
CustomSkinLoader.logger.info("Profile File not found.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
String json=IOUtils.toString(new FileInputStream(jsonFile));
|
|
|
|
|
if(json==null||json.equals("")){
|
|
|
|
|
CustomSkinLoader.logger.info("Profile not found.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
UserProfile p=toUserProfile(ssp.root,json,true);
|
|
|
|
|
if(p==null||p.isEmpty()){
|
|
|
|
|
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
|
|
|
|
return null;
|
|
|
|
|
}else{
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UserProfile toUserProfile(String root,String json,boolean local){
|
|
|
|
|
UniSkinAPI profile=CustomSkinLoader.GSON.fromJson(json, UniSkinAPI.class);
|
2016-04-03 13:01:06 +08:00
|
|
|
if(profile.errno!=0){
|
|
|
|
|
CustomSkinLoader.logger.info("Error: "+profile.msg);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2016-02-27 15:22:35 +08:00
|
|
|
UserProfile p=new UserProfile();
|
|
|
|
|
if(profile.skins!=null && !profile.skins.isEmpty()){
|
|
|
|
|
if(profile.model_preference!=null && !profile.model_preference.isEmpty()){
|
|
|
|
|
for(String s:profile.model_preference){
|
2016-03-13 00:17:11 +08:00
|
|
|
if(ModelManager0.checkModel(s)){
|
|
|
|
|
if(profile.skins.get(s)==null||profile.skins.get(s).equals(""))
|
|
|
|
|
continue;
|
2016-07-31 22:00:46 +08:00
|
|
|
p.skinUrl=root+TEXTURES+profile.skins.get(s);
|
|
|
|
|
if(local)
|
|
|
|
|
p.skinUrl=HttpTextureUtil.getLocalFakeUrl(p.skinUrl);
|
2016-02-27 15:22:35 +08:00
|
|
|
p.model=s;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(p.skinUrl==null){
|
|
|
|
|
String s=profile.skins.get("default");
|
|
|
|
|
if(s!=null){
|
2016-07-31 22:00:46 +08:00
|
|
|
p.skinUrl=root+TEXTURES+s;
|
|
|
|
|
if(local)
|
|
|
|
|
p.skinUrl=HttpTextureUtil.getLocalFakeUrl(p.skinUrl);
|
2016-02-27 15:22:35 +08:00
|
|
|
p.model="default";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-13 00:17:11 +08:00
|
|
|
if(profile.skins.get("cape")!=null && !profile.skins.get("cape").equals("")){
|
2016-07-31 22:00:46 +08:00
|
|
|
p.capeUrl=root+TEXTURES+profile.skins.get("cape");
|
|
|
|
|
if(local)
|
|
|
|
|
p.capeUrl=HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
|
2016-03-13 00:17:11 +08:00
|
|
|
}else if(profile.cape!=null && !profile.cape.equals("")){
|
2016-07-31 22:00:46 +08:00
|
|
|
p.capeUrl=root+TEXTURES+profile.cape;
|
|
|
|
|
if(local)
|
|
|
|
|
p.capeUrl=HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
|
2016-02-27 15:22:35 +08:00
|
|
|
}
|
2016-07-31 22:00:46 +08:00
|
|
|
return p;
|
2016-02-27 15:22:35 +08:00
|
|
|
}
|
|
|
|
|
}
|