55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package gameserver
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
_ "embed"
|
|
"encoding/hex"
|
|
"fmt"
|
|
|
|
"gac-hkrpg-go/internal/common"
|
|
)
|
|
|
|
//go:embed aa_round_sync.lua
|
|
var aaRoundRefreshAdapter []byte
|
|
|
|
// loadAARoundRefreshLua invalidates only the AA module's cached data, through
|
|
// its observed native request API. It never rewrites an incoming PeakId,
|
|
// starts a challenge, changes a scene or modifies saved selection/progression.
|
|
func loadAARoundRefreshLua(s *Session) ([]byte, error) {
|
|
selection, err := common.ReadAARoundSelection()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
groups := map[uint32]bool{}
|
|
var defaultGroup uint32
|
|
for _, stage := range getChallengeData().Peak {
|
|
if stage.GroupID != 0 {
|
|
groups[stage.GroupID] = true
|
|
if defaultGroup == 0 || stage.GroupID < defaultGroup {
|
|
defaultGroup = stage.GroupID
|
|
}
|
|
}
|
|
}
|
|
if defaultGroup == 0 {
|
|
return nil, fmt.Errorf("AA refresh has no resource-backed round")
|
|
}
|
|
desired := defaultGroup
|
|
if selection != nil {
|
|
if !groups[selection.PeakGroupID] {
|
|
return nil, fmt.Errorf("selected AA round %d is absent from loaded challenge data", selection.PeakGroupID)
|
|
}
|
|
desired = selection.PeakGroupID
|
|
}
|
|
cfg, err := common.LoadRuntimeConfig()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
digest := sha256.Sum256([]byte(fmt.Sprintf("%s/%d", cfg.ClientVersion, desired)))
|
|
deferred := s.ChallengeRun != nil || s.currencyWarsOpen
|
|
if _, active := CURRENT_BATTLE.Load(s.Token); active {
|
|
deferred = true
|
|
}
|
|
payload := fmt.Sprintf("\n_G.__GAC_AA_ROUND_REFRESH={desired_group=%d,revision=%s,deferred=%t}\n", desired, luaQuotedString(hex.EncodeToString(digest[:])), deferred)
|
|
return append([]byte(payload), aaRoundRefreshAdapter...), nil
|
|
}
|