Files
bl/logic/controller/user_cdk.go
昔念 026689f3ed ```
feat(cache): 添加复合键缓存操作支持

添加了基于 uint32+string 组合键的缓存操作方法,包括
GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和
ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景

fix(vscode): 添加 cSpell 配置支持 struc 词汇

refactor(session): 移除过时的会话管理方法

移除了基于单一字符串键的会话管理方法,因为已迁移到使用
复合键的缓存操作方式
```
2026-01-19 18:51:56 +08:00

57 lines
1.6 KiB
Go

package controller
import (
"blazing/common/socket/errorcode"
"blazing/logic/service/player"
"blazing/logic/service/user"
"blazing/modules/config/service"
"blazing/modules/player/model"
"time"
)
func (h Controller) CDK(data *user.C2S_GET_GIFT_COMPLETE, player *player.Player) (result *user.S2C_GET_GIFT_COMPLETE, err errorcode.ErrorCode) {
result = &user.S2C_GET_GIFT_COMPLETE{}
r := service.NewCdkService().Get(data.PassText)
if r == nil {
return nil, errorcode.ErrorCodes.ErrMolecularCodeNotExists
}
if r.ValidEndTime.Compare(time.Now()) == -1 {
return nil, errorcode.ErrorCodes.ErrMolecularCodeExpired
}
if !player.Service.Cdk.CanGet(uint32(r.ID)) {
return
}
if !service.NewCdkService().Set(data.PassText) {
return nil, errorcode.ErrorCodes.ErrMolecularCodeGiftsGone
}
result.Flag = 1
for _, v := range r.ElfRewardIds {
pet := service.NewPetRewardService().Get(v)
if pet != nil {
peti := model.GenPetInfo(int(pet.MonID), int(pet.DV), int(pet.Nature), int(pet.Effect), int(pet.Lv), nil)
player.Service.Pet.PetAdd(peti)
result.PetGift = append(result.PetGift, user.PetGiftInfo{PetID: peti.ID, CacthTime: peti.CatchTime})
}
}
for _, itemID := range r.ItemRewardIds {
iteminfo := service.NewItemService().GetItemCount(itemID)
player.ItemAdd(iteminfo.ItemId, iteminfo.ItemCnt)
result.GiftList = append(result.GiftList, user.GiftInfo{GiftID: iteminfo.ItemId, Count: iteminfo.ItemCnt})
}
if r.TitleRewardIds != 0 {
player.Service.Title.Give(r.TitleRewardIds)
result.Tile = r.TitleRewardIds
}
player.Service.Cdk.Log(uint32(r.ID))
return
}