diff --git a/config.json b/config.json index 1b5d46ff9..f9a092487 100644 --- a/config.json +++ b/config.json @@ -29,6 +29,7 @@ "QuestDebugTools": false, "EarthStatusOverride": 0, "EarthIDOverride": 0, + "DynamicSeasons": false, "EarthMonsterOverride": 0, "SaveDumps": { "Enabled": true, @@ -110,9 +111,9 @@ ], "Database": { "Host": "localhost", - "Port": 5433, + "Port": 5432, "User": "postgres", - "Password": "admin", + "Password": "", "Database": "erupe" }, "Sign": { diff --git a/config/config.go b/config/config.go index 7ef6c9bad..5c4ee693d 100644 --- a/config/config.go +++ b/config/config.go @@ -110,6 +110,7 @@ type DevModeOptions struct { QuestDebugTools bool // Enable various quest debug logs EarthStatusOverride int32 EarthIDOverride int32 + DynamicSeasons bool // Enables dynamic seasons EarthMonsterOverride int32 SaveDumps SaveDumpOptions } diff --git a/server/channelserver/handlers_quest.go b/server/channelserver/handlers_quest.go index 99002afe0..0da70b21d 100644 --- a/server/channelserver/handlers_quest.go +++ b/server/channelserver/handlers_quest.go @@ -51,8 +51,19 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) { zap.String("Filename", pkt.Filename), ) } - // Get quest file. - data, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename))) + + // Get quest file and convert to season if the option is enabled + var data []byte + var err error + + if s.server.erupeConfig.DevModeOptions.DynamicSeasons { + data, err = os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename))) + } else { + data, err = os.ReadFile(seasonConversion(s, filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename)))) + } + + // convert based on season + 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. @@ -64,6 +75,39 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) { } } +// Convert the file to load based on the season +func seasonConversion(s *Session, questPath string) string { + + // remove the last 6 from the quest path + newQuestPath := questPath[:len(questPath)-6] + + // Calculate the current day of the season in order to determine time scale + currentDayOfSeason := (time.Now().Unix()/6000)%15 + 1 + // Determine if it is day or night based on the current day of the season + timeCycle := uint8(((currentDayOfSeason % 1) * 24)) < 12 + + // Determine the current season based on a modulus of the current time + season := uint8((int(float64((time.Now().Unix() * int64(s.server.ID)) / (6000 * 15)))) % 3) + + var timeSet string + + // Determine the letter to append for day / night + if timeCycle { + timeSet = "n" + } else { + timeSet = "d" + } + + fileName := fmt.Sprintf("%s%s%d.bin", newQuestPath, timeSet, season) + + // Return the original if the season-based file does not exist for some reason + if _, err := os.Stat(fileName); err == nil { + return fileName + } else { + return questPath + } +} + func handleMsgMhfLoadFavoriteQuest(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfLoadFavoriteQuest) var data []byte diff --git a/server/entranceserver/make_resp.go b/server/entranceserver/make_resp.go index 0e2466865..cd4b97cdb 100644 --- a/server/entranceserver/make_resp.go +++ b/server/entranceserver/make_resp.go @@ -6,6 +6,7 @@ import ( _config "erupe-ce/config" "fmt" "net" + "time" "erupe-ce/common/stringsupport" @@ -13,9 +14,6 @@ import ( "erupe-ce/server/channelserver" ) -// Server Entries -var season uint8 - // Server Channels var currentplayers uint16 @@ -36,10 +34,8 @@ func encodeServerInfo(config *_config.Config, s *Server, local bool) []byte { } } sid := (4096 + serverIdx*256) + 16 - err := s.db.QueryRow("SELECT season FROM servers WHERE server_id=$1", sid).Scan(&season) - if err != nil { - season = 0 - } + //season := (uint8(float64((time.Now().Unix() + int64(sid)) / 1000))) % 3 + season := uint8((int(float64((time.Now().Unix() * int64(sid)) / (6000 * 15)))) % 3) if si.IP == "" { si.IP = config.Host }