#1: Implemented necessary Mojang APIs

This commit is contained in:
ErickSkrauch
2019-04-14 17:36:27 +03:00
parent 4386054ca1
commit 7db4d27fba
3 changed files with 225 additions and 19 deletions

View File

@@ -5,21 +5,10 @@ import (
"net/http"
"strings"
"github.com/elyby/chrly/api/mojang"
"github.com/gorilla/mux"
)
type signedTexturesResponse struct {
Id string `json:"id"`
Name string `json:"name"`
Props []property `json:"properties"`
}
type property struct {
Name string `json:"name"`
Signature string `json:"signature,omitempty"`
Value string `json:"value"`
}
func (cfg *Config) SignedTextures(response http.ResponseWriter, request *http.Request) {
cfg.Logger.IncCounter("signed_textures.request", 1)
username := parseUsername(mux.Vars(request)["username"])
@@ -30,23 +19,23 @@ func (cfg *Config) SignedTextures(response http.ResponseWriter, request *http.Re
return
}
responseData:= signedTexturesResponse{
Id: strings.Replace(rec.Uuid, "-", "", -1),
responseData := mojang.SignedTexturesResponse{
Id: strings.Replace(rec.Uuid, "-", "", -1),
Name: rec.Username,
Props: []property{
Props: []mojang.Property{
{
Name: "textures",
Name: "textures",
Signature: rec.MojangSignature,
Value: rec.MojangTextures,
Value: rec.MojangTextures,
},
{
Name: "chrly",
Name: "chrly",
Value: "how do you tame a horse in Minecraft?",
},
},
}
responseJson,_ := json.Marshal(responseData)
responseJson, _ := json.Marshal(responseData)
response.Header().Set("Content-Type", "application/json")
response.Write(responseJson)
}