81 lines
2.3 KiB
Go
81 lines
2.3 KiB
Go
package main
|
||
|
||
import (
|
||
"io/ioutil"
|
||
"net/http"
|
||
_ "net/http/pprof"
|
||
"os"
|
||
"rocommon"
|
||
"rocommon/service"
|
||
_ "rocommon/socket"
|
||
_ "rocommon/socket/http"
|
||
_ "rocommon/socket/tcp"
|
||
"roserver/baseserver"
|
||
model2 "roserver/baseserver/model"
|
||
_ "roserver/game/model"
|
||
selfmodel "roserver/game/model"
|
||
_ "roserver/game/msg"
|
||
_ "roserver/serverproto"
|
||
"runtime"
|
||
"strconv"
|
||
"syscall"
|
||
)
|
||
|
||
func main() {
|
||
//记录gate pid用来做关闭操作
|
||
sysType := runtime.GOOS
|
||
if sysType != "windows" {
|
||
if pid := syscall.Getpid(); pid != 1 {
|
||
fileName := "game_server.pid" + string(strconv.Itoa(pid))
|
||
ioutil.WriteFile(fileName, []byte(strconv.Itoa(pid)), 0777)
|
||
defer os.Remove(fileName)
|
||
}
|
||
}
|
||
|
||
//go func() {
|
||
// log.Fatal(http.ListenAndServe(":9091", nil))
|
||
//}()
|
||
|
||
baseserver.Init(model2.SERVICE_NODE_TYPE_GAME_STR, selfmodel.ConfigInit, &selfmodel.GameUpdate{})
|
||
|
||
sConfig := service.GetServiceConfig()
|
||
//配置文件初始化,如果后续做热更新的话,需要加锁,或者用sync.map
|
||
//CPUProfile goroutineBlock MemProfile
|
||
//prof := profile.Start(profile.CPUProfile, profile.BlockProfile, profile.MemProfile, profile.ProfilePath("./pprof/game.pprof"), profile.NoShutdownHook)
|
||
//prof := profile.Start(profile.CPUProfile, profile.ProfilePath("./pprof/game.pprof"), profile.NoShutdownHook)
|
||
//prof := profile.Start(profile.MemProfile, profile.ProfilePath("./pprof/gamemem.pprof"), profile.NoShutdownHook)
|
||
//prof := profile.Start(profile.TraceProfile, profile.ProfilePath("./pprof/gamemem.pprof"), profile.NoShutdownHook)
|
||
|
||
//创建监听器
|
||
var acceNode rocommon.ServerNode = nil
|
||
if sConfig.Node.Addr != "" {
|
||
acceNode = baseserver.CreateAcceptor(baseserver.ServiceParam{
|
||
ServiceType: "tcpAcceptor",
|
||
ServiceName: model2.SERVICE_NODE_TYPE_GAME_STR,
|
||
ProcName: "game.backend",
|
||
LisAddr: sConfig.Node.Addr,
|
||
}, sConfig)
|
||
}
|
||
|
||
//http
|
||
if sConfig.Node.ServerList != "" {
|
||
selfmodel.SetHttpNodeParam(&baseserver.ServiceParam{
|
||
ServiceType: "httpConnector",
|
||
ServiceName: "game",
|
||
//LisAddr: "serverlist.wtgame.cn:8088",
|
||
LisAddr: sConfig.Node.ServerList,
|
||
})
|
||
}
|
||
|
||
//根据运行参数判断是否开启pprof,
|
||
if *service.Pprof != "" {
|
||
go http.ListenAndServe(*service.Pprof, http.DefaultServeMux)
|
||
}
|
||
|
||
baseserver.Wait()
|
||
//prof.Stop()
|
||
baseserver.Exit(acceNode)
|
||
|
||
//gracenet.Net{}.list
|
||
}
|