feat(logic): 实现角色行走位置更新与账号加载功能 - 在 walk.go 中优化 Walk 方法,手动赋值替换 copier.Copy 提高可控性 - 在 main.go 中新增 loadAccounts 函数用于从 csv 文件加载账号并注册 - 新增 strings 包引用以支持文件内容按行分割 - 注释掉调试用的 fmt 打印语句,保留逻辑结构便于后续启用 - 在 base_sys_user.go 中增加 GetEamil 方法
85 lines
1.7 KiB
Go
85 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"runtime"
|
|
"strings"
|
|
|
|
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
|
|
"github.com/gogf/gf/v2/os/gproc"
|
|
|
|
_ "blazing/contrib/drivers/pgsql"
|
|
"blazing/logic/service/fight"
|
|
"blazing/logic/service/player"
|
|
|
|
"blazing/cool"
|
|
|
|
//"blazing/o/service"
|
|
"blazing/modules/base/service"
|
|
blservice "blazing/modules/blazing/service"
|
|
"net/http"
|
|
_ "net/http/pprof"
|
|
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
)
|
|
|
|
func PprofWeb() {
|
|
runtime.SetMutexProfileFraction(1) // (非必需)开启对锁调用的跟踪
|
|
runtime.SetBlockProfileRate(1) // (非必需)开启对阻塞操作的跟踪
|
|
err := http.ListenAndServe(":9909", nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
func signalHandlerForMain(sig os.Signal) {
|
|
fight.Fightpool.Release()
|
|
|
|
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
|
|
value.Save()
|
|
|
|
return true
|
|
})
|
|
fmt.Println("MainProcess is shutting down due to signal:", sig.String())
|
|
}
|
|
|
|
func main() {
|
|
//loadAccounts()
|
|
if cool.IsRedisMode {
|
|
go cool.ListenFunc(gctx.New())
|
|
}
|
|
|
|
go Start(cool.Config.PortBL) //注入service
|
|
if cool.Config.PortBL == 1 { //只分析1服务器的
|
|
go PprofWeb()
|
|
}
|
|
|
|
fmt.Println("Process start, pid:", os.Getpid())
|
|
|
|
gproc.AddSigHandlerShutdown(
|
|
|
|
signalHandlerForMain,
|
|
)
|
|
|
|
gproc.Listen()
|
|
}
|
|
|
|
func loadAccounts() {
|
|
t1, _ := os.Getwd()
|
|
data, err := os.ReadFile(t1 + "/b.csv")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
lines := strings.Split(string(data), "\n")
|
|
for _, line := range lines {
|
|
line = strings.TrimSpace(line)
|
|
if line == "" {
|
|
continue
|
|
}
|
|
t := service.NewBaseSysUserService().GetEamil(line)
|
|
|
|
blservice.NewUserService(uint32(t.ID)).Reg(t.Username, 0)
|
|
}
|
|
//fmt.Printf("加载 %d 个账号\n", len(accounts))
|
|
}
|