Exemplo n.º 1
0
Arquivo: http.go Projeto: dayl1k/imgd
func fetchSkin(username string) *mcSkin {
	if username == "char" {
		skin, _ := minecraft.FetchSkinForChar()
		return &mcSkin{Skin: skin}
	}

	if cache.has(strings.ToLower(username)) {
		stats.HitCache()
		return &mcSkin{Processed: nil, Skin: cache.pull(strings.ToLower(username))}
	}

	skin, err := minecraft.FetchSkinFromMojang(username)
	if err != nil {
		log.Error("Failed Skin Mojang: " + username + " (" + err.Error() + ")")
		// Let's fallback to S3 and try and serve at least an old skin...
		skin, err = minecraft.FetchSkinFromS3(username)
		if err != nil {
			log.Error("Failed Skin S3: " + username + " (" + err.Error() + ")")
			// Well, looks like they don't exist after all.
			skin, _ = minecraft.FetchSkinForChar()
		}
	}

	stats.MissCache()
	cache.add(strings.ToLower(username), skin)

	return &mcSkin{Processed: nil, Skin: skin}
}
Exemplo n.º 2
0
func fetchSkin(username string) minecraft.Skin {
	skin, err := minecraft.GetSkin(minecraft.User{Name: username})
	if err != nil {
		// Problem with the returned image, probably means we have an incorrect username
		// Hit the accounts api
		user, err := minecraft.GetUser(username)

		if err != nil {
			// There's no account for this person, serve char
			skin, _ = minecraft.FetchSkinForChar()
		} else {
			// Get valid skin
			skin, err = minecraft.GetSkin(user)
			if err != nil {
				// Their skin somehow errored, fallback
				skin, _ = minecraft.FetchSkinForChar()
			}
		}
	}

	return skin
}
Exemplo n.º 3
0
// What to do when failing to pull a skin from redis
func (c *CacheRedis) pullFailed(username string) minecraft.Skin {
	c.remove(username)
	char, _ := minecraft.FetchSkinForChar()
	return char
}
Exemplo n.º 4
0
// Should never be called.
func (c *CacheOff) pull(username string) minecraft.Skin {
	char, _ := minecraft.FetchSkinForChar()
	return char
}