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

137 lines
5.4 KiB
Go

package dnfbridge
import (
"sort"
"strconv"
"strings"
"time"
dnfrepo "longheng.io/server/internal/modules/dnf/repository"
)
const (
// currentCharacterRenameLogKeyPrefix namespaces one rename record inside the
// account metadata key/value store (the same store the old-name reservation
// already uses). The key carries the character id and the rename instant so
// records sort without a new table or schema migration:
//
// character_rename_log:<characterID>:<unixSeconds> = <serverID>|<previous name>
currentCharacterRenameLogKeyPrefix = "character_rename_log:"
// currentCharacterRenameLogLimit bounds the history kept per character. The
// window renders a short list; older records are pruned when a new one is
// appended so account metadata cannot grow without limit.
currentCharacterRenameLogLimit = 12
// currentCharacterRenameLogValueSeparator splits the recorded 大区 index from
// the previous name inside the metadata value.
currentCharacterRenameLogValueSeparator = "|"
)
// currentCharacterRenameLogEntry is one committed rename of one character.
type currentCharacterRenameLogEntry struct {
// Unix is the rename instant in seconds. The client feeds this straight to
// localtime() when it renders the record's date column.
Unix int64
// ServerID is the 大区 the rename happened on, as an index into the client's
// own 大区 table. HasServerID is false for records written before the index
// became part of the record; those fall back to the configured region.
ServerID byte
HasServerID bool
// OldName is the name the character carried before that rename. The current
// 90CN row layout carries no name field, so this is metadata for operators
// and for any later use -- it is deliberately not sent on the wire.
OldName string
}
func currentCharacterRenameLogKey(characterID string, unix int64) string {
return currentCharacterRenameLogKeyPrefix + strings.TrimSpace(characterID) + ":" + strconv.FormatInt(unix, 10)
}
func parseCurrentCharacterRenameLogKey(key, characterID string) (int64, bool) {
if !strings.HasPrefix(key, currentCharacterRenameLogKeyPrefix) {
return 0, false
}
rest := strings.TrimPrefix(key, currentCharacterRenameLogKeyPrefix)
separator := strings.LastIndex(rest, ":")
if separator <= 0 || strings.TrimSpace(rest[:separator]) != strings.TrimSpace(characterID) {
return 0, false
}
unix, err := strconv.ParseInt(strings.TrimSpace(rest[separator+1:]), 10, 64)
if err != nil {
return 0, false
}
return unix, true
}
// parseCurrentCharacterRenameLogValue splits "<serverID>|<previous name>".
//
// A value without the separator is treated as a bare previous name (records
// written before the 大区 index became part of the record still load) and
// reports ok=false so the projection can fall back to the configured region.
func parseCurrentCharacterRenameLogValue(value string) (byte, string, bool) {
trimmed := strings.TrimSpace(value)
if separator := strings.Index(trimmed, currentCharacterRenameLogValueSeparator); separator > 0 {
raw := strings.TrimSpace(trimmed[:separator])
if parsed, err := strconv.ParseUint(raw, 10, 8); err == nil {
return byte(parsed), strings.TrimSpace(trimmed[separator+1:]), true
}
}
return 0, trimmed, false
}
func encodeCurrentCharacterRenameLogValue(serverID byte, oldName string) string {
return strconv.FormatUint(uint64(serverID), 10) + currentCharacterRenameLogValueSeparator + oldName
}
// appendCurrentCharacterRenameLog records one rename on the account record that
// the rename transaction is already saving. Callers must invoke it inside that
// transaction so a rolled-back rename never leaves a record behind.
func appendCurrentCharacterRenameLog(account *dnfrepo.AccountRecord, characterID, oldName string, serverID byte, now time.Time) {
characterID = strings.TrimSpace(characterID)
oldName = strings.TrimSpace(oldName)
if account == nil || characterID == "" || oldName == "" {
return
}
if account.Metadata == nil {
account.Metadata = make(map[string]string, 4)
}
unix := now.Unix()
account.Metadata[currentCharacterRenameLogKey(characterID, unix)] = encodeCurrentCharacterRenameLogValue(serverID, oldName)
// Prune beyond the kept limit, oldest first. A same-second rename overwrites
// its own key, so the log never holds two records for one instant.
entries := currentCharacterRenameLogEntries(*account, characterID)
if len(entries) <= currentCharacterRenameLogLimit {
return
}
for _, entry := range entries[currentCharacterRenameLogLimit:] {
delete(account.Metadata, currentCharacterRenameLogKey(characterID, entry.Unix))
}
}
// currentCharacterRenameLogEntries returns one character's committed renames,
// newest first.
func currentCharacterRenameLogEntries(account dnfrepo.AccountRecord, characterID string) []currentCharacterRenameLogEntry {
characterID = strings.TrimSpace(characterID)
if characterID == "" || len(account.Metadata) == 0 {
return nil
}
entries := make([]currentCharacterRenameLogEntry, 0, 4)
for key, value := range account.Metadata {
unix, ok := parseCurrentCharacterRenameLogKey(key, characterID)
if !ok {
continue
}
serverID, oldName, hasServerID := parseCurrentCharacterRenameLogValue(value)
entries = append(entries, currentCharacterRenameLogEntry{
Unix: unix,
ServerID: serverID,
HasServerID: hasServerID,
OldName: oldName,
})
}
sort.Slice(entries, func(i, j int) bool { return entries[i].Unix > entries[j].Unix })
return entries
}