mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-07-05 16:02:23 +02:00
Compare commits
3 Commits
0526c7a0f1
...
68caa148f6
Author | SHA1 | Date | |
---|---|---|---|
|
68caa148f6 | ||
|
3269e30a25 | ||
|
87e8f00cd6 |
@ -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,14 +162,12 @@ func handleGetSessionData(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var clientSessionId string
|
if !r.URL.Query().Has("clientSessionId") {
|
||||||
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, clientSessionId)
|
err = db.UpdateActiveSession(uuid, r.URL.Query().Get("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
|
||||||
@ -434,10 +432,7 @@ func legacyHandleSaveData(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var clientSessionId string
|
clientSessionId := r.URL.Query().Get("clientSessionId")
|
||||||
if r.URL.Query().Has("clientSessionId") {
|
|
||||||
clientSessionId = r.URL.Query().Get("clientSessionId")
|
|
||||||
}
|
|
||||||
if clientSessionId == "" {
|
if clientSessionId == "" {
|
||||||
clientSessionId = legacyClientSessionId
|
clientSessionId = legacyClientSessionId
|
||||||
}
|
}
|
||||||
@ -709,14 +704,12 @@ func handleGetSystemData(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var clientSessionId string
|
if !r.URL.Query().Has("clientSessionId") {
|
||||||
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, clientSessionId)
|
err = db.UpdateActiveSession(uuid, r.URL.Query().Get("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
|
||||||
@ -823,5 +816,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)))
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ package db
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/pagefaultgames/rogueserver/defs"
|
"github.com/pagefaultgames/rogueserver/defs"
|
||||||
)
|
)
|
||||||
@ -69,8 +70,13 @@ 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
|
||||||
}
|
}
|
||||||
@ -120,8 +126,13 @@ 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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user