main.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package main
  2. import (
  3. "io/ioutil"
  4. _ "net/http/pprof"
  5. "os"
  6. "rocommon"
  7. "rocommon/service"
  8. _ "rocommon/socket"
  9. _ "rocommon/socket/http"
  10. _ "rocommon/socket/tcp"
  11. "roserver/baseserver"
  12. model2 "roserver/baseserver/model"
  13. _ "roserver/game/model"
  14. selfmodel "roserver/game/model"
  15. _ "roserver/game/msg"
  16. _ "roserver/serverproto"
  17. "runtime"
  18. "strconv"
  19. "syscall"
  20. )
  21. func main() {
  22. //记录gate pid用来做关闭操作
  23. sysType := runtime.GOOS
  24. if sysType != "windows" {
  25. if pid := syscall.Getpid(); pid != 1 {
  26. fileName := "game_server.pid" + string(strconv.Itoa(pid))
  27. ioutil.WriteFile(fileName, []byte(strconv.Itoa(pid)), 0777)
  28. defer os.Remove(fileName)
  29. }
  30. }
  31. //go func() {
  32. // log.Fatal(http.ListenAndServe(":9091", nil))
  33. //}()
  34. baseserver.Init(model2.SERVICE_NODE_TYPE_GAME_STR, selfmodel.ConfigInit, &selfmodel.GameUpdate{})
  35. sConfig := service.GetServiceConfig()
  36. //配置文件初始化,如果后续做热更新的话,需要加锁,或者用sync.map
  37. //CPUProfile goroutineBlock MemProfile
  38. //prof := profile.Start(profile.CPUProfile, profile.BlockProfile, profile.MemProfile, profile.ProfilePath("./pprof/game.pprof"), profile.NoShutdownHook)
  39. //prof := profile.Start(profile.CPUProfile, profile.ProfilePath("./pprof/game.pprof"), profile.NoShutdownHook)
  40. //prof := profile.Start(profile.MemProfile, profile.ProfilePath("./pprof/gamemem.pprof"), profile.NoShutdownHook)
  41. //prof := profile.Start(profile.TraceProfile, profile.ProfilePath("./pprof/gamemem.pprof"), profile.NoShutdownHook)
  42. //创建监听器
  43. var acceNode rocommon.ServerNode = nil
  44. if sConfig.Node.Addr != "" {
  45. acceNode = baseserver.CreateAcceptor(baseserver.ServiceParam{
  46. ServiceType: "tcpAcceptor",
  47. ServiceName: model2.SERVICE_NODE_TYPE_GAME_STR,
  48. ProcName: "game.backend",
  49. LisAddr: sConfig.Node.Addr,
  50. }, sConfig)
  51. }
  52. //http
  53. if sConfig.Node.ServerList != "" {
  54. selfmodel.SetHttpNodeParam(&baseserver.ServiceParam{
  55. ServiceType: "httpConnector",
  56. ServiceName: "game",
  57. //LisAddr: "serverlist.wtgame.cn:8088",
  58. LisAddr: sConfig.Node.ServerList,
  59. })
  60. }
  61. baseserver.Wait()
  62. //prof.Stop()
  63. baseserver.Exit(acceNode)
  64. //gracenet.Net{}.list
  65. }