From d1ff8ce3fe2ff13482fc74724c6d43fbc9722693 Mon Sep 17 00:00:00 2001 From: Frederico Santos Date: Tue, 4 Jun 2024 03:09:07 +0100 Subject: [PATCH] Reject saves with 2 days difference --- db/savedata.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/db/savedata.go b/db/savedata.go index bb593b8..fe324fc 100644 --- a/db/savedata.go +++ b/db/savedata.go @@ -21,6 +21,7 @@ import ( "bytes" "encoding/gob" "errors" + "time" "github.com/pagefaultgames/rogueserver/defs" ) @@ -75,6 +76,13 @@ func StoreSystemSaveData(uuid []byte, data defs.SystemSaveData) error { return errors.New("attempted to save an older system save") } + if data.Timestamp > int(time.Now().UTC().Add(time.Hour*48).UnixMilli()) { + return errors.New("attempted to save a future system save") + } + if data.Timestamp < int(time.Now().UTC().Add(-time.Hour*48).UnixMilli()) { + return errors.New("attempted to save a past system save") + } + var buf bytes.Buffer err = gob.NewEncoder(&buf).Encode(data) if err != nil { @@ -131,6 +139,13 @@ func StoreSessionSaveData(uuid []byte, data defs.SessionSaveData, slot int) erro return errors.New("attempted to save an older session") } + if data.Timestamp > int(time.Now().UTC().Add(time.Hour*48).UnixMilli()) { + return errors.New("attempted to save a future session save") + } + if data.Timestamp < int(time.Now().UTC().Add(-time.Hour*48).UnixMilli()) { + return errors.New("attempted to save a past session save") + } + var buf bytes.Buffer err = gob.NewEncoder(&buf).Encode(data) if err != nil {