优化掉落系统

This commit is contained in:
flswld committed 2023-11-16 21:35:51 +08:00
1 parent e9cacf064a
commit c352746496
30 files changed
+350 -204

No files matched your search

+1 -4
View File
@@ -18,10 +18,7 @@ var (
func main() {
flag.Parse()
go func() {
err := statsviz_serve.Serve("0.0.0.0:7890")
if err != nil {
panic(err)
}
_ = statsviz_serve.Serve("0.0.0.0:7890")
}()
err := app.Run(context.TODO(), *config)
if err != nil {
+3 -3
View File
@@ -9,15 +9,15 @@ import (
)
func DispatchCmd() *cobra.Command {
var cfg string
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "dispatch",
Short: "dispatch server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+3 -3
View File
@@ -9,15 +9,15 @@ import (
)
func GateCmd() *cobra.Command {
var cfg string
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "gate",
Short: "gate server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+3 -3
View File
@@ -9,14 +9,14 @@ import (
)
func GMCmd() *cobra.Command {
var cfg string
var configFile string
c := &cobra.Command{
Use: "gm",
Short: "gm server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+3 -3
View File
@@ -9,15 +9,15 @@ import (
)
func GSCmd() *cobra.Command {
var cfg string
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "gs",
Short: "game server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+2
View File
@@ -28,6 +28,8 @@ func main() {
GSCmd(),
MultiCmd(),
GMCmd(),
RobotCmd(),
NatsCmd(),
)
if err := rootCmd.Execute(); err != nil {
+3 -3
View File
@@ -9,15 +9,15 @@ import (
)
func MultiCmd() *cobra.Command {
var cfg string
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "multi",
Short: "multi server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+80
View File
@@ -0,0 +1,80 @@
package main
import (
"errors"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"time"
cfg "hk4e/common/config"
"github.com/nats-io/nats-server/v2/server"
"github.com/spf13/cobra"
)
func NatsCmd() *cobra.Command {
var configFile string
c := &cobra.Command{
Use: "nats",
Short: "nats server",
RunE: func(cmd *cobra.Command, args []string) error {
return RunNatsServer(configFile)
},
}
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
func RunNatsServer(configFile string) error {
cfg.InitConfig(configFile)
natsAddr := strings.ReplaceAll(cfg.GetConfig().MQ.NatsUrl, "nats://", "")
if strings.Contains(natsAddr, ",") {
return errors.New("not support nats cluster")
}
split := strings.Split(natsAddr, ":")
if len(split) != 2 {
return errors.New("nats addr format error")
}
host := split[0]
port, err := strconv.Atoi(split[1])
if err != nil {
return err
}
opts := &server.Options{
Host: host,
Port: port,
NoLog: false,
NoSigs: true,
MaxControlLine: 4096,
DisableShortFirstPing: true,
Trace: true,
Debug: true,
}
natsServer, err := server.NewServer(opts)
if err != nil {
return err
}
natsServer.ConfigureLogger()
go natsServer.Start()
ok := natsServer.ReadyForConnections(time.Second * 5)
if !ok {
return errors.New("nats server start error")
}
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
return nil
case syscall.SIGHUP:
default:
return nil
}
}
}
+3 -3
View File
@@ -9,14 +9,14 @@ import (
)
func NodeCmd() *cobra.Command {
var cfg string
var configFile string
c := &cobra.Command{
Use: "node",
Short: "node server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), cfg)
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&cfg, "config", "application.toml", "config file")
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+23
View File
@@ -0,0 +1,23 @@
package main
import (
"github.com/spf13/cobra"
"context"
"hk4e/robot/app"
)
func RobotCmd() *cobra.Command {
var configFile string
app.APPVERSION = VERSION
c := &cobra.Command{
Use: "robot",
Short: "robot server",
RunE: func(cmd *cobra.Command, args []string) error {
return app.Run(context.Background(), configFile)
},
}
c.Flags().StringVar(&configFile, "config", "application.toml", "config file")
return c
}
+1 -4
View File
@@ -18,10 +18,7 @@ var (
func main() {
flag.Parse()
go func() {
err := statsviz_serve.Serve("0.0.0.0:1234")
if err != nil {
panic(err)
}
_ = statsviz_serve.Serve("0.0.0.0:1234")
}()
err := app.Run(context.TODO(), *config)
if err != nil {