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,97 @@
|
||||
package filex
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func AtomicWriteFile(path string, data []byte, perm os.FileMode) error {
|
||||
if path == "" {
|
||||
return fmt.Errorf("atomic write path is required")
|
||||
}
|
||||
dir := filepath.Dir(path)
|
||||
if err := os.MkdirAll(dir, 0o750); err != nil {
|
||||
return fmt.Errorf("create directory: %w", err)
|
||||
}
|
||||
tmp, err := os.CreateTemp(dir, "."+filepath.Base(path)+".tmp-*")
|
||||
if err != nil {
|
||||
return fmt.Errorf("create temp file: %w", err)
|
||||
}
|
||||
tmpName := tmp.Name()
|
||||
closed := false
|
||||
defer func() {
|
||||
if !closed {
|
||||
_ = tmp.Close()
|
||||
}
|
||||
_ = os.Remove(tmpName)
|
||||
}()
|
||||
written, err := tmp.Write(data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("write temp file: %w", err)
|
||||
}
|
||||
if written != len(data) {
|
||||
return fmt.Errorf("write temp file: %w", io.ErrShortWrite)
|
||||
}
|
||||
if err := tmp.Chmod(perm); err != nil {
|
||||
return fmt.Errorf("chmod temp file: %w", err)
|
||||
}
|
||||
if err := tmp.Sync(); err != nil {
|
||||
return fmt.Errorf("sync temp file: %w", err)
|
||||
}
|
||||
if err := tmp.Close(); err != nil {
|
||||
return fmt.Errorf("close temp file: %w", err)
|
||||
}
|
||||
closed = true
|
||||
if err := os.Rename(tmpName, path); err == nil {
|
||||
return syncDir(dir)
|
||||
}
|
||||
if err := replaceWithBackup(tmpName, path); err != nil {
|
||||
return err
|
||||
}
|
||||
return syncDir(dir)
|
||||
}
|
||||
|
||||
func replaceWithBackup(tmpName, path string) error {
|
||||
backup := tmpName + ".bak"
|
||||
hadExisting := false
|
||||
if info, err := os.Stat(path); err == nil {
|
||||
if info.IsDir() {
|
||||
return fmt.Errorf("replace file %s: destination is a directory", path)
|
||||
}
|
||||
} else if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("stat existing file: %w", err)
|
||||
}
|
||||
if err := os.Rename(path, backup); err == nil {
|
||||
hadExisting = true
|
||||
} else if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("backup existing file: %w", err)
|
||||
}
|
||||
if err := os.Rename(tmpName, path); err != nil {
|
||||
if hadExisting {
|
||||
_ = os.Rename(backup, path)
|
||||
}
|
||||
return fmt.Errorf("replace file: %w", err)
|
||||
}
|
||||
if hadExisting {
|
||||
_ = os.Remove(backup)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func syncDir(dir string) error {
|
||||
file, err := os.Open(dir) //nolint:gosec // G304:目录来自调用点限定的输出路径。
|
||||
if err != nil {
|
||||
if runtime.GOOS == "windows" {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("open directory for sync: %w", err)
|
||||
}
|
||||
defer func() { _ = file.Close() }()
|
||||
if err := file.Sync(); err != nil && runtime.GOOS != "windows" {
|
||||
return fmt.Errorf("sync directory: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user