diff --git a/lib/routes/Cape.go b/lib/routes/Cape.go new file mode 100644 index 0000000..ff58a28 --- /dev/null +++ b/lib/routes/Cape.go @@ -0,0 +1,25 @@ +package routes + +import ( + "net/http" + + "github.com/gorilla/mux" + + "elyby/minecraft-skinsystem/lib/tools" +) + +func Cape(w http.ResponseWriter, r *http.Request) { + username := tools.ParseUsername(mux.Vars(r)["username"]) + http.Redirect(w, r, "http://skins.minecraft.net/MinecraftCloaks/" + username + ".png", 301) +} + +func CapeGET(w http.ResponseWriter, r *http.Request) { + username := r.URL.Query().Get("name") + if username == "" { + w.WriteHeader(http.StatusBadRequest) + return + } + + mux.Vars(r)["username"] = username + Cape(w, r) +} diff --git a/lib/routes/MinecraftPHP.go b/lib/routes/MinecraftPHP.go new file mode 100644 index 0000000..3457662 --- /dev/null +++ b/lib/routes/MinecraftPHP.go @@ -0,0 +1,28 @@ +package routes + +import ( + "net/http" + + "github.com/gorilla/mux" +) + +// Метод-наследие от первой версии системы скинов. +// Всё ещё иногда используется +// Просто конвертируем данные и отправляем их в основной обработчик +func MinecraftPHP(w http.ResponseWriter, r *http.Request) { + username := r.URL.Query().Get("name") + required := r.URL.Query().Get("type") + if username == "" || required == "" { + w.WriteHeader(http.StatusBadRequest) + return + } + + mux.Vars(r)["username"] = username + switch required { + case "skin": Skin(w, r) + case "cloack": Cape(w, r) + default: { + w.WriteHeader(http.StatusNotFound) + } + } +} diff --git a/lib/routes/Skin.go b/lib/routes/Skin.go index 161ea8f..9fed97d 100644 --- a/lib/routes/Skin.go +++ b/lib/routes/Skin.go @@ -22,3 +22,14 @@ func Skin(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, rec.Url, 301); } + +func SkinGET(w http.ResponseWriter, r *http.Request) { + username := r.URL.Query().Get("name") + if username == "" { + w.WriteHeader(http.StatusBadRequest) + return + } + + mux.Vars(r)["username"] = username + Skin(w, r) +} diff --git a/minecraft-skinsystem.go b/minecraft-skinsystem.go index c4ac5e0..0090ff5 100644 --- a/minecraft-skinsystem.go +++ b/minecraft-skinsystem.go @@ -23,7 +23,13 @@ func main() { router := mux.NewRouter().StrictSlash(true) router.HandleFunc("/", routes.NotFound) 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") + // Legacy + router.HandleFunc("/minecraft.php", routes.MinecraftPHP).Methods("GET") + router.HandleFunc("/skins/", routes.SkinGET).Methods("GET") + router.HandleFunc("/cloaks/", routes.CapeGET).Methods("GET") + // TODO: убрать этого, т.к. он стар router.HandleFunc("/system/setSkin", routes.SetSkin).Methods("POST")