mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 15:32:26 +08:00
refactor
This commit is contained in:
24
cmd/gs/.gitignore
vendored
Normal file
24
cmd/gs/.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
# GoLand
|
||||
.idea
|
||||
*.iml
|
||||
|
||||
# Binaries file
|
||||
bin
|
||||
|
||||
GameDataConfigTable
|
||||
14
cmd/gs/application.toml
Normal file
14
cmd/gs/application.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
[hk4e]
|
||||
resource_path = "./GameDataConfigTable"
|
||||
gacha_history_server = "https://hk4e.flswld.com/api/v1"
|
||||
|
||||
[logger]
|
||||
level = "DEBUG"
|
||||
method = "CONSOLE"
|
||||
track_line = true
|
||||
|
||||
[database]
|
||||
url = "mongodb://mongo:27017"
|
||||
|
||||
[mq]
|
||||
nats_url = "nats://nats1:4222,nats://nats2:4222,nats://nats3:4222"
|
||||
75
cmd/gs/main.go
Normal file
75
cmd/gs/main.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"hk4e/common/config"
|
||||
gdc "hk4e/gs/config"
|
||||
"hk4e/gs/constant"
|
||||
"hk4e/gs/dao"
|
||||
"hk4e/gs/game"
|
||||
"hk4e/gs/mq"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/protocol/cmd"
|
||||
|
||||
"github.com/arl/statsviz"
|
||||
)
|
||||
|
||||
func main() {
|
||||
filePath := "./application.toml"
|
||||
config.InitConfig(filePath)
|
||||
|
||||
logger.InitLogger("gs", config.CONF.Logger)
|
||||
logger.LOG.Info("gs start")
|
||||
|
||||
go func() {
|
||||
// 性能检测
|
||||
err := statsviz.RegisterDefault()
|
||||
if err != nil {
|
||||
logger.LOG.Error("statsviz init error: %v", err)
|
||||
}
|
||||
err = http.ListenAndServe("0.0.0.0:3456", nil)
|
||||
if err != nil {
|
||||
logger.LOG.Error("perf debug http start error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
constant.InitConstant()
|
||||
|
||||
gdc.InitGameDataConfig()
|
||||
|
||||
db := dao.NewDao()
|
||||
|
||||
netMsgInput := make(chan *cmd.NetMsg, 10000)
|
||||
netMsgOutput := make(chan *cmd.NetMsg, 10000)
|
||||
|
||||
messageQueue := mq.NewMessageQueue(netMsgInput, netMsgOutput)
|
||||
messageQueue.Start()
|
||||
|
||||
gameManager := game.NewGameManager(db, netMsgInput, netMsgOutput)
|
||||
gameManager.Start()
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
||||
for {
|
||||
s := <-c
|
||||
logger.LOG.Info("get a signal %s", s.String())
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
logger.LOG.Info("gs exit")
|
||||
gameManager.Stop()
|
||||
db.CloseDao()
|
||||
messageQueue.Close()
|
||||
time.Sleep(time.Second)
|
||||
return
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user