Update StoreSystemSaveData

pull/34/head
Pancakes 6 months ago
parent 52c5c9ee6c
commit 9efd1b751a
No known key found for this signature in database
GPG Key ID: 5792877BFA27DC8F

@ -72,25 +72,22 @@ func ReadSystemSaveData(uuid []byte) (defs.SystemSaveData, error) {
} }
func StoreSystemSaveData(uuid []byte, data defs.SystemSaveData) error { func StoreSystemSaveData(uuid []byte, data defs.SystemSaveData) error {
systemData, err := ReadSystemSaveData(uuid)
currentTime := time.Now() currentTime := time.Now()
futureTime := currentTime.Add(time.Hour * 24).UnixMilli() futureTime := currentTime.Add(time.Hour * 24).UnixMilli()
pastTime := currentTime.Add(-time.Hour * 24).UnixMilli() pastTime := currentTime.Add(-time.Hour * 24).UnixMilli()
systemData, err := ReadSystemSaveData(uuid)
if err == nil { // system save exists if err == nil { // system save exists
// Check if the new data timestamp is in the past against the system save but only if the system save is not past 24 hours from now // Check if the new data timestamp is in the past against the system save but only if the system save is not past 24 hours from now
if systemData.Timestamp > data.Timestamp && systemData.Timestamp < int(futureTime) { if systemData.Timestamp > data.Timestamp && systemData.Timestamp < int(futureTime) {
// Error if the new data timestamp is older than the current system save timestamp // Error if the new data timestamp is older than the current system save timestamp
return fmt.Errorf("attempted to save an older system save from %d when the current system save is from %d", return fmt.Errorf("attempted to save an older system save from %d when the current system save is from %d", data.Timestamp, systemData.Timestamp)
data.Timestamp,
systemData.Timestamp)
} }
} }
// Check if the data.Timestamp is too far in the future // Check if the data.Timestamp is too far in the future
if data.Timestamp > int(futureTime) { if data.Timestamp > int(futureTime) {
return fmt.Errorf("attempted to save a system save in the future from %d", data.Timestamp) return fmt.Errorf("attempted to save a system save in the future from %d", data.Timestamp)
} }
// Check if the data.Timestamp is too far in the past // Check if the data.Timestamp is too far in the past

Loading…
Cancel
Save