2026-01-19 18:51:56 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"blazing/common/socket/errorcode"
|
2026-04-08 15:49:03 +08:00
|
|
|
"blazing/cool"
|
2026-04-06 03:42:48 +08:00
|
|
|
logicplayer "blazing/logic/service/player"
|
2026-01-19 18:51:56 +08:00
|
|
|
"blazing/logic/service/user"
|
2026-04-06 03:42:48 +08:00
|
|
|
configservice "blazing/modules/config/service"
|
|
|
|
|
playerservice "blazing/modules/player/service"
|
2026-04-08 15:49:03 +08:00
|
|
|
"strings"
|
2026-01-19 18:51:56 +08:00
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-08 15:49:03 +08:00
|
|
|
// 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 处理控制器请求。
|
2026-04-06 03:42:48 +08:00
|
|
|
func (h Controller) CDK(data *C2S_GET_GIFT_COMPLETE, player *logicplayer.Player) (result *user.S2C_GET_GIFT_COMPLETE, err errorcode.ErrorCode) {
|
2026-04-08 15:49:03 +08:00
|
|
|
result = &user.S2C_GET_GIFT_COMPLETE{Type: data.Type}
|
2026-01-19 18:51:56 +08:00
|
|
|
|
2026-04-08 15:49:03 +08:00
|
|
|
cdkCode := strings.Trim(data.PassText, "\x00")
|
2026-04-06 03:42:48 +08:00
|
|
|
cdkService := configservice.NewCdkService()
|
2026-03-31 08:19:53 +08:00
|
|
|
now := time.Now()
|
|
|
|
|
|
2026-04-08 15:49:03 +08:00
|
|
|
r := cdkService.Get(cdkCode)
|
2026-01-19 18:51:56 +08:00
|
|
|
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 {
|
2026-01-19 18:51:56 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrMolecularCodeExpired
|
|
|
|
|
}
|
|
|
|
|
if !player.Service.Cdk.CanGet(uint32(r.ID)) {
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-04-08 15:49:03 +08:00
|
|
|
|
|
|
|
|
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) {
|
2026-01-19 18:51:56 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrMolecularCodeGiftsGone
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 03:42:48 +08:00
|
|
|
reward, grantErr := playerservice.NewCdkService(data.Head.UserID).GrantConfigReward(uint32(r.ID))
|
|
|
|
|
if grantErr != nil {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-19 18:51:56 +08:00
|
|
|
result.Flag = 1
|
2026-04-06 03:42:48 +08:00
|
|
|
appendGift := func(giftID, count int64) {
|
|
|
|
|
if giftID == 0 || count <= 0 {
|
|
|
|
|
return
|
2026-01-19 18:51:56 +08:00
|
|
|
}
|
2026-04-06 03:42:48 +08:00
|
|
|
result.GiftList = append(result.GiftList, user.GiftInfo{GiftID: giftID, Count: count})
|
2026-01-19 18:51:56 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-06 03:42:48 +08:00
|
|
|
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)
|
2026-01-19 18:51:56 +08:00
|
|
|
}
|
2026-04-06 03:42:48 +08:00
|
|
|
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]
|
2026-01-19 18:51:56 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-06 03:42:48 +08:00
|
|
|
player.Service.Cdk.Log(uint32(r.ID))
|
2026-01-19 18:51:56 +08:00
|
|
|
return
|
|
|
|
|
}
|