Files
90CNServer/pvf/internal/pvf/string_reference_workspace.go
T
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

88 lines
2.8 KiB
Go

package pvf
import (
"context"
"encoding/binary"
"sort"
)
// Limit retained workspace capacity, not the number of references a file may
// contain. The outer array is at most 2 MiB at this capacity on 64-bit systems;
// the offset map and the small token/field slices also use bounded capacity.
const maxRetainedStringReferences = 32768
// StringReferenceWorkspace reuses temporary storage across file snapshots. Its
// zero value is ready to use. Each worker must own its workspace exclusively.
type StringReferenceWorkspace struct {
byOffset map[int32]int
refs []StringReference
}
// Reset invalidates borrowed results and discards oversized storage. Call it
// after consuming a large result, before waiting for more work, so a blocked
// worker does not keep that file's temporary allocations alive.
func (w *StringReferenceWorkspace) Reset() {
if cap(w.refs) > maxRetainedStringReferences {
w.byOffset = nil
w.refs = nil
return
}
clear(w.byOffset)
w.refs = w.refs[:0]
}
// References returns sorted references borrowed from the workspace. The result
// and its nested slices are valid only until the next References or Reset call;
// consumers must finish reading them synchronously and must not modify them.
// Use StringReferenceInput.References when independently owned results are needed.
func (w *StringReferenceWorkspace) References(ctx context.Context, input StringReferenceInput) ([]StringReference, error) {
w.Reset()
if err := ctx.Err(); err != nil {
return nil, err
}
if w.byOffset == nil {
w.byOffset = make(map[int32]int)
}
add := func(offset int32) *StringReference {
index, ok := w.byOffset[offset]
if !ok {
index = len(w.refs)
if index < cap(w.refs) {
w.refs = w.refs[:index+1]
} else {
w.refs = append(w.refs, StringReference{})
}
ref := &w.refs[index]
ref.Offset = offset
ref.Occurrences = 0
ref.TokenTypes = ref.TokenTypes[:0]
// FileFields contains only the static "name" and "path" strings,
// never text borrowed from an archive or its decompressed chunks.
ref.FileFields = ref.FileFields[:0]
w.byOffset[offset] = index
}
ref := &w.refs[index]
ref.Occurrences++
return ref
}
ref := add(input.nameOff)
ref.FileFields = appendUniqueString(ref.FileFields, "name")
ref = add(input.pathOff)
ref.FileFields = appendUniqueString(ref.FileFields, "path")
for pos := 0; pos+5 <= len(input.raw); pos += 5 {
if pos%40960 == 0 {
if err := ctx.Err(); err != nil {
w.Reset()
return nil, err
}
}
switch input.raw[pos] {
case 3, 5, 6, 7, 8, 10:
ref = add(int32(binary.LittleEndian.Uint32(input.raw[pos+1:])))
ref.TokenTypes = appendUniqueInt32(ref.TokenTypes, int32(input.raw[pos]))
}
}
sort.Slice(w.refs, func(i, j int) bool { return w.refs[i].Offset < w.refs[j].Offset })
return w.refs, nil
}