Files
hanfuit 645b64fe21 DNF90 服务端与启动器完整源码(含 GM 工具功能增强)
服务端(Go):
- GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面
- GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新
- 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新)
- 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍
- 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0)
- 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算

启动器(Python/JS):
- 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭
- GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐)
- 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
2026-11-04 14:31:55 +08:00

106 lines
3.1 KiB
Go

package services
import (
"os"
"path/filepath"
"testing"
"time"
)
// BenchmarkRealResources measures the three user-visible startup stages with
// the real Script.pvf and ImagePacks2 resources. Run it through
// scripts/benchmark.sh, which uses -benchtime=1x so one run produces one
// comparable set of numbers.
func BenchmarkRealResources(b *testing.B) {
pvfPath := resolveBenchmarkPath(b, "PVF_TESTFILE", "Script.pvf")
npkDirectory := resolveBenchmarkPath(b, "NPK_TESTDIR", "ImagePacks2")
for iteration := 0; iteration < b.N; iteration++ {
core := NewCore()
archiveService := NewArchiveService(core)
openStartedAt := time.Now()
if _, err := archiveService.Open(pvfPath); err != nil {
b.Fatalf("打开 PVF 失败: %v", err)
}
openElapsedMs := durationMilliseconds(time.Since(openStartedAt))
indexStatus := waitBenchmarkSearchIndex(b, archiveService)
b.Logf("打开 Script.pvf 到可操作: %.3f ms", openElapsedMs)
b.Logf("构建 PVF 索引: %.3f ms", indexStatus.BuildDurationMs)
core.closeArchive()
settings := newSettingsService(filepath.Join(b.TempDir(), "settings.json"))
configured := DefaultAppSettings()
configured.NPKDirectory = npkDirectory
if err := settings.SaveSettings(configured); err != nil {
b.Fatalf("写入基准测试设置失败: %v", err)
}
imageService := &ImageService{
settings: settings,
cachePath: filepath.Join(b.TempDir(), "npk-image-index.json"),
cache: make(map[string]imageCacheEntry),
}
imageService.Initialize()
imageStatus := waitBenchmarkImageIndex(b, imageService)
b.Logf("构建 NPK 索引: %.3f ms", imageStatus.BuildDurationMs)
}
}
func resolveBenchmarkPath(b *testing.B, environment, fallback string) string {
b.Helper()
value := os.Getenv(environment)
if value == "" {
value = fallback
}
if filepath.IsAbs(value) {
if _, err := os.Stat(value); err == nil {
return value
}
} else {
candidates := []string{value, filepath.Join("..", value), filepath.Join("..", "..", value)}
for _, candidate := range candidates {
if _, err := os.Stat(candidate); err == nil {
absolute, err := filepath.Abs(candidate)
if err == nil {
return absolute
}
}
}
}
b.Skipf("%s 未找到: %s", environment, value)
return ""
}
func waitBenchmarkSearchIndex(b *testing.B, service *ArchiveService) IndexStatus {
b.Helper()
deadline := time.Now().Add(5 * time.Minute)
for time.Now().Before(deadline) {
status := service.IndexStatus()
switch status.State {
case IndexStateReady:
return status
case IndexStateError:
b.Fatalf("PVF 索引失败: %s", status.Error)
}
time.Sleep(time.Millisecond)
}
b.Fatalf("PVF 索引超时: %#v", service.IndexStatus())
return IndexStatus{}
}
func waitBenchmarkImageIndex(b *testing.B, service *ImageService) ImageIndexStatus {
b.Helper()
deadline := time.Now().Add(5 * time.Minute)
for time.Now().Before(deadline) {
status := service.IndexStatus()
switch status.State {
case ImageIndexStateReady:
return status
case ImageIndexStateError:
b.Fatalf("NPK 索引失败: %s", status.Error)
}
time.Sleep(time.Millisecond)
}
b.Fatalf("NPK 索引超时: %#v", service.IndexStatus())
return ImageIndexStatus{}
}