mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-04-26 14:16:18 +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
|
return
|
||||||
}
|
}
|
||||||
existingSave, err := savedata.GetSession(uuid, slot)
|
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 {
|
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)
|
httpError(w, r, fmt.Errorf("session out of date: existing wave index is greater"), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
@ -313,10 +316,14 @@ func handleUpdateAll(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
existingPlaytime, err := db.RetrievePlaytime(uuid)
|
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)
|
playtime, ok := data.System.GameStats.(map[string]interface{})["playTime"].(float64)
|
||||||
if !ok {
|
if !ok {
|
||||||
httpError(w, r, fmt.Errorf("no playtime found"), http.StatusBadRequest)
|
httpError(w, r, fmt.Errorf("no playtime found"), http.StatusBadRequest)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if float64(existingPlaytime) > playtime {
|
if float64(existingPlaytime) > playtime {
|
||||||
httpError(w, r, fmt.Errorf("session out of date: existing playtime is greater"), http.StatusBadRequest)
|
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)
|
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 {
|
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)
|
httpError(w, r, fmt.Errorf("session out of date: existing wave index is greater"), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
@ -407,10 +417,14 @@ func handleSystem(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
existingPlaytime, err := db.RetrievePlaytime(uuid)
|
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)
|
playtime, ok := system.GameStats.(map[string]interface{})["playTime"].(float64)
|
||||||
if !ok {
|
if !ok {
|
||||||
httpError(w, r, fmt.Errorf("no playtime found"), http.StatusBadRequest)
|
httpError(w, r, fmt.Errorf("no playtime found"), http.StatusBadRequest)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if float64(existingPlaytime) > playtime {
|
if float64(existingPlaytime) > playtime {
|
||||||
httpError(w, r, fmt.Errorf("session out of date: existing playtime is greater"), http.StatusBadRequest)
|
httpError(w, r, fmt.Errorf("session out of date: existing playtime is greater"), http.StatusBadRequest)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user