Skip to content

Commit

Permalink
Merge branch 'pagefaultgames:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
StrayanDropbear authored Jun 23, 2024
2 parents b34a1a8 + 4cac6b6 commit c7ca6d6
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 629 deletions.
24 changes: 3 additions & 21 deletions api/account/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package account

import (
"github.com/pagefaultgames/rogueserver/db"
"github.com/pagefaultgames/rogueserver/defs"
)

type InfoResponse struct {
Expand All @@ -29,24 +28,7 @@ type InfoResponse struct {

// /account/info - get account info
func Info(username string, uuid []byte) (InfoResponse, error) {
response := InfoResponse{Username: username, LastSessionSlot: -1}

highest := -1
for i := 0; i < defs.SessionSlotCount; i++ {
data, err := db.ReadSessionSaveData(uuid, i)
if err != nil {
continue
}

if data.Timestamp > highest {
highest = data.Timestamp
response.LastSessionSlot = i
}
}

if response.LastSessionSlot < 0 || response.LastSessionSlot >= defs.SessionSlotCount {
response.LastSessionSlot = -1
}

return response, nil
slot, _ := db.GetLatestSessionSaveDataSlot(uuid)

return InfoResponse{Username: username, LastSessionSlot: slot}, nil
}
10 changes: 2 additions & 8 deletions api/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,11 @@ func Init(mux *http.ServeMux) error {
mux.HandleFunc("GET /game/classicsessioncount", handleGameClassicSessionCount)

// savedata
mux.HandleFunc("GET /savedata/get", legacyHandleGetSaveData)
mux.HandleFunc("POST /savedata/update", legacyHandleSaveData)
mux.HandleFunc("GET /savedata/delete", legacyHandleSaveData) // TODO use deleteSystemSave
mux.HandleFunc("POST /savedata/clear", legacyHandleSaveData) // TODO use clearSessionData
mux.HandleFunc("GET /savedata/newclear", legacyHandleNewClear)
mux.HandleFunc("/savedata/session/{action}", handleSession)
mux.HandleFunc("/savedata/system/{action}", handleSystem)

// new session
mux.HandleFunc("POST /savedata/updateall", handleUpdateAll)
mux.HandleFunc("POST /savedata/system/verify", handleSystemVerify)
mux.HandleFunc("GET /savedata/system", handleGetSystemData)
mux.HandleFunc("GET /savedata/session", handleGetSessionData)

// daily
mux.HandleFunc("GET /daily/seed", handleDailySeed)
Expand Down
8 changes: 2 additions & 6 deletions api/daily/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func Init() error {
secret = newSecret
}

seed, err := recordNewDaily()
seed, err := db.TryAddDailyRun(Seed())
if err != nil {
log.Print(err)
}
Expand All @@ -71,7 +71,7 @@ func Init() error {
_, err = scheduler.AddFunc("@daily", func() {
time.Sleep(time.Second)

seed, err = recordNewDaily()
seed, err = db.TryAddDailyRun(Seed())
if err != nil {
log.Printf("error while recording new daily: %s", err)
} else {
Expand Down Expand Up @@ -99,7 +99,3 @@ func deriveSeed(seedTime time.Time) []byte {

return hashedSeed[:]
}

func recordNewDaily() (string, error) {
return db.TryAddDailyRun(Seed())
}
Loading

0 comments on commit c7ca6d6

Please sign in to comment.