Reject saves with 2 days difference

This commit is contained in:
Frederico Santos 2024-06-04 03:09:07 +01:00
parent 81b316f4c9
commit d1ff8ce3fe

View File

@ -21,6 +21,7 @@ import (
"bytes" "bytes"
"encoding/gob" "encoding/gob"
"errors" "errors"
"time"
"github.com/pagefaultgames/rogueserver/defs" "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") 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 var buf bytes.Buffer
err = gob.NewEncoder(&buf).Encode(data) err = gob.NewEncoder(&buf).Encode(data)
if err != nil { 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") 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 var buf bytes.Buffer
err = gob.NewEncoder(&buf).Encode(data) err = gob.NewEncoder(&buf).Encode(data)
if err != nil { if err != nil {