fix time calculations & undo config changes

This commit is contained in:
wish
2023-07-16 21:14:44 +10:00
parent 65ea285ee4
commit 411477f9b3
4 changed files with 47 additions and 74 deletions

View File

@@ -111,9 +111,9 @@
], ],
"Database": { "Database": {
"Host": "localhost", "Host": "localhost",
"Port": 5433, "Port": 5432,
"User": "postgres", "User": "postgres",
"Password": "admin", "Password": "",
"Database": "erupe" "Database": "erupe"
}, },
"Sign": { "Sign": {
@@ -137,13 +137,6 @@
{ "Port": 54001, "MaxPlayers": 100 }, { "Port": 54001, "MaxPlayers": 100 },
{ "Port": 54002, "MaxPlayers": 100 } { "Port": 54002, "MaxPlayers": 100 }
] ]
},
{
"Name": "Newbie 2", "Description": "", "IP": "", "Type": 3, "Recommended": 2, "AllowedClientFlags": 0,
"Channels": [
{ "Port": 54009, "MaxPlayers": 100 },
{ "Port": 54010, "MaxPlayers": 100 }
]
}, { }, {
"Name": "Normal", "Description": "", "IP": "", "Type": 1, "Recommended": 0, "AllowedClientFlags": 0, "Name": "Normal", "Description": "", "IP": "", "Type": 1, "Recommended": 0, "AllowedClientFlags": 0,
"Channels": [ "Channels": [

View File

@@ -37,13 +37,6 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
return return
} }
doAckBufSucceed(s, pkt.AckHandle, data) doAckBufSucceed(s, pkt.AckHandle, data)
} else {
if _, err := os.Stat(filepath.Join(s.server.erupeConfig.BinPath, "quest_override.bin")); err == nil {
data, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, "quest_override.bin"))
if err != nil {
panic(err)
}
doAckBufSucceed(s, pkt.AckHandle, data)
} else { } else {
if s.server.erupeConfig.DevModeOptions.QuestDebugTools && s.server.erupeConfig.DevMode { if s.server.erupeConfig.DevModeOptions.QuestDebugTools && s.server.erupeConfig.DevMode {
s.logger.Debug( s.logger.Debug(
@@ -56,14 +49,11 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
var data []byte var data []byte
var err error var err error
if s.server.erupeConfig.DevModeOptions.DynamicSeasons { if s.server.erupeConfig.DevModeOptions.DynamicSeasons && s.server.erupeConfig.DevMode {
data, err = os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename))) seasonConversion(s, 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 data, err = os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename)))
if err != nil { if err != nil {
s.logger.Error(fmt.Sprintf("Failed to open file: %s/quests/%s.bin", s.server.erupeConfig.BinPath, pkt.Filename)) s.logger.Error(fmt.Sprintf("Failed to open file: %s/quests/%s.bin", s.server.erupeConfig.BinPath, pkt.Filename))
// This will crash the game. // This will crash the game.
@@ -73,38 +63,27 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
doAckBufSucceed(s, pkt.AckHandle, data) doAckBufSucceed(s, pkt.AckHandle, data)
} }
} }
func seasonConversion(s *Session, questFile string) string {
// Determine the letter to append for day / night
var timeSet string
if TimeGameAbsolute() > 2880 {
timeSet = "d"
} else {
timeSet = "n"
} }
// 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]
// Determine if it is day or night based on the current day of the season
timeCycle := uint8(time.Now().Unix()/3000) % 2
// Determine the current season based on a modulus of the current time // Determine the current season based on a modulus of the current time
sid := (4096 + s.server.ID*256) * 6000 sid := int64(((s.server.ID & 0xFF00) - 4096) / 256)
season := ((TimeAdjusted().Unix() / 86400) + sid) % 3
season := uint8((int(float64((time.Now().Unix() * int64(sid)) / (6000 * 15)))) % 3) filename := fmt.Sprintf("%s%s%d", questFile[:5], timeSet, season)
var timeSet string // Return original file if file doesn't exist
if _, err := os.Stat(filename); err == nil {
// Determine the letter to append for day / night return filename
if timeCycle == 0 {
timeSet = "n"
} else { } else {
timeSet = "d" return questFile
}
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
} }
} }
@@ -126,10 +105,10 @@ func handleMsgMhfSaveFavoriteQuest(s *Session, p mhfpacket.MHFPacket) {
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
} }
func readOriginalPointers(string_pointer int32, quest []byte) []byte { func readOriginalPointers(stringPointer int32, quest []byte) []byte {
fileBytes := byteframe.NewByteFrameFromBytes(quest) fileBytes := byteframe.NewByteFrameFromBytes(quest)
fileBytes.SetLE() fileBytes.SetLE()
fileBytes.Seek(int64(string_pointer), io.SeekStart) fileBytes.Seek(int64(stringPointer), io.SeekStart)
questNamePointer := fileBytes.ReadInt32() questNamePointer := fileBytes.ReadInt32()
questMainPointer := fileBytes.ReadInt32() questMainPointer := fileBytes.ReadInt32()

View File

@@ -23,3 +23,7 @@ func TimeWeekStart() time.Time {
func TimeWeekNext() time.Time { func TimeWeekNext() time.Time {
return TimeWeekStart().Add(time.Hour * 24 * 7) return TimeWeekStart().Add(time.Hour * 24 * 7)
} }
func TimeGameAbsolute() uint32 {
return uint32((TimeAdjusted().Unix() - 2160) % 5760)
}

View File

@@ -3,12 +3,10 @@ package entranceserver
import ( import (
"encoding/binary" "encoding/binary"
"encoding/hex" "encoding/hex"
"erupe-ce/common/stringsupport"
_config "erupe-ce/config" _config "erupe-ce/config"
"fmt" "fmt"
"net" "net"
"time"
"erupe-ce/common/stringsupport"
"erupe-ce/common/byteframe" "erupe-ce/common/byteframe"
"erupe-ce/server/channelserver" "erupe-ce/server/channelserver"
@@ -33,9 +31,8 @@ func encodeServerInfo(config *_config.Config, s *Server, local bool) []byte {
continue continue
} }
} }
sid := (4096 + serverIdx*256) * 6000 sid := (4096 + serverIdx*256) * 6000
//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 == "" { if si.IP == "" {
si.IP = config.Host si.IP = config.Host
} }
@@ -48,7 +45,7 @@ func encodeServerInfo(config *_config.Config, s *Server, local bool) []byte {
bf.WriteUint16(0x0000) bf.WriteUint16(0x0000)
bf.WriteUint16(uint16(len(si.Channels))) bf.WriteUint16(uint16(len(si.Channels)))
bf.WriteUint8(si.Type) bf.WriteUint8(si.Type)
bf.WriteUint8(season) bf.WriteUint8(uint8(((channelserver.TimeAdjusted().Unix() / 86400) + int64(serverIdx)) % 3))
bf.WriteUint8(si.Recommended) bf.WriteUint8(si.Recommended)
if s.erupeConfig.RealClientMode <= _config.GG { if s.erupeConfig.RealClientMode <= _config.GG {