123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- package main
- import (
- "fmt"
- mhayaConst "github.com/mhaya/const"
- "github.com/mhaya/game/game_cluster/nodes/center/center"
- "github.com/mhaya/game/game_cluster/nodes/game/game"
- "github.com/mhaya/game/game_cluster/nodes/webadmin"
- // "github.com/mhaya/game/game_cluster/nodes/gate"
- "github.com/mhaya/game/game_cluster/nodes/master/master"
- "github.com/mhaya/game/game_cluster/nodes/web/web"
- "github.com/urfave/cli/v2"
- "os"
- )
- func main() {
- app := &cli.App{
- Name: "game cluster node",
- Description: "game cluster node game",
- Commands: []*cli.Command{
- versionCommand(),
- masterCommand(),
- centerCommand(),
- webCommand(),
- //gateCommand(),
- gameCommand(),
- webadminCommand(),
- },
- }
- _ = app.Run(os.Args)
- }
- func versionCommand() *cli.Command {
- return &cli.Command{
- Name: "version",
- Aliases: []string{"ver", "v"},
- Usage: "view version",
- UsageText: "game cluster node version",
- Action: func(c *cli.Context) error {
- fmt.Println(mhayaConst.Version())
- return nil
- },
- }
- }
- func masterCommand() *cli.Command {
- return &cli.Command{
- Name: "master",
- Usage: "run master node",
- UsageText: "node master --path=./game/config/profile-gc.json --node=m-master",
- Flags: getFlag(),
- Action: func(c *cli.Context) error {
- path, node := getParameters(c)
- master.Run(path, node)
- return nil
- },
- }
- }
- func centerCommand() *cli.Command {
- return &cli.Command{
- Name: "center",
- Usage: "run center node",
- UsageText: "node center --path=./game/config/profile-gc.json --node=m-center",
- Flags: getFlag(),
- Action: func(c *cli.Context) error {
- path, node := getParameters(c)
- center.Run(path, node)
- return nil
- },
- }
- }
- func webCommand() *cli.Command {
- return &cli.Command{
- Name: "web",
- Usage: "run web node",
- UsageText: "node web --path=./game/config/profile-gc.json --node=m-web-1",
- Flags: getFlag(),
- Action: func(c *cli.Context) error {
- path, node := getParameters(c)
- web.Run(path, node)
- return nil
- },
- }
- }
- func webadminCommand() *cli.Command {
- return &cli.Command{
- Name: "webadmin",
- Usage: "run webadmin node",
- UsageText: "node webadmin --path=./game/config/profile-gc.json --node=m-webadmin-1",
- Flags: getFlag(),
- Action: func(c *cli.Context) error {
- path, node := getParameters(c)
- webadmin.Run(path, node)
- return nil
- },
- }
- }
- /*func gateCommand() *cli.Command {
- return &cli.Command{
- Name: "gate",
- Usage: "run gate node",
- UsageText: "node gate --path=./game/config/profile-gc.json --node=m-gate-1",
- Flags: getFlag(),
- Action: func(c *cli.Context) error {
- path, node := getParameters(c)
- gate.Run(path, node)
- return nil
- },
- }
- }*/
- func gameCommand() *cli.Command {
- return &cli.Command{
- Name: "game",
- Usage: "run game node",
- UsageText: "node game --path=./game/config/profile-gc.json --node=10001",
- Flags: getFlag(),
- Action: func(c *cli.Context) error {
- path, node := getParameters(c)
- game.Run(path, node)
- return nil
- },
- }
- }
- func getParameters(c *cli.Context) (path, node string) {
- path = c.String("path")
- node = c.String("node")
- return path, node
- }
- func getFlag() []cli.Flag {
- return []cli.Flag{
- &cli.StringFlag{
- Name: "path",
- Usage: "profile config path",
- Required: false,
- Value: "./game/config/profile-gc.json",
- },
- &cli.StringFlag{
- Name: "node",
- Usage: "node id name",
- Required: true,
- Value: "",
- },
- }
- }
|