From c1ada7f862e7453d75f0c1cc966706788408a805 Mon Sep 17 00:00:00 2001 From: maru Date: Sun, 31 Dec 2023 16:42:59 -0500 Subject: [PATCH] Add hasGameSession to account info response --- api/account.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/api/account.go b/api/account.go index 3e68320..c9792f1 100644 --- a/api/account.go +++ b/api/account.go @@ -5,9 +5,11 @@ import ( "crypto/rand" "database/sql" "encoding/base64" + "encoding/hex" "encoding/json" "fmt" "net/http" + "os" "regexp" "github.com/Flashfyre/pokerogue-server/db" @@ -26,7 +28,8 @@ var isValidUsername = regexp.MustCompile(`^\w{1,16}$`).MatchString // /account/info - get account info type AccountInfoResponse struct{ - Username string `json:"string"` + Username string `json:"username"` + HasGameSession bool `json:"hasGameSession"` } func (s *Server) HandleAccountInfo(w http.ResponseWriter, r *http.Request) { @@ -36,7 +39,15 @@ func (s *Server) HandleAccountInfo(w http.ResponseWriter, r *http.Request) { return } - response, err := json.Marshal(AccountInfoResponse{Username: username}) + uuid, err := GetUuidFromRequest(r) // lazy + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + _, err = os.Stat("userdata/" + hex.EncodeToString(uuid) + "/session.pzs") + + response, err := json.Marshal(AccountInfoResponse{Username: username, HasGameSession: err != nil}) if err != nil { http.Error(w, fmt.Sprintf("failed to marshal response json: %s", err), http.StatusInternalServerError) return