docs & feat: add license & attribution notice (Apache-2.0 / GPL-3.0) and core system enhancements
This commit is contained in:
1 parent
507836d367
commit
ce6aabfc55
47 files changed
+5674
-724
No files matched your search
@@ -2,87 +2,114 @@ package gameserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gac-hkrpg-go/internal/common"
|
||||
pb "gac-hkrpg-go/protocol/proto"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"math"
|
||||
)
|
||||
|
||||
const archiveClientVersion uint32 = 4006
|
||||
|
||||
type cwArchiveStore struct {
|
||||
mu sync.RWMutex
|
||||
nextID uint32
|
||||
entries []*pb.FAIHLAKPABN
|
||||
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)
|
||||
}
|
||||
|
||||
var globalCWArchive = &cwArchiveStore{nextID: 1}
|
||||
|
||||
func cwRecordArchive(record *pb.OEDHMAHDECC, seasonID, subSeasonID uint32) *pb.FAIHLAKPABN {
|
||||
if record == nil {
|
||||
return nil
|
||||
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")
|
||||
}
|
||||
globalCWArchive.mu.Lock()
|
||||
defer globalCWArchive.mu.Unlock()
|
||||
|
||||
id := globalCWArchive.nextID
|
||||
globalCWArchive.nextID++
|
||||
|
||||
entry := &pb.FAIHLAKPABN{
|
||||
BAAGDILLLME: id,
|
||||
OBNEAIPKGKL: time.Now().Unix(),
|
||||
LJNGPCKPJLF: seasonID,
|
||||
GEGMHOMNBDG: subSeasonID,
|
||||
PMBNKEFCICH: archiveClientVersion,
|
||||
IECKKCHJMLP: false,
|
||||
BFLLJJBHLDF: proto.Clone(record).(*pb.OEDHMAHDECC),
|
||||
now, err := common.GameTime()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
globalCWArchive.entries = append(globalCWArchive.entries, entry)
|
||||
if len(globalCWArchive.entries) > 50 {
|
||||
globalCWArchive.entries = globalCWArchive.entries[len(globalCWArchive.entries)-50:]
|
||||
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 entry
|
||||
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(s *Session, req *pb.GridFightGetArchiveCsReq, rsp *pb.GridFightGetArchiveScRsp) error {
|
||||
rsp.Retcode = 0
|
||||
if req != nil {
|
||||
rsp.Type = req.Type
|
||||
cwHandle("GridFightGetArchive", func(_ *Session, req *pb.GridFightGetArchiveCsReq, rsp *pb.GridFightGetArchiveScRsp) error {
|
||||
c, err := common.LoadCurrencyWarsCatalog()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
globalCWArchive.mu.RLock()
|
||||
defer globalCWArchive.mu.RUnlock()
|
||||
|
||||
favourOnly := req != nil && req.Type == pb.MLJIILDNDPL_MLJIILDNDPL_FAGECPGMPEH
|
||||
for i := len(globalCWArchive.entries) - 1; i >= 0; i-- {
|
||||
e := globalCWArchive.entries[i]
|
||||
if favourOnly && !e.IECKKCHJMLP {
|
||||
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, proto.Clone(e).(*pb.FAIHLAKPABN))
|
||||
rsp.MCGGPONOCKC = append(rsp.MCGGPONOCKC, entries[i])
|
||||
}
|
||||
PacketLog(fmt.Sprintf("CW_GET_ARCHIVE type=%v entries=%d", rsp.Type, len(rsp.MCGGPONOCKC)))
|
||||
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)
|
||||
if req == nil {
|
||||
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
|
||||
}
|
||||
globalCWArchive.mu.Lock()
|
||||
defer globalCWArchive.mu.Unlock()
|
||||
|
||||
for _, e := range globalCWArchive.entries {
|
||||
if e.BAAGDILLLME == req.BAAGDILLLME {
|
||||
e.IECKKCHJMLP = req.IECKKCHJMLP
|
||||
rsp.BAAGDILLLME = req.BAAGDILLLME
|
||||
rsp.IECKKCHJMLP = req.IECKKCHJMLP
|
||||
rsp.Retcode = 0
|
||||
PacketLog(fmt.Sprintf("CW_FAVOUR_ARCHIVE id=%d favour=%t", req.BAAGDILLLME, req.IECKKCHJMLP))
|
||||
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
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user