Log last activity date

pull/1/head
Flashfyre 9 months ago
parent 967cbeecdd
commit 23eb0bbbe8

@ -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") {

@ -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)

Loading…
Cancel
Save