mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-15 08:25:09 +01:00
implement Quest caching
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
"ScreenshotAPIURL": "",
|
"ScreenshotAPIURL": "",
|
||||||
"DeleteOnSaveCorruption": false,
|
"DeleteOnSaveCorruption": false,
|
||||||
"ClientMode": "ZZ",
|
"ClientMode": "ZZ",
|
||||||
|
"QuestCacheExpiry": 300,
|
||||||
"DevMode": true,
|
"DevMode": true,
|
||||||
"DevModeOptions": {
|
"DevModeOptions": {
|
||||||
"AutoCreateAccount": true,
|
"AutoCreateAccount": true,
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ type Config struct {
|
|||||||
DeleteOnSaveCorruption bool // Attempts to save corrupted data will flag the save for deletion
|
DeleteOnSaveCorruption bool // Attempts to save corrupted data will flag the save for deletion
|
||||||
ClientMode string
|
ClientMode string
|
||||||
RealClientMode Mode
|
RealClientMode Mode
|
||||||
|
QuestCacheExpiry int // Number of seconds to keep quest data cached
|
||||||
DevMode bool
|
DevMode bool
|
||||||
|
|
||||||
DevModeOptions DevModeOptions
|
DevModeOptions DevModeOptions
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ func handleMsgMhfSaveFavoriteQuest(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadQuestFile(s *Session, questId int) []byte {
|
func loadQuestFile(s *Session, questId int) []byte {
|
||||||
|
data, exists := s.server.questCacheData[questId]
|
||||||
|
if exists && s.server.questCacheTime[questId].Add(time.Duration(s.server.erupeConfig.QuestCacheExpiry)*time.Second).After(time.Now()) {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
file, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%05dd0.bin", questId)))
|
file, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%05dd0.bin", questId)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -113,6 +118,8 @@ func loadQuestFile(s *Session, questId int) []byte {
|
|||||||
}
|
}
|
||||||
questBody.WriteBytes(newStrings.Data())
|
questBody.WriteBytes(newStrings.Data())
|
||||||
|
|
||||||
|
s.server.questCacheData[questId] = questBody.Data()
|
||||||
|
s.server.questCacheTime[questId] = time.Now()
|
||||||
return questBody.Data()
|
return questBody.Data()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"erupe-ce/common/byteframe"
|
"erupe-ce/common/byteframe"
|
||||||
ps "erupe-ce/common/pascalstring"
|
ps "erupe-ce/common/pascalstring"
|
||||||
@@ -73,6 +74,9 @@ type Server struct {
|
|||||||
name string
|
name string
|
||||||
|
|
||||||
raviente *Raviente
|
raviente *Raviente
|
||||||
|
|
||||||
|
questCacheData map[int][]byte
|
||||||
|
questCacheTime map[int]time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type Raviente struct {
|
type Raviente struct {
|
||||||
@@ -163,6 +167,8 @@ func NewServer(config *Config) *Server {
|
|||||||
state: make([]uint32, 30),
|
state: make([]uint32, 30),
|
||||||
support: make([]uint32, 30),
|
support: make([]uint32, 30),
|
||||||
},
|
},
|
||||||
|
questCacheData: make(map[int][]byte),
|
||||||
|
questCacheTime: make(map[int]time.Time),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mezeporta
|
// Mezeporta
|
||||||
|
|||||||
Reference in New Issue
Block a user