diff --git a/api/savedata.go b/api/savedata.go index e1861f2..5dedc38 100644 --- a/api/savedata.go +++ b/api/savedata.go @@ -6,10 +6,12 @@ import ( "encoding/hex" "encoding/json" "fmt" + "log" "net/http" "os" "strconv" + "github.com/Flashfyre/pokerogue-server/db" "github.com/klauspost/compress/zstd" ) @@ -128,6 +130,11 @@ func (s *Server) HandleSavedataUpdate(w http.ResponseWriter, r *http.Request) { return } + err = db.UpdateAccountLastActivity(uuid) + if err != nil { + log.Print("failed to update account last activity") + } + hexUuid := hex.EncodeToString(uuid) switch r.URL.Query().Get("datatype") { @@ -237,6 +244,11 @@ func (s *Server) HandleSavedataDelete(w http.ResponseWriter, r *http.Request) { return } + err = db.UpdateAccountLastActivity(uuid) + if err != nil { + log.Print("failed to update account last activity") + } + hexUuid := hex.EncodeToString(uuid) switch r.URL.Query().Get("datatype") { diff --git a/db/account.go b/db/account.go index b3912db..60e8807 100644 --- a/db/account.go +++ b/db/account.go @@ -29,6 +29,15 @@ func AddAccountSession(username string, token []byte) error { return nil } +func UpdateAccountLastActivity(uuid []byte) error { + _, err := handle.Exec("UPDATE accounts SET lastActivity = UTC_TIMESTAMP() WHERE uuid = ?", uuid) + if err != nil { + return err + } + + return nil +} + func GetUsernameFromToken(token []byte) (string, error) { var username string err := handle.QueryRow("SELECT a.username FROM accounts a JOIN sessions s ON s.uuid = a.uuid WHERE s.token = ? AND s.expire > UTC_TIMESTAMP()", token).Scan(&username)