Log last activity date

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

@ -6,10 +6,12 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
"github.com/Flashfyre/pokerogue-server/db"
"github.com/klauspost/compress/zstd" "github.com/klauspost/compress/zstd"
) )
@ -128,6 +130,11 @@ func (s *Server) HandleSavedataUpdate(w http.ResponseWriter, r *http.Request) {
return return
} }
err = db.UpdateAccountLastActivity(uuid)
if err != nil {
log.Print("failed to update account last activity")
}
hexUuid := hex.EncodeToString(uuid) hexUuid := hex.EncodeToString(uuid)
switch r.URL.Query().Get("datatype") { switch r.URL.Query().Get("datatype") {
@ -237,6 +244,11 @@ func (s *Server) HandleSavedataDelete(w http.ResponseWriter, r *http.Request) {
return return
} }
err = db.UpdateAccountLastActivity(uuid)
if err != nil {
log.Print("failed to update account last activity")
}
hexUuid := hex.EncodeToString(uuid) hexUuid := hex.EncodeToString(uuid)
switch r.URL.Query().Get("datatype") { switch r.URL.Query().Get("datatype") {

@ -29,6 +29,15 @@ func AddAccountSession(username string, token []byte) error {
return nil 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) { func GetUsernameFromToken(token []byte) (string, error) {
var username string 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) 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