Skip to content

Commit

Permalink
implement Quest caching
Browse files Browse the repository at this point in the history
  • Loading branch information
sekaiwish committed Nov 16, 2023
1 parent 15253cd commit 72bda06
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"ScreenshotAPIURL": "",
"DeleteOnSaveCorruption": false,
"ClientMode": "ZZ",
"QuestCacheExpiry": 300,
"DevMode": true,
"DevModeOptions": {
"AutoCreateAccount": true,
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Config struct {
DeleteOnSaveCorruption bool // Attempts to save corrupted data will flag the save for deletion
ClientMode string
RealClientMode Mode
QuestCacheExpiry int // Number of seconds to keep quest data cached
DevMode bool

DevModeOptions DevModeOptions
Expand Down
7 changes: 7 additions & 0 deletions server/channelserver/handlers_quest.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func handleMsgMhfSaveFavoriteQuest(s *Session, p mhfpacket.MHFPacket) {
}

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)))
if err != nil {
return nil
Expand Down Expand Up @@ -113,6 +118,8 @@ func loadQuestFile(s *Session, questId int) []byte {
}
questBody.WriteBytes(newStrings.Data())

s.server.questCacheData[questId] = questBody.Data()
s.server.questCacheTime[questId] = time.Now()
return questBody.Data()
}

Expand Down
6 changes: 6 additions & 0 deletions server/channelserver/sys_channel_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"strings"
"sync"
"time"

"erupe-ce/common/byteframe"
ps "erupe-ce/common/pascalstring"
Expand Down Expand Up @@ -73,6 +74,9 @@ type Server struct {
name string

raviente *Raviente

questCacheData map[int][]byte
questCacheTime map[int]time.Time
}

type Raviente struct {
Expand Down Expand Up @@ -163,6 +167,8 @@ func NewServer(config *Config) *Server {
state: make([]uint32, 30),
support: make([]uint32, 30),
},
questCacheData: make(map[int][]byte),
questCacheTime: make(map[int]time.Time),
}

// Mezeporta
Expand Down

0 comments on commit 72bda06

Please sign in to comment.