mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-04-04 12:07:13 +08:00
Reject saves with 2 days difference
This commit is contained in:
parent
81b316f4c9
commit
d1ff8ce3fe
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user