From e8309a488a1e5e41b450106ac0ce63e4edd51260 Mon Sep 17 00:00:00 2001 From: Frederico Santos Date: Sun, 2 Jun 2024 20:03:27 +0100 Subject: [PATCH] Refactor saving session and system data to prevent saving older versions --- db/savedata.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/savedata.go b/db/savedata.go index 77c4351..bb593b8 100644 --- a/db/savedata.go +++ b/db/savedata.go @@ -71,7 +71,7 @@ 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 { + if err == nil && systemData.Timestamp > data.Timestamp { return errors.New("attempted to save an older system save") } @@ -127,7 +127,7 @@ func GetLatestSessionSaveDataSlot(uuid []byte) (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 { + if err == nil && session.Seed == data.Seed && session.WaveIndex > data.WaveIndex { return errors.New("attempted to save an older session") }