refactor(socket): 重构 ClientData 结构体并优化相关逻辑
- 简化 ClientData 结构体,移除不必要的方法 - 优化 Player 结构体,调整 Conn 类型 - 更新 wscodec.go 中的 Conn 结构体 - 删除未使用的 XML 相关文件和代码 - 调整 ServerEvent 和 controller 中的相关逻辑
This commit is contained in:
84
common/data/xmlres/file.go
Normal file
84
common/data/xmlres/file.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package xmlres
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/ECUST-XX/xml"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gfsnotify"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
)
|
||||
|
||||
var path string
|
||||
|
||||
func getXml[T any](path string) T {
|
||||
|
||||
// 解析XML到结构体
|
||||
var xmls T
|
||||
t1 := gfile.GetBytes(path)
|
||||
xml.Unmarshal(t1, &xmls)
|
||||
|
||||
return xmls
|
||||
}
|
||||
|
||||
var (
|
||||
MapConfig Maps //地图配置
|
||||
ItemsConfig Items //物品配置
|
||||
TalkConfig TalkCount //任务配置
|
||||
Monster MonsterRoot //野怪配置
|
||||
Skill MovesTbl //技能配置
|
||||
)
|
||||
|
||||
func initfile() {
|
||||
path1, _ := os.Getwd()
|
||||
path = path1 + "/public/assets/"
|
||||
MapConfig = getXml[Maps](path + "210.xml")
|
||||
ItemsConfig = getXml[Items](path + "43.xml")
|
||||
TalkConfig = getXml[TalkCount](path + "talk.xml")
|
||||
Monster = getXml[MonsterRoot](path + "地图配置野怪.xml")
|
||||
Skill = getXml[MovesTbl](path + "227.xml")
|
||||
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
initfile() //先初始化一次
|
||||
|
||||
go func() {
|
||||
|
||||
if !gfile.Exists(path) {
|
||||
fileHandle, _ := gfile.Create(path)
|
||||
fileHandle.Close()
|
||||
}
|
||||
|
||||
//updatersares()
|
||||
ctx := gctx.New()
|
||||
_, err := gfsnotify.Add(path, func(event *gfsnotify.Event) {
|
||||
if event.IsCreate() {
|
||||
glog.Debug(ctx, "创建文件 : ", event.Path)
|
||||
}
|
||||
if event.IsWrite() {
|
||||
glog.Debug(ctx, "写入文件 : ", event.Path)
|
||||
initfile() //先初始化一次
|
||||
}
|
||||
if event.IsRemove() {
|
||||
glog.Debug(ctx, "删除文件 : ", event.Path)
|
||||
}
|
||||
if event.IsRename() {
|
||||
glog.Debug(ctx, "重命名文件 : ", event.Path)
|
||||
}
|
||||
if event.IsChmod() {
|
||||
glog.Debug(ctx, "修改权限 : ", event.Path)
|
||||
}
|
||||
glog.Debug(ctx, event)
|
||||
}, true)
|
||||
|
||||
if err != nil {
|
||||
glog.Fatal(ctx, err)
|
||||
} else {
|
||||
select {}
|
||||
}
|
||||
}()
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user