| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package main
- import (
- "io/ioutil"
- _ "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,
- })
- }
- baseserver.Wait()
- //prof.Stop()
- baseserver.Exit(acceNode)
- //gracenet.Net{}.list
- }
|