服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
116 lines
2.8 KiB
Go
116 lines
2.8 KiB
Go
// Package pvf 提供 DNF 类 PVF 资源的启动期内存加载能力。
|
|
//
|
|
// 框架只负责把 PVF 文件作为不可变资源装入内存并暴露元信息,不在平台层解释
|
|
// DNF 玩法字段;解析、索引和业务校验应放在游戏项目层。
|
|
package pvf
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const DefaultMaxBytes int64 = 1024 * 1024 * 1024
|
|
|
|
// NoMaxBytes disables the optional PVF file-size guard. The archive still
|
|
// requires a readable regular file and must pass the normal PVF parser.
|
|
const NoMaxBytes int64 = -1
|
|
const rfc3339Nano = time.RFC3339Nano
|
|
|
|
var (
|
|
ErrPathRequired = errors.New("pvf path is required")
|
|
ErrTooLarge = errors.New("pvf exceeds max bytes")
|
|
)
|
|
|
|
type Options struct {
|
|
Path string
|
|
MaxBytes int64
|
|
ChunkCacheBytes int64
|
|
TextCacheBytes int64
|
|
}
|
|
|
|
type Snapshot struct {
|
|
Path string `json:"path"`
|
|
Size int64 `json:"size"`
|
|
Checksum string `json:"checksum"`
|
|
LoadedAt time.Time `json:"loaded_at"`
|
|
}
|
|
|
|
type Bundle struct {
|
|
snapshot Snapshot
|
|
data []byte
|
|
chunkCacheBytes int64
|
|
textCacheBytes int64
|
|
}
|
|
|
|
func Load(options Options) (*Bundle, error) {
|
|
options.Path = strings.TrimSpace(options.Path)
|
|
if options.Path == "" {
|
|
return nil, ErrPathRequired
|
|
}
|
|
maxBytes := options.MaxBytes
|
|
if maxBytes == 0 {
|
|
maxBytes = DefaultMaxBytes
|
|
}
|
|
if maxBytes < NoMaxBytes {
|
|
return nil, fmt.Errorf("pvf max bytes must be positive or %d to disable the limit", NoMaxBytes)
|
|
}
|
|
info, err := os.Stat(options.Path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("stat pvf %q: %w", options.Path, err)
|
|
}
|
|
if !info.Mode().IsRegular() {
|
|
return nil, fmt.Errorf("pvf path %q is not a regular file", options.Path)
|
|
}
|
|
if maxBytes != NoMaxBytes && info.Size() > maxBytes {
|
|
return nil, fmt.Errorf("%w: got %d want <= %d", ErrTooLarge, info.Size(), maxBytes)
|
|
}
|
|
data, err := os.ReadFile(options.Path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("read pvf %q: %w", options.Path, err)
|
|
}
|
|
if maxBytes != NoMaxBytes && int64(len(data)) > maxBytes {
|
|
return nil, fmt.Errorf("%w: got %d want <= %d", ErrTooLarge, len(data), maxBytes)
|
|
}
|
|
sum := sha256.Sum256(data)
|
|
return &Bundle{
|
|
snapshot: Snapshot{
|
|
Path: options.Path,
|
|
Size: int64(len(data)),
|
|
Checksum: hex.EncodeToString(sum[:]),
|
|
LoadedAt: time.Now().UTC(),
|
|
},
|
|
data: data,
|
|
chunkCacheBytes: options.ChunkCacheBytes,
|
|
textCacheBytes: options.TextCacheBytes,
|
|
}, nil
|
|
}
|
|
|
|
func (b *Bundle) Snapshot() Snapshot {
|
|
if b == nil {
|
|
return Snapshot{}
|
|
}
|
|
return b.snapshot
|
|
}
|
|
|
|
func (b *Bundle) Bytes() []byte {
|
|
if b == nil {
|
|
return nil
|
|
}
|
|
out := make([]byte, len(b.data))
|
|
copy(out, b.data)
|
|
return out
|
|
}
|
|
|
|
func (b *Bundle) Reader() *bytes.Reader {
|
|
if b == nil {
|
|
return bytes.NewReader(nil)
|
|
}
|
|
return bytes.NewReader(b.data)
|
|
}
|