服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
217 lines
7.8 KiB
Go
217 lines
7.8 KiB
Go
package cargo
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"longheng.io/server/internal/modules/dnf/alignedcmd"
|
|
"longheng.io/server/internal/modules/dnf/dnfenum"
|
|
dnfproto "longheng.io/server/internal/modules/dnf/protocol"
|
|
)
|
|
|
|
type handler struct{}
|
|
|
|
func NewHandler() alignedcmd.Handler {
|
|
return handler{}
|
|
}
|
|
|
|
func (handler) Domain() dnfenum.AlignedDomain {
|
|
return dnfenum.AlignedDomainCargo
|
|
}
|
|
|
|
func (handler) Handle(ctx context.Context, req alignedcmd.Request) (alignedcmd.Result, error) {
|
|
switch dnfenum.CmdPacket(req.Opcode) {
|
|
case dnfenum.CmdPacketCreateAccountCargo:
|
|
cmd := NewAccountCommand(req, "create_account_cargo")
|
|
return handleAccountPlan(ctx, req, cmd)
|
|
case dnfenum.CmdPacketUpgradeAccountCargo:
|
|
cmd := NewAccountCommand(req, "upgrade_account_cargo")
|
|
return handleAccountPlan(ctx, req, cmd)
|
|
case dnfenum.CmdPacketDepositMoney:
|
|
parsed, err := DecodeGoldRequest(req.Body)
|
|
cmd := NewMoneyCommand(req, MoneyDeposit, parsed)
|
|
return handleMoneyPlan(ctx, req, cmd, err)
|
|
case dnfenum.CmdPacketWithdrawMoney:
|
|
parsed, err := DecodeGoldRequest(req.Body)
|
|
cmd := NewMoneyCommand(req, MoneyWithdraw, parsed)
|
|
return handleMoneyPlan(ctx, req, cmd, err)
|
|
default:
|
|
return alignedcmd.Result{
|
|
Handled: false,
|
|
ResponseAllowed: false,
|
|
Operation: "unregistered",
|
|
Reason: fmt.Sprintf("cargo module has no opcode %d handler", req.Opcode),
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
func handleAccountPlan(ctx context.Context, req alignedcmd.Request, cmd Command) (alignedcmd.Result, error) {
|
|
owner, err := NewOwner(req.Repositories)
|
|
if err != nil {
|
|
return ownerBlockedResult(cmd.Operation, cmd.String(), err), nil
|
|
}
|
|
result, err := owner.ApplyAccount(ctx, cmd.Operation, AccountCommand{
|
|
AccountID: cmd.AccountID,
|
|
SelectedCharacterID: cmd.SelectedCharacterID,
|
|
})
|
|
if err != nil {
|
|
return ownerBlockedResult(cmd.Operation, cmd.String(), err), nil
|
|
}
|
|
return ownerAppliedResult(req.Opcode, cmd.Operation, cmd.String(), result), nil
|
|
}
|
|
|
|
func handleMoneyPlan(ctx context.Context, req alignedcmd.Request, cmd Command, parseErr error) (alignedcmd.Result, error) {
|
|
if parseErr != nil {
|
|
return blockedParsedResult(cmd.Operation, cmd.String(), parseErr), nil
|
|
}
|
|
owner, err := NewOwner(req.Repositories)
|
|
if err != nil {
|
|
return ownerBlockedResult(cmd.Operation, cmd.String(), err), nil
|
|
}
|
|
result, err := owner.ApplyMoney(ctx, MoneyCommand{
|
|
AccountID: cmd.AccountID,
|
|
SelectedCharacterID: cmd.SelectedCharacterID,
|
|
Direction: cmd.MoneyDirection,
|
|
Amount: cmd.Amount,
|
|
})
|
|
if err != nil {
|
|
return ownerBlockedResult(cmd.Operation, cmd.String(), err), nil
|
|
}
|
|
return ownerAppliedResult(req.Opcode, cmd.Operation, cmd.String(), result), nil
|
|
}
|
|
|
|
func blockedResult(operation string, summary string) alignedcmd.Result {
|
|
return alignedcmd.Result{
|
|
Handled: true,
|
|
ResponseAllowed: false,
|
|
Operation: operation,
|
|
Reason: fmt.Sprintf("parsed %s: %s; success ACK is blocked until cargo asset writes are closed", operation, summary),
|
|
}
|
|
}
|
|
|
|
func blockedParsedResult(operation string, summary string, err error) alignedcmd.Result {
|
|
if err != nil {
|
|
return alignedcmd.Result{
|
|
Handled: true,
|
|
ResponseAllowed: false,
|
|
Operation: operation,
|
|
Reason: fmt.Sprintf("%s body parse failed: %v; success ACK is blocked", operation, err),
|
|
}
|
|
}
|
|
return blockedResult(operation, summary)
|
|
}
|
|
|
|
func ownerBlockedResult(operation string, summary string, err error) alignedcmd.Result {
|
|
return alignedcmd.Result{
|
|
Handled: true,
|
|
ResponseAllowed: false,
|
|
Operation: operation,
|
|
Reason: fmt.Sprintf("parsed %s: %s; cargo owner preflight failed: %v; success ACK is blocked", operation, summary, err),
|
|
}
|
|
}
|
|
|
|
func ownerAppliedResult(opcode uint16, operation string, summary string, result PlanResult) alignedcmd.Result {
|
|
responses := cargoUpperResponses(opcode, operation, result)
|
|
postActions := make([]alignedcmd.PostAction, 0, 1)
|
|
if operation == "create_account_cargo" || operation == "upgrade_account_cargo" {
|
|
// The list-12 body belongs to the bridge because it is decoded by the
|
|
// current EXE's item-list reader. Do not send the former empty/replayed
|
|
// cargo body here: it lost account-owned rows and mixed owner state.
|
|
//
|
|
// 开通/升级都改变了金库容量,必须先重建仓库底板再发列表:当前 EXE 的面板格子
|
|
// 是建面板时按容量铺的,只更新列表数据不会把锁去掉(现场 2026-09-18:扩容后
|
|
// 格子还画着锁、实际能放东西,切一下仓库页才正常)。
|
|
postActions = append(postActions, alignedcmd.PostActionResetCargoPadBeforeItemLists)
|
|
if result.Cost.Kind == CostMaterial {
|
|
// The material is a real list-0 stack. Refresh the character-owned
|
|
// containers after its durable transaction as well as list 12.
|
|
postActions = append(postActions, alignedcmd.PostActionRefreshSelectedItemContainers)
|
|
}
|
|
postActions = append(postActions, alignedcmd.PostActionRefreshSelectedAccountCargo)
|
|
}
|
|
out := alignedcmd.Result{
|
|
Handled: true,
|
|
ResponseAllowed: len(responses) > 0,
|
|
Operation: operation,
|
|
Reason: fmt.Sprintf(
|
|
"parsed %s: %s; cargo owner applied account=%s char=%s direction=%s amount=%d charGold=%d charCera=%d cargoGold=%d cargoLevel=%d cargoCreated=%t cost=%s/%d changed=%t; C# order response opened",
|
|
operation,
|
|
summary,
|
|
result.AccountID,
|
|
result.CharacterID,
|
|
result.Direction,
|
|
result.Amount,
|
|
result.CharacterGold,
|
|
result.CharacterCera,
|
|
result.CargoGold,
|
|
result.CargoLevel,
|
|
result.CargoCreated,
|
|
result.Cost.Kind,
|
|
result.Cost.Amount,
|
|
result.Changed,
|
|
),
|
|
UpperResponses: responses,
|
|
PostActions: postActions,
|
|
}
|
|
// 金库创建/升级用点券付款时,这就是一次"点券消费"。模块自己知道花了多少、
|
|
// 花在什么上,所以在这里上报给 bridge 记账(点券消费记录)。
|
|
// CharacterCera 是事务提交后的权威余额,扣费失败时 Changed=false 不会走到这里。
|
|
if result.Changed && result.Cost.Kind == CostCera && result.Cost.Amount > 0 {
|
|
out.CeraSpent = result.Cost.Amount
|
|
out.CeraAfter = result.CharacterCera
|
|
out.CeraSpentNote = cargoCeraSpentNote(operation, result)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// cargoCeraSpentNote 给点券消费记录写一句人话,说明这笔钱花在哪个金库阶段。
|
|
func cargoCeraSpentNote(operation string, result PlanResult) string {
|
|
switch operation {
|
|
case "create_account_cargo":
|
|
return fmt.Sprintf("金库创建(开通账号金库,升级到 %d 阶段)", result.CargoLevel)
|
|
case "upgrade_account_cargo":
|
|
return fmt.Sprintf("金库升级(账号金库升到 %d 阶段)", result.CargoLevel)
|
|
default:
|
|
return operation
|
|
}
|
|
}
|
|
|
|
func cargoUpperResponses(opcode uint16, operation string, result PlanResult) []alignedcmd.UpperResponse {
|
|
switch operation {
|
|
case "deposit_money", "withdraw_money":
|
|
return []alignedcmd.UpperResponse{
|
|
class1Response(opcode, buildCargoGoldAck(result.CargoGold)),
|
|
class0Response(msgItemListUpdate, buildGoldUpdateBody(result.CharacterGold)),
|
|
}
|
|
case "create_account_cargo", "upgrade_account_cargo":
|
|
responses := []alignedcmd.UpperResponse{class1Response(opcode, buildSuccessAck())}
|
|
switch result.Cost.Kind {
|
|
case CostGold:
|
|
responses = append(responses, class0Response(msgItemListUpdate, buildGoldUpdateBody(result.CharacterGold)))
|
|
case CostCera:
|
|
responses = append(responses, class0Response(msgCeraUpdate, buildCeraUpdateBody(result.CharacterCera)))
|
|
}
|
|
return responses
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func class1Response(opcode uint16, body []byte) alignedcmd.UpperResponse {
|
|
return alignedcmd.UpperResponse{
|
|
MsgID: opcode,
|
|
Body: body,
|
|
Classification: dnfproto.DefaultChannelClassification,
|
|
AllowCodec: true,
|
|
}
|
|
}
|
|
|
|
func class0Response(msgID uint16, body []byte) alignedcmd.UpperResponse {
|
|
return alignedcmd.UpperResponse{
|
|
MsgID: msgID,
|
|
Body: body,
|
|
Classification: 0,
|
|
AllowCodec: true,
|
|
}
|
|
}
|