12345678910111213141516171819202122232425262728 |
- package mc
- import (
- "encoding/base64"
- "encoding/json"
- "log"
- "os"
- )
- //DownloadSkin is exported function
- func (mc *Handler) DownloadSkin() {
- if _, err := os.Stat(mc.savePath + "/" + mc.UUID + ".png"); os.IsNotExist(err) {
- resp := httpReq("https://sessionserver.mojang.com/session/minecraft/profile/" + mc.UUID)
- var profileArray profile
- json.Unmarshal(resp, &profileArray)
- if len(profileArray.Error) > 0 {
- log.Println("Error when reading profiles. Download aborted.")
- copy("default_skin.png", mc.savePath+"/"+mc.UUID+".png")
- } else {
- decoded, _ := base64.URLEncoding.DecodeString(profileArray.Properties[0].Value)
- var textureArray texture
- json.Unmarshal([]byte(decoded), &textureArray)
- downloadFile(mc.savePath+"/"+mc.UUID+".png", textureArray.Textures.SKIN.URL)
- }
- } else {
- log.Println("Skin exists, not downloading")
- }
- }
|