mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-13 07:25:03 +01:00
diva scheduler and cleanup
This commit is contained in:
@@ -2,11 +2,100 @@ package channelserver
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"time"
|
||||
|
||||
"erupe-ce/common/byteframe"
|
||||
"erupe-ce/network/mhfpacket"
|
||||
)
|
||||
|
||||
func cleanupDiva(s *Session) {
|
||||
s.server.db.Exec("DELETE FROM events WHERE event_type='diva'")
|
||||
}
|
||||
|
||||
func generateDivaTimestamps(s *Session, start uint32, debug bool) []uint32 {
|
||||
timestamps := make([]uint32, 6)
|
||||
midnight := Time_Current_Midnight()
|
||||
if debug && start <= 3 {
|
||||
midnight := uint32(midnight.Unix())
|
||||
switch start {
|
||||
case 1:
|
||||
timestamps[0] = midnight
|
||||
timestamps[1] = timestamps[0] + 601200
|
||||
timestamps[2] = timestamps[1] + 3900
|
||||
timestamps[3] = timestamps[1] + 604800
|
||||
timestamps[4] = timestamps[3] + 3900
|
||||
timestamps[5] = timestamps[3] + 604800
|
||||
case 2:
|
||||
timestamps[0] = midnight - 605100
|
||||
timestamps[1] = midnight - 3900
|
||||
timestamps[2] = midnight
|
||||
timestamps[3] = timestamps[1] + 604800
|
||||
timestamps[4] = timestamps[3] + 3900
|
||||
timestamps[5] = timestamps[3] + 604800
|
||||
case 3:
|
||||
timestamps[0] = midnight - 1213800
|
||||
timestamps[1] = midnight - 608700
|
||||
timestamps[2] = midnight - 604800
|
||||
timestamps[3] = midnight - 3900
|
||||
timestamps[4] = midnight
|
||||
timestamps[5] = timestamps[3] + 604800
|
||||
}
|
||||
return timestamps
|
||||
}
|
||||
if start == 0 || Time_Current_Adjusted().Unix() > int64(start)+2977200 {
|
||||
cleanupDiva(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 ('diva', to_timestamp($1)::timestamp without time zone)", start)
|
||||
}
|
||||
timestamps[0] = start
|
||||
timestamps[1] = timestamps[0] + 601200
|
||||
timestamps[2] = timestamps[1] + 3900
|
||||
timestamps[3] = timestamps[1] + 604800
|
||||
timestamps[4] = timestamps[3] + 3900
|
||||
timestamps[5] = timestamps[3] + 604800
|
||||
return timestamps
|
||||
}
|
||||
|
||||
func handleMsgMhfGetUdSchedule(s *Session, p mhfpacket.MHFPacket) {
|
||||
pkt := p.(*mhfpacket.MsgMhfGetUdSchedule)
|
||||
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='diva'")
|
||||
for rows.Next() {
|
||||
rows.Scan(&id, &start)
|
||||
}
|
||||
|
||||
var timestamps []uint32
|
||||
if s.server.erupeConfig.DevMode && s.server.erupeConfig.DevModeOptions.DivaEvent >= 0 {
|
||||
if s.server.erupeConfig.DevModeOptions.DivaEvent == 0 {
|
||||
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||
return
|
||||
}
|
||||
timestamps = generateDivaTimestamps(s, uint32(s.server.erupeConfig.DevModeOptions.DivaEvent), true)
|
||||
} else {
|
||||
timestamps = generateDivaTimestamps(s, start, false)
|
||||
}
|
||||
|
||||
if timestamps[0] > uint32(Time_Current_Adjusted().Unix()) {
|
||||
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||
return
|
||||
}
|
||||
|
||||
bf.WriteUint32(id)
|
||||
for _, timestamp := range timestamps {
|
||||
bf.WriteUint32(timestamp)
|
||||
}
|
||||
|
||||
bf.WriteUint16(0x19) // Unk 00011001
|
||||
bf.WriteUint16(0x2D) // Unk 00101101
|
||||
bf.WriteUint16(0x02) // Unk 00000010
|
||||
bf.WriteUint16(0x02) // Unk 00000010
|
||||
|
||||
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
|
||||
}
|
||||
|
||||
func handleMsgMhfGetKijuInfo(s *Session, p mhfpacket.MHFPacket) {
|
||||
pkt := p.(*mhfpacket.MsgMhfGetKijuInfo)
|
||||
// Temporary canned response
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"erupe-ce/common/byteframe"
|
||||
"erupe-ce/network/mhfpacket"
|
||||
timeServerFix "erupe-ce/server/channelserver/timeserver"
|
||||
)
|
||||
|
||||
func handleMsgMhfRegisterEvent(s *Session, p mhfpacket.MHFPacket) {
|
||||
@@ -234,49 +233,6 @@ func handleMsgMhfUseKeepLoginBoost(s *Session, p mhfpacket.MHFPacket) {
|
||||
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
||||
}
|
||||
|
||||
func handleMsgMhfGetUdSchedule(s *Session, p mhfpacket.MHFPacket) {
|
||||
pkt := p.(*mhfpacket.MsgMhfGetUdSchedule)
|
||||
var t = timeServerFix.Tstatic_midnight()
|
||||
var event int = s.server.erupeConfig.DevModeOptions.DivaEvent
|
||||
|
||||
year, month, day := t.Date()
|
||||
midnight := time.Date(year, month, day, 0, 0, 0, 0, t.Location())
|
||||
// Events with time limits are Festival with Sign up, Soul Week and Winners Weeks
|
||||
// Diva Defense with Prayer, Interception and Song weeks
|
||||
// Mezeporta Festival with simply 'available' being a weekend thing
|
||||
resp := byteframe.NewByteFrame()
|
||||
resp.WriteUint32(0x1d5fda5c) // Unk (1d5fda5c, 0b5397df)
|
||||
|
||||
if event == 1 {
|
||||
resp.WriteUint32(uint32(midnight.Add(24 * 21 * time.Hour).Unix())) // Week 1 Timestamp, Festi start?
|
||||
} else {
|
||||
resp.WriteUint32(uint32(midnight.Add(-24 * 21 * time.Hour).Unix())) // Week 1 Timestamp, Festi start?
|
||||
}
|
||||
|
||||
if event == 2 {
|
||||
resp.WriteUint32(uint32(midnight.Add(24 * 14 * time.Hour).Unix())) // Week 2 Timestamp
|
||||
resp.WriteUint32(uint32(midnight.Add(24 * 14 * time.Hour).Unix())) // Week 2 Timestamp
|
||||
} else {
|
||||
resp.WriteUint32(uint32(midnight.Add(-24 * 14 * time.Hour).Unix())) // Week 2 Timestamp
|
||||
resp.WriteUint32(uint32(midnight.Add(-24 * 14 * time.Hour).Unix())) // Week 2 Timestamp
|
||||
}
|
||||
|
||||
if event == 3 {
|
||||
resp.WriteUint32(uint32(midnight.Add((24) * 7 * time.Hour).Unix())) // Diva Defense Interception
|
||||
resp.WriteUint32(uint32(midnight.Add((24) * 14 * time.Hour).Unix())) // Diva Defense Greeting Song
|
||||
} else {
|
||||
resp.WriteUint32(uint32(midnight.Add((-24) * 7 * time.Hour).Unix())) // Diva Defense Interception
|
||||
resp.WriteUint32(uint32(midnight.Add((-24) * 14 * time.Hour).Unix())) // Diva Defense Greeting Song
|
||||
}
|
||||
|
||||
resp.WriteUint16(0x19) // Unk 00011001
|
||||
resp.WriteUint16(0x2d) // Unk 00101101
|
||||
resp.WriteUint16(0x02) // Unk 00000010
|
||||
resp.WriteUint16(0x02) // Unk 00000010
|
||||
|
||||
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
|
||||
}
|
||||
|
||||
func handleMsgMhfGetUdInfo(s *Session, p mhfpacket.MHFPacket) {
|
||||
pkt := p.(*mhfpacket.MsgMhfGetUdInfo)
|
||||
// Message that appears on the Diva Defense NPC and triggers the green exclamation mark
|
||||
|
||||
@@ -946,7 +946,7 @@ func handleMsgMhfInfoGuild(s *Session, p mhfpacket.MHFPacket) {
|
||||
bf.WriteBytes(guildLeaderName)
|
||||
bf.WriteBytes([]byte{0x00, 0x00, 0x00, 0x00}) // Unk
|
||||
bf.WriteBool(false) // isReturnGuild
|
||||
bf.WriteBool(false) // Unk
|
||||
bf.WriteBool(false) // earnedSpecialHall
|
||||
bf.WriteBytes([]byte{0x02, 0x02}) // Unk
|
||||
bf.WriteUint32(guild.EventRP)
|
||||
ps.Uint8(bf, guild.PugiName1, true)
|
||||
|
||||
Reference in New Issue
Block a user