From 6cf7c1a4b772435f240ce24f38faa4b495b252eb Mon Sep 17 00:00:00 2001 From: stratic-dev Date: Thu, 11 Jul 2024 20:48:09 +0100 Subject: [PATCH] Removed EarthStatus for Event System --- config.json | 3 +- config/config.go | 3 +- network/mhfpacket/msg_mhf_post_tiny_bin.go | 3 + network/mhfpacket/msg_mhf_post_tower_info.go | 4 +- server/channelserver/handlers.go | 127 ++++++++++++++++++- server/channelserver/handlers_data.go | 17 +++ server/channelserver/handlers_tower.go | 48 +++++-- 7 files changed, 183 insertions(+), 22 deletions(-) diff --git a/config.json b/config.json index 76ba2d5f5..e706301e9 100644 --- a/config.json +++ b/config.json @@ -23,8 +23,7 @@ "AutoCreateAccount": true, "DefaultCourses": [1, 23, 24], - "EarthStatus": 0, - "EarthID": 0, + "EarthDebug":true, "EarthMonsters": [116, 107, 2, 36], "SaveDumps": { "Enabled": true, diff --git a/config/config.go b/config/config.go index 52642956b..2341f97b5 100644 --- a/config/config.go +++ b/config/config.go @@ -82,8 +82,7 @@ type Config struct { CommandPrefix string // The prefix for commands AutoCreateAccount bool // Automatically create accounts if they don't exist DefaultCourses []uint16 - EarthStatus int32 - EarthID int32 + EarthDebug bool EarthMonsters []int32 SaveDumps SaveDumpOptions Screenshots ScreenshotsOptions diff --git a/network/mhfpacket/msg_mhf_post_tiny_bin.go b/network/mhfpacket/msg_mhf_post_tiny_bin.go index dd464d18d..0e2d1db12 100644 --- a/network/mhfpacket/msg_mhf_post_tiny_bin.go +++ b/network/mhfpacket/msg_mhf_post_tiny_bin.go @@ -2,6 +2,7 @@ package mhfpacket import ( "errors" + "fmt" "erupe-ce/common/byteframe" "erupe-ce/network" @@ -31,6 +32,8 @@ func (m *MsgMhfPostTinyBin) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Client m.Unk2 = bf.ReadUint8() m.Unk3 = bf.ReadUint8() m.Data = bf.ReadBytes(uint(bf.ReadUint16())) + fmt.Printf("MsgMhfPostTinyBin: Unk0:[%d] Unk1:[%d] Unk2:[%d] Unk3:[%d] \n\n", m.Unk0, m.Unk1, m.Unk2, m.Unk3) + return nil } diff --git a/network/mhfpacket/msg_mhf_post_tower_info.go b/network/mhfpacket/msg_mhf_post_tower_info.go index 3808777e5..73c94b9de 100644 --- a/network/mhfpacket/msg_mhf_post_tower_info.go +++ b/network/mhfpacket/msg_mhf_post_tower_info.go @@ -20,7 +20,7 @@ type MsgMhfPostTowerInfo struct { Unk6 int32 Unk7 int32 Block1 int32 - Unk9 int64 + TimeTaken int64 } // Opcode returns the ID associated with this packet type. @@ -40,7 +40,7 @@ func (m *MsgMhfPostTowerInfo) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Clie m.Unk6 = bf.ReadInt32() m.Unk7 = bf.ReadInt32() m.Block1 = bf.ReadInt32() - m.Unk9 = bf.ReadInt64() + m.TimeTaken = bf.ReadInt64() return nil } diff --git a/server/channelserver/handlers.go b/server/channelserver/handlers.go index addb20bf5..ef5db3839 100644 --- a/server/channelserver/handlers.go +++ b/server/channelserver/handlers.go @@ -10,6 +10,7 @@ import ( _config "erupe-ce/config" "fmt" "io" + "log" "net" "strings" "time" @@ -32,7 +33,7 @@ func stubEnumerateNoResults(s *Session, ackHandle uint32) { func doAckEarthSucceed(s *Session, ackHandle uint32, data []*byteframe.ByteFrame) { bf := byteframe.NewByteFrame() - bf.WriteUint32(uint32(s.server.erupeConfig.EarthID)) + bf.WriteUint32(0) bf.WriteUint32(0) bf.WriteUint32(0) bf.WriteUint32(uint32(len(data))) @@ -1088,14 +1089,130 @@ func handleMsgMhfUnreserveSrg(s *Session, p mhfpacket.MHFPacket) { } func handleMsgMhfKickExportForce(s *Session, p mhfpacket.MHFPacket) {} +func cleanupEarthStatus(s *Session) { + s.server.db.Exec("DELETE FROM events WHERE event_type='tower'") + s.server.db.Exec("DELETE FROM events WHERE event_type='pallone'") + s.server.db.Exec("DELETE FROM events WHERE event_type='conquest'") + +} +func generateEarthStatusTimestamps(s *Session, start uint32, debug bool) []uint32 { + timestamps := make([]uint32, 3) + midnight := TimeMidnight() + if start == 0 || TimeAdjusted().Unix() > int64(start)+2977200 { + cleanupEarthStatus(s) + // Generate a new festa, starting midnight tomorrow + start = uint32(midnight.Add(24 * time.Hour).Unix()) + s.server.db.Exec("INSERT INTO events (event_type, start_time) VALUES ('tower', to_timestamp($1)::timestamp without time zone)", start) + } + if debug { + timestamps[0] = uint32(TimeWeekStart().Unix()) + timestamps[1] = uint32(TimeWeekNext().Unix()) + timestamps[1] = uint32(TimeWeekNext().Add((time.Duration(7) * time.Hour * 24)).Unix()) + + } else { + timestamps[0] = start + timestamps[1] = timestamps[0] + 604800 + timestamps[2] = timestamps[1] + 604800 + } + return timestamps +} func handleMsgMhfGetEarthStatus(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfGetEarthStatus) bf := byteframe.NewByteFrame() - bf.WriteUint32(uint32(TimeWeekStart().Unix())) // Start - bf.WriteUint32(uint32(TimeWeekNext().Unix())) // End - bf.WriteInt32(s.server.erupeConfig.EarthStatus) - bf.WriteInt32(s.server.erupeConfig.EarthID) + //Conquest + var conquestTimestamps []uint32 + var debug = s.server.erupeConfig.EarthDebug + conquestId, conquestStart := int32(0xBEEFEE), uint32(0) + rows, _ := s.server.db.Queryx("SELECT id, (EXTRACT(epoch FROM start_time)::int) as start_time FROM events WHERE event_type='conquest'") + if rows == nil { + log.Println("No rows found") + + } else { + for rows.Next() { + rows.Scan(&conquestId, &conquestStart) + } + } + conquestTimestamps = generateEarthStatusTimestamps(s, conquestStart, debug) + if TimeAdjusted().After(time.UnixMilli(int64(conquestTimestamps[1]))) { + bf.WriteUint32(conquestTimestamps[0]) // Start + bf.WriteUint32(conquestTimestamps[1]) // End + bf.WriteInt32(1) //Conquest Earth Status ID //1 and 2 UNK the difference + bf.WriteInt32(conquestId) //ID + } else { + bf.WriteUint32(conquestTimestamps[1]) // Start + bf.WriteUint32(conquestTimestamps[2]) // End + bf.WriteInt32(2) //Conquest Earth Status ID //1 and 2 UNK the difference + bf.WriteInt32(conquestId) //ID + } + for i, m := range s.server.erupeConfig.EarthMonsters { + //Changed from G9 to G8 to get conquest working in g9.1 + if _config.ErupeConfig.RealClientMode <= _config.G8 { + if i == 3 { + break + } + } + if i == 4 { + break + } + bf.WriteInt32(m) + } + //Pallone + var palloneTimestamps []uint32 + palloneId, palloneStart := int32(0xBEEFEE), uint32(0) + rows, _ = s.server.db.Queryx("SELECT id, (EXTRACT(epoch FROM start_time)::int) as start_time FROM events WHERE event_type='pallone'") + + if rows == nil { + log.Println("No rows found") + + } else { + for rows.Next() { + rows.Scan(&palloneId, &palloneStart) + } + } + palloneTimestamps = generateEarthStatusTimestamps(s, palloneStart, debug) + if TimeAdjusted().After(time.UnixMilli(int64(palloneTimestamps[1]))) { + bf.WriteUint32(palloneTimestamps[0]) // Start + bf.WriteUint32(palloneTimestamps[1]) // End + bf.WriteInt32(11) //Pallone Earth Status ID //11 is Fest //12 is Reward + bf.WriteInt32(palloneId) //ID + } else { + bf.WriteUint32(palloneTimestamps[1]) // Start + bf.WriteUint32(palloneTimestamps[2]) // End + bf.WriteInt32(12) //Pallone Earth Status ID //11 is Fest //12 is Reward + bf.WriteInt32(palloneId) //ID + } + + for i, m := range s.server.erupeConfig.EarthMonsters { + //Changed from G9 to G8 to get conquest working in g9.1 + if _config.ErupeConfig.RealClientMode <= _config.G8 { + if i == 3 { + break + } + } + if i == 4 { + break + } + bf.WriteInt32(m) + } + + //TOWER + var towerTimestamps []uint32 + towerId, towerStart := int32(0xBEEFEE), uint32(0) + rows, _ = s.server.db.Queryx("SELECT id, (EXTRACT(epoch FROM start_time)::int) as start_time FROM events WHERE event_type='tower'") + if rows == nil { + log.Println("No rows found") + + } else { + for rows.Next() { + rows.Scan(&towerId, &towerStart) + } + } + towerTimestamps = generateEarthStatusTimestamps(s, towerStart, debug) + bf.WriteUint32(towerTimestamps[0]) // Start + bf.WriteUint32(towerTimestamps[1]) // End + bf.WriteInt32(21) //Tower Earth Status ID + bf.WriteInt32(towerId) //ID for i, m := range s.server.erupeConfig.EarthMonsters { //Changed from G9 to G8 to get conquest working in g9.1 if _config.ErupeConfig.RealClientMode <= _config.G8 { diff --git a/server/channelserver/handlers_data.go b/server/channelserver/handlers_data.go index d613c10ff..aed2407de 100644 --- a/server/channelserver/handlers_data.go +++ b/server/channelserver/handlers_data.go @@ -4,6 +4,7 @@ import ( "erupe-ce/common/mhfmon" "erupe-ce/common/stringsupport" _config "erupe-ce/config" + "fmt" "io" "os" @@ -1010,6 +1011,17 @@ func handleMsgMhfGetPaperData(s *Session, p mhfpacket.MHFPacket) { switch pkt.ID { case 0: + //PaperMissionData Target + // 1: Total Floors + // 2: TRP Acquired + // 3: Treasure Chests + // 4: Old Tresure Chests + // 5: Defeat Large Monster + // 6: Dist 1 Dure Slays + // 7: Dist 2 Dure Slays + // 8: Dist 3 Dure Slays + // 9: Dist 4 Dure Slays + paperMissions = PaperMission{ []PaperMissionTimetable{{TimeMidnight(), TimeMidnight().Add(24 * time.Hour)}}, []PaperMissionData{{1, 1, 50, 7, 10, 8, 11}, @@ -1032,6 +1044,11 @@ func handleMsgMhfGetPaperData(s *Session, p mhfpacket.MHFPacket) { //Value is based in 6001 for items {1012, 1, 0, 0, 0, 0, 0}, {1012, 2, 0, 0, 0, 0, 0}, + + //Its possible that these also controll the annoucement banners and chat messages ... + // Functions to look at... + //tower_announce_move() -> disp_tower_announce() + // sendTowerVenomChatMsg() } case 5: //On load into MezePorta diff --git a/server/channelserver/handlers_tower.go b/server/channelserver/handlers_tower.go index f8e7874aa..8e37d4a1d 100644 --- a/server/channelserver/handlers_tower.go +++ b/server/channelserver/handlers_tower.go @@ -24,8 +24,15 @@ type TowerInfoSkill struct { } type TowerInfoHistory struct { - Unk0 []int16 // 5 - Unk1 []int16 // 5 + Unk0 TowerHistory // 5 + Unk1 TowerHistory // 5 +} +type TowerHistory struct { + Unk0 int16 + Unk1 int16 + Unk2 int16 + Unk3 int16 + Unk4 int16 } type TowerInfoLevel struct { @@ -53,11 +60,25 @@ func handleMsgMhfGetTowerInfo(s *Session, p mhfpacket.MHFPacket) { Level []TowerInfoLevel } + history1 := TowerHistory{ + Unk0: 1, + Unk1: 2, + Unk2: 3, + Unk3: 4, + Unk4: 5, + } + history2 := TowerHistory{ + Unk0: 1, + Unk1: 2, + Unk2: 3, + Unk3: 4, + Unk4: 5, + } towerInfo := TowerInfo{ TRP: []TowerInfoTRP{{0, 0}}, Skill: []TowerInfoSkill{{0, make([]int16, 64)}}, - History: []TowerInfoHistory{{make([]int16, 5), make([]int16, 5)}}, - Level: []TowerInfoLevel{{0, 0, 0, 0}, {0, 0, 0, 0}}, + History: []TowerInfoHistory{{history1, history2}}, + Level: []TowerInfoLevel{{0, 5, 5, 5}, {0, 5, 5, 5}}, } var tempSkills string @@ -95,12 +116,17 @@ func handleMsgMhfGetTowerInfo(s *Session, p mhfpacket.MHFPacket) { case 4: for _, history := range towerInfo.History { bf := byteframe.NewByteFrame() - for i := range history.Unk0 { - bf.WriteInt16(history.Unk0[i]) - } - for i := range history.Unk1 { - bf.WriteInt16(history.Unk1[i]) - } + bf.WriteInt16(history.Unk0.Unk0) + bf.WriteInt16(history.Unk0.Unk1) + bf.WriteInt16(history.Unk0.Unk2) + bf.WriteInt16(history.Unk0.Unk3) + bf.WriteInt16(history.Unk0.Unk4) + + bf.WriteInt16(history.Unk1.Unk0) + bf.WriteInt16(history.Unk1.Unk1) + bf.WriteInt16(history.Unk1.Unk2) + bf.WriteInt16(history.Unk1.Unk3) + bf.WriteInt16(history.Unk1.Unk4) data = append(data, bf) } case 3, 5: @@ -131,7 +157,7 @@ func handleMsgMhfPostTowerInfo(s *Session, p mhfpacket.MHFPacket) { zap.Int32("Unk6", pkt.Unk6), zap.Int32("Unk7", pkt.Unk7), zap.Int32("Block1", pkt.Block1), - zap.Int64("Unk9", pkt.Unk9), + zap.Int64("TimeTaken", pkt.TimeTaken), ) }