From 4edeaedea3f37c1ee4f625924251c0ab258bfae9 Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Sun, 5 Nov 2023 15:23:34 -0500 Subject: [PATCH 01/14] fix: Restore seasons functionality into quests --- server/channelserver/handlers_quest.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index da3c8166a..5c5fb9613 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -47,6 +47,10 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) { ) } + if s.server.erupeConfig.GameplayOptions.SeasonOverride { + pkt.Filename = seasonConversion(s, pkt.Filename) + } + data, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename))) if err != nil { s.logger.Error(fmt.Sprintf("Failed to open file: %s/quests/%s.bin", s.server.erupeConfig.BinPath, pkt.Filename)) @@ -58,6 +62,28 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) { } } +func questSuffix(s *Session) string { + // Determine the letter to append for day / night + var timeSet string + if TimeGameAbsolute() > 2880 { + timeSet = "d" + } else { + timeSet = "n" + } + return fmt.Sprintf("%s%d", timeSet, s.server.Season()) +} + +func seasonConversion(s *Session, questFile string) string { + filename := fmt.Sprintf("%s%s", questFile[:5], questSuffix(s)) + + // Return original file if file doesn't exist + if _, err := os.Stat(filename); err == nil { + return filename + } else { + return questFile + } +} + func handleMsgMhfLoadFavoriteQuest(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfLoadFavoriteQuest) var data []byte From 68de64a05f57fccafd68aaaa381433e7b8fbba92 Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Sun, 5 Nov 2023 19:08:02 -0500 Subject: [PATCH 02/14] fix: Fixed issue with seasons not properly displaying on client --- config.json | 10 +++++----- server/channelserver/handlers_quest.go | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/config.json b/config.json index 31629b894..467512410 100644 --- a/config.json +++ b/config.json @@ -17,8 +17,8 @@ "AutoCreateAccount": true, "CleanDB": false, "MaxLauncherHR": false, - "LogInboundMessages": true, - "LogOutboundMessages": true, + "LogInboundMessages": false, + "LogOutboundMessages": false, "MaxHexdumpLength": 256, "DivaEvent": 0, "FestaEvent": -1, @@ -67,7 +67,7 @@ "EnableHiganjimaEvent": false, "EnableNierEvent": false, "DisableRoad": false, - "SeasonOverride": false + "SeasonOverride": true }, "Discord": { "Enabled": false, @@ -120,9 +120,9 @@ ], "Database": { "Host": "localhost", - "Port": 5432, + "Port": 5433, "User": "postgres", - "Password": "", + "Password": "admin", "Database": "erupe" }, "Sign": { diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index 5c5fb9613..40c52f6c4 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -51,8 +51,16 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) { pkt.Filename = seasonConversion(s, pkt.Filename) } + // custom quests expect there to be only a d0 for quests, rewrite quests to try for d0 if the quest file doesn't exist + if _, err := os.Stat(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename))); err != nil { + pkt.Filename = fmt.Sprintf("%s%s", pkt.Filename[:5], "d0") + } + + s.logger.Info("Sent " + pkt.Filename) + data, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename))) if err != nil { + s.logger.Error(fmt.Sprintf("Failed to open file: %s/quests/%s.bin", s.server.erupeConfig.BinPath, pkt.Filename)) // This will crash the game. doAckBufSucceed(s, pkt.AckHandle, data) @@ -77,10 +85,15 @@ func seasonConversion(s *Session, questFile string) string { filename := fmt.Sprintf("%s%s", questFile[:5], questSuffix(s)) // Return original file if file doesn't exist - if _, err := os.Stat(filename); err == nil { + if _, err := os.Stat(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", filename))); err == nil { return filename } else { - return questFile + // Load d0 if the regular quest file doesn't exist (Fixes custom quests) + if _, err := os.Stat(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", questFile))); err == nil { + return questFile + } + + return fmt.Sprintf("%s%s", questFile[:5], "d0") } } From cce64d40108b0cb16a425ccd8285b954f036d80d Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Sun, 5 Nov 2023 19:19:55 -0500 Subject: [PATCH 03/14] fix: Removed random print from code --- server/channelserver/handlers_quest.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index 40c52f6c4..c7961ea20 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -56,8 +56,6 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) { pkt.Filename = fmt.Sprintf("%s%s", pkt.Filename[:5], "d0") } - s.logger.Info("Sent " + pkt.Filename) - data, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename))) if err != nil { From 5e760da8bc8c570f7b1296e0f1d41038627773d0 Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Sun, 5 Nov 2023 19:21:12 -0500 Subject: [PATCH 04/14] chore: Removed credentials --- config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index 467512410..aeb04eadf 100644 --- a/config.json +++ b/config.json @@ -120,9 +120,9 @@ ], "Database": { "Host": "localhost", - "Port": 5433, + "Port": 5432, "User": "postgres", - "Password": "admin", + "Password": "", "Database": "erupe" }, "Sign": { From af519a59cf67dad91e15f322beb66b75d1a49b2e Mon Sep 17 00:00:00 2001 From: wish Date: Tue, 7 Nov 2023 16:50:39 +1100 Subject: [PATCH 05/14] rewrite EnumerateStage & parse ReserveStage --- network/mhfpacket/msg_sys_reserve_stage.go | 5 ++--- server/channelserver/handlers_stage.go | 22 ++++++++++------------ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/network/mhfpacket/msg_sys_reserve_stage.go b/network/mhfpacket/msg_sys_reserve_stage.go index 13e47c41b..d2f688af4 100644 --- a/network/mhfpacket/msg_sys_reserve_stage.go +++ b/network/mhfpacket/msg_sys_reserve_stage.go @@ -3,7 +3,6 @@ package mhfpacket import ( "errors" "erupe-ce/common/byteframe" - "erupe-ce/common/bfutil" "erupe-ce/network" "erupe-ce/network/clientctx" ) @@ -24,8 +23,8 @@ func (m *MsgSysReserveStage) Opcode() network.PacketID { func (m *MsgSysReserveStage) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { m.AckHandle = bf.ReadUint32() m.Ready = bf.ReadUint8() - stageIDLength := bf.ReadUint8() - m.StageID = string(bfutil.UpToNull(bf.ReadBytes(uint(stageIDLength)))) + _ = bf.ReadUint8() // StageID length + m.StageID = string(bf.ReadNullTerminatedBytes()) return nil } diff --git a/server/channelserver/handlers_stage.go b/server/channelserver/handlers_stage.go index 983d6e79e..be7ab1267 100644 --- a/server/channelserver/handlers_stage.go +++ b/server/channelserver/handlers_stage.go @@ -367,9 +367,9 @@ func handleMsgSysEnumerateStage(s *Session, p mhfpacket.MHFPacket) { defer s.server.stagesLock.RUnlock() // Build the response - resp := byteframe.NewByteFrame() bf := byteframe.NewByteFrame() - var joinable int + var joinable uint16 + bf.WriteUint16(0) for sid, stage := range s.server.stages { stage.RLock() @@ -377,34 +377,32 @@ func handleMsgSysEnumerateStage(s *Session, p mhfpacket.MHFPacket) { stage.RUnlock() continue } - if !strings.Contains(stage.id, pkt.StagePrefix) { stage.RUnlock() continue } - joinable++ - resp.WriteUint16(uint16(len(stage.reservedClientSlots))) // Reserved players. - resp.WriteUint16(0) // Unk + bf.WriteUint16(uint16(len(stage.reservedClientSlots))) + bf.WriteUint16(0) // Unk if len(stage.clients) > 0 { bf.WriteUint16(1) } else { bf.WriteUint16(0) } - resp.WriteUint16(stage.maxPlayers) // Max players. + bf.WriteUint16(stage.maxPlayers) if len(stage.password) > 0 { // This byte has also been seen as 1 // The quest is also recognised as locked when this is 2 - resp.WriteUint8(3) + bf.WriteUint8(2) } else { - resp.WriteUint8(0) + bf.WriteUint8(0) } - ps.Uint8(resp, sid, false) + ps.Uint8(bf, sid, false) stage.RUnlock() } - bf.WriteUint16(uint16(joinable)) - bf.WriteBytes(resp.Data()) + bf.Seek(0, 0) + bf.WriteUint16(joinable) doAckBufSucceed(s, pkt.AckHandle, bf.Data()) } From 378dfd03723d2a696b8be617221bd77cc71ceee6 Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Tue, 7 Nov 2023 21:16:03 -0500 Subject: [PATCH 06/14] fix: Fixed issues with improper loading of areas --- server/channelserver/handlers_quest.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index c7961ea20..2cd326e3c 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -68,19 +68,8 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) { } } -func questSuffix(s *Session) string { - // Determine the letter to append for day / night - var timeSet string - if TimeGameAbsolute() > 2880 { - timeSet = "d" - } else { - timeSet = "n" - } - return fmt.Sprintf("%s%d", timeSet, s.server.Season()) -} - func seasonConversion(s *Session, questFile string) string { - filename := fmt.Sprintf("%s%s", questFile[:5], questSuffix(s)) + filename := fmt.Sprintf("%s%d", questFile[:6], s.server.Season()) // Return original file if file doesn't exist if _, err := os.Stat(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", filename))); err == nil { From 611cb2da5bcd96acd658fbbf7eaa3fdf1b6eb94e Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Wed, 8 Nov 2023 13:28:05 -0500 Subject: [PATCH 07/14] feat: Request custom files based on time of day. --- server/channelserver/handlers_quest.go | 42 +++++++++----------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index 2cd326e3c..98ce7c8bc 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -51,7 +51,7 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) { pkt.Filename = seasonConversion(s, pkt.Filename) } - // custom quests expect there to be only a d0 for quests, rewrite quests to try for d0 if the quest file doesn't exist + // Default to d0 for any other quest that has no alternative versions if _, err := os.Stat(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename))); err != nil { pkt.Filename = fmt.Sprintf("%s%s", pkt.Filename[:5], "d0") } @@ -71,16 +71,26 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) { func seasonConversion(s *Session, questFile string) string { filename := fmt.Sprintf("%s%d", questFile[:6], s.server.Season()) - // Return original file if file doesn't exist + // Return the seasonal file if _, err := os.Stat(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", filename))); err == nil { return filename } else { - // Load d0 if the regular quest file doesn't exist (Fixes custom quests) + // Attempt to return the requested quest file if the seasonal file doesn't exist if _, err := os.Stat(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", questFile))); err == nil { return questFile } - return fmt.Sprintf("%s%s", questFile[:5], "d0") + // For custom quests, we need to return the day or night version of the quest. + var time string + + if TimeGameAbsolute() > 2880 { + time = "d" + } else { + time = "n" + } + + // Request a file based on day or night + return fmt.Sprintf("%s%s%d", questFile[:5], time, 0) } } @@ -184,30 +194,6 @@ func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) { bf.WriteUint16(0) // Unk bf.WriteUint16(uint16(len(data))) bf.WriteBytes(data) - - // Time Flag Replacement - // Bitset Structure: b8 UNK, b7 Required Objective, b6 UNK, b5 Night, b4 Day, b3 Cold, b2 Warm, b1 Spring - // if the byte is set to 0 the game choses the quest file corresponding to whatever season the game is on - bf.Seek(25, 0) - flagByte := bf.ReadUint8() - bf.Seek(25, 0) - if s.server.erupeConfig.GameplayOptions.SeasonOverride { - bf.WriteUint8(flagByte & 0b11100000) - } else { - bf.WriteUint8(flagByte) - } - - // Bitset Structure Quest Variant 1: b8 UL Fixed, b7 UNK, b6 UNK, b5 UNK, b4 G Rank, b3 HC to UL, b2 Fix HC, b1 Hiden - // Bitset Structure Quest Variant 2: b8 Road, b7 High Conquest, b6 Fixed Difficulty, b5 No Active Feature, b4 Timer, b3 No Cuff, b2 No Halk Pots, b1 Low Conquest - // Bitset Structure Quest Variant 3: b8 No Sigils, b7 UNK, b6 Interception, b5 Zenith, b4 No GP Skills, b3 No Simple Mode?, b2 GSR to GR, b1 No Reward Skills - - bf.Seek(175, 0) - questVariant3 := bf.ReadUint8() - questVariant3 &= 0b11011111 // disable Interception flag - bf.Seek(175, 0) - bf.WriteUint8(questVariant3) - - bf.Seek(0, 2) ps.Uint8(bf, "", true) // Debug/Notes string for quest return bf.Data(), nil } From 3e4e325675243e3523b0baebe25418059fb639c5 Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Sat, 11 Nov 2023 03:42:08 -0500 Subject: [PATCH 08/14] feat: Implement event quest season/time flag override --- patch-schema/10-event-quest-flags.sql | 5 ++++ server/channelserver/handlers_quest.go | 32 +++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 patch-schema/10-event-quest-flags.sql diff --git a/patch-schema/10-event-quest-flags.sql b/patch-schema/10-event-quest-flags.sql new file mode 100644 index 000000000..24b59db6a --- /dev/null +++ b/patch-schema/10-event-quest-flags.sql @@ -0,0 +1,5 @@ +BEGIN; + +ALTER TABLE IF EXISTS public.event_quests ADD COLUMN IF NOT EXISTS flag_override integer NOT NULL DEFAULT -1; + +END; \ No newline at end of file diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index 98ce7c8bc..7eaf45292 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -156,7 +156,8 @@ func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) { var id, mark uint32 var questId int var maxPlayers, questType uint8 - rows.Scan(&id, &maxPlayers, &questType, &questId, &mark) + var questFlags int8 + rows.Scan(&id, &maxPlayers, &questType, &questId, &mark, &questFlags) data := loadQuestFile(s, questId) if data == nil { @@ -194,6 +195,35 @@ func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) { bf.WriteUint16(0) // Unk bf.WriteUint16(uint16(len(data))) bf.WriteBytes(data) + + // Time Flag Replacement + // Bitset Structure: b8 UNK, b7 Required Objective, b6 UNK, b5 Night, b4 Day, b3 Cold, b2 Warm, b1 Spring + // if the byte is set to 0 the game choses the quest file corresponding to whatever season the game is on + bf.Seek(25, 0) + flagByte := bf.ReadUint8() + bf.Seek(25, 0) + if s.server.erupeConfig.GameplayOptions.SeasonOverride { + bf.WriteUint8(flagByte & 0b11100000) + } else { + // Allow for seasons to be specified in database, otherwise use the one in the file. + if questFlags == -1 { + bf.WriteUint8(flagByte) + } else { + bf.WriteUint8(uint8(questFlags)) + } + } + + // Bitset Structure Quest Variant 1: b8 UL Fixed, b7 UNK, b6 UNK, b5 UNK, b4 G Rank, b3 HC to UL, b2 Fix HC, b1 Hiden + // Bitset Structure Quest Variant 2: b8 Road, b7 High Conquest, b6 Fixed Difficulty, b5 No Active Feature, b4 Timer, b3 No Cuff, b2 No Halk Pots, b1 Low Conquest + // Bitset Structure Quest Variant 3: b8 No Sigils, b7 UNK, b6 Interception, b5 Zenith, b4 No GP Skills, b3 No Simple Mode?, b2 GSR to GR, b1 No Reward Skills + + bf.Seek(175, 0) + questVariant3 := bf.ReadUint8() + questVariant3 &= 0b11011111 // disable Interception flag + bf.Seek(175, 0) + bf.WriteUint8(questVariant3) + + bf.Seek(0, 2) ps.Uint8(bf, "", true) // Debug/Notes string for quest return bf.Data(), nil } From f588d47aa18f19f598800f13331abc6e470b7327 Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Sun, 12 Nov 2023 16:01:19 -0500 Subject: [PATCH 09/14] chore: Reset config files --- config.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config.json b/config.json index aeb04eadf..31629b894 100644 --- a/config.json +++ b/config.json @@ -17,8 +17,8 @@ "AutoCreateAccount": true, "CleanDB": false, "MaxLauncherHR": false, - "LogInboundMessages": false, - "LogOutboundMessages": false, + "LogInboundMessages": true, + "LogOutboundMessages": true, "MaxHexdumpLength": 256, "DivaEvent": 0, "FestaEvent": -1, @@ -67,7 +67,7 @@ "EnableHiganjimaEvent": false, "EnableNierEvent": false, "DisableRoad": false, - "SeasonOverride": true + "SeasonOverride": false }, "Discord": { "Enabled": false, From a9b8bb4c56a315bc768713a6d34906cdf3f25b20 Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Thu, 16 Nov 2023 02:00:01 -0500 Subject: [PATCH 10/14] fix: Added flags to sql query --- config.json | 4 ++-- server/channelserver/handlers_quest.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config.json b/config.json index 31629b894..5dcb6ef51 100644 --- a/config.json +++ b/config.json @@ -120,9 +120,9 @@ ], "Database": { "Host": "localhost", - "Port": 5432, + "Port": 5433, "User": "postgres", - "Password": "", + "Password": "admin", "Database": "erupe" }, "Sign": { diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index 7eaf45292..91a000c5b 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -234,7 +234,7 @@ func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) { bf := byteframe.NewByteFrame() bf.WriteUint16(0) - rows, _ := s.server.db.Query("SELECT id, COALESCE(max_players, 4) AS max_players, quest_type, quest_id, COALESCE(mark, 0) AS mark FROM event_quests ORDER BY quest_id") + rows, _ := s.server.db.Query("SELECT id, COALESCE(max_players, 4) AS max_players, quest_type, quest_id, COALESCE(mark, 0) AS mark, flags FROM event_quests ORDER BY quest_id") for rows.Next() { data, err := makeEventQuest(s, rows) if err != nil { From 34044f72b043089484c2f1852ccde178fcf6b888 Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Thu, 16 Nov 2023 11:07:00 -0500 Subject: [PATCH 11/14] chore: Fix config.json --- config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index 5dcb6ef51..31629b894 100644 --- a/config.json +++ b/config.json @@ -120,9 +120,9 @@ ], "Database": { "Host": "localhost", - "Port": 5433, + "Port": 5432, "User": "postgres", - "Password": "admin", + "Password": "", "Database": "erupe" }, "Sign": { From 2e2d129871089000b52e43f4a379d990b3ca3195 Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Thu, 16 Nov 2023 11:10:46 -0500 Subject: [PATCH 12/14] docs: Fix annotation for custom quest conditions --- server/channelserver/handlers_quest.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index 91a000c5b..999519766 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -80,7 +80,8 @@ func seasonConversion(s *Session, questFile string) string { return questFile } - // For custom quests, we need to return the day or night version of the quest. + // If the code reaches this point, it's most likely a custom quest with no seasonal variations in the files. + // Since event quests when seasonal pick day or night and the client requests either one, we need to differentiate between the two to prevent issues. var time string if TimeGameAbsolute() > 2880 { @@ -89,7 +90,7 @@ func seasonConversion(s *Session, questFile string) string { time = "n" } - // Request a file based on day or night + // Request a D0 or N0 file depending on the time of day. The time of day matters since the client will quite a few issues if it's different to the one it requests. return fmt.Sprintf("%s%s%d", questFile[:5], time, 0) } } From 6384d79a7ab00a0bda0cc197b679df9cc9b7548e Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Thu, 16 Nov 2023 11:29:31 -0500 Subject: [PATCH 13/14] fix: Removed unnecessary condition --- server/channelserver/handlers_quest.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index 999519766..7c782fb60 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -51,14 +51,8 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) { pkt.Filename = seasonConversion(s, pkt.Filename) } - // Default to d0 for any other quest that has no alternative versions - if _, err := os.Stat(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename))); err != nil { - pkt.Filename = fmt.Sprintf("%s%s", pkt.Filename[:5], "d0") - } - data, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename))) if err != nil { - s.logger.Error(fmt.Sprintf("Failed to open file: %s/quests/%s.bin", s.server.erupeConfig.BinPath, pkt.Filename)) // This will crash the game. doAckBufSucceed(s, pkt.AckHandle, data) From 490aecd94b5c31e368e01be2193881024cc6d839 Mon Sep 17 00:00:00 2001 From: wish Date: Sat, 18 Nov 2023 15:44:59 +1100 Subject: [PATCH 14/14] rewrite comments & change quest flag code --- ...est-flags.sql => 11-event-quest-flags.sql} | 2 +- server/channelserver/handlers_quest.go | 23 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) rename patch-schema/{10-event-quest-flags.sql => 11-event-quest-flags.sql} (62%) diff --git a/patch-schema/10-event-quest-flags.sql b/patch-schema/11-event-quest-flags.sql similarity index 62% rename from patch-schema/10-event-quest-flags.sql rename to patch-schema/11-event-quest-flags.sql index 24b59db6a..5f88d732d 100644 --- a/patch-schema/10-event-quest-flags.sql +++ b/patch-schema/11-event-quest-flags.sql @@ -1,5 +1,5 @@ BEGIN; -ALTER TABLE IF EXISTS public.event_quests ADD COLUMN IF NOT EXISTS flag_override integer NOT NULL DEFAULT -1; +ALTER TABLE IF EXISTS public.event_quests ADD COLUMN IF NOT EXISTS flags integer; END; \ No newline at end of file diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index 7c782fb60..fbabec35d 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -70,22 +70,22 @@ func seasonConversion(s *Session, questFile string) string { return filename } else { // Attempt to return the requested quest file if the seasonal file doesn't exist - if _, err := os.Stat(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", questFile))); err == nil { + if _, err = os.Stat(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", questFile))); err == nil { return questFile } // If the code reaches this point, it's most likely a custom quest with no seasonal variations in the files. // Since event quests when seasonal pick day or night and the client requests either one, we need to differentiate between the two to prevent issues. - var time string + var _time string if TimeGameAbsolute() > 2880 { - time = "d" + _time = "d" } else { - time = "n" + _time = "n" } - // Request a D0 or N0 file depending on the time of day. The time of day matters since the client will quite a few issues if it's different to the one it requests. - return fmt.Sprintf("%s%s%d", questFile[:5], time, 0) + // Request a d0 or n0 file depending on the time of day. The time of day matters and issues will occur if it's different to the one it requests. + return fmt.Sprintf("%s%s%d", questFile[:5], _time, 0) } } @@ -149,10 +149,9 @@ func loadQuestFile(s *Session, questId int) []byte { func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) { var id, mark uint32 - var questId int + var questId, flags int var maxPlayers, questType uint8 - var questFlags int8 - rows.Scan(&id, &maxPlayers, &questType, &questId, &mark, &questFlags) + rows.Scan(&id, &maxPlayers, &questType, &questId, &mark, &flags) data := loadQuestFile(s, questId) if data == nil { @@ -201,10 +200,10 @@ func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) { bf.WriteUint8(flagByte & 0b11100000) } else { // Allow for seasons to be specified in database, otherwise use the one in the file. - if questFlags == -1 { + if flags < 0 { bf.WriteUint8(flagByte) } else { - bf.WriteUint8(uint8(questFlags)) + bf.WriteUint8(uint8(flags)) } } @@ -229,7 +228,7 @@ func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) { bf := byteframe.NewByteFrame() bf.WriteUint16(0) - rows, _ := s.server.db.Query("SELECT id, COALESCE(max_players, 4) AS max_players, quest_type, quest_id, COALESCE(mark, 0) AS mark, flags FROM event_quests ORDER BY quest_id") + rows, _ := s.server.db.Query("SELECT id, COALESCE(max_players, 4) AS max_players, quest_type, quest_id, COALESCE(mark, 0) AS mark, COALESCE(flags, -1) FROM event_quests ORDER BY quest_id") for rows.Next() { data, err := makeEventQuest(s, rows) if err != nil {