From e652691b298a20acc4f8d115c406fdab081d32bf Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sat, 1 Apr 2017 12:18:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D1=83=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/data/SignedTexturesResponse.go | 14 +++++++++++ lib/data/SkinItem.go | 19 ++++++++------ lib/routes/SignedTextures.go | 40 ++++++++++++++++++++++++++++++ lib/worker/handlers.go | 9 ++++--- lib/worker/models.go | 17 +++++++------ minecraft-skinsystem.go | 1 + 6 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 lib/data/SignedTexturesResponse.go create mode 100644 lib/routes/SignedTextures.go 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