diff --git a/lib/data/SignedTexturesResponse.go b/lib/data/SignedTexturesResponse.go new file mode 100644 index 0000000..cf0ec16 --- /dev/null +++ b/lib/data/SignedTexturesResponse.go @@ -0,0 +1,14 @@ +package data + +type SignedTexturesResponse struct { + Id string `json:"id"` + Name string `json:"name"` + IsEly bool `json:"ely,omitempty"` + Props []Property `json:"properties"` +} + +type Property struct { + Name string `json:"name"` + Signature string `json:"signature"` + Value string `json:"value"` +} diff --git a/lib/data/SkinItem.go b/lib/data/SkinItem.go index cc19253..eb88735 100644 --- a/lib/data/SkinItem.go +++ b/lib/data/SkinItem.go @@ -12,14 +12,17 @@ import ( ) type SkinItem struct { - UserId int `json:"userId"` - Username string `json:"username"` - SkinId int `json:"skinId"` - Url string `json:"url"` - Is1_8 bool `json:"is1_8"` - IsSlim bool `json:"isSlim"` - Hash string `json:"hash"` - oldUsername string + UserId int `json:"userId"` + Uuid string `json:"uuid"` + Username string `json:"username"` + SkinId int `json:"skinId"` + Url string `json:"url"` + Is1_8 bool `json:"is1_8"` + IsSlim bool `json:"isSlim"` + Hash string `json:"hash"` + MojangTextures string `json:"mojangTextures"` + MojangSignature string `json:"mojangSignature"` + oldUsername string } const accountIdToUsernameKey string = "hash:username-to-account-id" diff --git a/lib/routes/SignedTextures.go b/lib/routes/SignedTextures.go new file mode 100644 index 0000000..750a515 --- /dev/null +++ b/lib/routes/SignedTextures.go @@ -0,0 +1,40 @@ +package routes + +import ( + "strings" + "net/http" + "encoding/json" + + "github.com/gorilla/mux" + + "elyby/minecraft-skinsystem/lib/data" + "elyby/minecraft-skinsystem/lib/tools" + "elyby/minecraft-skinsystem/lib/services" +) + +func SignedTextures(w http.ResponseWriter, r *http.Request) { + services.Logger.IncCounter("signed_textures.request", 1) + username := tools.ParseUsername(mux.Vars(r)["username"]) + + rec, err := data.FindSkinByUsername(username) + if (err != nil || rec.SkinId == 0) { + w.WriteHeader(http.StatusNoContent) + return + } + + responseData:= data.SignedTexturesResponse{ + Id: strings.Replace(rec.Uuid, "-", "", -1), + Name: rec.Username, + Props: []data.Property{ + { + Name: "textures", + Signature: rec.MojangSignature, + Value: rec.MojangTextures, + }, + }, + } + + response,_ := json.Marshal(responseData) + w.Header().Set("Content-Type", "application/json") + w.Write(response) +} diff --git a/lib/worker/handlers.go b/lib/worker/handlers.go index b573275..072fefd 100644 --- a/lib/worker/handlers.go +++ b/lib/worker/handlers.go @@ -42,11 +42,14 @@ func handleSkinChanged(model skinChanged) (bool) { return true } + record.Uuid = model.Uuid record.SkinId = model.SkinId - record.Hash = model.Hash - record.Is1_8 = model.Is1_8 + record.Hash = model.Hash + record.Is1_8 = model.Is1_8 record.IsSlim = model.IsSlim - record.Url = model.Url + record.Url = model.Url + record.MojangTextures = model.MojangTextures + record.MojangSignature = model.MojangSignature record.Save() diff --git a/lib/worker/models.go b/lib/worker/models.go index eede2c2..0844112 100644 --- a/lib/worker/models.go +++ b/lib/worker/models.go @@ -7,11 +7,14 @@ type usernameChanged struct { } type skinChanged struct { - AccountId int `json:"userId"` - SkinId int `json:"skinId"` - OldSkinId int `json:"oldSkinId"` - Hash string `json:"hash"` - Is1_8 bool `json:"is1_8"` - IsSlim bool `json:"isSlim"` - Url string `json:"url"` + AccountId int `json:"userId"` + Uuid string `json:"uuid"` + SkinId int `json:"skinId"` + OldSkinId int `json:"oldSkinId"` + Hash string `json:"hash"` + Is1_8 bool `json:"is1_8"` + IsSlim bool `json:"isSlim"` + Url string `json:"url"` + MojangTextures string `json:"mojangTextures"` + MojangSignature string `json:"mojangSignature"` } diff --git a/minecraft-skinsystem.go b/minecraft-skinsystem.go index 8f93a9a..b8eefb6 100644 --- a/minecraft-skinsystem.go +++ b/minecraft-skinsystem.go @@ -85,6 +85,7 @@ func main() { router.HandleFunc("/skins/{username}", routes.Skin).Methods("GET").Name("skins") router.HandleFunc("/cloaks/{username}", routes.Cape).Methods("GET").Name("cloaks") router.HandleFunc("/textures/{username}", routes.Textures).Methods("GET").Name("textures") + router.HandleFunc("/textures/signed/{username}", routes.SignedTextures).Methods("GET").Name("signedTextures") router.HandleFunc("/skins/{username}/face", routes.Face).Methods("GET").Name("faces") router.HandleFunc("/skins/{username}/face.png", routes.Face).Methods("GET").Name("faces") // Legacy