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": {
"Host": "localhost",
"Port": 5433,
"Port": 5432,
"User": "postgres",
"Password": "admin",
"Password": "",
"Database": "erupe"
},
"Sign": {
@@ -137,13 +137,6 @@
{ "Port": 54001, "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,
"Channels": [

View File

@@ -37,13 +37,6 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
return
}
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 {
if s.server.erupeConfig.DevModeOptions.QuestDebugTools && s.server.erupeConfig.DevMode {
s.logger.Debug(
@@ -56,14 +49,11 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
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))))
if s.server.erupeConfig.DevModeOptions.DynamicSeasons && s.server.erupeConfig.DevMode {
seasonConversion(s, 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 {
s.logger.Error(fmt.Sprintf("Failed to open file: %s/quests/%s.bin", s.server.erupeConfig.BinPath, pkt.Filename))
// This will crash the game.
@@ -72,39 +62,28 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
}
doAckBufSucceed(s, pkt.AckHandle, data)
}
}
}
// 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
sid := (4096 + s.server.ID*256) * 6000
season := uint8((int(float64((time.Now().Unix() * int64(sid)) / (6000 * 15)))) % 3)
var timeSet string
func seasonConversion(s *Session, questFile string) string {
// Determine the letter to append for day / night
if timeCycle == 0 {
timeSet = "n"
} else {
var timeSet string
if TimeGameAbsolute() > 2880 {
timeSet = "d"
} else {
timeSet = "n"
}
fileName := fmt.Sprintf("%s%s%d.bin", newQuestPath, timeSet, season)
// Determine the current season based on a modulus of the current time
sid := int64(((s.server.ID & 0xFF00) - 4096) / 256)
season := ((TimeAdjusted().Unix() / 86400) + sid) % 3
// Return the original if the season-based file does not exist for some reason
if _, err := os.Stat(fileName); err == nil {
return fileName
filename := fmt.Sprintf("%s%s%d", questFile[:5], timeSet, season)
// Return original file if file doesn't exist
if _, err := os.Stat(filename); err == nil {
return filename
} else {
return questPath
return questFile
}
}
@@ -126,10 +105,10 @@ func handleMsgMhfSaveFavoriteQuest(s *Session, p mhfpacket.MHFPacket) {
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.SetLE()
fileBytes.Seek(int64(string_pointer), io.SeekStart)
fileBytes.Seek(int64(stringPointer), io.SeekStart)
questNamePointer := fileBytes.ReadInt32()
questMainPointer := fileBytes.ReadInt32()

View File

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