| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package main
- import (
- "io/ioutil"
- "os"
- "rocommon"
- "rocommon/service"
- _ "rocommon/socket"
- _ "rocommon/socket/tcp"
- "roserver/baseserver"
- "roserver/baseserver/model"
- _ "roserver/battlerecord/msg"
- "runtime"
- "strconv"
- "syscall"
- )
- func main() {
- //记录battleboss pid用来做关闭操作
- sysType := runtime.GOOS
- if sysType != "windows" {
- if pid := syscall.Getpid(); pid != 1 {
- fileName := "battlerecord_server.pid" + strconv.Itoa(pid)
- ioutil.WriteFile(fileName, []byte(strconv.Itoa(pid)), 0777)
- defer os.Remove(fileName)
- }
- }
- //CPU
- //prof := profile.Start(profile.CPUProfile, profile.ProfilePath("./pprof/rank.pprof"), profile.NoShutdownHook)
- //prof := profile.Start(profile.MemProfile, profile.ProfilePath("./pprof/rankmem.pprof"), profile.NoShutdownHook)
- baseserver.Init(model.SERVICE_NODE_TYPE_BATTLERECORD_STR, nil, nil)
- //先建立服务器对应的连接,在监听客户端
- sConfig := service.GetServiceConfig()
- //配置文件初始化,如果后续做热更新的话,需要加锁,或者用sync.map
- //创建监听器
- var acceNode rocommon.ServerNode = nil
- if sConfig.Node.Addr != "" {
- acceNode = baseserver.CreateAcceptor(baseserver.ServiceParam{
- ServiceType: "tcpAcceptor",
- ServiceName: model.SERVICE_NODE_TYPE_BATTLERECORD_STR,
- ProcName: "common.backend",
- LisAddr: sConfig.Node.Addr,
- }, sConfig)
- }
- for _, concern := range sConfig.Node.Concern {
- //建立需要链接的服务器,可以通过服务器发现etcd来处理(包含在了CreateConnector中)
- baseserver.CreateConnector(baseserver.ServiceParam{
- DiscoveryServiceName: concern,
- DiscoveryServiceZone: sConfig.Node.Zone,
- ServiceType: "tcpConnector",
- ServiceName: model.SERVICE_NODE_TYPE_BATTLERECORD_STR,
- ProcName: "common.backend",
- })
- }
- baseserver.Wait()
- //CPU
- //prof.Stop()
- baseserver.Exit(acceNode)
- }
|