mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:22:26 +08:00
refactor
This commit is contained in:
@@ -1,43 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"hk4e/common/config"
|
||||
"hk4e/dispatch/controller"
|
||||
"hk4e/dispatch/dao"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/dispatch/app"
|
||||
)
|
||||
|
||||
var (
|
||||
config = flag.String("config", "application.toml", "config file")
|
||||
)
|
||||
|
||||
func main() {
|
||||
filePath := "./application.toml"
|
||||
config.InitConfig(filePath)
|
||||
|
||||
logger.InitLogger("dispatch", config.CONF.Logger)
|
||||
logger.LOG.Info("dispatch start")
|
||||
|
||||
db := dao.NewDao()
|
||||
|
||||
_ = controller.NewController(db)
|
||||
|
||||
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("dispatch exit")
|
||||
db.CloseDao()
|
||||
time.Sleep(time.Second)
|
||||
return
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
return
|
||||
}
|
||||
flag.Parse()
|
||||
//go statsviz_serve.Serve("0.0.0.0:2345")
|
||||
err := app.Run(context.TODO(), *config)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"hk4e/common/config"
|
||||
"hk4e/gate/forward"
|
||||
"hk4e/gate/mq"
|
||||
"hk4e/gate/net"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/protocol/cmd"
|
||||
"hk4e/gate/app"
|
||||
"hk4e/pkg/statsviz_serve"
|
||||
)
|
||||
|
||||
"github.com/arl/statsviz"
|
||||
var (
|
||||
config = flag.String("config", "application.toml", "config file")
|
||||
)
|
||||
|
||||
func main() {
|
||||
filePath := "./application.toml"
|
||||
config.InitConfig(filePath)
|
||||
|
||||
logger.InitLogger("gate", config.CONF.Logger)
|
||||
logger.LOG.Info("gate start")
|
||||
|
||||
go func() {
|
||||
// 性能检测
|
||||
err := statsviz.RegisterDefault()
|
||||
if err != nil {
|
||||
logger.LOG.Error("statsviz init error: %v", err)
|
||||
}
|
||||
err = http.ListenAndServe("0.0.0.0:2345", nil)
|
||||
if err != nil {
|
||||
logger.LOG.Error("perf debug http start error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
kcpEventInput := make(chan *net.KcpEvent)
|
||||
kcpEventOutput := make(chan *net.KcpEvent)
|
||||
protoMsgInput := make(chan *net.ProtoMsg, 10000)
|
||||
protoMsgOutput := make(chan *net.ProtoMsg, 10000)
|
||||
netMsgInput := make(chan *cmd.NetMsg, 10000)
|
||||
netMsgOutput := make(chan *cmd.NetMsg, 10000)
|
||||
|
||||
connectManager := net.NewKcpConnectManager(protoMsgInput, protoMsgOutput, kcpEventInput, kcpEventOutput)
|
||||
connectManager.Start()
|
||||
|
||||
forwardManager := forward.NewForwardManager(protoMsgInput, protoMsgOutput, kcpEventInput, kcpEventOutput, netMsgInput, netMsgOutput)
|
||||
forwardManager.Start()
|
||||
|
||||
messageQueue := mq.NewMessageQueue(netMsgInput, netMsgOutput)
|
||||
messageQueue.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("gate exit")
|
||||
messageQueue.Close()
|
||||
time.Sleep(time.Second)
|
||||
return
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
return
|
||||
}
|
||||
flag.Parse()
|
||||
go statsviz_serve.Serve("0.0.0.0:2345")
|
||||
err := app.Run(context.TODO(), *config)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"hk4e/common/config"
|
||||
"hk4e/gm/controller"
|
||||
"hk4e/pkg/logger"
|
||||
"hk4e/gm/app"
|
||||
)
|
||||
|
||||
var (
|
||||
config = flag.String("config", "application.toml", "config file")
|
||||
)
|
||||
|
||||
func main() {
|
||||
filePath := "./application.toml"
|
||||
config.InitConfig(filePath)
|
||||
|
||||
logger.InitLogger("gm", config.CONF.Logger)
|
||||
logger.LOG.Info("gm start")
|
||||
|
||||
_ = controller.NewController()
|
||||
|
||||
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("gm exit")
|
||||
time.Sleep(time.Second)
|
||||
return
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
return
|
||||
}
|
||||
flag.Parse()
|
||||
err := app.Run(context.TODO(), *config)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,75 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
_ "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"
|
||||
"hk4e/gs/app"
|
||||
"hk4e/pkg/statsviz_serve"
|
||||
)
|
||||
|
||||
"github.com/arl/statsviz"
|
||||
var (
|
||||
config = flag.String("config", "application.toml", "config file")
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
flag.Parse()
|
||||
go statsviz_serve.Serve("0.0.0.0:3456")
|
||||
err := app.Run(context.TODO(), *config)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
23
cmd/hk4e/dispatch.go
Normal file
23
cmd/hk4e/dispatch.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hk4e/dispatch/app"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// DispatchCmd
|
||||
func DispatchCmd() *cobra.Command {
|
||||
var cfg string
|
||||
c := &cobra.Command{
|
||||
Use: "dispatch",
|
||||
Short: "dispatch server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return app.Run(context.Background(), cfg)
|
||||
},
|
||||
}
|
||||
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
|
||||
return c
|
||||
}
|
||||
23
cmd/hk4e/gate.go
Normal file
23
cmd/hk4e/gate.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hk4e/gate/app"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// GateCmd 检查配表命令
|
||||
func GateCmd() *cobra.Command {
|
||||
var cfg string
|
||||
c := &cobra.Command{
|
||||
Use: "gate",
|
||||
Short: "gate server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return app.Run(context.Background(), cfg)
|
||||
},
|
||||
}
|
||||
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
|
||||
return c
|
||||
}
|
||||
23
cmd/hk4e/gm.go
Normal file
23
cmd/hk4e/gm.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hk4e/gm/app"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// GMCmd
|
||||
func GMCmd() *cobra.Command {
|
||||
var cfg string
|
||||
c := &cobra.Command{
|
||||
Use: "gm",
|
||||
Short: "gm server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return app.Run(context.Background(), cfg)
|
||||
},
|
||||
}
|
||||
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
|
||||
return c
|
||||
}
|
||||
23
cmd/hk4e/gs.go
Normal file
23
cmd/hk4e/gs.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hk4e/gs/app"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// GSCmd
|
||||
func GSCmd() *cobra.Command {
|
||||
var cfg string
|
||||
c := &cobra.Command{
|
||||
Use: "gs",
|
||||
Short: "game server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return app.Run(context.Background(), cfg)
|
||||
},
|
||||
}
|
||||
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
|
||||
return c
|
||||
}
|
||||
33
cmd/hk4e/main.go
Normal file
33
cmd/hk4e/main.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
config = flag.String("config", "application.toml", "config file")
|
||||
)
|
||||
|
||||
func main() {
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "hk4e",
|
||||
Short: "hk4e server",
|
||||
SilenceUsage: true,
|
||||
}
|
||||
rootCmd.AddCommand(
|
||||
GSCmd(),
|
||||
GMCmd(),
|
||||
DispatchCmd(),
|
||||
GateCmd(),
|
||||
)
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user