Files
bl/logic/controller/user_cdk.go

102 lines
3.0 KiB
Go
Raw Normal View History

package controller
import (
"blazing/common/socket/errorcode"
"blazing/cool"
logicplayer "blazing/logic/service/player"
"blazing/logic/service/user"
configservice "blazing/modules/config/service"
playerservice "blazing/modules/player/service"
"strings"
"time"
)
// DonationServerIDs 返回当前可用于捐赠冠名的服务器ID列表。
func (h Controller) DonationServerIDs(data *C2S_GET_DONATION_SERVER_IDS, player *logicplayer.Player) (result *user.S2C_GET_DONATION_SERVER_IDS, err errorcode.ErrorCode) {
return &user.S2C_GET_DONATION_SERVER_IDS{
ServerIDs: configservice.NewServerService().GetDonationAvailableServerIDs(),
}, 0
}
2026-04-05 23:13:06 +08:00
// CDK 处理控制器请求。
func (h Controller) CDK(data *C2S_GET_GIFT_COMPLETE, player *logicplayer.Player) (result *user.S2C_GET_GIFT_COMPLETE, err errorcode.ErrorCode) {
result = &user.S2C_GET_GIFT_COMPLETE{Type: data.Type}
cdkCode := strings.Trim(data.PassText, "\x00")
cdkService := configservice.NewCdkService()
2026-03-31 08:19:53 +08:00
now := time.Now()
r := cdkService.Get(cdkCode)
if r == nil {
return nil, errorcode.ErrorCodes.ErrMolecularCodeNotExists
}
2026-02-13 03:04:04 +08:00
if r.BindUserId != 0 && r.BindUserId != data.Head.UserID {
return nil, errorcode.ErrorCodes.ErrMolecularCodeFrozen
}
2026-03-31 08:19:53 +08:00
if r.ValidEndTime.Compare(now) == -1 {
return nil, errorcode.ErrorCodes.ErrMolecularCodeExpired
}
if !player.Service.Cdk.CanGet(uint32(r.ID)) {
return
}
if r.CDKType == configservice.CDKTypeServerNaming {
if data.Type != configservice.CDKTypeServerNaming {
return nil, errorcode.ErrorCodes.ErrSystemError
}
serverName := cool.Filter.Replace(strings.Trim(data.ServerName, "\x00"), '*')
if data.ServerID == 0 || serverName == "" {
return nil, errorcode.ErrorCodes.ErrSystemError
}
serverInfo, useErr := cdkService.UseServerNamingCDK(nil, cdkCode, data.Head.UserID, data.ServerID, serverName)
if useErr != nil {
return nil, errorcode.ErrorCodes.ErrSystemError
}
result.Flag = 1
result.ServerID = serverInfo.OnlineID
result.ServerName = serverInfo.Name
player.Service.Cdk.Log(uint32(r.ID))
return result, 0
}
if data.Type == configservice.CDKTypeServerNaming {
return nil, errorcode.ErrorCodes.ErrSystemError
}
if !cdkService.Set(cdkCode) {
return nil, errorcode.ErrorCodes.ErrMolecularCodeGiftsGone
}
reward, grantErr := playerservice.NewCdkService(data.Head.UserID).GrantConfigReward(uint32(r.ID))
if grantErr != nil {
return nil, errorcode.ErrorCodes.ErrSystemError
}
result.Flag = 1
appendGift := func(giftID, count int64) {
if giftID == 0 || count <= 0 {
return
}
result.GiftList = append(result.GiftList, user.GiftInfo{GiftID: giftID, Count: count})
}
appendGift(1, reward.Coins)
appendGift(3, reward.ExpPool)
appendGift(5, reward.Gold)
appendGift(9, reward.EVPool)
for _, item := range reward.Items {
appendGift(item.ItemId, item.ItemCnt)
}
for _, pet := range reward.Pets {
result.PetGift = append(result.PetGift, user.PetGiftInfo{PetID: pet.PetID, CacthTime: pet.CatchTime})
}
if len(reward.TitleIDs) > 0 {
result.Tile = reward.TitleIDs[0]
}
player.Service.Cdk.Log(uint32(r.ID))
return
}