AY 4 年之前
父节点
当前提交
7066625e0b
共有 2 个文件被更改,包括 26 次插入14 次删除
  1. 二进制
      __debug_bin
  2. 26 14
      mod/mc/skin.go

二进制
__debug_bin


+ 26 - 14
mod/mc/skin.go

@@ -5,29 +5,41 @@ import (
 	"encoding/json"
 	"log"
 	"os"
+	"regexp"
 )
 
 //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 {
-			if len(profileArray.Properties) > 0 {
-				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 {
-				copy("default_skin.png", mc.savePath+"/"+mc.UUID+".png")
+		if IsValidUUID(mc.UUID) {
+			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 {
+				if len(profileArray.Properties) > 0 {
+					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 {
+					copy("default_skin.png", mc.savePath+"/"+mc.UUID+".png")
+					log.Println("Error when reading profiles. Download aborted.")
+				}
 			}
+		} else {
+			log.Println("Invaild UUID...")
 		}
 	} else {
 		//log.Println("Skin exists, not downloading")
 	}
 }
+
+//vaild UUID
+//https://stackoverflow.com/questions/25051675/how-to-validate-uuid-v4-in-go
+func IsValidUUID(uuid string) bool {
+	r := regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$")
+	return r.MatchString(uuid)
+}