DNF90 服务端与启动器完整源码(含 GM 工具功能增强)
服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
This commit is contained in:
commit
645b64fe21
4388 files changed
+1405457
No files matched your search
@@ -0,0 +1,193 @@
|
||||
package dnfbridge
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
|
||||
"longheng.io/server/internal/modules/dnf/channelcatalog"
|
||||
"longheng.io/server/internal/modules/dnf/dnfenum"
|
||||
"longheng.io/server/internal/modules/dnf/dungeoncmd"
|
||||
dnfproto "longheng.io/server/internal/modules/dnf/protocol"
|
||||
"longheng.io/server/internal/modules/dnf/worldmap"
|
||||
)
|
||||
|
||||
func TestCurrentDungeonPlayResultShapeAcceptsOnlyWriterDerivedLengths(t *testing.T) {
|
||||
accepted := make(map[int]struct{})
|
||||
for rows := 0; rows <= currentDungeonPlayResultMaximumDynamicRows; rows++ {
|
||||
for _, test := range []struct {
|
||||
bodyLen int
|
||||
optional bool
|
||||
}{
|
||||
{bodyLen: currentDungeonPlayResultBaseSize + rows*currentDungeonPlayResultDynamicRowSize},
|
||||
{bodyLen: currentDungeonPlayResultOptionalBaseSize + rows*currentDungeonPlayResultDynamicRowSize, optional: true},
|
||||
} {
|
||||
accepted[test.bodyLen] = struct{}{}
|
||||
gotRows, gotOptional, ok := currentDungeonPlayResultShape(make([]byte, test.bodyLen))
|
||||
if !ok || gotRows != rows || gotOptional != test.optional {
|
||||
t.Fatalf("body_len=%d shape=(%d,%t,%t) want=(%d,%t,true)",
|
||||
test.bodyLen, gotRows, gotOptional, ok, rows, test.optional)
|
||||
}
|
||||
}
|
||||
}
|
||||
for bodyLen := 0; bodyLen <= currentDungeonPlayResultOptionalBaseSize+
|
||||
currentDungeonPlayResultMaximumDynamicRows*currentDungeonPlayResultDynamicRowSize+4; bodyLen++ {
|
||||
_, expected := accepted[bodyLen]
|
||||
_, _, got := currentDungeonPlayResultShape(make([]byte, bodyLen))
|
||||
if got != expected {
|
||||
t.Fatalf("body_len=%d valid=%t want=%t", bodyLen, got, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleDungeonSetPlayResultCapturesOnceWithoutRewardOrResponse(t *testing.T) {
|
||||
service, runtime, session, conn, targetKey := prepareCompletedSettlementRuntime(t)
|
||||
conn.write.Reset()
|
||||
body := make([]byte, currentDungeonPlayResultBaseSize+currentDungeonPlayResultDynamicRowSize)
|
||||
body[0] = 3
|
||||
binary.LittleEndian.PutUint16(body[1:3], 99)
|
||||
binary.LittleEndian.PutUint32(body[3:7], 0x11223344)
|
||||
|
||||
if err := service.handleDungeonSetPlayResult(session, body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if conn.write.Len() != 0 {
|
||||
t.Fatalf("captured op46 emitted unproven result/reward packets=%x", conn.write.Bytes())
|
||||
}
|
||||
if !runtime.settlementPlayResultReceived ||
|
||||
runtime.settlementPlayResultDynamicRows != 1 ||
|
||||
runtime.settlementPlayResultOptionalField ||
|
||||
!bytes.Equal(runtime.settlementPlayResultBody, body) {
|
||||
t.Fatalf("captured state=%+v body=%x", runtime, runtime.settlementPlayResultBody)
|
||||
}
|
||||
if !runtime.settlementEntrySent || runtime.townReturnPending || runtime.townReturnOp24Sent ||
|
||||
runtime.Session.Snapshot().Run.Status != worldmap.DungeonRunCompleted ||
|
||||
runtime.bossDieCheckTargetObjectKey != uint16(targetKey) {
|
||||
t.Fatalf("op46 changed completion owner=%+v", runtime)
|
||||
}
|
||||
|
||||
if err := service.handleDungeonSetPlayResult(session, append([]byte(nil), body...)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conflict := append([]byte(nil), body...)
|
||||
conflict[len(conflict)-1] = 0x7f
|
||||
if err := service.handleDungeonSetPlayResult(session, conflict); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if conn.write.Len() != 0 || !bytes.Equal(runtime.settlementPlayResultBody, body) {
|
||||
t.Fatalf("op46 replay/conflict mutated owner body=%x wrote=%x", runtime.settlementPlayResultBody, conn.write.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleGameUpperRoutesCurrentPlayResultAndRejectsWrongClassOrStage(t *testing.T) {
|
||||
t.Run("ready class one", func(t *testing.T) {
|
||||
service, runtime, session, conn, _ := prepareCompletedSettlementRuntime(t)
|
||||
conn.write.Reset()
|
||||
body := make([]byte, currentDungeonPlayResultOptionalBaseSize)
|
||||
packet, err := dnfproto.BuildChannelPacket(
|
||||
uint16(dnfenum.CmdPacketSetPlayResult), body, 0, dnfproto.DefaultChannelClassification,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.handleGameUpper(session, packet); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !runtime.settlementPlayResultReceived || !runtime.settlementPlayResultOptionalField ||
|
||||
runtime.settlementPlayResultDynamicRows != 0 || conn.write.Len() != 0 {
|
||||
t.Fatalf("routed op46 state=%+v wrote=%x", runtime, conn.write.Bytes())
|
||||
}
|
||||
})
|
||||
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
classification byte
|
||||
bodyLen int
|
||||
ready bool
|
||||
}{
|
||||
{name: "wrong class", classification: 2, bodyLen: currentDungeonPlayResultBaseSize, ready: true},
|
||||
{name: "malformed length", classification: dnfproto.DefaultChannelClassification, bodyLen: currentDungeonPlayResultBaseSize + 1, ready: true},
|
||||
{name: "before settlement entry", classification: dnfproto.DefaultChannelClassification, bodyLen: currentDungeonPlayResultBaseSize},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
service, runtime := prepareTutorialScopeRuntime(t, tutorialScopeFixtureOptions{singleMonster: true})
|
||||
conn := &bufferConn{}
|
||||
session := &gameSession{
|
||||
conn: conn,
|
||||
connID: "rejected-op46-test",
|
||||
selectedCharacterID: 99,
|
||||
dungeon: dungeonSessionState{runtime: runtime},
|
||||
}
|
||||
if test.ready {
|
||||
completeSettlementRuntimeForTest(t, service, runtime, session)
|
||||
conn.write.Reset()
|
||||
}
|
||||
packet, err := dnfproto.BuildChannelPacket(
|
||||
uint16(dnfenum.CmdPacketSetPlayResult), make([]byte, test.bodyLen), 0, test.classification,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.handleGameUpper(session, packet); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if runtime.settlementPlayResultReceived || conn.write.Len() != 0 {
|
||||
t.Fatalf("rejected op46 captured=%t wrote=%x", runtime.settlementPlayResultReceived, conn.write.Bytes())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func prepareCompletedSettlementRuntime(t *testing.T) (*Service, *runtimeDungeonState, *gameSession, *bufferConn, uint32) {
|
||||
t.Helper()
|
||||
service, runtime := prepareTutorialScopeRuntime(t, tutorialScopeFixtureOptions{singleMonster: true})
|
||||
repositories, ok := service.repositoryGroup()
|
||||
if !ok {
|
||||
t.Fatal("completed-settlement repository group unavailable")
|
||||
}
|
||||
// A completed return now restores the normal selected-actor skill manager
|
||||
// before its equipment-bearing mode1. Keep this shared fixture on the same
|
||||
// PVF-backed skill path as an actual client session.
|
||||
enableTownMoveSkillProjection(t, service, repositories, "99")
|
||||
conn := &bufferConn{}
|
||||
channel := channelcatalog.Channel{ServerID: 1, ID: 19, Type: 1, Name: "ch.19", Port: 10019}
|
||||
session := &gameSession{
|
||||
conn: conn,
|
||||
connID: "completed-settlement-runtime-test",
|
||||
channel: channel,
|
||||
residentChannel: channel,
|
||||
selectedCharacterID: 99,
|
||||
dungeon: dungeonSessionState{runtime: runtime},
|
||||
}
|
||||
targetKey := completeSettlementRuntimeForTest(t, service, runtime, session)
|
||||
return service, runtime, session, conn, targetKey
|
||||
}
|
||||
|
||||
func completeSettlementRuntimeForTest(
|
||||
t *testing.T,
|
||||
service *Service,
|
||||
runtime *runtimeDungeonState,
|
||||
session *gameSession,
|
||||
) uint32 {
|
||||
t.Helper()
|
||||
if _, err := runtime.Room.AnnounceAllActors(runtime.Session); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
targetKey := runtime.Room.Snapshot().Monsters[0].ObjectKey
|
||||
deathBody := make([]byte, dungeoncmd.DieMonsterRequestSize)
|
||||
binary.LittleEndian.PutUint32(deathBody[0:4], targetKey)
|
||||
binary.LittleEndian.PutUint16(deathBody[4:6], session.selectedCharacterID)
|
||||
if err := service.handleDungeonMonsterDeath(session, deathBody); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.handleDungeonBossDieCheck(
|
||||
session,
|
||||
bossDieCheckRequestBody(session.selectedCharacterID, uint16(targetKey)),
|
||||
); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !runtime.settlementEntrySent || runtime.Session.Snapshot().Run.Status != worldmap.DungeonRunCompleted {
|
||||
t.Fatalf("settlement fixture incomplete state=%+v", runtime)
|
||||
}
|
||||
return targetKey
|
||||
}
|
||||
Reference in new issue
Block a user