From 74efcd6311bc4d32327773ca7f9c77d53a3f8111 Mon Sep 17 00:00:00 2001 From: Frederico Santos Date: Sun, 2 Jun 2024 19:31:29 +0100 Subject: [PATCH] chore: Refactor saving system data to prevent saving older sessions --- db/savedata.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/db/savedata.go b/db/savedata.go index 021602f..77c4351 100644 --- a/db/savedata.go +++ b/db/savedata.go @@ -70,8 +70,13 @@ func ReadSystemSaveData(uuid []byte) (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 - err := gob.NewEncoder(&buf).Encode(data) + err = gob.NewEncoder(&buf).Encode(data) if err != nil { return err }