@ -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
}
}