diff --git a/lib/routes/Face.go b/lib/routes/Face.go new file mode 100644 index 0000000..7b99996 --- /dev/null +++ b/lib/routes/Face.go @@ -0,0 +1,31 @@ +package routes + +import ( + "log" + "net/http" + + "github.com/gorilla/mux" + + "elyby/minecraft-skinsystem/lib/tools" + "elyby/minecraft-skinsystem/lib/data" +) + +const defaultHash = "default" + +func Face(w http.ResponseWriter, r *http.Request) { + username := tools.ParseUsername(mux.Vars(r)["username"]) + log.Println("request skin for username " + username); + rec, err := data.FindByUsername(username) + var hash string + if (err != nil || rec.SkinId == 0) { + hash = defaultHash; + } else { + hash = rec.Hash + } + + http.Redirect(w, r, tools.BuildElyUrl(buildFaceUrl(hash)), 301); +} + +func buildFaceUrl(hash string) string { + return "/minecfaft/skin_buffer/faces/" + hash + ".png" +} diff --git a/minecraft-skinsystem.go b/minecraft-skinsystem.go index 513aa30..1f99e2a 100644 --- a/minecraft-skinsystem.go +++ b/minecraft-skinsystem.go @@ -49,6 +49,8 @@ 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("/skins/{username}/face", routes.Face).Methods("GET").Name("faces") + router.HandleFunc("/skins/{username}/face.png", routes.Face).Methods("GET").Name("faces") // Legacy router.HandleFunc("/minecraft.php", routes.MinecraftPHP).Methods("GET") router.HandleFunc("/skins/", routes.SkinGET).Methods("GET")