feat: 新增CDK兑换冠名接口

This commit is contained in:
xinian
2026-04-08 18:12:02 +08:00
parent 1ca0ff344e
commit 28b6386963
4 changed files with 120 additions and 57 deletions

View File

@@ -2,7 +2,6 @@ package controller
import (
"blazing/common/socket/errorcode"
"blazing/cool"
logicplayer "blazing/logic/service/player"
"blazing/logic/service/user"
configservice "blazing/modules/config/service"
@@ -11,16 +10,9 @@ import (
"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
}
// 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}
result = &user.S2C_GET_GIFT_COMPLETE{}
cdkCode := strings.Trim(data.PassText, "\x00")
cdkService := configservice.NewCdkService()
@@ -39,32 +31,6 @@ func (h Controller) CDK(data *C2S_GET_GIFT_COMPLETE, player *logicplayer.Player)
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
}