|
|
@ -18,11 +18,7 @@
|
|
|
|
package account
|
|
|
|
package account
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/pagefaultgames/rogueserver/db"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/pagefaultgames/rogueserver/defs"
|
|
|
|
"github.com/pagefaultgames/rogueserver/defs"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -33,24 +29,16 @@ type InfoResponse struct {
|
|
|
|
|
|
|
|
|
|
|
|
// /account/info - get account info
|
|
|
|
// /account/info - get account info
|
|
|
|
func Info(username string, uuid []byte) (InfoResponse, error) {
|
|
|
|
func Info(username string, uuid []byte) (InfoResponse, error) {
|
|
|
|
var latestSave time.Time
|
|
|
|
response := InfoResponse{Username: username, LastSessionSlot: -1}
|
|
|
|
latestSaveID := -1
|
|
|
|
|
|
|
|
for id := range defs.SessionSlotCount {
|
|
|
|
slot, err := db.GetLatestSessionSaveDataSlot(uuid)
|
|
|
|
fileName := "session"
|
|
|
|
if err != nil {
|
|
|
|
if id != 0 {
|
|
|
|
return response, err
|
|
|
|
fileName += strconv.Itoa(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if slot >= defs.SessionSlotCount {
|
|
|
|
stat, err := os.Stat(fmt.Sprintf("userdata/%x/%s.pzs", uuid, fileName))
|
|
|
|
response.LastSessionSlot = -1
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if stat.ModTime().After(latestSave) {
|
|
|
|
|
|
|
|
latestSave = stat.ModTime()
|
|
|
|
|
|
|
|
latestSaveID = id
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return InfoResponse{Username: username, LastSessionSlot: latestSaveID}, nil
|
|
|
|
return response, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|