服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
148 lines
6.5 KiB
Go
148 lines
6.5 KiB
Go
package dnfbridge
|
|
|
|
import (
|
|
"context"
|
|
"encoding/binary"
|
|
"math"
|
|
"testing"
|
|
"time"
|
|
|
|
"longheng.io/server/internal/modules/dnf/dnfenum"
|
|
"longheng.io/server/internal/modules/dnf/premium"
|
|
dnfrepo "longheng.io/server/internal/modules/dnf/repository"
|
|
dnfrepomemory "longheng.io/server/internal/modules/dnf/repository/memory"
|
|
)
|
|
|
|
func TestCurrentPremiumContractGrantAutoActivatesBeforeOp14Projection(t *testing.T) {
|
|
repositories := dnfrepomemory.NewMemoryGroup()
|
|
ctx := context.Background()
|
|
if err := repositories.Account.Save(ctx, dnfrepo.AccountRecord{AccountID: "account-1", Metadata: make(map[string]string)}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := repositories.Character.Save(ctx, dnfrepo.CharacterRecord{CharacterID: "19", AccountID: "account-1", Stats: make(map[string]int64)}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
contract := dnfrepo.ItemStack{ItemID: 44, Count: 2}
|
|
entry := currentItemListEntryFromStack(dnfrepo.MainInventoryListType, 10, contract)
|
|
contract.RawEntry = append([]byte(nil), entry.data[:]...)
|
|
if err := repositories.Inventory.Save(ctx, dnfrepo.InventoryRecord{
|
|
CharacterID: "19",
|
|
Slots: map[string]dnfrepo.ItemStack{"0:10": contract},
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := repositories.Equipment.Save(ctx, dnfrepo.EquipmentRecord{CharacterID: "19", Entries: make(map[string]dnfrepo.EquipmentEntry)}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
connection := &bufferConn{}
|
|
service := &Service{
|
|
options: options{
|
|
accountID: "account-1",
|
|
gameUpperHeader: gameUpperHeaderChannel13,
|
|
gameUpperBodyCodec: gameUpperBodyCodecPlain,
|
|
},
|
|
premiumCatalog: ¤tPremiumCatalog{
|
|
contractsByItem: map[int64]currentPremiumContractInfo{
|
|
44: {ItemID: 44, PremiumType: premium.TypeOverSkill, DurationSeconds: 3 * 86400},
|
|
},
|
|
},
|
|
repositoryProvider: func() (dnfrepo.Group, bool) { return repositories, true },
|
|
}
|
|
session := &gameSession{conn: connection, connID: "contract-auto-activation", selectedCharacterID: 19}
|
|
body := buildCurrentItemUpdateBody(dnfrepo.MainInventoryListType, []currentItemListEntry{entry})
|
|
if err := service.sendGameUpperRawClass(session, uint16(dnfenum.CmdPacketWalkoutPartyMember), body, 0); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
notification, rest := splitGameServerUpperPacket(t, connection.write.Bytes())
|
|
if notification.Header.Classification != 0 || notification.Header.MsgID != currentPremiumActivatedMsgID ||
|
|
len(notification.Body) != 11 || notification.Body[2] != byte(premium.TypeOverSkill) {
|
|
t.Fatalf("activation notification = header=%+v body=%x", notification.Header, notification.Body)
|
|
}
|
|
remaining := int64(binary.LittleEndian.Uint64(notification.Body[3:11]))
|
|
if remaining < 6*86400-30 || remaining > 6*86400 {
|
|
t.Fatalf("remaining = %d, want about six days", remaining)
|
|
}
|
|
update, trailing := splitGameServerUpperPacket(t, rest)
|
|
if len(trailing) != 0 || update.Header.Classification != 0 ||
|
|
update.Header.MsgID != uint16(dnfenum.CmdPacketWalkoutPartyMember) ||
|
|
len(update.Body) != 3+currentItemListEntryWireSize || update.Body[0] != dnfrepo.MainInventoryListType ||
|
|
binary.LittleEndian.Uint16(update.Body[1:3]) != 1 ||
|
|
binary.LittleEndian.Uint16(update.Body[3:5]) != 10 ||
|
|
binary.LittleEndian.Uint32(update.Body[5:9]) != math.MaxUint32 ||
|
|
binary.LittleEndian.Uint32(update.Body[9:13]) != 0 {
|
|
t.Fatalf("post-activation update = header=%+v body=%x trailing=%x", update.Header, update.Body, trailing)
|
|
}
|
|
|
|
inventory, found, err := repositories.Inventory.Load(ctx, "19")
|
|
if err != nil || !found {
|
|
t.Fatalf("load inventory found=%t err=%v", found, err)
|
|
}
|
|
if _, exists := inventory.Slots["0:10"]; exists {
|
|
t.Fatalf("contract entered inventory after notification: %+v", inventory.Slots)
|
|
}
|
|
account, found, err := repositories.Account.Load(ctx, "account-1")
|
|
if err != nil || !found {
|
|
t.Fatalf("load account found=%t err=%v", found, err)
|
|
}
|
|
expire := premium.ExpireAt(account, premium.TypeOverSkill)
|
|
if expire-time.Now().UTC().Unix() < 6*86400-30 || expire-time.Now().UTC().Unix() > 6*86400 {
|
|
t.Fatalf("expire = %d, want about six days", expire)
|
|
}
|
|
}
|
|
|
|
func TestCurrentPremiumContractSelectionMigrationDoesNotEmitPrematureNotification(t *testing.T) {
|
|
repositories := dnfrepomemory.NewMemoryGroup()
|
|
ctx := context.Background()
|
|
if err := repositories.Account.Save(ctx, dnfrepo.AccountRecord{AccountID: "account-1", Metadata: make(map[string]string)}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := repositories.Character.Save(ctx, dnfrepo.CharacterRecord{CharacterID: "19", AccountID: "account-1", Stats: make(map[string]int64)}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := repositories.Inventory.Save(ctx, dnfrepo.InventoryRecord{
|
|
CharacterID: "19",
|
|
Slots: map[string]dnfrepo.ItemStack{
|
|
"0:20": {ItemID: 31, Count: 1},
|
|
"0:21": {ItemID: 44, Count: 1},
|
|
"0:22": {ItemID: 500, Count: 9},
|
|
},
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := repositories.Equipment.Save(ctx, dnfrepo.EquipmentRecord{CharacterID: "19", Entries: make(map[string]dnfrepo.EquipmentEntry)}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
connection := &bufferConn{}
|
|
service := &Service{
|
|
options: options{accountID: "account-1", gameUpperHeader: gameUpperHeaderChannel13, gameUpperBodyCodec: gameUpperBodyCodecPlain},
|
|
premiumCatalog: ¤tPremiumCatalog{contractsByItem: map[int64]currentPremiumContractInfo{
|
|
31: {ItemID: 31, PremiumType: premium.TypeOverEquip, DurationSeconds: 3 * 86400},
|
|
44: {ItemID: 44, PremiumType: premium.TypeOverSkill, DurationSeconds: 3 * 86400},
|
|
}},
|
|
repositoryProvider: func() (dnfrepo.Group, bool) { return repositories, true },
|
|
}
|
|
session := &gameSession{conn: connection, connID: "contract-select-migration", selectedCharacterID: 19}
|
|
if err := service.reconcileCurrentPremiumInventoryBeforeList(ctx, session, "test_select", false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if connection.write.Len() != 0 {
|
|
t.Fatalf("selection migration emitted packet before select ACK: %x", connection.write.Bytes())
|
|
}
|
|
inventory, _, _ := repositories.Inventory.Load(ctx, "19")
|
|
if len(inventory.Slots) != 1 || inventory.Slots["0:22"].Count != 9 {
|
|
t.Fatalf("selection migration inventory = %+v", inventory.Slots)
|
|
}
|
|
account, _, _ := repositories.Account.Load(ctx, "account-1")
|
|
entries := currentSelectAckPremiumEntries(account, time.Now().UTC())
|
|
if len(entries) != 1+2*9 || entries[0] != 2 {
|
|
t.Fatalf("select ACK premium entries = %x", entries)
|
|
}
|
|
for offset := 1; offset < len(entries); offset += 9 {
|
|
if entries[offset] != byte(premium.TypeOverEquip) && entries[offset] != byte(premium.TypeOverSkill) {
|
|
t.Fatalf("unexpected premium type in select ACK entries: %x", entries)
|
|
}
|
|
}
|
|
}
|