Skip to content

Commit

Permalink
fix a issue with fake players
Browse files Browse the repository at this point in the history
  • Loading branch information
zlainsama committed Feb 23, 2016
1 parent bcb10e1 commit adf57d0
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {

apply plugin: 'forge'

version = "1.7.10-v8a"
version = "1.7.10-v8b"
group= "lain.mods.skinport"
archivesBaseName = "SkinPort"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ObjectUtils;
import com.google.common.base.Strings;

public class CrafatarCachedCapeProvider implements ISkinProvider
Expand Down Expand Up @@ -45,15 +46,16 @@ public ISkin getSkin(AbstractClientPlayer player)
final SkinData data = new SkinData();
data.profile = player.getGameProfile();
final boolean skipUUID = PlayerUtils.isOfflinePlayer(player);
final UUID fbID = player.getUniqueID();
pool.execute(new Runnable()
{

@Override
public void run()
{
BufferedImage image = null;
UUID uuid = data.profile.getId();
String name = data.profile.getName();
UUID uuid = ObjectUtils.defaultIfNull(data.profile.getId(), fbID);
String name = ObjectUtils.defaultIfNull(data.profile.getName(), "");

if (!skipUUID)
{
Expand Down Expand Up @@ -200,14 +202,13 @@ private BufferedImage readImageCached(File workDir, String local, URL remote, Pr
if (code / 100 == 2)
{
etag = Strings.emptyToNull(conn.getHeaderField("Etag"));
t = conn.getExpiration();
t = Math.max(conn.getExpiration(), System.currentTimeMillis() + 60000);
try
{
FileUtils.copyInputStreamToFile(conn.getInputStream(), file1);
if (etag != null)
FileUtils.writeStringToFile(file2, etag, "UTF-8");
if (t > 0)
FileUtils.writeStringToFile(file3, Long.toString(t), "UTF-8");
FileUtils.writeStringToFile(file3, Long.toString(t), "UTF-8");
}
catch (IOException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ObjectUtils;
import com.google.common.base.Strings;

public class CrafatarCachedSkinProvider implements ISkinProvider
Expand Down Expand Up @@ -46,15 +47,16 @@ public ISkin getSkin(AbstractClientPlayer player)
final SkinData data = new SkinData();
data.profile = player.getGameProfile();
final boolean skipUUID = PlayerUtils.isOfflinePlayer(player);
final UUID fbID = player.getUniqueID();
pool.execute(new Runnable()
{

@Override
public void run()
{
BufferedImage image = null;
UUID uuid = data.profile.getId();
String name = data.profile.getName();
UUID uuid = ObjectUtils.defaultIfNull(data.profile.getId(), fbID);
String name = ObjectUtils.defaultIfNull(data.profile.getName(), "");

if (!skipUUID)
{
Expand Down Expand Up @@ -205,14 +207,13 @@ private BufferedImage readImageCached(File workDir, String local, URL remote, Pr
if (code / 100 == 2)
{
etag = Strings.emptyToNull(conn.getHeaderField("Etag"));
t = conn.getExpiration();
t = Math.max(conn.getExpiration(), System.currentTimeMillis() + 60000);
try
{
FileUtils.copyInputStreamToFile(conn.getInputStream(), file1);
if (etag != null)
FileUtils.writeStringToFile(file2, etag, "UTF-8");
if (t > 0)
FileUtils.writeStringToFile(file3, Long.toString(t), "UTF-8");
FileUtils.writeStringToFile(file3, Long.toString(t), "UTF-8");
}
catch (IOException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ObjectUtils;
import com.google.common.base.Strings;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;

Expand Down Expand Up @@ -47,6 +48,7 @@ public ISkin getSkin(AbstractClientPlayer player)
final SkinData data = new SkinData();
data.profile = player.getGameProfile();
final boolean flag = PlayerUtils.isOfflinePlayer(player);
final UUID fbID = player.getUniqueID();
pool.execute(new Runnable()
{

Expand All @@ -57,7 +59,7 @@ public void run()
data.profile = MojangService.getProfile(data.profile.getName(), data.profile);

BufferedImage image = null;
UUID uuid = data.profile.getId();
UUID uuid = ObjectUtils.defaultIfNull(data.profile.getId(), fbID);

@SuppressWarnings("unchecked")
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures = Minecraft.getMinecraft().func_152342_ad().func_152788_a(data.profile);
Expand Down Expand Up @@ -195,14 +197,13 @@ private BufferedImage readImageCached(File workDir, String local, URL remote, Pr
if (code / 100 == 2)
{
etag = Strings.emptyToNull(conn.getHeaderField("Etag"));
t = conn.getExpiration();
t = Math.max(conn.getExpiration(), System.currentTimeMillis() + 60000);
try
{
FileUtils.copyInputStreamToFile(conn.getInputStream(), file1);
if (etag != null)
FileUtils.writeStringToFile(file2, etag, "UTF-8");
if (t > 0)
FileUtils.writeStringToFile(file3, Long.toString(t), "UTF-8");
FileUtils.writeStringToFile(file3, Long.toString(t), "UTF-8");
}
catch (IOException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ObjectUtils;
import com.google.common.base.Strings;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;

Expand Down Expand Up @@ -48,6 +49,7 @@ public ISkin getSkin(AbstractClientPlayer player)
final SkinData data = new SkinData();
data.profile = player.getGameProfile();
final boolean flag = PlayerUtils.isOfflinePlayer(player);
final UUID fbID = player.getUniqueID();
pool.execute(new Runnable()
{

Expand All @@ -58,7 +60,7 @@ public void run()
data.profile = MojangService.getProfile(data.profile.getName(), data.profile);

BufferedImage image = null;
UUID uuid = data.profile.getId();
UUID uuid = ObjectUtils.defaultIfNull(data.profile.getId(), fbID);

@SuppressWarnings("unchecked")
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures = Minecraft.getMinecraft().func_152342_ad().func_152788_a(data.profile);
Expand Down Expand Up @@ -200,14 +202,13 @@ private BufferedImage readImageCached(File workDir, String local, URL remote, Pr
if (code / 100 == 2)
{
etag = Strings.emptyToNull(conn.getHeaderField("Etag"));
t = conn.getExpiration();
t = Math.max(conn.getExpiration(), System.currentTimeMillis() + 60000);
try
{
FileUtils.copyInputStreamToFile(conn.getInputStream(), file1);
if (etag != null)
FileUtils.writeStringToFile(file2, etag, "UTF-8");
if (t > 0)
FileUtils.writeStringToFile(file3, Long.toString(t), "UTF-8");
FileUtils.writeStringToFile(file3, Long.toString(t), "UTF-8");
}
catch (IOException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public Optional<GameProfile> load(String key) throws Exception
if (in != null)
{
GameProfile parsed = gson.fromJson(IOUtils.toString(in, Charsets.UTF_8), GameProfile.class);
return Optional.of(Minecraft.getMinecraft().func_152347_ac().fillProfileProperties(new GameProfile(parsed.getId(), parsed.getName()), false));
if (parsed != null && parsed.getId() != null)
return Optional.of(Minecraft.getMinecraft().func_152347_ac().fillProfileProperties(new GameProfile(parsed.getId(), parsed.getName()), false));
}
}
catch (JsonSyntaxException ignored)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lain.mods.skinport.api.ISkinProvider;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import org.apache.commons.lang3.ObjectUtils;

public class UserManagedCapeProvider implements ISkinProvider
{
Expand All @@ -28,9 +29,9 @@ public UserManagedCapeProvider()
@Override
public ISkin getSkin(AbstractClientPlayer player)
{
BufferedImage image = readImage(String.format("capes/uuid/%s.png", player.getGameProfile().getId().toString().replaceAll("-", "")));
BufferedImage image = readImage(String.format("skins/uuid/%s.png", ObjectUtils.defaultIfNull(player.getGameProfile().getId(), player.getUniqueID()).toString().replaceAll("-", "")));
if (image == null)
image = readImage(String.format("capes/%s.png", player.getGameProfile().getName()));
image = readImage(String.format("skins/%s.png", ObjectUtils.defaultIfNull(player.getGameProfile().getName(), "")));
if (image == null)
return null;
SkinData data = new SkinData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lain.mods.skinport.api.ISkinProvider;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import org.apache.commons.lang3.ObjectUtils;

public class UserManagedSkinProvider implements ISkinProvider
{
Expand All @@ -29,9 +30,9 @@ public UserManagedSkinProvider()
@Override
public ISkin getSkin(AbstractClientPlayer player)
{
BufferedImage image = readImage(String.format("skins/uuid/%s.png", player.getGameProfile().getId().toString().replaceAll("-", "")));
BufferedImage image = readImage(String.format("skins/uuid/%s.png", ObjectUtils.defaultIfNull(player.getGameProfile().getId(), player.getUniqueID()).toString().replaceAll("-", "")));
if (image == null)
image = readImage(String.format("skins/%s.png", player.getGameProfile().getName()));
image = readImage(String.format("skins/%s.png", ObjectUtils.defaultIfNull(player.getGameProfile().getName(), "")));
if (image == null)
return null;
SkinData data = new SkinData();
Expand Down

0 comments on commit adf57d0

Please sign in to comment.