You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rogueserver/api/account/info.go

40 lines
785 B
Go

package account
import (
"fmt"
"os"
"strconv"
"time"
"github.com/pagefaultgames/pokerogue-server/defs"
)
type InfoResponse struct {
Username string `json:"username"`
LastSessionSlot int `json:"lastSessionSlot"`
}
// /account/info - get account info
func Info(username string, uuid []byte) (InfoResponse, error) {
var latestSave time.Time
latestSaveID := -1
for id := range defs.SessionSlotCount {
fileName := "session"
if id != 0 {
fileName += strconv.Itoa(id)
}
stat, err := os.Stat(fmt.Sprintf("userdata/%x/%s.pzs", uuid, fileName))
if err != nil {
continue
}
if stat.ModTime().After(latestSave) {
latestSave = stat.ModTime()
latestSaveID = id
}
}
return InfoResponse{Username: username, LastSessionSlot: latestSaveID}, nil
}