mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-04-04 20:17:15 +08:00
chore: Refactor saving session data to prevent saving older sessions
This commit is contained in:
parent
0526c7a0f1
commit
5b96cd6082
@ -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"
|
||||||
)
|
)
|
||||||
@ -120,8 +121,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…
x
Reference in New Issue
Block a user