From 7b41d76ba9e3e66ebc9d6bb0a88a9c5b01d496bd Mon Sep 17 00:00:00 2001 From: pg9182 <96569817+pg9182@users.noreply.github.com> Date: Thu, 13 Oct 2022 16:50:43 -0400 Subject: pkg/api/api0: Implement /client/mainmenupromos Also support varying it so things like version-specific messages can be shown. --- pkg/api/api0/api.go | 5 ++++ pkg/api/api0/client.go | 66 ++++++++++++++++++++++++++++++++++++++++++++ pkg/api/api0/clientserver.go | 32 --------------------- pkg/api/api0/server.go | 12 ++++++++ 4 files changed, 83 insertions(+), 32 deletions(-) create mode 100644 pkg/api/api0/client.go delete mode 100644 pkg/api/api0/clientserver.go create mode 100644 pkg/api/api0/server.go (limited to 'pkg/api') diff --git a/pkg/api/api0/api.go b/pkg/api/api0/api.go index 33207a1..7d1e638 100644 --- a/pkg/api/api0/api.go +++ b/pkg/api/api0/api.go @@ -28,6 +28,9 @@ type Handler struct { // PdataStorage stores player data. It must be non-nil. PdataStorage PdataStorage + // MainMenuPromos gets the main menu promos to return for a request. + MainMenuPromos func(*http.Request) MainMenuPromos + // NotFound handles requests not handled by this Handler. NotFound http.Handler } @@ -37,6 +40,8 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set("Server", "Atlas") switch r.URL.Path { + case "/client/mainmenupromos": + h.handleMainMenuPromos(w, r) case "/accounts/write_persistence": h.handleAccountsWritePersistence(w, r) case "/accounts/get_username": diff --git a/pkg/api/api0/client.go b/pkg/api/api0/client.go new file mode 100644 index 0000000..7874872 --- /dev/null +++ b/pkg/api/api0/client.go @@ -0,0 +1,66 @@ +package api0 + +import ( + "net/http" +) + +type MainMenuPromos struct { + NewInfo MainMenuPromosNew `json:"newInfo"` + LargeButton MainMenuPromosButtonLarge `json:"largeButton"` + SmallButton1 MainMenuPromosButtonSmall `json:"smallButton1"` + SmallButton2 MainMenuPromosButtonSmall `json:"smallButton2"` +} + +type MainMenuPromosNew struct { + Title1 string `json:"Title1"` + Title2 string `json:"Title2"` + Title3 string `json:"Title3"` +} + +type MainMenuPromosButtonLarge struct { + Title string `json:"Title"` + Text string `json:"Text"` + Url string `json:"Url"` + ImageIndex int `json:"ImageIndex"` +} + +type MainMenuPromosButtonSmall struct { + Title string `json:"Title"` + Url string `json:"Url"` + ImageIndex int `json:"ImageIndex"` +} + +func (h *Handler) handleMainMenuPromos(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodOptions && r.Method != http.MethodHead && r.Method != http.MethodGet { + http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) + return + } + + w.Header().Set("Cache-Control", "private, no-cache, no-store") + w.Header().Set("Expires", "0") + w.Header().Set("Pragma", "no-cache") + + if r.Method == http.MethodOptions { + w.Header().Set("Allow", "OPTIONS, HEAD, GET") + w.WriteHeader(http.StatusNoContent) + return + } + + var p MainMenuPromos + if h.MainMenuPromos != nil { + p = h.MainMenuPromos(r) + } + respJSON(w, r, http.StatusOK, p) +} + +/* + /client/origin_auth: + GET: + /client/auth_with_server: + POST: + /client/auth_with_self: + POST: + + /client/servers: + GET: +*/ diff --git a/pkg/api/api0/clientserver.go b/pkg/api/api0/clientserver.go deleted file mode 100644 index 858e8aa..0000000 --- a/pkg/api/api0/clientserver.go +++ /dev/null @@ -1,32 +0,0 @@ -package api0 - -/* - /accounts/write_persistence: - POST: - - /accounts/lookup_uid: - GET: - /accounts/get_username: - GET: - - /client/mainmenupromos: - GET: - - /client/origin_auth: - GET: - /client/auth_with_server: - POST: - /client/auth_with_self: - POST: - - /client/servers: - POST: - /server/add_server: - POST: - /server/heartbeat: - POST: - /server/update_values: - POST: - /server/remove_server: - DELETE: -*/ diff --git a/pkg/api/api0/server.go b/pkg/api/api0/server.go new file mode 100644 index 0000000..d1a94bb --- /dev/null +++ b/pkg/api/api0/server.go @@ -0,0 +1,12 @@ +package api0 + +/* + /server/add_server: + POST: + /server/heartbeat: + POST: + /server/update_values: + POST: + /server/remove_server: + DELETE: +*/ -- cgit v1.2.3