mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-23 14:32:27 +08:00
拆分战斗服务器
This commit is contained in:
50
fight/app/app.go
Normal file
50
fight/app/app.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"hk4e/common/config"
|
||||
"hk4e/common/mq"
|
||||
"hk4e/fight/engine"
|
||||
"hk4e/gs/constant"
|
||||
"hk4e/pkg/logger"
|
||||
)
|
||||
|
||||
func Run(ctx context.Context, configFile string) error {
|
||||
config.InitConfig(configFile)
|
||||
|
||||
logger.InitLogger("fight")
|
||||
logger.Warn("fight start")
|
||||
|
||||
constant.InitConstant()
|
||||
|
||||
messageQueue := mq.NewMessageQueue(mq.FIGHT, "1")
|
||||
defer messageQueue.Close()
|
||||
|
||||
_ = engine.NewFightEngine(messageQueue)
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
case s := <-c:
|
||||
logger.Warn("get a signal %s", s.String())
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
logger.Warn("fight exit")
|
||||
time.Sleep(time.Second)
|
||||
return nil
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user