rogueserver/api/utils.go

24 lines
386 B
Go
Raw Normal View History

2024-03-16 18:51:13 -07:00
package api
import (
"crypto/md5"
"encoding/binary"
"math"
"time"
)
var seedKey []byte // 32 bytes
func SetSeedKey(key []byte) {
seedKey = key
}
func SeedFromTime(seedTime time.Time) []byte {
day := make([]byte, 8)
binary.BigEndian.PutUint64(day, uint64(math.Floor(float64(seedTime.Unix())/float64(time.Hour*24))))
sum := md5.Sum(append(seedKey, day...))
return sum[:]
}