diff --git a/config.json b/config.json index f8b597fea..567776e51 100644 --- a/config.json +++ b/config.json @@ -105,8 +105,9 @@ "SeasonOverride": false, "EnumerateEvent": { "Enabled":false, - "EventID":8, + "EventID":2, "Duration":172800, + "RestartAfter":2977200, "QuestIDs": [20001, 20004, 20005, 20006, 20011, 20012, 20013, 20018, 20019, 20020, 20021, 20022, 20023, 20024, 20025, 20026, 20027, 20028, 20029] } }, diff --git a/config/config.go b/config/config.go index 9a8fdb329..4fe6ba46c 100644 --- a/config/config.go +++ b/config/config.go @@ -140,10 +140,11 @@ type CapLinkOptions struct { } type EnumerateEventOptions struct { - QuestIDs []uint16 - EventID uint16 - Enabled bool - Duration int + QuestIDs []uint16 + EventID uint16 + Enabled bool + Duration int + RestartAfter int } // GameplayOptions has various gameplay modifiers diff --git a/server/channelserver/handlers_event.go b/server/channelserver/handlers_event.go index f73d81bc0..70f358f1b 100644 --- a/server/channelserver/handlers_event.go +++ b/server/channelserver/handlers_event.go @@ -16,18 +16,44 @@ type Event struct { Unk2 uint16 Unk3 uint16 Unk4 uint16 - StartTime time.Time - EndTime time.Time + StartTime uint32 + EndTime uint32 QuestFileIDs []uint16 } +func cleanupEnumEvent(s *Session) { + s.server.db.Exec("DELETE FROM events WHERE event_type='ancientdragon'") +} +func generateEnumEventTimestamps(s *Session, start uint32) []uint32 { + timestamps := make([]uint32, 2) + midnight := TimeMidnight() + //if start is 0 or start is after a duration + if start == 0 || TimeAdjusted().Unix() > int64(start)+int64(s.server.erupeConfig.GameplayOptions.EnumerateEvent.RestartAfter) { + cleanupEnumEvent(s) + // Generate a new diva defense, starting midnight tomorrow + start = uint32(midnight.Add(24 * time.Hour).Unix()) + s.server.db.Exec("INSERT INTO events (event_type, start_time) VALUES ('ancientdragon', to_timestamp($1)::timestamp without time zone)", start) + } + timestamps[0] = start + timestamps[1] = timestamps[0] + uint32(s.server.erupeConfig.GameplayOptions.EnumerateEvent.Duration) + return timestamps +} + func handleMsgMhfEnumerateEvent(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfEnumerateEvent) bf := byteframe.NewByteFrame() + id, start := uint32(0xCAFEBEEF), uint32(0) + rows, _ := s.server.db.Queryx("SELECT id, (EXTRACT(epoch FROM start_time)::int) as start_time FROM events WHERE event_type='ancientdragon'") + for rows.Next() { + rows.Scan(&id, &start) + } + var timestamps []uint32 events := []Event{} + if s.server.erupeConfig.GameplayOptions.EnumerateEvent.Enabled { - events = append(events, Event{s.server.erupeConfig.GameplayOptions.EnumerateEvent.EventID, 0, 0, 0, 0, TimeWeekNext().Add(-time.Duration(s.server.erupeConfig.GameplayOptions.EnumerateEvent.Duration) * time.Second), TimeWeekNext(), s.server.erupeConfig.GameplayOptions.EnumerateEvent.QuestIDs}) + timestamps = generateEnumEventTimestamps(s, start) + events = append(events, Event{s.server.erupeConfig.GameplayOptions.EnumerateEvent.EventID, 0, 0, 0, 0, timestamps[0], timestamps[1], s.server.erupeConfig.GameplayOptions.EnumerateEvent.QuestIDs}) } bf.WriteUint8(uint8(len(events))) @@ -37,8 +63,8 @@ func handleMsgMhfEnumerateEvent(s *Session, p mhfpacket.MHFPacket) { bf.WriteUint16(event.Unk2) bf.WriteUint16(event.Unk3) bf.WriteUint16(event.Unk4) - bf.WriteUint32(uint32(event.StartTime.Unix())) - bf.WriteUint32(uint32(event.EndTime.Unix())) + bf.WriteUint32(event.StartTime) + bf.WriteUint32(event.EndTime) if event.EventType == 2 { bf.WriteUint8(uint8(len(event.QuestFileIDs))) for _, qf := range event.QuestFileIDs {