mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-13 15:34:38 +01:00
fix time calculations & undo config changes
This commit is contained in:
11
config.json
11
config.json
@@ -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": [
|
||||||
|
|||||||
@@ -38,73 +38,52 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
doAckBufSucceed(s, pkt.AckHandle, data)
|
doAckBufSucceed(s, pkt.AckHandle, data)
|
||||||
} else {
|
} else {
|
||||||
if _, err := os.Stat(filepath.Join(s.server.erupeConfig.BinPath, "quest_override.bin")); err == nil {
|
if s.server.erupeConfig.DevModeOptions.QuestDebugTools && s.server.erupeConfig.DevMode {
|
||||||
data, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, "quest_override.bin"))
|
s.logger.Debug(
|
||||||
if err != nil {
|
"Quest",
|
||||||
panic(err)
|
zap.String("Filename", pkt.Filename),
|
||||||
}
|
)
|
||||||
doAckBufSucceed(s, pkt.AckHandle, data)
|
|
||||||
} else {
|
|
||||||
if s.server.erupeConfig.DevModeOptions.QuestDebugTools && s.server.erupeConfig.DevMode {
|
|
||||||
s.logger.Debug(
|
|
||||||
"Quest",
|
|
||||||
zap.String("Filename", 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.
|
|
||||||
doAckBufSucceed(s, pkt.AckHandle, data)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
doAckBufSucceed(s, pkt.AckHandle, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get quest file and convert to season if the option is enabled
|
||||||
|
var data []byte
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if s.server.erupeConfig.DevModeOptions.DynamicSeasons && s.server.erupeConfig.DevMode {
|
||||||
|
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))
|
||||||
|
// This will crash the game.
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, data)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
doAckBufSucceed(s, pkt.AckHandle, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the file to load based on the season
|
func seasonConversion(s *Session, questFile string) string {
|
||||||
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
|
|
||||||
|
|
||||||
// Determine the letter to append for day / night
|
// Determine the letter to append for day / night
|
||||||
if timeCycle == 0 {
|
var timeSet string
|
||||||
timeSet = "n"
|
if TimeGameAbsolute() > 2880 {
|
||||||
} else {
|
|
||||||
timeSet = "d"
|
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
|
filename := fmt.Sprintf("%s%s%d", questFile[:5], timeSet, season)
|
||||||
if _, err := os.Stat(fileName); err == nil {
|
|
||||||
return fileName
|
// Return original file if file doesn't exist
|
||||||
|
if _, err := os.Stat(filename); err == nil {
|
||||||
|
return filename
|
||||||
} else {
|
} 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})
|
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()
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user