2017-08-20 03:52:42 +05:30
|
|
|
package http
|
2017-06-30 21:10:25 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2019-04-27 04:16:15 +05:30
|
|
|
|
|
|
|
"github.com/elyby/chrly/api/mojang"
|
2017-06-30 21:10:25 +05:30
|
|
|
)
|
|
|
|
|
2017-08-20 03:52:42 +05:30
|
|
|
func (cfg *Config) SignedTextures(response http.ResponseWriter, request *http.Request) {
|
|
|
|
cfg.Logger.IncCounter("signed_textures.request", 1)
|
|
|
|
username := parseUsername(mux.Vars(request)["username"])
|
2017-06-30 21:10:25 +05:30
|
|
|
|
2019-04-27 04:16:15 +05:30
|
|
|
var responseData *mojang.SignedTexturesResponse
|
|
|
|
|
2017-08-20 03:52:42 +05:30
|
|
|
rec, err := cfg.SkinsRepo.FindByUsername(username)
|
2019-04-27 04:16:15 +05:30
|
|
|
if err == nil && rec.SkinId != 0 && rec.MojangTextures != "" {
|
|
|
|
responseData = &mojang.SignedTexturesResponse{
|
|
|
|
Id: strings.Replace(rec.Uuid, "-", "", -1),
|
|
|
|
Name: rec.Username,
|
|
|
|
Props: []*mojang.Property{
|
|
|
|
{
|
|
|
|
Name: "textures",
|
|
|
|
Signature: rec.MojangSignature,
|
|
|
|
Value: rec.MojangTextures,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
} else if request.URL.Query().Get("proxy") != "" {
|
|
|
|
responseData = <-cfg.MojangTexturesQueue.GetTexturesForUsername(username)
|
2017-06-30 21:10:25 +05:30
|
|
|
}
|
|
|
|
|
2019-04-27 04:16:15 +05:30
|
|
|
if responseData == nil {
|
|
|
|
response.WriteHeader(http.StatusNoContent)
|
|
|
|
return
|
2017-06-30 21:10:25 +05:30
|
|
|
}
|
|
|
|
|
2019-04-28 03:13:22 +05:30
|
|
|
responseData.Props = append(responseData.Props, &mojang.Property{
|
|
|
|
Name: "chrly",
|
|
|
|
Value: "how do you tame a horse in Minecraft?",
|
|
|
|
})
|
|
|
|
|
2019-04-14 20:06:27 +05:30
|
|
|
responseJson, _ := json.Marshal(responseData)
|
2017-06-30 21:10:25 +05:30
|
|
|
response.Header().Set("Content-Type", "application/json")
|
|
|
|
response.Write(responseJson)
|
|
|
|
}
|