Compare commits

..

No commits in common. "68caa148f6a965f01ea503d42f56daad6799e5f7" and "0526c7a0f197ecec009cbd59b9e07cab00b01a44" have entirely different histories.

2 changed files with 18 additions and 22 deletions

View File

@ -143,7 +143,7 @@ func handleGameTitleStats(w http.ResponseWriter, r *http.Request) {
} }
func handleGameClassicSessionCount(w http.ResponseWriter, r *http.Request) { func handleGameClassicSessionCount(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(strconv.Itoa(classicSessionCount))) _, _ = w.Write([]byte(strconv.Itoa(classicSessionCount)))
} }
func handleGetSessionData(w http.ResponseWriter, r *http.Request) { func handleGetSessionData(w http.ResponseWriter, r *http.Request) {
@ -162,12 +162,14 @@ func handleGetSessionData(w http.ResponseWriter, r *http.Request) {
} }
} }
if !r.URL.Query().Has("clientSessionId") { var clientSessionId string
if r.URL.Query().Has("clientSessionId") {
clientSessionId = r.URL.Query().Get("clientSessionId")
} else {
httpError(w, r, fmt.Errorf("missing clientSessionId"), http.StatusBadRequest) httpError(w, r, fmt.Errorf("missing clientSessionId"), http.StatusBadRequest)
return
} }
err = db.UpdateActiveSession(uuid, r.URL.Query().Get("clientSessionId")) err = db.UpdateActiveSession(uuid, clientSessionId)
if err != nil { if err != nil {
httpError(w, r, fmt.Errorf("failed to update active session: %s", err), http.StatusBadRequest) httpError(w, r, fmt.Errorf("failed to update active session: %s", err), http.StatusBadRequest)
return return
@ -432,7 +434,10 @@ func legacyHandleSaveData(w http.ResponseWriter, r *http.Request) {
} }
} }
clientSessionId := r.URL.Query().Get("clientSessionId") var clientSessionId string
if r.URL.Query().Has("clientSessionId") {
clientSessionId = r.URL.Query().Get("clientSessionId")
}
if clientSessionId == "" { if clientSessionId == "" {
clientSessionId = legacyClientSessionId clientSessionId = legacyClientSessionId
} }
@ -704,12 +709,14 @@ func handleGetSystemData(w http.ResponseWriter, r *http.Request) {
return return
} }
if !r.URL.Query().Has("clientSessionId") { var clientSessionId string
if r.URL.Query().Has("clientSessionId") {
clientSessionId = r.URL.Query().Get("clientSessionId")
} else {
httpError(w, r, fmt.Errorf("missing clientSessionId"), http.StatusBadRequest) httpError(w, r, fmt.Errorf("missing clientSessionId"), http.StatusBadRequest)
return
} }
err = db.UpdateActiveSession(uuid, r.URL.Query().Get("clientSessionId")) err = db.UpdateActiveSession(uuid, clientSessionId)
if err != nil { if err != nil {
httpError(w, r, fmt.Errorf("failed to update active session: %s", err), http.StatusBadRequest) httpError(w, r, fmt.Errorf("failed to update active session: %s", err), http.StatusBadRequest)
return return
@ -816,5 +823,5 @@ func handleDailyRankingPageCount(w http.ResponseWriter, r *http.Request) {
httpError(w, r, err, http.StatusInternalServerError) httpError(w, r, err, http.StatusInternalServerError)
} }
w.Write([]byte(strconv.Itoa(count))) _, _ = w.Write([]byte(strconv.Itoa(count)))
} }

View File

@ -20,7 +20,6 @@ package db
import ( import (
"bytes" "bytes"
"encoding/gob" "encoding/gob"
"errors"
"github.com/pagefaultgames/rogueserver/defs" "github.com/pagefaultgames/rogueserver/defs"
) )
@ -70,13 +69,8 @@ func ReadSystemSaveData(uuid []byte) (defs.SystemSaveData, error) {
} }
func StoreSystemSaveData(uuid []byte, data defs.SystemSaveData) error { func StoreSystemSaveData(uuid []byte, data defs.SystemSaveData) error {
systemData, err := ReadSystemSaveData(uuid)
if err == nil && systemData.Timestamp > data.Timestamp {
return errors.New("attempted to save an older system save")
}
var buf bytes.Buffer var buf bytes.Buffer
err = gob.NewEncoder(&buf).Encode(data) err := gob.NewEncoder(&buf).Encode(data)
if err != nil { if err != nil {
return err return err
} }
@ -126,13 +120,8 @@ func GetLatestSessionSaveDataSlot(uuid []byte) (int, error) {
} }
func StoreSessionSaveData(uuid []byte, data defs.SessionSaveData, slot int) error { func StoreSessionSaveData(uuid []byte, data defs.SessionSaveData, slot int) error {
session, err := ReadSessionSaveData(uuid, slot)
if err == nil && session.Seed == data.Seed && session.WaveIndex > data.WaveIndex {
return errors.New("attempted to save an older session")
}
var buf bytes.Buffer var buf bytes.Buffer
err = gob.NewEncoder(&buf).Encode(data) err := gob.NewEncoder(&buf).Encode(data)
if err != nil { if err != nil {
return err return err
} }