服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
79 lines
2.5 KiB
Go
79 lines
2.5 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"longheng.io/server/internal/platform/config"
|
|
"longheng.io/server/internal/platform/health"
|
|
)
|
|
|
|
func (a *Application) preflight(ctx context.Context) error {
|
|
a.health.SetStartupStep("preflight", health.StateStarting, "checking dependencies")
|
|
if err := a.checkStartupSafety(); err != nil {
|
|
a.health.SetStartupStep("preflight", health.StateDegraded, err.Error())
|
|
a.incMetric("service_start_errors_total", map[string]string{"component": "config", "phase": "preflight"})
|
|
return err
|
|
}
|
|
checkCtx, cancel := context.WithTimeout(ctx, defPreflight)
|
|
defer cancel()
|
|
|
|
if err := a.checkDependency(checkCtx, "registry", a.registry); err != nil {
|
|
return err
|
|
}
|
|
if err := a.checkDependency(checkCtx, "bus", a.bus); err != nil {
|
|
return err
|
|
}
|
|
for _, comp := range a.components {
|
|
checker, ok := comp.(PreflightChecker)
|
|
if !ok {
|
|
continue
|
|
}
|
|
a.health.SetComponent(comp.Name(), health.StateStarting, "preflight")
|
|
if err := checker.Preflight(checkCtx); err != nil {
|
|
a.health.SetComponent(comp.Name(), health.StateDegraded, err.Error())
|
|
a.health.SetStartupStep("preflight", health.StateDegraded, err.Error())
|
|
a.incMetric("service_start_errors_total", map[string]string{"component": comp.Name(), "phase": "preflight"})
|
|
return fmt.Errorf("preflight component %s: %w", comp.Name(), err)
|
|
}
|
|
a.health.SetComponent(comp.Name(), health.StateStarting, "preflight ok")
|
|
}
|
|
|
|
a.health.SetStartupStep("preflight", health.StateReady, "dependencies ready")
|
|
return nil
|
|
}
|
|
|
|
func (a *Application) checkStartupSafety() error {
|
|
cfg := a.configSnapshot()
|
|
environment := strings.ToLower(strings.TrimSpace(cfg.Service.Environment))
|
|
if !config.IsProdLikeEnv(environment) {
|
|
return nil
|
|
}
|
|
if strings.EqualFold(strings.TrimSpace(cfg.Admin.Token), "local-admin-token") {
|
|
return fmt.Errorf("admin.token must not use local-admin-token outside local/dev/test environments")
|
|
}
|
|
if err := cfg.Validate(); err != nil {
|
|
return fmt.Errorf("startup config safety: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (a *Application) checkDependency(ctx context.Context, name string, dependency any) error {
|
|
if dependency == nil {
|
|
return nil
|
|
}
|
|
checker, ok := dependency.(interface {
|
|
Check(context.Context) error
|
|
})
|
|
if !ok {
|
|
return nil
|
|
}
|
|
if err := checker.Check(ctx); err != nil {
|
|
a.health.SetStartupStep("preflight", health.StateDegraded, err.Error())
|
|
a.incMetric("service_start_errors_total", map[string]string{"component": name, "phase": "preflight"})
|
|
return fmt.Errorf("preflight %s: %w", name, err)
|
|
}
|
|
return nil
|
|
}
|