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,126 @@
|
||||
package discovery
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"longheng.io/server/internal/platform/registry"
|
||||
)
|
||||
|
||||
type NodeProbe func(context.Context, registry.Node) error
|
||||
|
||||
type ProbeOptions struct {
|
||||
Service string
|
||||
Timeout time.Duration
|
||||
Probe NodeProbe
|
||||
OnChange func(ProbeResult)
|
||||
}
|
||||
|
||||
type ProbeResult struct {
|
||||
Service string `json:"service"`
|
||||
NodeID string `json:"node_id"`
|
||||
Healthy bool `json:"healthy"`
|
||||
Error string `json:"error,omitempty"`
|
||||
CheckedAt time.Time `json:"checked_at"`
|
||||
}
|
||||
|
||||
func (r *Resolver) MustAlive(ctx context.Context, service, nodeID string) (bool, error) {
|
||||
node, ok, err := r.lookupNodeDirect(ctx, service, nodeID)
|
||||
if err != nil || !ok {
|
||||
return false, err
|
||||
}
|
||||
if r.rejectsMaintaining(node) {
|
||||
return false, nil
|
||||
}
|
||||
return nodeAccepting(node), nil
|
||||
}
|
||||
|
||||
func (r *Resolver) ProbeNodes(ctx context.Context, options ProbeOptions) ([]ProbeResult, error) {
|
||||
if r == nil || r.reg == nil {
|
||||
return nil, ErrNoRegistry
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
service := strings.TrimSpace(options.Service)
|
||||
if service == "" {
|
||||
return nil, ErrNoNodes
|
||||
}
|
||||
if options.Probe == nil {
|
||||
return nil, ErrNoProbe
|
||||
}
|
||||
nodes, err := r.reg.List(ctx, service)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
now := r.now().UTC()
|
||||
results := make([]ProbeResult, 0, len(nodes))
|
||||
for _, node := range nodes {
|
||||
if strings.TrimSpace(node.NodeID) == "" {
|
||||
continue
|
||||
}
|
||||
result := ProbeResult{
|
||||
Service: service,
|
||||
NodeID: node.NodeID,
|
||||
CheckedAt: now,
|
||||
}
|
||||
probeCtx := ctx
|
||||
cancel := func() {}
|
||||
if options.Timeout > 0 {
|
||||
probeCtx, cancel = context.WithTimeout(ctx, options.Timeout)
|
||||
}
|
||||
err := options.Probe(probeCtx, node)
|
||||
cancel()
|
||||
if err != nil {
|
||||
result.Error = err.Error()
|
||||
r.MarkFailure(node.NodeID)
|
||||
} else {
|
||||
result.Healthy = true
|
||||
r.MarkSuccess(node.NodeID)
|
||||
}
|
||||
r.Invalidate(service)
|
||||
if options.OnChange != nil {
|
||||
options.OnChange(result)
|
||||
}
|
||||
results = append(results, result)
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) lookupNodeDirect(ctx context.Context, service, nodeID string) (registry.Node, bool, error) {
|
||||
if r == nil || r.reg == nil {
|
||||
return registry.Node{}, false, ErrNoRegistry
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
service = strings.TrimSpace(service)
|
||||
nodeID = strings.TrimSpace(nodeID)
|
||||
if service == "" {
|
||||
return registry.Node{}, false, ErrNoNodes
|
||||
}
|
||||
if nodeID == "" {
|
||||
return registry.Node{}, false, nil
|
||||
}
|
||||
nodes, err := r.reg.List(ctx, service)
|
||||
if err != nil {
|
||||
return registry.Node{}, false, err
|
||||
}
|
||||
for _, node := range nodes {
|
||||
if strings.TrimSpace(node.NodeID) == nodeID {
|
||||
return node, true, nil
|
||||
}
|
||||
}
|
||||
return registry.Node{}, false, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) rejectsMaintaining(node registry.Node) bool {
|
||||
if r == nil {
|
||||
return false
|
||||
}
|
||||
r.mu.Lock()
|
||||
reject := r.rejectMaintaining
|
||||
r.mu.Unlock()
|
||||
return reject && nodeMaintaining(node.Meta)
|
||||
}
|
||||
Reference in new issue
Block a user