skin.go 860 B

12345678910111213141516171819202122232425262728
  1. package mc
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "log"
  6. "os"
  7. )
  8. //DownloadSkin is exported function
  9. func (mc *Handler) DownloadSkin() {
  10. if _, err := os.Stat(mc.savePath + "/" + mc.UUID + ".png"); os.IsNotExist(err) {
  11. resp := httpReq("https://sessionserver.mojang.com/session/minecraft/profile/" + mc.UUID)
  12. var profileArray profile
  13. json.Unmarshal(resp, &profileArray)
  14. if len(profileArray.Error) > 0 {
  15. log.Println("Error when reading profiles. Download aborted.")
  16. copy("default_skin.png", mc.savePath+"/"+mc.UUID+".png")
  17. } else {
  18. decoded, _ := base64.URLEncoding.DecodeString(profileArray.Properties[0].Value)
  19. var textureArray texture
  20. json.Unmarshal([]byte(decoded), &textureArray)
  21. downloadFile(mc.savePath+"/"+mc.UUID+".png", textureArray.Textures.SKIN.URL)
  22. }
  23. } else {
  24. log.Println("Skin exists, not downloading")
  25. }
  26. }