add persistent featured weapons

This commit is contained in:
wish
2022-10-23 12:45:10 +11:00
parent e5e3750045
commit 7691b84259
4 changed files with 42 additions and 23 deletions

View File

@@ -2,6 +2,7 @@
"Host": "127.0.0.1", "Host": "127.0.0.1",
"BinPath": "bin", "BinPath": "bin",
"DisableSoftCrash": false, "DisableSoftCrash": false,
"FeaturedWeapons": 2,
"devmode": true, "devmode": true,
"devmodeoptions": { "devmodeoptions": {
"EnableLauncherServer": false, "EnableLauncherServer": false,

View File

@@ -15,6 +15,7 @@ type Config struct {
Host string `mapstructure:"Host"` Host string `mapstructure:"Host"`
BinPath string `mapstructure:"BinPath"` BinPath string `mapstructure:"BinPath"`
DisableSoftCrash bool // Disables the 'Press Return to exit' dialog allowing scripts to reboot the server automatically DisableSoftCrash bool // Disables the 'Press Return to exit' dialog allowing scripts to reboot the server automatically
FeaturedWeapons int // Number of Active Feature weapons to generate daily
DevMode bool DevMode bool
DevModeOptions DevModeOptions DevModeOptions DevModeOptions

View File

@@ -0,0 +1,9 @@
BEGIN;
CREATE TABLE IF NOT EXISTS public.feature_weapon
(
start_time timestamp without time zone NOT NULL,
featured integer NOT NULL
);
END;

View File

@@ -53,38 +53,46 @@ func handleMsgMhfEnumerateEvent(s *Session, p mhfpacket.MHFPacket) {
} }
type activeFeature struct { type activeFeature struct {
StartTime time.Time StartTime time.Time `db:"start_time"`
ActiveFeatures uint32 ActiveFeatures uint32 `db:"featured"`
Unk1 uint16
} }
func handleMsgMhfGetWeeklySchedule(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfGetWeeklySchedule(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfGetWeeklySchedule) pkt := p.(*mhfpacket.MsgMhfGetWeeklySchedule)
persistentEventSchedule := make([]activeFeature, 8) // generate day after weekly restart
for x := -1; x < 7; x++ { var features []activeFeature
feat := generateActiveWeapons(14) // number of active weapons rows, _ := s.server.db.Queryx(`SELECT start_time, featured FROM feature_weapon WHERE start_time=$1 OR start_time=$2`, Time_Current_Midnight().Add(-24*time.Hour), Time_Current_Midnight())
// TODO: only generate this once per restart (server should be restarted weekly) for rows.Next() {
// then load data from db instead of regenerating var feature activeFeature
persistentEventSchedule[x+1] = activeFeature{ rows.StructScan(&feature)
StartTime: Time_Current_Midnight().Add(time.Duration(24*x) * time.Hour), features = append(features, feature)
ActiveFeatures: uint32(feat), }
Unk1: 0,
if len(features) < 2 {
if len(features) == 0 {
feature := generateFeatureWeapons(s.server.erupeConfig.FeaturedWeapons)
feature.StartTime = Time_Current_Midnight().Add(-24 * time.Hour)
features = append(features, feature)
s.server.db.Exec(`INSERT INTO feature_weapon VALUES ($1, $2)`, feature.StartTime, feature.ActiveFeatures)
} }
feature := generateFeatureWeapons(s.server.erupeConfig.FeaturedWeapons)
feature.StartTime = Time_Current_Midnight()
features = append(features, feature)
s.server.db.Exec(`INSERT INTO feature_weapon VALUES ($1, $2)`, feature.StartTime, feature.ActiveFeatures)
} }
resp := byteframe.NewByteFrame() bf := byteframe.NewByteFrame()
resp.WriteUint8(uint8(len(persistentEventSchedule))) // Entry count, client only parses the first 7 or 8. bf.WriteUint8(2)
resp.WriteUint32(uint32(Time_Current_Adjusted().Add(-5 * time.Minute).Unix())) // 5 minutes ago server time bf.WriteUint32(uint32(Time_Current_Adjusted().Add(-5 * time.Minute).Unix()))
for _, feature := range features {
for _, es := range persistentEventSchedule { bf.WriteUint32(uint32(feature.StartTime.Unix()))
resp.WriteUint32(uint32(es.StartTime.Unix())) bf.WriteUint32(feature.ActiveFeatures)
resp.WriteUint32(es.ActiveFeatures) bf.WriteUint16(0)
resp.WriteUint16(es.Unk1)
} }
doAckBufSucceed(s, pkt.AckHandle, resp.Data()) doAckBufSucceed(s, pkt.AckHandle, bf.Data())
} }
func generateActiveWeapons(count int) int { func generateFeatureWeapons(count int) activeFeature {
nums := make([]int, 0) nums := make([]int, 0)
var result int var result int
r := rand.New(rand.NewSource(time.Now().UnixNano())) r := rand.New(rand.NewSource(time.Now().UnixNano()))
@@ -104,7 +112,7 @@ func generateActiveWeapons(count int) int {
for _, num := range nums { for _, num := range nums {
result += int(math.Pow(2, float64(num))) result += int(math.Pow(2, float64(num)))
} }
return result return activeFeature{ActiveFeatures: uint32(result)}
} }
type loginBoost struct { type loginBoost struct {