mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-04-21 11:46:19 +08:00
chore: Handle session out of date errors in savedata API
This commit is contained in:
parent
6f28c579c8
commit
4e4ac38e20
@ -198,7 +198,10 @@ func handleSession(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
existingSave, err := savedata.GetSession(uuid, slot)
|
||||
if err == nil {
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
httpError(w, r, fmt.Errorf("failed to retrieve session save data: %s", err), http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
if existingSave.Seed == session.Seed && existingSave.WaveIndex > session.WaveIndex {
|
||||
httpError(w, r, fmt.Errorf("session out of date: existing wave index is greater"), http.StatusBadRequest)
|
||||
return
|
||||
@ -313,10 +316,14 @@ func handleUpdateAll(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
existingPlaytime, err := db.RetrievePlaytime(uuid)
|
||||
if err == nil {
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
httpError(w, r, fmt.Errorf("failed to retrieve playtime: %s", err), http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
playtime, ok := data.System.GameStats.(map[string]interface{})["playTime"].(float64)
|
||||
if !ok {
|
||||
httpError(w, r, fmt.Errorf("no playtime found"), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if float64(existingPlaytime) > playtime {
|
||||
httpError(w, r, fmt.Errorf("session out of date: existing playtime is greater"), http.StatusBadRequest)
|
||||
@ -325,7 +332,10 @@ func handleUpdateAll(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
existingSave, err := savedata.GetSession(uuid, data.SessionSlotId)
|
||||
if err == nil {
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
httpError(w, r, fmt.Errorf("failed to retrieve session save data: %s", err), http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
if existingSave.Seed == data.Session.Seed && existingSave.WaveIndex > data.Session.WaveIndex {
|
||||
httpError(w, r, fmt.Errorf("session out of date: existing wave index is greater"), http.StatusBadRequest)
|
||||
return
|
||||
@ -407,10 +417,14 @@ func handleSystem(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
existingPlaytime, err := db.RetrievePlaytime(uuid)
|
||||
if err == nil {
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
httpError(w, r, fmt.Errorf("failed to retrieve playtime: %s", err), http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
playtime, ok := system.GameStats.(map[string]interface{})["playTime"].(float64)
|
||||
if !ok {
|
||||
httpError(w, r, fmt.Errorf("no playtime found"), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if float64(existingPlaytime) > playtime {
|
||||
httpError(w, r, fmt.Errorf("session out of date: existing playtime is greater"), http.StatusBadRequest)
|
||||
|
Loading…
x
Reference in New Issue
Block a user