package main import ( cherryApp "f1-game/internal/cherry_app" "f1-game/internal/constant" "f1-game/internal/version" "f1-game/nodes/center" "f1-game/nodes/chat" "f1-game/nodes/game" "f1-game/nodes/gate" sandMap "f1-game/nodes/map" "f1-game/nodes/master" "f1-game/nodes/ops" "f1-game/nodes/record" "f1-game/nodes/web" "fmt" "os" cherryFacade "github.com/cherry-game/cherry/facade" cherryProfile "github.com/cherry-game/cherry/profile" "github.com/urfave/cli/v2" ) var ( nodeTypeRunMap = map[string]func(cherryFacade.INode){} ) func init() { nodeTypeRunMap[constant.NodeCenter] = center.Run nodeTypeRunMap[constant.NodeGame] = game.Run nodeTypeRunMap[constant.NodeGate] = gate.Run nodeTypeRunMap[constant.NodeMaster] = master.Run nodeTypeRunMap[constant.NodeWeb] = web.Run nodeTypeRunMap[constant.NodeOPS] = ops.Run nodeTypeRunMap[constant.NodeChat] = chat.Run nodeTypeRunMap[constant.NodeMap] = sandMap.Run nodeTypeRunMap[constant.NodeRecord] = record.Run } func main() { app := &cli.App{ Usage: "f1 game server node", Commands: []*cli.Command{ runCommand(), versionCommand(), }, } if err := app.Run(os.Args); err != nil { fmt.Println(err) } } func runCommand() *cli.Command { return &cli.Command{ Name: "run", Usage: "-path=./config/profile-dev.json -node=10001", Flags: cherryApp.GetFlag(), Action: func(ctx *cli.Context) error { path, nodeID := cherryApp.GetParameters(ctx) node, err := cherryProfile.Init(path, nodeID) if err != nil { return err } runFunc, found := nodeTypeRunMap[node.NodeType()] if !found { return fmt.Errorf("[NodeType = %s] not found", node.NodeType()) } runFunc(node) return nil }, } } func versionCommand() *cli.Command { return &cli.Command{ Name: "version", Aliases: []string{"ver", "v"}, Usage: "view node version", Action: func(c *cli.Context) error { version.Print() return nil }, } }