From e30313ebfaf38d865b0d14f41203c056c843618f Mon Sep 17 00:00:00 2001 From: Saint Wish <6036821+SaintWish@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:21:03 -0500 Subject: [PATCH] add depreciated API routes to let servers know --- cmd/cmd.go | 20 ++++++++++++++++++++ internal/controller/controller.go | 5 +++++ internal/static/static.go | 1 + pkg/response/response.go | 11 +++++++++++ 4 files changed, 37 insertions(+) diff --git a/cmd/cmd.go b/cmd/cmd.go index b3b0804..ce9b077 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -111,6 +111,8 @@ func Run(args []string) (error) { ServerUnixHash: a.Hashes.ServerUnix, ScriptsHash: a.Hashes.Scripts, }) + + // API version 2 router.Route(static.APIVersion, func(r chi.Router) { r.Use(mw.BasicAuth) @@ -189,6 +191,24 @@ func Run(args []string) (error) { } }) + router.Route(static.OldAPIVersion, func(r chi.Router) { + r.Route("/", func(r chi.Router) { + r.Get("/sc/{hash}", con.DepreciatedAPIVersion) + r.Get("/ban/{steamid:[0-9]+}", con.DepreciatedAPIVersion) + r.Get("/map/{name}/{hash}", con.DepreciatedAPIVersion) + r.Get("/ping", con.DepreciatedAPIVersion) + + r.Route("/character", func(r chi.Router) { + r.Get("/{steamid:[0-9]+}/{slot:[0-9]}", con.DepreciatedAPIVersion) + r.Get("/export/{steamid:[0-9]+}/{slot:[0-9]}", con.DepreciatedAPIVersion) + + r.Post("/", con.DepreciatedAPIVersion) + r.Put("/{uid}", con.DepreciatedAPIVersion) + r.Delete("/{uid}", con.DepreciatedAPIVersion) + }) + }) + }) + ///////////////////////// //Auto certificate ///////////////////////// diff --git a/internal/controller/controller.go b/internal/controller/controller.go index af829cc..ab7baf1 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -129,4 +129,9 @@ func (c *Controller) GetServerVerify(w http.ResponseWriter, r *http.Request) { c.logger.Warn("Failed server verfication", "IP", r.RemoteAddr) response.Result(w, false) +} + +// DEPRECIATED +func (c *Controller) DepreciatedAPIVersion(w http.ResponseWriter, r *http.Request) { + response.DepreciatedError(w) } \ No newline at end of file diff --git a/internal/static/static.go b/internal/static/static.go index 8955c19..871cfb1 100644 --- a/internal/static/static.go +++ b/internal/static/static.go @@ -6,6 +6,7 @@ import ( const ( APIVersion = "/api/v2" // we're on v2 now, v1 used SQLite for database backend. + OldAPIVersion = "/api/v1" // this version was v1.x.x version of the FN server before the rewrite. ) var ( diff --git a/pkg/response/response.go b/pkg/response/response.go index f3ffff5..39863f6 100644 --- a/pkg/response/response.go +++ b/pkg/response/response.go @@ -134,4 +134,15 @@ func GenericError(w http.ResponseWriter) { w: w, } resp.SendJson() +} + +func DepreciatedError(w http.ResponseWriter) { + resp := Response{ + Status: false, + Code: http.StatusUpgradeRequired, + Error: "Server is out of date!", + Data: nil, + w: w, + } + resp.SendJson() } \ No newline at end of file