117 lines
3.3 KiB
Go
117 lines
3.3 KiB
Go
package gameserver
|
|
|
|
import (
|
|
"fmt"
|
|
"gac-hkrpg-go/internal/common"
|
|
pb "gac-hkrpg-go/protocol/proto"
|
|
"google.golang.org/protobuf/proto"
|
|
"math"
|
|
)
|
|
|
|
func cwArchiveSnapshot(c *common.CurrencyWarsCatalog) (*common.CurrencyWarsSnapshot, error) {
|
|
cfg, err := common.LoadRuntimeConfig()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return common.ReadCurrencyWarsSnapshot(cfg.PlayerUID, c.ClientVersion, c.Provenance.GameAssemblySHA256)
|
|
}
|
|
|
|
func (s *Session) saveCurrencyWarsTerminal(data *pb.GridFightGetDataScRsp, c *common.CurrencyWarsCatalog, record *pb.OEDHMAHDECC) error {
|
|
if record == nil || s.currencyWarsRevision >= math.MaxUint32 {
|
|
return fmt.Errorf("CW archive record/identifier invalid")
|
|
}
|
|
now, err := common.GameTime()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
entry := &pb.FAIHLAKPABN{BAAGDILLLME: uint32(s.currencyWarsRevision + 1), OBNEAIPKGKL: now.Unix(), LJNGPCKPJLF: c.ActiveSeasonID, GEGMHOMNBDG: c.ActiveSubSeasonID, BFLLJJBHLDF: proto.Clone(record).(*pb.OEDHMAHDECC)}
|
|
// Client-version encoding is unmapped; do not invent it from a patch number.
|
|
wire, err := proto.Marshal(entry)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return s.saveCurrencyWarsSnapshot(data, c, nil, wire)
|
|
}
|
|
|
|
func cwReadArchives(snapshot *common.CurrencyWarsSnapshot) ([]*pb.FAIHLAKPABN, error) {
|
|
if snapshot == nil {
|
|
return nil, nil
|
|
}
|
|
var entries []*pb.FAIHLAKPABN
|
|
for _, wire := range snapshot.Archives {
|
|
entry := new(pb.FAIHLAKPABN)
|
|
if err := proto.Unmarshal(wire, entry); err != nil {
|
|
return nil, fmt.Errorf("decode CW archive: %w", err)
|
|
}
|
|
if entry.BAAGDILLLME == 0 || entry.BFLLJJBHLDF == nil {
|
|
return nil, fmt.Errorf("CW archive entry incomplete")
|
|
}
|
|
entries = append(entries, entry)
|
|
}
|
|
return entries, nil
|
|
}
|
|
|
|
func init() {
|
|
cwHandle("GridFightGetArchive", func(_ *Session, req *pb.GridFightGetArchiveCsReq, rsp *pb.GridFightGetArchiveScRsp) error {
|
|
c, err := common.LoadCurrencyWarsCatalog()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
snapshot, err := cwArchiveSnapshot(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
entries, err := cwReadArchives(snapshot)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
rsp.Type = req.Type
|
|
for i := len(entries) - 1; i >= 0; i-- {
|
|
if req.Type == pb.MLJIILDNDPL_MLJIILDNDPL_FAGECPGMPEH && !entries[i].IECKKCHJMLP {
|
|
continue
|
|
}
|
|
rsp.MCGGPONOCKC = append(rsp.MCGGPONOCKC, entries[i])
|
|
}
|
|
return nil
|
|
})
|
|
cwHandle("FavourArchive", func(s *Session, req *pb.FavourArchiveCsReq, rsp *pb.FavourArchiveScRsp) error {
|
|
rsp.Retcode = uint32(pb.Retcode_RET_GRID_FIGHT_PARAM_NOT_MATCH)
|
|
c, err := common.LoadCurrencyWarsCatalog()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
snapshot, err := cwArchiveSnapshot(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if snapshot == nil || snapshot.Revision != s.currencyWarsRevision {
|
|
return nil
|
|
}
|
|
entries, err := cwReadArchives(snapshot)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for i, entry := range entries {
|
|
if entry.BAAGDILLLME != req.BAAGDILLLME {
|
|
continue
|
|
}
|
|
entry.IECKKCHJMLP = req.IECKKCHJMLP
|
|
wire, err := proto.Marshal(entry)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
snapshot.Archives[i] = wire
|
|
revision, err := common.CommitCurrencyWarsSnapshot(s.currencyWarsRevision, *snapshot)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
s.currencyWarsRevision = revision
|
|
rsp.BAAGDILLLME = req.BAAGDILLLME
|
|
rsp.IECKKCHJMLP = req.IECKKCHJMLP
|
|
rsp.Retcode = 0
|
|
return nil
|
|
}
|
|
return nil
|
|
})
|
|
}
|